App.vue 5.3 KB

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