App.vue 4.8 KB

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