Skip to content

Commit

Permalink
fix(mitt): logout and clear the mitt
Browse files Browse the repository at this point in the history
  • Loading branch information
anncwb committed Jan 14, 2021
1 parent b9d53a7 commit 0aeec5e
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 17 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 8 additions & 6 deletions src/components/Table/src/hooks/useDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 4 additions & 0 deletions src/logics/mitt/tabChange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ export function listenerLastChangeTab(
mitt.on(key, callback);
immediate && callback(lastChangeTab);
}

export function removeTabChangeListener() {
mitt.clear();
}
9 changes: 0 additions & 9 deletions src/router/guard/permissionGuard.ts
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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 changes: 14 additions & 0 deletions src/router/guard/stateGuard.ts
Original file line number Diff line number Diff line change
@@ -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();
}
});
}

0 comments on commit 0aeec5e

Please sign in to comment.