Commit 0aeec5e9d727fc6291fa2d6edaedb4c3e1ef0dad

Authored by vben
1 parent b9d53a71

fix(mitt): logout and clear the mitt

package.json
@@ -45,7 +45,7 @@ @@ -45,7 +45,7 @@
45 "devDependencies": { 45 "devDependencies": {
46 "@commitlint/cli": "^11.0.0", 46 "@commitlint/cli": "^11.0.0",
47 "@commitlint/config-conventional": "^11.0.0", 47 "@commitlint/config-conventional": "^11.0.0",
48 - "@iconify/json": "^1.1.285", 48 + "@iconify/json": "^1.1.286",
49 "@ls-lint/ls-lint": "^1.9.2", 49 "@ls-lint/ls-lint": "^1.9.2",
50 "@purge-icons/generated": "^0.5.1", 50 "@purge-icons/generated": "^0.5.1",
51 "@types/echarts": "^4.9.3", 51 "@types/echarts": "^4.9.3",
@@ -62,7 +62,7 @@ @@ -62,7 +62,7 @@
62 "@types/zxcvbn": "^4.4.0", 62 "@types/zxcvbn": "^4.4.0",
63 "@typescript-eslint/eslint-plugin": "^4.13.0", 63 "@typescript-eslint/eslint-plugin": "^4.13.0",
64 "@typescript-eslint/parser": "^4.13.0", 64 "@typescript-eslint/parser": "^4.13.0",
65 - "@vitejs/plugin-legacy": "^1.2.0", 65 + "@vitejs/plugin-legacy": "^1.2.1",
66 "@vitejs/plugin-vue": "^1.0.5", 66 "@vitejs/plugin-vue": "^1.0.5",
67 "@vitejs/plugin-vue-jsx": "^1.0.2", 67 "@vitejs/plugin-vue-jsx": "^1.0.2",
68 "@vue/compiler-sfc": "^3.0.5", 68 "@vue/compiler-sfc": "^3.0.5",
src/components/Table/src/hooks/useDataSource.ts
@@ -181,12 +181,14 @@ export function useDataSource( @@ -181,12 +181,14 @@ export function useDataSource(
181 const resultTotal: number = isArrayResult ? 0 : get(res, totalField); 181 const resultTotal: number = isArrayResult ? 0 : get(res, totalField);
182 182
183 // 假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行 183 // 假如数据变少,导致总页数变少并小于当前选中页码,通过getPaginationRef获取到的页码是不正确的,需获取正确的页码再次执行
184 - const currentTotalPage = Math.ceil(resultTotal / pageSize);  
185 - if (current > currentTotalPage) {  
186 - setPagination({  
187 - current: currentTotalPage,  
188 - });  
189 - fetch(opt); 184 + if (resultTotal) {
  185 + const currentTotalPage = Math.ceil(resultTotal / pageSize);
  186 + if (current > currentTotalPage) {
  187 + setPagination({
  188 + current: currentTotalPage,
  189 + });
  190 + fetch(opt);
  191 + }
190 } 192 }
191 193
192 if (afterFetch && isFunction(afterFetch)) { 194 if (afterFetch && isFunction(afterFetch)) {
src/logics/mitt/tabChange.ts
@@ -25,3 +25,7 @@ export function listenerLastChangeTab( @@ -25,3 +25,7 @@ export function listenerLastChangeTab(
25 mitt.on(key, callback); 25 mitt.on(key, callback);
26 immediate && callback(lastChangeTab); 26 immediate && callback(lastChangeTab);
27 } 27 }
  28 +
  29 +export function removeTabChangeListener() {
  30 + mitt.clear();
  31 +}
src/router/guard/permissionGuard.ts
1 import type { Router, RouteRecordRaw } from 'vue-router'; 1 import type { Router, RouteRecordRaw } from 'vue-router';
2 2
3 -import { appStore } from '/@/store/modules/app';  
4 import { permissionStore } from '/@/store/modules/permission'; 3 import { permissionStore } from '/@/store/modules/permission';
5 4
6 import { PageEnum } from '/@/enums/pageEnum'; 5 import { PageEnum } from '/@/enums/pageEnum';
7 import { getToken } from '/@/utils/auth'; 6 import { getToken } from '/@/utils/auth';
8 7
9 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/constant'; 8 import { PAGE_NOT_FOUND_ROUTE } from '/@/router/constant';
10 -// import { RootRoute } from '../routes/index';  
11 9
12 const LOGIN_PATH = PageEnum.BASE_LOGIN; 10 const LOGIN_PATH = PageEnum.BASE_LOGIN;
13 11
@@ -69,11 +67,4 @@ export function createPermissionGuard(router: Router) { @@ -69,11 +67,4 @@ export function createPermissionGuard(router: Router) {
69 permissionStore.commitDynamicAddedRouteState(true); 67 permissionStore.commitDynamicAddedRouteState(true);
70 next(nextData); 68 next(nextData);
71 }); 69 });
72 -  
73 - router.afterEach((to) => {  
74 - // Just enter the login page and clear the authentication information  
75 - if (to.path === LOGIN_PATH) {  
76 - appStore.resumeAllState();  
77 - }  
78 - });  
79 } 70 }
src/router/guard/stateGuard.ts 0 → 100644
  1 +import type { Router } from 'vue-router';
  2 +import { appStore } from '/@/store/modules/app';
  3 +import { PageEnum } from '/@/enums/pageEnum';
  4 +import { removeTabChangeListener } from '/@/logics/mitt/tabChange';
  5 +
  6 +export function createHttpGuard(router: Router) {
  7 + router.afterEach((to) => {
  8 + // Just enter the login page and clear the authentication information
  9 + if (to.path === PageEnum.BASE_LOGIN) {
  10 + appStore.resumeAllState();
  11 + removeTabChangeListener();
  12 + }
  13 + });
  14 +}