角色弹框
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
import axios, { AxiosInstance, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
||||
import { Session } from '/@/utils/storage';
|
||||
import {useMessage, useMessageBox} from '/@/hooks/message';
|
||||
import { useMessage, useMessageBox } from '/@/hooks/message';
|
||||
import qs from 'qs';
|
||||
import other from './other';
|
||||
import {paramsFilter} from "/@/flow";
|
||||
import { paramsFilter } from "/@/flow";
|
||||
import { wrapEncryption, encryptRequestParams, decrypt } from './apiCrypto';
|
||||
import mittBus from '/@/utils/mitt';
|
||||
import { needRoleSelection, isRoleDialogTriggered, setRoleDialogTriggered } from '/@/utils/roleSelect';
|
||||
|
||||
// 常用header
|
||||
export enum CommonHeaderEnum {
|
||||
@@ -81,6 +83,12 @@ service.interceptors.request.use(
|
||||
// 自动适配单体和微服务架构不同的URL
|
||||
config.url = other.adaptationUrl(config.url);
|
||||
|
||||
// 发送请求时判断:已登录但缺少角色信息则弹出角色选择;若弹框已触发则不再重复弹出
|
||||
if (token && needRoleSelection() && !isRoleDialogTriggered()) {
|
||||
setRoleDialogTriggered(true);
|
||||
mittBus.emit('openRoleSelectDialog');
|
||||
}
|
||||
|
||||
// 处理完毕,返回config对象
|
||||
return config;
|
||||
},
|
||||
|
||||
24
src/utils/roleSelect.ts
Normal file
24
src/utils/roleSelect.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Local } from '/@/utils/storage';
|
||||
|
||||
/** Local 是否缺少角色信息(缺任一则需弹出角色选择) */
|
||||
export function needRoleSelection(): boolean {
|
||||
try {
|
||||
const roleCode = Local.get('roleCode');
|
||||
const roleName = Local.get('roleName');
|
||||
const roleId = Local.get('roleId');
|
||||
return !roleCode || !roleName || !roleId;
|
||||
} catch {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/** 角色选择弹框是否已触发(防止多请求同时触发时重复弹出) */
|
||||
let roleDialogTriggered = false;
|
||||
|
||||
export function isRoleDialogTriggered(): boolean {
|
||||
return roleDialogTriggered;
|
||||
}
|
||||
|
||||
export function setRoleDialogTriggered(value: boolean): void {
|
||||
roleDialogTriggered = value;
|
||||
}
|
||||
Reference in New Issue
Block a user