2023-07-02 17:06:00 +08:00
|
|
|
import { useUserInfo } from '@/store/userInfo';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断当前用户是否拥有指定权限
|
|
|
|
|
* @param code 权限code
|
2023-07-06 20:59:22 +08:00
|
|
|
* @returns
|
2023-07-02 17:06:00 +08:00
|
|
|
*/
|
2025-08-31 21:46:10 +08:00
|
|
|
export function hasPerm(code: string): boolean {
|
2023-11-14 17:36:51 +08:00
|
|
|
if (!code) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2023-07-02 17:06:00 +08:00
|
|
|
return useUserInfo().userInfo.permissions.some((v: any) => v === code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断用户是否拥有权限对象里对应的code
|
|
|
|
|
* @returns {"xxx:save": true} key->permission code
|
2024-10-20 03:52:23 +00:00
|
|
|
* @param permCodes
|
2023-07-02 17:06:00 +08:00
|
|
|
*/
|
2025-08-31 21:46:10 +08:00
|
|
|
export function hasPerms(permCodes: any[]): Record<string, boolean> {
|
2024-10-20 03:52:23 +00:00
|
|
|
const res = {} as { [key: string]: boolean };
|
2023-07-02 17:06:00 +08:00
|
|
|
for (let permCode of permCodes) {
|
|
|
|
|
if (hasPerm(permCode)) {
|
|
|
|
|
res[permCode] = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return res;
|
2023-07-06 20:59:22 +08:00
|
|
|
}
|