mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-25 03:00:23 +08:00
33 lines
642 B
TypeScript
33 lines
642 B
TypeScript
import { isArray, isString } from 'radash'
|
|
import { useAuthStore } from '@/store'
|
|
|
|
/** 权限判断 */
|
|
export function usePermission() {
|
|
const authStore = useAuthStore()
|
|
|
|
function hasPermission(
|
|
permission: Auth.RoleType | Auth.RoleType[] | undefined,
|
|
) {
|
|
if (!permission)
|
|
return true
|
|
|
|
if (!authStore.userInfo)
|
|
return false
|
|
const { role } = authStore.userInfo
|
|
|
|
let has = role === 'super'
|
|
if (!has) {
|
|
if (isArray(permission))
|
|
has = permission.includes(role)
|
|
|
|
if (isString(permission))
|
|
has = permission === role
|
|
}
|
|
return has
|
|
}
|
|
|
|
return {
|
|
hasPermission,
|
|
}
|
|
}
|