15815213711
2022-03-07 56f8b51c26bd1fb7e1fdc62acab5151cdf83c860
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import {Directive} from "@vue/runtime-core";
import store from "@/store";
 
/**
 * v-hasPermi 操作权限处理
 */
export const hasPermi: Directive = {
    mounted(el, binding, vNode) {
        const {value} = binding;
        const all_permission = "*:*:*";
        const permissions = store.getters?.permissions
        if (value && value instanceof Array && value.length > 0) {
            const permissionFlag = value;
            const hasPermissions = permissions.some((permission: any) => {
                return all_permission === permission || permissionFlag.includes(permission)
            })
            if (!hasPermissions) {
                el.parentNode?.removeChild(el)
            }
        } else {
            throw new Error("请设置操作权限标签值")
        }
    }
}