mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-07-09 06:21:57 +08:00
Refactor permission utility function
This commit is contained in:
@@ -1,19 +0,0 @@
|
||||
import store from '@/store'
|
||||
|
||||
// 检查是否有权限
|
||||
export function hasPermission(permission: string | null = null) {
|
||||
if (!permission) return true
|
||||
// permission是一个以.分隔的字符串,例如:'user.create'
|
||||
const permissionList = permission.split('.')
|
||||
let permissions_obj = store.state.auth.permissions
|
||||
for (const element of permissionList) {
|
||||
if (!permissions_obj[element]) {
|
||||
return false
|
||||
} else if (typeof permissions_obj[element] === 'object') {
|
||||
permissions_obj = permissions_obj[element]
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
Reference in New Issue
Block a user