App.vue 4.5 KB

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