App.vue 4.4 KB

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