feat: implement RBAC for inbound buy module with field-level permissions
Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
@ -56,7 +56,7 @@
|
||||
</div>
|
||||
|
||||
<div class="right-actions">
|
||||
<el-button type="primary" :icon="Plus" @click="handleCreate" class="add-btn">新增</el-button>
|
||||
<el-button v-if="userStore.hasPermission('inbound_buy:operation')" type="primary" :icon="Plus" @click="handleCreate" class="add-btn">新增</el-button>
|
||||
<el-button :icon="Refresh" circle @click="fetchData" class="circle-btn" />
|
||||
|
||||
<el-popover placement="bottom-end" title="列配置" :width="500" trigger="click">
|
||||
@ -67,13 +67,13 @@
|
||||
<div class="col-group-title">基础信息</div>
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="12" v-for="c in baseColumns" :key="c.prop">
|
||||
<el-checkbox :label="c.prop">{{ c.label }}</el-checkbox>
|
||||
<el-checkbox :label="c.prop" :disabled="!hasColumnPermission(c.prop)">{{ c.label }}</el-checkbox>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<div class="col-group-title" style="margin-top:10px">库存与商务</div>
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="12" v-for="c in stockColumns" :key="c.prop">
|
||||
<el-checkbox :label="c.prop">{{ c.label }}</el-checkbox>
|
||||
<el-checkbox :label="c.prop" :disabled="!hasColumnPermission(c.prop)">{{ c.label }}</el-checkbox>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-checkbox-group>
|
||||
@ -167,7 +167,7 @@
|
||||
</el-table-column>
|
||||
</template>
|
||||
|
||||
<el-table-column label="操作" width="220" fixed="right" align="center">
|
||||
<el-table-column v-if="userStore.hasPermission('inbound_buy:operation')" label="操作" width="220" fixed="right" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-button link type="warning" size="default" @click="handlePrint(row)">
|
||||
<el-icon><Printer/></el-icon> 打印
|
||||
@ -613,6 +613,7 @@ const vLoadmore = {
|
||||
// ------------------------------------
|
||||
// 状态与变量
|
||||
// ------------------------------------
|
||||
const userStore = useUserStore()
|
||||
const loading = ref(false)
|
||||
const submitting = ref(false)
|
||||
const visible = ref(false)
|
||||
@ -703,6 +704,80 @@ const stockColumns = [
|
||||
|
||||
const allColumns = [...baseColumns, ...stockColumns]
|
||||
|
||||
// 列与权限Code的映射关系(数据库中的code)
|
||||
const permissionMap: Record<string, string> = {
|
||||
id: 'inbound_buy:id',
|
||||
base_id: 'inbound_buy:base_id',
|
||||
company_name: 'inbound_buy:company_name',
|
||||
material_name: 'inbound_buy:material_name',
|
||||
material_type: 'inbound_buy:material_type',
|
||||
category: 'inbound_buy:category',
|
||||
spec_model: 'inbound_buy:spec_model',
|
||||
unit: 'inbound_buy:unit',
|
||||
sku: 'inbound_buy:sku',
|
||||
inbound_date: 'inbound_buy:inbound_date',
|
||||
barcode: 'inbound_buy:barcode',
|
||||
sn_bn: 'inbound_buy:sn_bn',
|
||||
status: 'inbound_buy:status',
|
||||
inspection_status: 'inbound_buy:inspection_status',
|
||||
qty_inbound: 'inbound_buy:qty_inbound',
|
||||
qty_stock: 'inbound_buy:qty_stock',
|
||||
qty_available: 'inbound_buy:qty_available',
|
||||
warehouse_loc: 'inbound_buy:warehouse_loc',
|
||||
tax_rate: 'inbound_buy:tax_rate',
|
||||
unit_price: 'inbound_buy:unit_price',
|
||||
total_price: 'inbound_buy:total_price',
|
||||
currency: 'inbound_buy:currency',
|
||||
exchange_rate: 'inbound_buy:exchange_rate',
|
||||
supplier_name: 'inbound_buy:supplier_name',
|
||||
purchaser: 'inbound_buy:purchaser',
|
||||
purchaser_email: 'inbound_buy:purchaser_email',
|
||||
source_link: 'inbound_buy:source_link',
|
||||
detail_link: 'inbound_buy:detail_link',
|
||||
arrival_photo: 'inbound_buy:arrival_photo',
|
||||
inspection_report: 'inbound_buy:inspection_report'
|
||||
}
|
||||
|
||||
// 根据用户权限初始化列显示状态
|
||||
const initColumnPermissions = () => {
|
||||
// 超级管理员跳过权限检查,显示所有列
|
||||
if (userStore.role === 'SUPER_ADMIN' || userStore.username === 'IRIS') {
|
||||
return
|
||||
}
|
||||
|
||||
// 普通用户:严格执行列级权限控制,没有权限的列必须隐藏
|
||||
// 遍历 allColumns,将没有权限的列从 visibleColumnProps 中移除
|
||||
const allowedColumns = allColumns.filter(col => {
|
||||
const code = permissionMap[col.prop]
|
||||
if (code) {
|
||||
return userStore.hasPermission(code)
|
||||
}
|
||||
// 如果没有映射,默认隐藏
|
||||
return false
|
||||
}).map(col => col.prop)
|
||||
|
||||
// 更新 visibleColumnProps,只保留有权限的列
|
||||
// 同时保持用户之前已经选择的有权限的列
|
||||
const currentVisible = visibleColumnProps.value.filter(prop => allowedColumns.includes(prop))
|
||||
// 如果当前没有可见列,则使用 allowedColumns 作为默认
|
||||
if (currentVisible.length === 0) {
|
||||
visibleColumnProps.value = allowedColumns
|
||||
} else {
|
||||
visibleColumnProps.value = currentVisible
|
||||
}
|
||||
}
|
||||
|
||||
// 检查列权限
|
||||
const hasColumnPermission = (prop: string) => {
|
||||
if (userStore.role === 'SUPER_ADMIN' || userStore.username === 'IRIS') {
|
||||
return true
|
||||
}
|
||||
const code = permissionMap[prop]
|
||||
return code ? userStore.hasPermission(code) : false
|
||||
}
|
||||
|
||||
const allColumns = [...baseColumns, ...stockColumns]
|
||||
|
||||
const defaultColumns = [
|
||||
'company_name',
|
||||
'material_name', 'material_type', 'category', 'spec_model', 'unit',
|
||||
@ -1180,6 +1255,8 @@ const getStatusType = (status: string) => { const map: any = {'在库': 'success
|
||||
const formatMoney = (val: any, currency = '¥') => { const num = Number(val); return isNaN(num) ? '-' : `${currency} ${num.toFixed(2)}` }
|
||||
|
||||
onMounted(() => {
|
||||
// 先根据权限初始化列显示状态
|
||||
initColumnPermissions()
|
||||
fetchData()
|
||||
fetchOptions()
|
||||
})
|
||||
@ -1374,4 +1451,4 @@ onMounted(() => {
|
||||
.long-dropdown .el-input__suffix {
|
||||
z-index: 10;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user