App.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div class="app-container dark-theme " @contextmenu.prevent>
  3. <!-- 中文配置 -->
  4. <a-config-provider :locale="zhCN">
  5. <a-spin :tip="tip" :spinning="spinning" size="large">
  6. <router-view />
  7. </a-spin>
  8. </a-config-provider>
  9. </div>
  10. </template>
  11. <script lang="ts">
  12. import { defineComponent, ref, watchEffect, provide } from 'vue';
  13. import { globalDataRefresh } from '@/services/bus/index';
  14. import { notice } from '@/services/bus/system';
  15. import eventBus from '@/utils/eventBus/index';
  16. import TimerUtils from '@/utils/timer/timerUtil';
  17. import Router from '@/router';
  18. import APP from '@/services';
  19. import { Modal } from 'ant-design-vue';
  20. import { setLoadComplete } from '@/common/methods';
  21. import { isLogin, logout } from '@/services/bus/login';
  22. import zhCN from 'ant-design-vue/es/locale/zh_CN';
  23. import { initTheme } from '@/common/config/theme';
  24. let lastTime = new Date().getTime();
  25. function logoutAction() {
  26. logout();
  27. APP.closeServer();
  28. Router.replace('/login');
  29. }
  30. // 设置太久没有操作界面,自动退出界面功能
  31. function setOvertime() {
  32. window.addEventListener('mousemove', () => {
  33. lastTime = new Date().getTime(); //更新当前时间
  34. });
  35. const mimut = 30;
  36. const timeOut = mimut * 60 * 1000; //设置超时时间: 5分钟
  37. TimerUtils.setInterval(
  38. () => {
  39. const currentTime = new Date().getTime();
  40. if (currentTime - lastTime > timeOut) {
  41. //判断是否超时
  42. if (isLogin()) {
  43. Modal.info({
  44. title: '系统提示:',
  45. content: `您已超过${mimut}分钟没有进行任何操作,已自动退出登录!`,
  46. okType: 'primary',
  47. okText: '确定',
  48. keyboard: false,
  49. });
  50. logoutAction();
  51. }
  52. }
  53. },
  54. timeOut,
  55. 'overtimeInterval'
  56. );
  57. }
  58. export default defineComponent({
  59. name: 'app',
  60. components: {},
  61. setup() {
  62. initTheme();
  63. let spinning = ref<boolean>(false);
  64. const tip = ref<string>('');
  65. // 登出状态展示
  66. eventBus.$onOnly('logout', () => {
  67. tip.value = '跳转中...';
  68. spinning.value = true;
  69. TimerUtils.setTimeout(
  70. () => {
  71. spinning.value = false;
  72. logoutAction();
  73. },
  74. 1000,
  75. 'logoutTimer'
  76. );
  77. });
  78. // 注册市场状态变更通知
  79. eventBus.$onOnly('marketStatusChangeNtf', ({ Status }: { Status: number }) => {
  80. if (Status === 1) {
  81. logoutAction();
  82. Modal.info({
  83. title: '系统提示:',
  84. content: '系统结算,请重新登录',
  85. okType: 'primary',
  86. okText: '确定'
  87. })
  88. }
  89. })
  90. // 登录成功
  91. // eventBus.$onOnly('loginSuccess', setOvertime);
  92. // 监听路由的变化
  93. watchEffect(() => Router.currentRoute && provide('current-route', Router.currentRoute));
  94. // 监听刷新事件
  95. window.addEventListener(
  96. 'load',
  97. () => {
  98. tip.value = '数据初始化...';
  99. lastTime = new Date().getTime(); //更新当前时间
  100. spinning.value = true;
  101. // 注册全局loadComplete事件 保证loadComplete变量及时更新
  102. setLoadComplete(false);
  103. globalDataRefresh()
  104. .then((res) => {
  105. setLoadComplete(true);
  106. eventBus.$emit('loadComplete');
  107. spinning.value = false;
  108. })
  109. .catch((err) => {
  110. console.error(err);
  111. spinning.value = false;
  112. });
  113. },
  114. true
  115. );
  116. // setOvertime();
  117. // 订阅交易通知
  118. notice(() => {
  119. Modal.info({
  120. title: '系统提示:',
  121. content: '请重新登录',
  122. okType: 'primary',
  123. okText: '确定',
  124. keyboard: false,
  125. onOk() {
  126. Router.replace('/login');
  127. },
  128. });
  129. });
  130. return {
  131. tip,
  132. spinning,
  133. zhCN,
  134. };
  135. },
  136. });
  137. </script>
  138. <style lang="less">
  139. .app-container {
  140. width: 100%;
  141. height: auto;
  142. min-height: 100%;
  143. }
  144. #app {
  145. width: 100%;
  146. height: auto;
  147. min-height: 100%;
  148. font-family: Avenir, Helvetica, Arial, sans-serif;
  149. -webkit-font-smoothing: antialiased;
  150. -moz-osx-font-smoothing: grayscale;
  151. text-align: center;
  152. color: @m-black24;
  153. background-color: @m-white5;
  154. display: flex;
  155. justify-content: center;
  156. overflow-y: hidden;
  157. img {
  158. cursor: pointer;
  159. }
  160. }
  161. #nav {
  162. padding: 30px;
  163. a {
  164. font-weight: bold;
  165. color: @m-black24;
  166. &.router-link-exact-active {
  167. color: @m-green5;
  168. }
  169. }
  170. }
  171. </style>