fetch(modify):修改原来的bug
All checks were successful
构建并部署前端到测试环境 / build-and-deploy (push) Successful in 4m53s

This commit is contained in:
sexygoat
2026-01-31 11:18:37 +08:00
parent 8a1388608c
commit 31440b2904
62 changed files with 3025 additions and 1421 deletions

View File

@@ -1,17 +1,41 @@
import { router } from '@/router'
import { App, Directive } from 'vue'
import { App, Directive, DirectiveBinding } from 'vue'
import { useUserStore } from '@/store/modules/user'
/**
* 权限指令(后端控制模式可用)
* 权限指令
* 用法:
* v-permission="'menu:get'" - 单个权限
* v-permission="['menu:get', 'role:get']" - 多个权限(满足任意一个即可)
* v-permission:all="['menu:get', 'role:get']" - 多个权限(需要全部满足)
*
* 兼容旧的v-auth指令:
* <el-button v-auth="'add'">按钮</el-button>
*/
const authDirective: Directive = {
const permissionDirective: Directive = {
mounted(el: HTMLElement, binding: DirectiveBinding) {
const authList = (router.currentRoute.value.meta.authList as Array<{ auth_mark: string }>) || []
const userStore = useUserStore()
const { value, arg } = binding
const hasPermission = authList.some((item) => item.auth_mark === binding.value)
// 如果没有值,直接返回
if (!value) return
let hasPermission = false
if (typeof value === 'string') {
// 单个权限
hasPermission = userStore.hasPermission(value)
} else if (Array.isArray(value)) {
// 多个权限
if (arg === 'all') {
// 需要全部满足
hasPermission = userStore.hasAllPermissions(value)
} else {
// 满足任意一个即可
hasPermission = userStore.hasAnyPermission(value)
}
}
// 如果没有权限,移除元素
if (!hasPermission) {
el.parentNode?.removeChild(el)
}
@@ -19,5 +43,7 @@ const authDirective: Directive = {
}
export function setupPermissionDirective(app: App) {
app.directive('auth', authDirective)
// 注册为 v-permission 和 v-auth (向后兼容)
app.directive('permission', permissionDirective)
app.directive('auth', permissionDirective)
}