feat: add MaterialBase permission control with field-level filtering

Co-authored-by: aider (openai/DeepSeek-V3.2-Thinking) <aider@aider.chat>
This commit is contained in:
dxc
2026-02-27 10:16:43 +08:00
parent c86e67b793
commit 73ee163352
3 changed files with 131 additions and 12 deletions

View File

@ -71,7 +71,7 @@
<el-icon style="margin-right: 5px"><Download /></el-icon>导出库存统计
</el-button>
<el-button type="primary" @click="handleAdd" style="margin-right: 10px">
<el-button v-if="userStore.hasPermission('material:base:write')" type="primary" @click="handleAdd" style="margin-right: 10px">
<el-icon style="margin-right: 5px"><Plus /></el-icon>新增
</el-button>
@ -210,14 +210,15 @@
:active-value="1"
:inactive-value="0"
:loading="scope.row.statusLoading"
:disabled="!userStore.hasPermission('material:base:write')"
@change="handleStatusChange(scope.row)"
/>
</template>
</el-table-column>
<el-table-column v-if="userStore.hasPermission('operation')" label="操作" min-width="150" fixed="right" align="center">
<el-table-column v-if="userStore.hasPermission('material:base:write') || userStore.hasPermission('material:base:delete')" label="操作" min-width="150" fixed="right" align="center">
<template #default="scope">
<el-button link type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
<el-button link type="danger" size="small" @click="handleDelete(scope.row)">删除</el-button>
<el-button v-if="userStore.hasPermission('material:base:write')" link type="primary" size="small" @click="handleEdit(scope.row)">编辑</el-button>
<el-button v-if="userStore.hasPermission('material:base:delete')" link type="danger" size="small" @click="handleDelete(scope.row)">删除</el-button>
</template>
</el-table-column>
</el-table>
@ -530,8 +531,8 @@ const initColumnPermissions = () => {
Object.keys(columns).forEach(key => {
const code = permissionMap[key];
if (code) {
// 如果用户有该权限则显示列默认true否则隐藏
columns[key].visible = userStore.hasPermission(code);
// 严格执行权限检查:不具备权限的列必须隐藏
columns[key].visible = !!userStore.hasPermission(code);
}
});
};