UNIVPLMDataIntegration/Web/src/utils/authFunction.ts

67 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-06-15 13:02:35 +08:00
import { useUserInfo } from '/@/stores/userInfo';
import { judgementSameArr } from '/@/utils/arrayOperation';
import { resolveDirective, withDirectives } from 'vue';
2024-06-15 13:02:35 +08:00
/**
*
* @param value
* @returns `true`
*/
export function auth(value: string): boolean {
const stores = useUserInfo();
2024-07-22 02:54:41 +08:00
return stores.userInfos.authApiList.some((v: string) => v === value);
2024-06-15 13:02:35 +08:00
}
/**
* true
* @param value
* @returns `true`
*/
export function auths(value: Array<string>): boolean {
let flag = false;
const stores = useUserInfo();
2024-07-22 02:54:41 +08:00
stores.userInfos.authApiList.map((val: string) => {
2024-06-15 13:02:35 +08:00
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();
2024-07-22 02:54:41 +08:00
return judgementSameArr(value, stores.userInfos.authApiList);
2024-06-15 13:02:35 +08:00
}
/**
* 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]]);
}