App.vue 4.7 KB

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