Browse Source

feat(权限管理): 权限控制逻辑

zhangrenyuan/feature-20250728113353-金币前端三期
lihui 3 weeks ago
parent
commit
8d492ef8cb
  1. 69
      src/utils/menuTreePermission.js
  2. 9
      src/utils/menuUtils.js
  3. 58
      src/views/audit/rechargeAudit.vue

69
src/utils/menuTreePermission.js

@ -0,0 +1,69 @@
// 菜单权限映射(按 menu_type 排序)
export const permissionMapping = {
System_Management: 1, // 系统管理
// menu_type 2: 主功能菜单
Workbench: 2, // 工作台
Financial_Audit: 3, // 财务审核
Exchange_Rate_Management: 4, // 汇率管理
Recharge_Management: 5, // 充值管理
Consumption_Management: 6, // 消耗管理
Refund_Management: 7, // 退款管理
Customer_Account_Details: 8, // 客户账户明细
Permission_Management: 9, // 权限管理
// menu_type 3: 子功能菜单
Gold_Coin_Recharge: 34, // 金币充值
Gold_Coin_Consumption: 35, // 金币消耗
Gold_Coin_Refund: 37, // 金币退款
Gold_Coin_Audit: 40, // 金币审核
Golden_Bean_Recharge: 41, // 金豆充值
Golden_Bean_Consumption: 42, // 金豆消耗
Golden_Bean_Audit: 43, // 金豆审核
Gold_Coin_Customer_Account_Details: 44, // 金币客户账户明细
Golden_Bean_Customer_Account_Details: 45, // 金豆客户账户明细
// menu_type 4: 功能操作权限
Workbench_Display: 10, // 工作台展示
View_Recharge_Audit: 11, // 查看充值审核
Recharge_Approval: 12, // 充值审批
View_Refund_Audit: 13, // 查看退款审核
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, // 查看金币余额
View_Permission: 25, // 查看权限
Add_User: 26, // 新增用户
Change_Status: 27, // 改变状态
Modify_Permission: 28, // 修改权限
Delete_User: 29, // 删除用户
View_Role: 30, // 查看角色
Edit_Role: 36, // 编辑角色
Recharge_Audit: 31, // 充值审核
Refund_Audit: 32, // 退款审核
};
// 递归查找菜单中是否存在目标id
export const findMenuById = (menuList, targetId) => {
for (const menu of menuList) {
if (menu.id === targetId) {
return true; // 找到目标菜单
}
// 如果有子菜单,递归查找
if (menu.children && menu.children.length > 0) {
const found = findMenuById(menu.children, targetId);
if (found) return true;
}
}
return false;
};

9
src/utils/menuUtils.js

