From 9ba171db2727a504efd2fc46f26419e5383fdd2e Mon Sep 17 00:00:00 2001 From: lihui Date: Fri, 1 Aug 2025 13:31:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor=EF=BC=9A=E9=80=9A=E8=BF=87=E6=98=A0?= =?UTF-8?q?=E5=B0=84id=20=E5=88=A4=E6=96=AD=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/menuTreePermission.js | 35 ++++++++++---- src/views/audit/gold/audit.vue | 33 +++++-------- src/views/consume/gold/coinConsume.vue | 82 ++++++++++++++------------------ src/views/recharge/gold/coinRecharge.vue | 82 ++++++++++++++------------------ src/views/refund/gold/coinRefund.vue | 82 ++++++++++++++------------------ src/views/usergold/gold/clientCount.vue | 82 ++++++++++++++------------------ 6 files changed, 178 insertions(+), 218 deletions(-) diff --git a/src/utils/menuTreePermission.js b/src/utils/menuTreePermission.js index f1a8a01..6b6f1b1 100644 --- a/src/utils/menuTreePermission.js +++ b/src/utils/menuTreePermission.js @@ -33,14 +33,19 @@ export const permissionMapping = { Refund_Approval: 14, // 退款审批 Exchange_Rate_View: 15, // 汇率查看 Exchange_Rate_Modification: 16, // 汇率修改 - Submit_Gold_Coin_Recharge: 17, // 提交金币充值 - View_Gold_Coin_Recharge_Details: 18, // 查看金币充值明细 - Submit_Gold_Coin_Consumption: 19, // 提交金币消耗 - View_Gold_Coin_Consumption_Details: 20, // 查看金币消耗明细 - Submit_Gold_Coin_Refund: 21, // 提交金币退款 - View_Gold_Coin_Refund_Details: 22, // 查看金币退款明细 - View_Gold_Coin_Details: 23, // 查看金币明细 - View_Gold_Coin_Balance: 24, // 查看金币余额 + + Submit_Gold_Coin_Recharge: 17, // 提交金币充值 // coinRecharge页面 + View_Gold_Coin_Recharge_Details: 18, // 查看金币充值明细 // coinRecharge页面 + + Submit_Gold_Coin_Consumption: 19, // 提交金币消耗 // coinConsume页面 + View_Gold_Coin_Consumption_Details: 20, // 查看金币消耗明细 // coinConsume页面 + + Submit_Gold_Coin_Refund: 21, // 提交金币退款 // coinRefund页面 + View_Gold_Coin_Refund_Details: 22, // 查看金币退款明细 // coinRefund页面 + + View_Gold_Coin_Details: 23, // 查看金币明细 //usergold页面 + View_Gold_Coin_Balance: 24, // 查看金币余额 //usergold页面 + View_Permission: 25, // 查看权限 Add_User: 26, // 新增用户 Change_Status: 27, // 改变状态 @@ -49,8 +54,8 @@ export const permissionMapping = { View_Role: 30, // 查看角色 Edit_Role: 36, // 编辑角色 - Recharge_Audit: 31, // 充值审核 - Refund_Audit: 32, // 退款审核 + Recharge_Audit: 31, // 充值审核(金币) // audit页面 + Refund_Audit: 32, // 退款审核(金币) // audit页面 }; // 递归查找菜单中是否存在目标id @@ -66,4 +71,14 @@ export const findMenuById = (menuList, targetId) => { } } return false; +}; + +// 递归判断某个 menuId 是否存在 +export const hasMenuPermission = (tree, targetId) => { + for (const node of tree) { + console.log(node.id) + if (node.id === targetId) return true; + if (node.children && hasMenuPermission(node.children, targetId)) return true; + } + return false; }; \ No newline at end of file diff --git a/src/views/audit/gold/audit.vue b/src/views/audit/gold/audit.vue index db972c8..f4359f3 100644 --- a/src/views/audit/gold/audit.vue +++ b/src/views/audit/gold/audit.vue @@ -25,7 +25,7 @@ import {ref, watch, onMounted} from 'vue'; import {useRouter, useRoute} from 'vue-router'; import {storeToRefs} from 'pinia'; import {useAdminStore} from '@/store/index.js'; -import {permissionMapping} from "@/utils/menuTreePermission.js"; +import {hasMenuPermission, permissionMapping} from "@/utils/menuTreePermission.js"; const router = useRouter(); const route = useRoute(); @@ -41,34 +41,26 @@ const navigateTo = (name) => { router.push({name}); }; -// 递归判断某个 menuId 是否存在 -const hasMenuPermission = (tree, targetId) => { - for (const node of tree) { - console.log(node.id) - if (node.id === targetId) return true; - if (node.children && hasMenuPermission(node.children, targetId)) return true; - } - return false; -}; -// 默认路由判断 - 使用 ID 匹配 -const getDefaultAuditRoute = () => { - if (!menuTree.value || !menuTree.value.length) return 'rechargeAudit'; +// 初始化权限状态 +const initPermissions = () => { + if (!menuTree.value || !menuTree.value.length) return; - // 使用 ID hasRecharge.value = hasMenuPermission(menuTree.value, permissionMapping.Recharge_Audit); hasRefund.value = hasMenuPermission(menuTree.value, permissionMapping.Refund_Audit); +}; - - // 优先判断充值权限,没有则判断退款权限 - if (hasRecharge) return 'rechargeAudit'; - if (hasRefund) return 'refundAudit'; - - return 'rechargeAudit'; // 默认回退选项 +// 默认跳转逻辑 +const getDefaultAuditRoute = () => { + initPermissions(); + if (hasRecharge.value) return 'rechargeAudit'; + if (hasRefund.value) return 'refundAudit'; + return 'rechargeAudit'; }; // 监听路由变化更新标签状态 watch(() => route.name, (newName) => { + initPermissions() if (newName === 'rechargeAudit' || newName === 'refundAudit') { activeTab.value = newName; } else if (newName === 'audit') { @@ -80,6 +72,7 @@ watch(() => route.name, (newName) => { // 初始化逻辑 onMounted(() => { + initPermissions() if (route.name === 'audit') { const defaultRoute = getDefaultAuditRoute(); navigateTo(defaultRoute); diff --git a/src/views/consume/gold/coinConsume.vue b/src/views/consume/gold/coinConsume.vue index 176d49f..ee7824b 100644 --- a/src/views/consume/gold/coinConsume.vue +++ b/src/views/consume/gold/coinConsume.vue @@ -4,14 +4,16 @@ 新增消耗 金币消耗明细 @@ -23,79 +25,65 @@ + \ No newline at end of file diff --git a/src/views/recharge/gold/coinRecharge.vue b/src/views/recharge/gold/coinRecharge.vue index 48b4b18..e5676bb 100644 --- a/src/views/recharge/gold/coinRecharge.vue +++ b/src/views/recharge/gold/coinRecharge.vue @@ -4,14 +4,16 @@ 新增充值 金币充值明细 @@ -23,79 +25,65 @@ + \ No newline at end of file diff --git a/src/views/refund/gold/coinRefund.vue b/src/views/refund/gold/coinRefund.vue index 184ae62..c0eeadb 100644 --- a/src/views/refund/gold/coinRefund.vue +++ b/src/views/refund/gold/coinRefund.vue @@ -4,14 +4,16 @@ 新增退款 金币退款明细 @@ -23,79 +25,65 @@ + \ No newline at end of file diff --git a/src/views/usergold/gold/clientCount.vue b/src/views/usergold/gold/clientCount.vue index f07220a..5535fa2 100644 --- a/src/views/usergold/gold/clientCount.vue +++ b/src/views/usergold/gold/clientCount.vue @@ -4,14 +4,16 @@ 金币明细 金币余额 @@ -23,79 +25,65 @@ + \ No newline at end of file