mirror of
https://github.com/soybeanjs/soybean-admin.git
synced 2025-10-15 22:33:40 +08:00
35 lines
794 B
TypeScript
35 lines
794 B
TypeScript
import UAParser from 'ua-parser-js';
|
|
import { useAuthStore } from '@/store';
|
|
import { isArray, isString } from '@/utils';
|
|
|
|
/** 获取设备信息 */
|
|
export function useDeviceInfo() {
|
|
const parser = new UAParser();
|
|
const result = parser.getResult();
|
|
return result;
|
|
}
|
|
|
|
/** 权限判断 */
|
|
export function usePermission() {
|
|
const auth = useAuthStore();
|
|
|
|
function hasPermission(permission: Auth.RoleType | Auth.RoleType[]) {
|
|
const { userRole } = auth.userInfo;
|
|
|
|
let has = userRole === 'super';
|
|
if (!has) {
|
|
if (isArray(permission)) {
|
|
has = (permission as Auth.RoleType[]).includes(userRole);
|
|
}
|
|
if (isString(permission)) {
|
|
has = (permission as Auth.RoleType) === userRole;
|
|
}
|
|
}
|
|
return has;
|
|
}
|
|
|
|
return {
|
|
hasPermission
|
|
};
|
|
}
|