feat: 完成多模块功能迭代与优化
本次提交包含多模块功能更新: 1. 权限系统重构:移除硬编码admin放行逻辑,新增精细化权限控制,完善权限树形结构与用户/角色保护 2. 新增物料导入导出接口,补充台账查询条件 3. 优化列表查询排序逻辑,新增区域编码大小写不敏感搜索 4. 修复帮助抽屉重复弹出问题,补充页面权限控制 5. 新增弱密码提示逻辑,优化MES/WMS用户/角色管理权限 6. 调整路由结构,新增权限校验脚本与前端权限树重构 7. 补充数据库字段与依赖包更新
This commit is contained in:
@@ -9,10 +9,29 @@ import { can } from '../utils/perm'
|
||||
const loading = ref(false)
|
||||
const list = ref([])
|
||||
const perms = ref([]) // 全部权限(MENU + BUTTON)
|
||||
const treeRef = ref()
|
||||
|
||||
// 权限树:按 type 分组(菜单在前,按钮在后)
|
||||
const menuPerms = computed(() => perms.value.filter((p) => p.type === 'MENU'))
|
||||
const buttonPerms = computed(() => perms.value.filter((p) => p.type === 'BUTTON'))
|
||||
// 权限树:一级=菜单,二级=该菜单下的按钮;全局按钮(parentCode空)归入「通用」分组
|
||||
const permTree = computed(() => {
|
||||
const menus = perms.value.filter((p) => p.type === 'MENU')
|
||||
const buttons = perms.value.filter((p) => p.type === 'BUTTON')
|
||||
const nodes = menus.map((m) => {
|
||||
const kids = buttons
|
||||
.filter((b) => b.parentCode === m.code)
|
||||
.map((b) => ({ label: b.name, code: b.code }))
|
||||
return { label: m.name, code: m.code, children: kids }
|
||||
})
|
||||
// 全局按钮(无 parentCode 才归入「通用」分组;导出已按菜单拆分,故不再有该分组)
|
||||
const globalBtns = buttons.filter((b) => !b.parentCode)
|
||||
if (globalBtns.length) {
|
||||
nodes.push({
|
||||
label: '通用',
|
||||
global: true,
|
||||
children: globalBtns.map((b) => ({ label: b.name, code: b.code }))
|
||||
})
|
||||
}
|
||||
return nodes
|
||||
})
|
||||
|
||||
async function loadRoles() {
|
||||
loading.value = true
|
||||
@@ -34,6 +53,14 @@ onMounted(async () => {
|
||||
await Promise.all([loadRoles(), loadPerms()])
|
||||
})
|
||||
|
||||
// 从 el-tree 的 key 中取回所有权限码(根/父节点 code 即权限码本身)
|
||||
function treeCheckedCodes() {
|
||||
if (!treeRef.value) return []
|
||||
const keys = treeRef.value.getCheckedKeys().concat(treeRef.value.getHalfCheckedKeys() || [])
|
||||
// 剔除非叶子半选带来的父节点误判:父节点 code 本身就是有效权限码,直接保留并去重
|
||||
return [...new Set(keys)]
|
||||
}
|
||||
|
||||
/* ---------- 新增 / 编辑 弹窗 ---------- */
|
||||
const dialog = reactive({ show: false, editingId: 0, name: '', code: '', remark: '', checked: [] })
|
||||
const saving = ref(false)
|
||||
@@ -49,6 +76,12 @@ function openEdit(row) {
|
||||
dialog.remark = row.remark || ''
|
||||
dialog.checked = [...(row.permissionCodes || [])]
|
||||
dialog.show = true
|
||||
// 弹窗打开后待树渲染完成再回显勾选(nextTick + 等待树数据就绪)
|
||||
setTimeout(() => {
|
||||
if (treeRef.value) {
|
||||
treeRef.value.setCheckedKeys(dialog.checked)
|
||||
}
|
||||
}, 60)
|
||||
}
|
||||
function onCheckedChange() {
|
||||
/* 勾选状态由 el-tree 管理,无需额外逻辑 */
|
||||
@@ -57,6 +90,8 @@ function onCheckedChange() {
|
||||
async function save() {
|
||||
if (!dialog.name.trim()) return ElMessage.warning('请输入角色名称')
|
||||
if (!isEdit.value && !dialog.code.trim()) return ElMessage.warning('请输入角色编码')
|
||||
// 从树取回勾选 + 半选(父菜单)的权限码
|
||||
dialog.checked = treeCheckedCodes()
|
||||
saving.value = true
|
||||
try {
|
||||
if (isEdit.value) {
|
||||
@@ -145,7 +180,7 @@ function permSummary(arr) {
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="140" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button v-if="can('role:edit')" link type="primary" size="small" @click="openEdit(row)">编辑权限</el-button>
|
||||
<el-button v-if="can('role:edit')" link type="primary" size="small" :disabled="row.code === 'admin'" @click="openEdit(row)">编辑权限</el-button>
|
||||
<el-button v-if="can('role:delete')" link type="danger" size="small" @click="removeRole(row)">删除</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
@@ -167,26 +202,10 @@ function permSummary(arr) {
|
||||
<el-form-item label="权限设置" required>
|
||||
<div class="perm-tree" v-loading="!perms.length">
|
||||
<template v-if="perms.length">
|
||||
<div class="perm-section">
|
||||
<div class="perm-title">菜单权限</div>
|
||||
<div class="perm-chips">
|
||||
<el-checkbox v-for="p in menuPerms" :key="p.code"
|
||||
:model-value="dialog.checked.includes(p.code)"
|
||||
@change="(v) => v ? dialog.checked.push(p.code) : (dialog.checked = dialog.checked.filter(c => c !== p.code))">
|
||||
{{ p.name }}
|
||||
</el-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="perm-section">
|
||||
<div class="perm-title">按钮权限</div>
|
||||
<div class="perm-chips">
|
||||
<el-checkbox v-for="p in buttonPerms" :key="p.code"
|
||||
:model-value="dialog.checked.includes(p.code)"
|
||||
@change="(v) => v ? dialog.checked.push(p.code) : (dialog.checked = dialog.checked.filter(c => c !== p.code))">
|
||||
{{ p.name }}
|
||||
</el-checkbox>
|
||||
</div>
|
||||
</div>
|
||||
<div class="perm-tip">菜单项勾选=可见该菜单;其下按钮勾选=可用该按钮(勾选互不影响)</div>
|
||||
<el-tree ref="treeRef" :data="permTree" show-checkbox node-key="code"
|
||||
check-strictly default-expand-all :props="{ label: 'label', children: 'children' }"
|
||||
@check="onCheckedChange" />
|
||||
</template>
|
||||
<el-empty v-else description="暂无权限数据(可先执行初始化)" :image-size="60" />
|
||||
</div>
|
||||
@@ -202,9 +221,6 @@ function permSummary(arr) {
|
||||
|
||||
<style scoped>
|
||||
.mb12 { margin-bottom: 12px; }
|
||||
.perm-tree { border: 1px solid #ebeef5; border-radius: 4px; padding: 12px; max-height: 320px; overflow: auto; }
|
||||
.perm-section { margin-bottom: 10px; }
|
||||
.perm-title { font-weight: 600; color: #303133; margin-bottom: 8px; font-size: 13px; }
|
||||
.perm-chips { display: flex; flex-wrap: wrap; gap: 4px 14px; }
|
||||
.perm-chips .el-checkbox { margin-right: 0; }
|
||||
.perm-tree { border: 1px solid #ebeef5; border-radius: 4px; padding: 12px; max-height: 340px; overflow: auto; }
|
||||
.perm-tip { color: #909399; font-size: 12px; margin-bottom: 8px; }
|
||||
</style>
|
||||
Reference in New Issue
Block a user