/** * @Description: 按钮权限 * @Author: zenghua.wang * @Date: 2022-08-30 09:42:47 * @LastEditors: zenghua.wang * @LastEditTime: 2024-06-08 19:50:47 */ import { useUserStore } from '@/store/modules/user'; export function useAuth(app) { app.directive('auth', (el, binding) => { const { value } = binding; const all_permission = '*:*:*'; const UserStore = useUserStore(); const permissions = UserStore.getAuths() ?? []; 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 { // console.log('button permissions are not supported.'); } }); }