vben
2021-01-15 0aeec5e9d727fc6291fa2d6edaedb4c3e1ef0dad
fix(mitt): logout and clear the mitt
1个文件已添加
4个文件已修改
45 ■■■■■ 已修改文件
package.json 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/components/Table/src/hooks/useDataSource.ts 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/logics/mitt/tabChange.ts 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/guard/permissionGuard.ts 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/guard/stateGuard.ts 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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",
src/components/Table/src/hooks/useDataSource.ts
@@ -181,12 +181,14 @@
      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)) {
src/logics/mitt/tabChange.ts
@@ -25,3 +25,7 @@
  mitt.on(key, callback);
  immediate && callback(lastChangeTab);
}
export function removeTabChangeListener() {
  mitt.clear();
}
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;
@@ -68,12 +66,5 @@
    const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
    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();
    }
  });
}
src/router/guard/stateGuard.ts
New file
@@ -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();
    }
  });
}