Эх сурвалжийг харах

feat(auth): 根据权限动态隐藏菜单项

- 在 auth store 中引入权限判断逻辑
- 实现根据权限隐藏"门店装修"和"财务管理"菜单功能
- 优化权限工具函数,支持可选提示信息参数
- 修复 coupon 和 voucher 管理页面样式问题
- 调整表格头部按钮布局,改善用户体验
congxuesong 1 сар өмнө
parent
commit
7751fb0af5

+ 22 - 1
src/stores/modules/auth.ts

@@ -2,6 +2,7 @@ import { defineStore } from "pinia";
 import { AuthState } from "@/stores/interface";
 import { getAuthButtonListApi, getAuthMenuListApi } from "@/api/modules/login";
 import { getFlatMenuList, getShowMenuList, getAllBreadcrumbList } from "@/utils";
+import { usePermission } from "@/utils/permission";
 export const useAuthStore = defineStore({
   id: "geeker-auth",
   state: (): AuthState => ({
@@ -33,7 +34,27 @@ export const useAuthStore = defineStore({
     // Get AuthMenuList
     async getAuthMenuList() {
       const { data } = (await getAuthMenuListApi()) as any;
-      console.log(data, "ddd-000d");
+
+      const hasPermission = await usePermission();
+      if (!hasPermission) {
+        // 根据权限隐藏"门店装修"和"财务管理"菜单
+        const hideMenuNames = ["storeDecoration", "financialManagement"];
+        // 递归查找并隐藏指定菜单
+        const hideMenus = (menuList: any[]) => {
+          menuList.forEach(menu => {
+            // 根据菜单名称判断是否需要隐藏
+            if (menu.name && hideMenuNames.includes(menu.name)) {
+              menu.meta.isHide = true;
+            }
+            // 递归处理子菜单
+            if (menu.children && menu.children.length > 0) {
+              hideMenus(menu.children);
+            }
+          });
+        };
+        hideMenus(data);
+      }
+
       this.authMenuList = data;
     },
     // Set RouteName

+ 7 - 3
src/utils/permission.ts

@@ -6,7 +6,7 @@ import { getUserByPhone, getDetail } from "@/api/modules/homeEntry";
  * @description 判断是否有操作权限
  * @returns {Boolean} 是否有权限
  */
-export async function usePermission(str) {
+export async function usePermission(tip?: string) {
   let type = true;
   if (!localGet("createdId")) {
     let params = {
@@ -26,12 +26,16 @@ export async function usePermission(str) {
       }
     } else {
       type = false;
-      ElMessage.warning(`请完成商家入驻后再进行${str}`);
+      if (tip) {
+        ElMessage.warning(`请完成商家入驻后再进行${tip}`);
+      }
       return type;
     }
     if (!localGet("businessSection")) {
       type = false;
-      ElMessage.warning(`请完成商家入驻后重新登录再进行${str}`);
+      if (tip) {
+        ElMessage.warning(`请完成商家入驻后重新登录再进行${tip}`);
+      }
       return type;
     }
   }

+ 3 - 1
src/views/couponManagement/index.vue

@@ -349,8 +349,10 @@ const closeDialog = () => {
   white-space: normal; // 允许自然换行
 }
 .table-header-btn {
+  .button {
+    margin-bottom: 10px;
+  }
   .tabs {
-    margin-top: 10px;
     :deep(.el-tabs__nav-wrap::after) {
       height: 0;
     }

+ 3 - 1
src/views/voucherManagement/index.vue

@@ -380,8 +380,10 @@ const closeDialog = () => {
   white-space: normal; // 允许自然换行
 }
 .table-header-btn {
+  .button {
+    margin-bottom: 10px;
+  }
   .tabs {
-    margin-top: 10px;
     :deep(.el-tabs__nav-wrap::after) {
       height: 0;
     }