2025-04-18 09:06:30 +01:00

33 lines
895 B
JavaScript

/**
* @Description: 按钮权限
* @Author: zenghua.wang
* @Date: 2022-08-30 09:42:47
* @LastEditors: zenghua.wang
* @LastEditTime: 2024-01-30 13:59:50
*/
// import { CACHE_KEY, useCache } from '@/hooks/web/useCache';
export function useAuth(app) {
app.directive('auth', (el, binding) => {
// const { wsCache } = useCache();
const { value } = binding;
const all_permission = '*:*:*';
const permissions = []; //wsCache.get(CACHE_KEY.USER).permissions;
if (value && value instanceof Array && value.length > 0) {
const permissionFlag = value;
const hasAuth = permissions.some((permission) => {
return all_permission === permission || permissionFlag.includes(permission);
});
if (!hasAuth) {
el.parentNode && el.parentNode.removeChild(el);
}
} else {
// throw new Error('no auth to access it.');
}
});
}