mirror of
https://github.com/un-pany/v3-admin-vite.git
synced 2025-04-20 19:09:21 +08:00
perf: 代码优化 directives/permission
This commit is contained in:
parent
94d96c95e7
commit
9618a17ab5
@ -5,14 +5,15 @@ import { useUserStoreHook } from "@/store/modules/user"
|
||||
export const permission: Directive = {
|
||||
mounted(el, binding) {
|
||||
const { value } = binding
|
||||
const roles = useUserStoreHook().roles
|
||||
if (value && value instanceof Array && value.length > 0) {
|
||||
const { roles } = useUserStoreHook()
|
||||
if (Array.isArray(value) && value.length > 0) {
|
||||
const permissionRoles = value
|
||||
const hasPermission = roles.some((role) => {
|
||||
return permissionRoles.includes(role)
|
||||
})
|
||||
const hasPermission = roles.some((role) => permissionRoles.includes(role))
|
||||
if (!hasPermission) {
|
||||
el.style.display = "none"
|
||||
// 隐藏
|
||||
// el.style.display = "none"
|
||||
// 销毁
|
||||
el.parentNode?.removeChild(el)
|
||||
}
|
||||
} else {
|
||||
throw new Error(`need roles! Like v-permission="['admin','editor']"`)
|
||||
|
Loading…
x
Reference in New Issue
Block a user