App.vue 4.7 KB

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