Ben Lin
2024-07-24 e5e7d8032f938f4142c05fa71fb09ff73058b740
权限守护更新
已修改2个文件
24 ■■■■ 文件已修改
src/router/guard/permissionGuard.ts 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/store/modules/user.ts 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/router/guard/permissionGuard.ts
@@ -9,12 +9,14 @@
import { RootRoute } from '@/router/routes';
import { isNullOrUnDef } from '/@/utils/is';
import { useMessage } from '/@/hooks/web/useMessage';
const LOGIN_PATH = PageEnum.BASE_LOGIN;
const ROOT_PATH = RootRoute.path;
const whitePathList: PageEnum[] = [LOGIN_PATH];
const { createMessage, createErrorModal } = useMessage();
export function createPermissionGuard(router: Router) {
  const userStore = useUserStoreWithOut();
@@ -84,11 +86,15 @@
          return;
        }
      } catch (err) {
        createErrorModal({
            title: '警告',
            content: token+' '+err,
            getContainer: () => document.body,
          });
        next();
        return;
      }
    }
    // 动态路由加载(首次)
    if (!permissionStore.getIsDynamicAddedRoute) {
      const routes = await permissionStore.buildRoutesAction();
src/store/modules/user.ts
@@ -4,7 +4,7 @@
 * @version:
 * @Date: 2024-06-18 15:09:47
 * @LastEditors: Ben Lin
 * @LastEditTime: 2024-07-17 20:52:52
 * @LastEditTime: 2024-07-24 16:17:11
 */
import type { UserInfo } from '#/store';
import type { ErrorMessageMode } from '#/axios';
@@ -28,6 +28,7 @@
import { getMenuAuthList } from '/@/api/sys/menu';
import { iV_USER_MENU } from '/@/api/tigerapi/model/vModel';
import { getSysParam } from '/@/api/tigerapi/system';
import { ApiAction } from '/@/api/model/baseModel';
interface UserState {
  userInfo: Nullable<UserInfo>;
@@ -163,9 +164,12 @@
      /* 从系统参数获取启用哪种权限 */
      var action = await getSysParam({ group: 'ByAuthActive' });
      if (action.IsSuccessed) {
        userInfo.byOrg = action.Data.filter((x) => x.PARAM_CODE == 'ByOrgActive')[0].PARAM_VALUE == 'Y';
        userInfo.byProd = action.Data.filter((x) => x.PARAM_CODE == 'ByProdActive')[0].PARAM_VALUE == 'Y';
        userInfo.byWh = action.Data.filter((x) => x.PARAM_CODE == 'ByWhActive')[0].PARAM_VALUE == 'Y';
        userInfo.byOrg =
          action.Data.filter((x) => x.PARAM_CODE == 'ByOrgActive')[0].PARAM_VALUE == 'Y';
        userInfo.byProd =
          action.Data.filter((x) => x.PARAM_CODE == 'ByProdActive')[0].PARAM_VALUE == 'Y';
        userInfo.byWh =
          action.Data.filter((x) => x.PARAM_CODE == 'ByWhActive')[0].PARAM_VALUE == 'Y';
      }
      const { roles = [] } = userInfo;
      if (isArray(roles)) {
@@ -184,7 +188,7 @@
    async logout(goLogin = false) {
      if (this.getToken) {
        try {
          await doLogout({ Data: this.getToken });
          await doLogout({ Data: this.getToken } as unknown as ApiAction<string>);
        } catch {
          console.log('注销Token失败');
        }
@@ -218,7 +222,7 @@
        prodCode: data.FTY_CODE, //globSetting.useOrg == 'N' ? data.FTY_CODE : '',
        avatar: '',
        roles: vUserMenu.Data.Items as unknown as iV_USER_MENU[],
      };
      } as unknown as UserInfo;
      this.setUserInfo(userInfo);
      //console.log(data[0].LOGINNAME);
      return userInfo;