zhangwei
3 天以前 019b6cf4ccaa06fc5ca8f5dc5663975eb027d360
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { useUserInfo } from '/@/stores/userInfo';
import { judgementSameArr } from '/@/utils/arrayOperation';
import { resolveDirective, withDirectives } from 'vue';
 
/**
 * 单个权限验证
 * @param value 权限值
 * @returns 有权限,返回 `true`,反之则反
 */
export function auth(value: string): boolean {
    const stores = useUserInfo();
    return stores.userInfos.authBtnList.some((v: string) => v === value);
}
 
/**
 * 多个权限验证,满足一个则为 true
 * @param value 权限值
 * @returns 有权限,返回 `true`,反之则反
 */
export function auths(value: Array<string>): boolean {
    let flag = false;
    const stores = useUserInfo();
    stores.userInfos.authBtnList.map((val: string) => {
        value.map((v: string) => {
            if (val === v) flag = true;
        });
    });
    return flag;
}
 
/**
 * 多个权限验证,全部满足则为 true
 * @param value 权限值
 * @returns 有权限,返回 `true`,反之则反
 */
export function authAll(value: Array<string>): boolean {
    const stores = useUserInfo();
    return judgementSameArr(value, stores.userInfos.authBtnList);
}
/**
 * 单个权限验证,是否满足,返回VNode
 * @param VNode 元素
 * @param value 权限值
 * @returns VNode
 */
export function hAuth<T extends VNode>(el: T, value: string): T {
    return withDirectives(el, [[resolveDirective('auth'), value]]);
}
/**
 * 多个权限验证,判断是否满足一个,返回VNode
 * @param VNode 元素
 * @param value 权限值
 * @returns VNode
 */
export function hAuths<T extends VNode>(el: T, value: Array<string>): T {
    return withDirectives(el, [[resolveDirective('auths'), value]]);
}
/**
 * 多个权限验证,判断是否全部满足,返回VNode
 * @param VNode 元素
 * @param value 权限值
 * @returns VNode
 */
export function hAuthAll<T extends VNode>(el: T, value: Array<string>): T {
    return withDirectives(el, [[resolveDirective('auth-all'), value]]);
}