App.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. APP.closeQuote();
  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. // 设置 ico
  61. async function setIcon() {
  62. const link: any = document.querySelector("link[rel*='icon']") || document.createElement('link');
  63. const obj = {
  64. type: 'image/x-icon',
  65. rel: 'shortcut icon',
  66. href: './favicon.ico',
  67. }
  68. Object.assign(link, obj)
  69. const config = await getAppConfig();
  70. document.title = config.data.icoTitle
  71. document.getElementsByTagName('head')[0].appendChild(link);
  72. }
  73. export default defineComponent({
  74. name: 'app',
  75. components: {},
  76. setup() {
  77. initTheme();
  78. let spinning = ref<boolean>(false);
  79. const tip = ref<string>('');
  80. // 登出状态展示
  81. eventBus.$onOnly('logout', () => {
  82. tip.value = '跳转中...';
  83. spinning.value = true;
  84. TimerUtils.setTimeout(
  85. () => {
  86. spinning.value = false;
  87. logoutAction();
  88. },
  89. 1000,
  90. 'logoutTimer'
  91. );
  92. });
  93. onMounted(() => {
  94. setIcon();
  95. });
  96. // 登录成功
  97. // eventBus.$onOnly('loginSuccess', setOvertime);
  98. // 监听路由的变化
  99. watchEffect(() => Router.currentRoute && provide('current-route', Router.currentRoute));
  100. // 监听刷新事件
  101. window.addEventListener(
  102. 'load',
  103. () => {
  104. tip.value = '数据初始化...';
  105. lastTime = new Date().getTime(); //更新当前时间
  106. spinning.value = true;
  107. // 注册全局loadComplete事件 保证loadComplete变量及时更新
  108. setLoadComplete(false);
  109. globalDataRefresh()
  110. .then((res) => {
  111. setLoadComplete(true);
  112. eventBus.$emit('loadComplete');
  113. spinning.value = false;
  114. })
  115. .catch((err) => {
  116. console.error(err);
  117. spinning.value = false;
  118. });
  119. },
  120. true
  121. );
  122. // setOvertime();
  123. // 订阅交易通知
  124. notice((msg: string) => {
  125. Modal.info({
  126. title: '系统提示:',
  127. content: `${msg},请重新登录。`,
  128. okType: 'primary',
  129. okText: '确定',
  130. keyboard: false,
  131. onOk() {
  132. Router.replace('/login');
  133. },
  134. });
  135. });
  136. return {
  137. tip,
  138. spinning,
  139. zhCN,
  140. };
  141. },
  142. });
  143. </script>
  144. <style lang="less">
  145. .app-container {
  146. width: 100%;
  147. height: auto;
  148. min-height: 100%;
  149. }
  150. #app {
  151. width: 100%;
  152. height: auto;
  153. min-height: 100%;
  154. font-family: Avenir, Helvetica, Arial, sans-serif;
  155. -webkit-font-smoothing: antialiased;
  156. -moz-osx-font-smoothing: grayscale;
  157. text-align: center;
  158. color: @m-black24;
  159. background-color: @m-white5;
  160. display: flex;
  161. justify-content: center;
  162. overflow-y: hidden;
  163. img {
  164. cursor: pointer;
  165. }
  166. }
  167. #nav {
  168. padding: 30px;
  169. a {
  170. font-weight: bold;
  171. color: @m-black24;
  172. &.router-link-exact-active {
  173. color: @m-green5;
  174. }
  175. }
  176. }
  177. </style>