@ -7,7 +7,7 @@ export function filterMenu(menuList) {
...menu,
children: menu.children ? filterMenu(menu.children) : []
}))
.sort((a, b) => a.priority - b.priority); // 按 id 升序
.sort((a, b) => a.id - b.id); // 按 id 升序
}
// 辅助函数:查找第一个可访问的菜单项
@ -21,6 +21,7 @@ export function findFirstAccessibleMenu(menuList) {
} else if (menu.menuType === 2) { // 目录
return menu
} else if (menu.menuType === 3) { // 菜单
console.log('菜单:', menu)
return menu
}
}
@ -33,24 +34,30 @@ export const getRoutePath = (menu) => {
const routeMap = {
'工作台': '/workspace',
'财务审核': '/audit',
'金币审核': '/audit',
'金豆审核': '/beanAudit',
'汇率管理': '/rate',
'充值管理': '/coinRecharge',
'金币充值': '/coinRecharge',
'金豆充值': '/beanRecharge',
'消耗管理': '/coinConsume',
'金币消耗': '/coinConsume',
'金豆消耗': '/beanConsume',
'退款管理': '/coinRefund',
'金币退款': '/coinRefund',
// '金豆退款': '/beanRefund',
'权限管理': '/permissions',
'客户账户明细': '/usergold',
'金币客户账户明细': '/usergold',
'金豆客户账户明细': '/userbean',
};

58
src/views/audit/rechargeAudit.vue

@ -35,10 +35,16 @@
<div class="time-group">
<el-text size="large" style="width: 80px">充值时间</el-text>
<el-date-picker v-model="getTime" type="datetimerange" range-separator="" start-placeholder="起始时间"
end-placeholder="结束时间" style="width: 400px" @change="handleDatePickerChange"/>
<el-button @click="getToday()" style="margin-left: 10px" :type="activeTimeRange === 'today' ? 'primary' : ''"> </el-button>
<el-button @click="getYesterday()" style="margin-left: 10px" :type="activeTimeRange === 'yesterday' ? 'primary' : ''"> </el-button>
<el-button @click="get7Days()" style="margin-left: 10px" :type="activeTimeRange === '7days' ? 'primary' : ''"> 近7天</el-button>
end-placeholder="结束时间" style="width: 400px" @change="handleDatePickerChange"/>
<el-button @click="getToday()" style="margin-left: 10px"
:type="activeTimeRange === 'today' ? 'primary' : ''">
</el-button>
<el-button @click="getYesterday()" style="margin-left: 10px"
:type="activeTimeRange === 'yesterday' ? 'primary' : ''">
</el-button>
<el-button @click="get7Days()" style="margin-left: 10px"
:type="activeTimeRange === '7days' ? 'primary' : ''"> 近7天
</el-button>
<el-button @click="resetSearch" type="success">重置</el-button>
<el-button type="primary" @click="handleSearch">查询</el-button>
</div>
@ -95,7 +101,9 @@
<el-table-column prop="payModel" label="支付方式" width="110px"/>
<el-table-column prop="voucher" label="支付凭证" width="110px">
<template #default="scope">
<div v-if="scope.row.voucher" style="display: flex; justify-content: center; align-items: center; cursor: pointer;" @click="previewImage(scope.row.voucher)">
<div v-if="scope.row.voucher"
style="display: flex; justify-content: center; align-items: center; cursor: pointer;"
@click="previewImage(scope.row.voucher)">
<img :src="scope.row.voucher" alt="支付凭证" style="width: auto; height: 40px;">
</div>
<div v-else style="display: flex; justify-content: center; align-items: center; height: 40px;">--</div>
@ -173,6 +181,8 @@ import {ElMessage} from 'element-plus'
import request from '@/util/http'
import moment from 'moment'
import API from '@/util/http'
import {useAdminStore} from "@/store/index.js";
import {storeToRefs} from "pinia";
//
const trimJwCode = () => {
if (rechargeAudit.value.jwcode) {
@ -200,7 +210,7 @@ const rechargeAudit = ref({
startTime: "", //
endTime: "", //
market: "", //
auditStatus : "0",
auditStatus: "0",
})
//
@ -501,23 +511,33 @@ const handlePagination = (type, val) => {
getStats()
}
const adminStore = useAdminStore();
const {menuTree} = storeToRefs(adminStore);
import {permissionMapping, findMenuById} from "@/utils/menuTreePermission.js"
//
const handleApprove = async (row) => {
try {
const params = {
orderCode: row.orderCode,
auditId: adminData.value.id,
action: 1,
rejectReason: ''
if (findMenuById(menuTree.value, permissionMapping.Recharge_Approval)) {
try {
const params = {
orderCode: row.orderCode,
auditId: adminData.value.id,
action: 1,
rejectReason: ''
}
await request({url: '/audit/audit', data: params})
ElMessage.success('审核通过成功')
await getRecharge()
await getStats()
} catch (error) {
console.error('审核通过失败', error)
ElMessage.error('操作失败')
}
await request({url: '/audit/audit', data: params})
ElMessage.success('审核通过成功')
await getRecharge()
await getStats()
} catch (error) {
console.error('审核通过失败', error)
ElMessage.error('操作失败')
}else {
ElMessage.error('无权限')
}
}
//

Loading…
Cancel
Save