Explorar el Código

优化退出登录

li.shaoyi hace 3 años
padre
commit
78e093e1a9
Se han modificado 3 ficheros con 8 adiciones y 4 borrados
  1. 2 0
      src/App.vue
  2. 0 2
      src/services/bus/login.ts
  3. 6 2
      src/utils/websocket/index.ts

+ 2 - 0
src/App.vue

@@ -22,6 +22,7 @@ import TimerUtils from '@/utils/timer/timerUtil';
 import { Modal } from 'ant-design-vue';
 import zhCN from 'ant-design-vue/es/locale/zh_CN';
 import { defineComponent, onMounted, provide, ref, watchEffect } from 'vue';
+
 let lastTime = new Date().getTime();
 
 // 设置太久没有操作界面,自动退出界面功能
@@ -80,6 +81,7 @@ export default defineComponent({
       spinning.value = true;
       TimerUtils.setTimeout(
         () => {
+          TimerUtils.clearAll();
           spinning.value = false;
           logout();
         },

+ 0 - 2
src/services/bus/login.ts

@@ -1,5 +1,4 @@
 import APP from '@/services';
-import timerUtil from '@/utils/timer/timerUtil'
 import { isAllEnum } from '@/services/bus/allEnum';
 import { checkTokenAction } from '@/services/bus/token';
 import { getAllEnums, GetPCMenus, getServerTime, queryErrorInfos, QueryTableDefine } from '@/services/go/commonService/index';
@@ -19,7 +18,6 @@ export const logout = (): void => {
     removeLoginData();
     APP.closeServer();
     APP.closeQuote();
-    timerUtil.clearAll();
     Router.replace('/login');
 };
 

+ 6 - 2
src/utils/websocket/index.ts

@@ -179,13 +179,17 @@ export class MTP2WebSocket<T extends Package40 | Package50> {
      * 主动断开连接,断开后不会自动重连
      */
     close() {
-        console.warn(this.packageType, this.host, '主动断开');
         clearTimeout(this.reconnectTimer);
         this.stopBeatTimer();
         this.uuid = v4();
         this.reconnectCount = 0;
         this.reconnectInterval = this.defaultReconnectInterval;
-        this.socket?.close();
+
+        if (this.socket) {
+            this.socket.close();
+            console.warn(this.packageType, this.host, '主动断开');
+        }
+
         this.reset(); // 不等待 ws.onclose 响应强制重置实例
     }