wangzhibo
6 天以前 7bd866831780abcf5a59c4cbb7d1be456eea7c99
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
import { useStore } from '../store';
import { isObject } from 'lodash-es';
 
function parse(value: any) {
    const { menu } = useStore();
 
    if (typeof value == 'string') {
        return value ? menu.perms.some((e: any) => e.includes(value.replace(/\s/g, ''))) : false;
    } else {
        return Boolean(value);
    }
}
 
export function checkPerm(value: string | { or?: string[]; and?: string[] }) {
    if (!value) {
        return false;
    }
 
    if (isObject(value)) {
        if (value.or) {
            return value.or.some(parse);
        }
 
        if (value.and) {
            return value.and.some((e: any) => !parse(e)) ? false : true;
        }
    }
 
    return parse(value);
}