😎优化前端获取角色集合及判断
This commit is contained in:
parent
699063658b
commit
133e56075b
2
Web/src/types/pinia.d.ts
vendored
2
Web/src/types/pinia.d.ts
vendored
@ -6,7 +6,7 @@
|
|||||||
declare interface UserInfos<T = any> {
|
declare interface UserInfos<T = any> {
|
||||||
authApiList: string[];
|
authApiList: string[];
|
||||||
photo: string;
|
photo: string;
|
||||||
roles: string[];
|
roles: T[];
|
||||||
time: number;
|
time: number;
|
||||||
userName: string;
|
userName: string;
|
||||||
[key: string]: T;
|
[key: string]: T;
|
||||||
|
|||||||
@ -113,6 +113,26 @@ export const posId = (): number => userInfos?.posId;
|
|||||||
*/
|
*/
|
||||||
export const posName = (): string => userInfos?.posName;
|
export const posName = (): string => userInfos?.posName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色集合
|
||||||
|
* @returns 获取角色集合
|
||||||
|
*/
|
||||||
|
export const roles = (): any => userInfos?.roles;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否有指定角色编码
|
||||||
|
* @param code
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
export const hasRoleCode = (code: string): boolean => {
|
||||||
|
return userInfos.roles.find((u) => u.code === code) ? true : false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否有某接口权限
|
||||||
|
* @param privilege
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
export const hasPrivilege = (privilege: string): boolean => {
|
export const hasPrivilege = (privilege: string): boolean => {
|
||||||
return userInfos.authApiList.includes(privilege);
|
return userInfos.authApiList.includes(privilege);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user