import { auth } from '@/utils/auth.js' /** * 权限指令 * 使用方式: * v-auth="'user:add'" // 单个权限 * v-auth="['user:add', 'user:edit']" // 多个权限(满足其一即可) */ export const authDirective = { mounted(el, binding) { checkAuth(el, binding) }, updated(el, binding) { checkAuth(el, binding) } } /** * 权限检查逻辑 */ function checkAuth(el, binding) { const hasAuth = auth.check(binding.value) if (!hasAuth) { // 没有权限时隐藏元素 el.style.display = 'none' // 或者完全移除元素(根据需求选择) // if (el.parentNode) { // el.parentNode.removeChild(el) // } } else { // 有权限时确保显示 el.style.display = '' } }