Przeglądaj źródła

fix(mitt): logout and clear the mitt

vben 4 lat temu
rodzic
commit
0aeec5e9d7

+ 2 - 2
package.json

@@ -45,7 +45,7 @@
   "devDependencies": {
     "@commitlint/cli": "^11.0.0",
     "@commitlint/config-conventional": "^11.0.0",
-    "@iconify/json": "^1.1.285",
+    "@iconify/json": "^1.1.286",
     "@ls-lint/ls-lint": "^1.9.2",
     "@purge-icons/generated": "^0.5.1",
     "@types/echarts": "^4.9.3",
@@ -62,7 +62,7 @@
     "@types/zxcvbn": "^4.4.0",
     "@typescript-eslint/eslint-plugin": "^4.13.0",
     "@typescript-eslint/parser": "^4.13.0",
-    "@vitejs/plugin-legacy": "^1.2.0",
+    "@vitejs/plugin-legacy": "^1.2.1",
     "@vitejs/plugin-vue": "^1.0.5",
     "@vitejs/plugin-vue-jsx": "^1.0.2",
     "@vue/compiler-sfc": "^3.0.5",

+ 8 - 6
src/components/Table/src/hooks/useDataSource.ts

@@ -181,12 +181,14 @@ export function useDataSource(
       const resultTotal: number = isArrayResult ? 0 : get(res, totalField);
 
       // 假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行
-      const currentTotalPage = Math.ceil(resultTotal / pageSize);
-      if (current > currentTotalPage) {
-        setPagination({
-          current: currentTotalPage,
-        });
-        fetch(opt);
+      if (resultTotal) {
+        const currentTotalPage = Math.ceil(resultTotal / pageSize);
+        if (current > currentTotalPage) {
+          setPagination({
+            current: currentTotalPage,
+          });
+          fetch(opt);
+        }
       }
 
       if (afterFetch && isFunction(afterFetch)) {

+ 4 - 0
src/logics/mitt/tabChange.ts

@@ -25,3 +25,7 @@ export function listenerLastChangeTab(
   mitt.on(key, callback);
   immediate && callback(lastChangeTab);
 }
+
+export function removeTabChangeListener() {
+  mitt.clear();
+}

+ 0 - 9
src/router/guard/permissionGuard.ts

@@ -1,13 +1,11 @@
 import type { Router, RouteRecordRaw } from 'vue-router';
 
-import { appStore } from '/@/store/modules/app';
 import { permissionStore } from '/@/store/modules/permission';
 
 import { PageEnum } from '/@/enums/pageEnum';
 import { getToken } from '/@/utils/auth';
 
 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/constant';
-// import { RootRoute } from '../routes/index';
 
 const LOGIN_PATH = PageEnum.BASE_LOGIN;
 
@@ -69,11 +67,4 @@ export function createPermissionGuard(router: Router) {
     permissionStore.commitDynamicAddedRouteState(true);
     next(nextData);
   });
-
-  router.afterEach((to) => {
-    // Just enter the login page and clear the authentication information
-    if (to.path === LOGIN_PATH) {
-      appStore.resumeAllState();
-    }
-  });
 }

+ 14 - 0
src/router/guard/stateGuard.ts

@@ -0,0 +1,14 @@
+import type { Router } from 'vue-router';
+import { appStore } from '/@/store/modules/app';
+import { PageEnum } from '/@/enums/pageEnum';
+import { removeTabChangeListener } from '/@/logics/mitt/tabChange';
+
+export function createHttpGuard(router: Router) {
+  router.afterEach((to) => {
+    // Just enter the login page and clear the authentication information
+    if (to.path === PageEnum.BASE_LOGIN) {
+      appStore.resumeAllState();
+      removeTabChangeListener();
+    }
+  });
+}