From 7e604b1cb6ecb16ec94f5965092663b94e120e5a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E5=8B=87?= <2058152148@qq.com>
Date: Sat, 14 Dec 2024 23:39:32 +0800
Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E4=BB=A3=E7=A0=81=E9=83=A8?=
=?UTF-8?q?=E5=88=86=E4=BF=AE=E6=94=B9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
frontend/src/core/directives/action.js | 10 ++
frontend/src/layouts/BlankLayout.vue | 8 +-
frontend/src/layouts/PageView.vue | 17 +++
frontend/src/layouts/RouteView.vue | 11 ++
frontend/src/layouts/UserLayout.vue | 13 +-
frontend/src/views/exception/404.vue | 7 +-
frontend/src/views/exception/500.vue | 6 +-
frontend/src/views/home/Banner.vue | 14 +-
frontend/src/views/home/List.vue | 9 +-
frontend/src/views/home/ListItem.vue | 9 ++
frontend/src/views/home/Page1.vue | 20 +++
frontend/src/views/list/QuestionTableList.vue | 142 ++++++++++++++++++
.../views/list/modules/QuestionEditModal.vue | 21 ++-
.../views/list/modules/QuestionViewModal.vue | 17 ++-
14 files changed, 286 insertions(+), 18 deletions(-)
diff --git a/frontend/src/core/directives/action.js b/frontend/src/core/directives/action.js
index 7ea921e..57f5dd3 100644
--- a/frontend/src/core/directives/action.js
+++ b/frontend/src/core/directives/action.js
@@ -14,16 +14,26 @@ import store from '../../store'
*
* @see https://github.com/sendya/ant-design-pro-vue/pull/53
*/
+/**
+ * 创建一个 Vue 自定义指令 'action',用于控制元素基于用户权限的显示
+ */
const action = Vue.directive('action', {
inserted: function (el, binding, vnode) {
+ // 获取指令的参数,即动作名称
const actionName = binding.arg
+ // 从 Vuex store 中获取当前用户的角色信息
const roles = store.getters.roles
+ // 获取当前路由的权限配置
const elVal = vnode.context.$route.meta.permission
+ // 确保权限配置为数组形式
const permissionId = elVal instanceof String && [elVal] || elVal
+ // 遍历用户角色的权限列表
roles.permissions.forEach(p => {
+ // 如果当前权限ID不在元素的权限配置中,直接返回
if (!permissionId.includes(p.permissionId)) {
return
}
+ // 如果当前权限有动作列表限制,且动作列表中不包含指令的参数,移除或隐藏元素
if (p.actionList && !p.actionList.includes(actionName)) {
el.parentNode && el.parentNode.removeChild(el) || (el.style.display = 'none')
}
diff --git a/frontend/src/layouts/BlankLayout.vue b/frontend/src/layouts/BlankLayout.vue
index 1bfbfbf..2032e13 100644
--- a/frontend/src/layouts/BlankLayout.vue
+++ b/frontend/src/layouts/BlankLayout.vue
@@ -1,16 +1,20 @@
+
diff --git a/frontend/src/layouts/PageView.vue b/frontend/src/layouts/PageView.vue
index 32ce5c2..05fbaea 100644
--- a/frontend/src/layouts/PageView.vue
+++ b/frontend/src/layouts/PageView.vue
@@ -1,10 +1,16 @@
+
+
+
+
+
+
{{ description }}
@@ -15,12 +21,15 @@
+
+
+
+
+
+