fix:填写人功能
This commit is contained in:
parent
0b25c98276
commit
df23f924e0
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -20,10 +20,16 @@
|
||||
<div class="header-right">
|
||||
<el-button
|
||||
v-if="flowStatus === 'APPROVING'"
|
||||
type="primary"
|
||||
@click="handleApprove"
|
||||
@click="handleReject"
|
||||
>
|
||||
审批
|
||||
退回
|
||||
</el-button>
|
||||
<el-button
|
||||
v-if="flowStatus === 'APPROVING'"
|
||||
type="primary"
|
||||
@click="handleSubmit"
|
||||
>
|
||||
提交
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@ -156,30 +162,23 @@
|
||||
|
||||
<!-- 审批弹窗 -->
|
||||
<el-dialog
|
||||
title="审核"
|
||||
:title="approvalDialogTitle"
|
||||
:visible.sync="approvalDialogVisible"
|
||||
width="500px"
|
||||
:close-on-click-modal="false"
|
||||
append-to-body
|
||||
@close="handleApprovalDialogClose"
|
||||
>
|
||||
<el-form ref="approvalForm" :model="approvalFormData" label-width="80px">
|
||||
<el-form-item label="审核">
|
||||
<el-radio-group v-model="approvalFormData.result">
|
||||
<el-radio label="PASS">
|
||||
通过
|
||||
</el-radio>
|
||||
<el-radio label="REJECT">
|
||||
退回
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注">
|
||||
<el-form ref="approvalForm" :model="approvalFormData" :rules="approvalFormRules" label-width="80px">
|
||||
<el-form-item
|
||||
:label="approvalActionType === 'reject' ? '退回意见:' : '提交意见:'"
|
||||
prop="opinion"
|
||||
>
|
||||
<el-input
|
||||
v-model="approvalFormData.opinion"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请输入备注"
|
||||
:placeholder="approvalActionType === 'reject' ? '请输入退回意见' : '请输入提交意见'"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@ -221,11 +220,18 @@ export default {
|
||||
changeTablePageNumber: 1,
|
||||
changeTablePageSize: 10,
|
||||
approvalDialogVisible: false,
|
||||
approvalActionType: '', // 'reject' 或 'submit'
|
||||
approvalDialogTitle: '审核',
|
||||
approvalFormData: {
|
||||
result: '',
|
||||
opinion: ''
|
||||
},
|
||||
approvalSubmitting: false
|
||||
approvalSubmitting: false,
|
||||
approvalFormRules: {
|
||||
opinion: [
|
||||
{ required: true, message: '请输入意见', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@ -543,9 +549,26 @@ export default {
|
||||
return formattedStep
|
||||
})
|
||||
},
|
||||
handleApprove() {
|
||||
handleReject() {
|
||||
this.approvalActionType = 'reject'
|
||||
this.approvalDialogTitle = '退回'
|
||||
this.approvalFormData = {
|
||||
result: '',
|
||||
result: 'REJECT',
|
||||
opinion: ''
|
||||
}
|
||||
this.approvalDialogVisible = true
|
||||
// 清除表单验证
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.approvalForm) {
|
||||
this.$refs.approvalForm.clearValidate()
|
||||
}
|
||||
})
|
||||
},
|
||||
handleSubmit() {
|
||||
this.approvalActionType = 'submit'
|
||||
this.approvalDialogTitle = '提交'
|
||||
this.approvalFormData = {
|
||||
result: 'PASS',
|
||||
opinion: ''
|
||||
}
|
||||
this.approvalDialogVisible = true
|
||||
@ -558,6 +581,8 @@ export default {
|
||||
},
|
||||
handleApprovalDialogClose() {
|
||||
this.approvalDialogVisible = false
|
||||
this.approvalActionType = ''
|
||||
this.approvalDialogTitle = '审核'
|
||||
this.approvalFormData = {
|
||||
result: '',
|
||||
opinion: ''
|
||||
@ -568,10 +593,10 @@ export default {
|
||||
}
|
||||
},
|
||||
handleApprovalSubmit() {
|
||||
// 验证是否选择了审核结果
|
||||
if (!this.approvalFormData.result) {
|
||||
this.$message.warning('请选择审核结果(通过或退回)')
|
||||
return
|
||||
// 表单验证
|
||||
this.$refs.approvalForm.validate((valid) => {
|
||||
if (!valid) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!this.detail || !this.detail.flowId) {
|
||||
@ -611,6 +636,7 @@ export default {
|
||||
.finally(() => {
|
||||
this.approvalSubmitting = false
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,13 +51,13 @@
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="dispatchType !== 'update_param'" label="部门:" prop="department">
|
||||
<el-form-item label="部门:" prop="department">
|
||||
<el-select
|
||||
v-model="formData.department"
|
||||
placeholder="请选择部门"
|
||||
clearable
|
||||
style="width: 100%"
|
||||
:disabled="!formData.subsystem"
|
||||
:disabled="dispatchType === 'update_param' ? (!formData.subsystem || !formData.partsName) : !formData.subsystem"
|
||||
@change="handleDepartmentChange"
|
||||
>
|
||||
<el-option
|
||||
@ -77,22 +77,13 @@
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item v-if="dispatchType === 'update_param'" label="现填写人:">
|
||||
<el-input
|
||||
v-model="formData.currentFillerName"
|
||||
disabled
|
||||
placeholder="暂无填写人"
|
||||
readonly
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item :label="dispatchType === 'update_param' ? '填写人:' : '责任人:'" prop="userId">
|
||||
<el-form-item :label="dispatchType === 'update_param' ? '人员:' : '责任人:'" prop="userId">
|
||||
<el-select
|
||||
v-model="formData.userId"
|
||||
:placeholder="dispatchType === 'update_param' ? '请输入填写人姓名进行搜索' : '请输入责任人姓名进行搜索'"
|
||||
:placeholder="dispatchType === 'update_param' ? '请输入人员姓名进行搜索' : '请输入责任人姓名进行搜索'"
|
||||
style="width: 100%"
|
||||
clearable
|
||||
:disabled="dispatchType === 'update_param' ? !formData.partsName : !formData.department"
|
||||
:disabled="!formData.department"
|
||||
filterable
|
||||
remote
|
||||
reserve-keyword
|
||||
@ -190,19 +181,18 @@ export default {
|
||||
{ required: true, message: '请选择子系统', trigger: 'change' }
|
||||
],
|
||||
userId: [
|
||||
{ required: true, message: this.dispatchType === 'update_param' ? '请选择填写人' : '请选择责任人', trigger: 'change' }
|
||||
{ required: true, message: this.dispatchType === 'update_param' ? '请选择人员' : '请选择责任人', trigger: 'change' }
|
||||
]
|
||||
}
|
||||
// 添加部门验证(两种模式都需要)
|
||||
rules.department = [
|
||||
{ required: true, message: '请选择部门', trigger: 'change' }
|
||||
]
|
||||
// 如果是批量修改填写人,添加零部件名称验证
|
||||
if (this.dispatchType === 'update_param') {
|
||||
rules.partsName = [
|
||||
{ required: true, message: '请选择零部件名称', trigger: 'change' }
|
||||
]
|
||||
} else {
|
||||
// 如果是批量修改责任人,添加部门验证
|
||||
rules.department = [
|
||||
{ required: true, message: '请选择部门', trigger: 'change' }
|
||||
]
|
||||
}
|
||||
return rules
|
||||
}
|
||||
@ -355,8 +345,8 @@ export default {
|
||||
partsNameSet.add(paramPartsName)
|
||||
}
|
||||
}
|
||||
// 收集部门名称(仅用于批量修改责任人)
|
||||
if (this.dispatchType !== 'update_param' && param.department) {
|
||||
// 收集部门名称(两种模式都需要)
|
||||
if (param.department) {
|
||||
departmentSet.add(param.department)
|
||||
}
|
||||
}
|
||||
@ -371,11 +361,10 @@ export default {
|
||||
partsNamesArray.unshift('/')
|
||||
}
|
||||
this.availablePartsNames = partsNamesArray
|
||||
}
|
||||
|
||||
// 如果是批量修改责任人,直接设置部门列表(不依赖零部件名称)
|
||||
if (this.dispatchType !== 'update_param') {
|
||||
// 转换为数组格式
|
||||
// 对于批量修改填写人,部门列表应该在选择了零部件名称之后才筛选
|
||||
this.availableDepartments = []
|
||||
} else {
|
||||
// 批量修改责任人:设置部门列表(转换为数组格式)
|
||||
this.availableDepartments = Array.from(departmentSet).map((dept) => ({
|
||||
department: dept
|
||||
}))
|
||||
@ -387,32 +376,29 @@ export default {
|
||||
},
|
||||
// 处理零部件名称选择变化(仅用于批量修改填写人)
|
||||
handlePartsNameChange(partsName) {
|
||||
// 清空现填写人和新填写人
|
||||
// 清空部门、现填写人和新填写人
|
||||
this.formData.department = ''
|
||||
this.formData.currentFillerId = ''
|
||||
this.formData.currentFillerName = ''
|
||||
this.formData.userId = ''
|
||||
this.formData.userNumber = ''
|
||||
this.formData.username = ''
|
||||
this.availableDepartments = []
|
||||
this.userOptions = []
|
||||
// 根据子系统和零部件名称查找现填写人
|
||||
// 根据子系统和零部件名称筛选部门列表
|
||||
if (partsName && this.formData.subsystem) {
|
||||
this.findCurrentFiller()
|
||||
} else {
|
||||
this.formData.currentFillerId = ''
|
||||
this.formData.currentFillerName = ''
|
||||
this.filterDepartmentsByPartsName()
|
||||
}
|
||||
},
|
||||
// 查找现填写人(根据子系统和零部件名称)
|
||||
findCurrentFiller() {
|
||||
// 根据子系统和零部件名称筛选部门列表(仅用于批量修改填写人)
|
||||
filterDepartmentsByPartsName() {
|
||||
if (!this.formData.subsystem || !this.formData.partsName) {
|
||||
this.formData.currentFillerId = ''
|
||||
this.formData.currentFillerName = ''
|
||||
this.availableDepartments = []
|
||||
return
|
||||
}
|
||||
|
||||
// 从 versionData 中查找现填写人
|
||||
const currentVersionData = this.versionData[this.currentVersionId] || {}
|
||||
let foundFiller = null
|
||||
const departmentSet = new Set()
|
||||
|
||||
// 遍历所有零部件名称(partsName)
|
||||
Object.keys(currentVersionData).forEach((dataPartsName) => {
|
||||
@ -424,36 +410,17 @@ export default {
|
||||
if (
|
||||
param.subsystemName === this.formData.subsystem &&
|
||||
paramPartsName === this.formData.partsName &&
|
||||
param.filledByUserId
|
||||
param.department
|
||||
) {
|
||||
// 找到第一个有填写人的参数,使用其填写人信息
|
||||
if (!foundFiller) {
|
||||
foundFiller = {
|
||||
userId: param.filledByUserId,
|
||||
username: param.filledBy || ''
|
||||
}
|
||||
}
|
||||
departmentSet.add(param.department)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
if (foundFiller) {
|
||||
// 如果找到了填写人,尝试从 fillerPersons 中获取完整信息
|
||||
const fillerPerson = this.fillerPersons.find(
|
||||
(p) => p.userId === foundFiller.userId || p.id === foundFiller.userId
|
||||
)
|
||||
if (fillerPerson) {
|
||||
this.formData.currentFillerId = fillerPerson.userId || fillerPerson.id || ''
|
||||
this.formData.currentFillerName = fillerPerson.userName || foundFiller.username || ''
|
||||
} else {
|
||||
this.formData.currentFillerId = foundFiller.userId || ''
|
||||
this.formData.currentFillerName = foundFiller.username || ''
|
||||
}
|
||||
} else {
|
||||
// 没有现填写人
|
||||
this.formData.currentFillerId = ''
|
||||
this.formData.currentFillerName = ''
|
||||
}
|
||||
// 转换为数组格式
|
||||
this.availableDepartments = Array.from(departmentSet).map((dept) => ({
|
||||
department: dept
|
||||
}))
|
||||
},
|
||||
// 处理部门选择变化
|
||||
handleDepartmentChange(department) {
|
||||
@ -494,19 +461,11 @@ export default {
|
||||
},
|
||||
// 远程搜索责任人/填写人
|
||||
handleRemoteSearch(query) {
|
||||
// 如果是批量修改填写人,只需要检查零部件名称
|
||||
if (this.dispatchType === 'update_param') {
|
||||
if (!this.formData.partsName) {
|
||||
this.userOptions = []
|
||||
return
|
||||
}
|
||||
} else {
|
||||
// 批量修改责任人,需要检查部门
|
||||
// 两种模式都需要检查部门
|
||||
if (!this.formData.department) {
|
||||
this.userOptions = []
|
||||
return
|
||||
}
|
||||
}
|
||||
if (!query || query.trim() === '') {
|
||||
if (this.formData.userId) {
|
||||
const selectedOptions = this.userOptions.filter((opt) => opt.userId === this.formData.userId)
|
||||
@ -609,7 +568,7 @@ export default {
|
||||
return
|
||||
}
|
||||
if (!this.formData.userId) {
|
||||
const fieldName = this.dispatchType === 'update_param' ? '填写人' : '责任人'
|
||||
const fieldName = this.dispatchType === 'update_param' ? '人员' : '责任人'
|
||||
this.$message.warning(`请选择${fieldName}`)
|
||||
return
|
||||
}
|
||||
@ -626,6 +585,7 @@ export default {
|
||||
const confirmData = {
|
||||
subsystem: this.formData.subsystem,
|
||||
partsName: this.formData.partsName,
|
||||
department: this.formData.department,
|
||||
userId: this.formData.userId, // 确保传递userId
|
||||
userNumber: this.formData.userNumber || this.formData.userId, // 如果没有 userNumber,使用 userId
|
||||
username: this.formData.username || ''
|
||||
|
||||
@ -19,8 +19,11 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="header-right">
|
||||
<el-button type="primary" size="small" @click="handleApprove">
|
||||
审批
|
||||
<el-button size="small" @click="handleReject">
|
||||
退回
|
||||
</el-button>
|
||||
<el-button type="primary" size="small" @click="handleSubmit">
|
||||
提交
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
@ -137,7 +140,7 @@
|
||||
|
||||
<!-- 审批弹窗 -->
|
||||
<el-dialog
|
||||
title="审批"
|
||||
:title="approvalDialogTitle"
|
||||
:visible.sync="approvalDialogVisible"
|
||||
width="500px"
|
||||
:close-on-click-modal="false"
|
||||
@ -150,22 +153,15 @@
|
||||
:rules="approvalFormRules"
|
||||
label-width="80px"
|
||||
>
|
||||
<el-form-item label="审批结果" prop="operator">
|
||||
<el-radio-group v-model="approvalFormData.operator">
|
||||
<el-radio label="同意">
|
||||
同意
|
||||
</el-radio>
|
||||
<el-radio label="拒绝">
|
||||
拒绝
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="说明" prop="comment">
|
||||
<el-form-item
|
||||
:label="approvalActionType === 'reject' ? '退回意见:' : '提交意见:'"
|
||||
prop="comment"
|
||||
>
|
||||
<el-input
|
||||
v-model="approvalFormData.comment"
|
||||
type="textarea"
|
||||
:rows="4"
|
||||
placeholder="请输入审批说明"
|
||||
:placeholder="approvalActionType === 'reject' ? '请输入退回意见' : '请输入提交意见'"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@ -214,6 +210,8 @@ export default {
|
||||
changeTablePageSize: 10,
|
||||
activitiRecordDTOS: [], // 审批流程数据
|
||||
approvalDialogVisible: false,
|
||||
approvalActionType: '', // 'reject' 或 'submit'
|
||||
approvalDialogTitle: '审批',
|
||||
approvalFormData: {
|
||||
operator: '同意',
|
||||
comment: ''
|
||||
@ -329,8 +327,7 @@ export default {
|
||||
},
|
||||
approvalFormRules() {
|
||||
return {
|
||||
operator: [{ required: true, message: '请选择审批结果', trigger: 'change' }],
|
||||
comment: [{ required: true, message: '请输入审批说明', trigger: 'blur' }]
|
||||
comment: [{ required: true, message: '请输入意见', trigger: 'blur' }]
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -572,8 +569,24 @@ export default {
|
||||
handleBack() {
|
||||
this.$emit('close')
|
||||
},
|
||||
handleApprove() {
|
||||
// 打开审批弹窗
|
||||
handleReject() {
|
||||
this.approvalActionType = 'reject'
|
||||
this.approvalDialogTitle = '退回'
|
||||
this.approvalFormData = {
|
||||
operator: '拒绝',
|
||||
comment: ''
|
||||
}
|
||||
this.approvalDialogVisible = true
|
||||
// 清除表单验证
|
||||
this.$nextTick(() => {
|
||||
if (this.$refs.approvalForm) {
|
||||
this.$refs.approvalForm.clearValidate()
|
||||
}
|
||||
})
|
||||
},
|
||||
handleSubmit() {
|
||||
this.approvalActionType = 'submit'
|
||||
this.approvalDialogTitle = '提交'
|
||||
this.approvalFormData = {
|
||||
operator: '同意',
|
||||
comment: ''
|
||||
@ -589,7 +602,10 @@ export default {
|
||||
handleApprovalSubmit() {
|
||||
// 表单验证
|
||||
this.$refs.approvalForm.validate((valid) => {
|
||||
if (valid) {
|
||||
if (!valid) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (!this.detail || !this.detail.id) {
|
||||
this.$message.error('缺少审批数据')
|
||||
return
|
||||
@ -602,8 +618,8 @@ export default {
|
||||
}
|
||||
|
||||
// 构建提交数据
|
||||
// 将"同意"转换为"PASS","拒绝"转换为"REJECT"
|
||||
const operator = this.approvalFormData.operator === '同意' ? 'PASS' : 'REJECT'
|
||||
// 根据操作类型设置 operator:退回为 'REJECT',提交为 'PASS'
|
||||
const operator = this.approvalActionType === 'reject' ? 'REJECT' : 'PASS'
|
||||
const submitData = {
|
||||
approvalId: approvalId,
|
||||
operator: operator,
|
||||
@ -622,22 +638,28 @@ export default {
|
||||
.asyncThen((resp) => {
|
||||
console.log('审批提交成功')
|
||||
|
||||
this.approvalDialogVisible = false
|
||||
this.approvalSubmitting = false
|
||||
this.handleApprovalDialogClose()
|
||||
// 重新加载审批详情数据
|
||||
this.getApprovalDetail()
|
||||
// 通知父组件刷新数据
|
||||
this.$emit('refresh')
|
||||
this.approvalSubmitting = false
|
||||
})
|
||||
.asyncErrorCatch((err) => {
|
||||
console.error('审批提交失败:', err)
|
||||
this.$message.error(err.message || '审批提交失败,请重试')
|
||||
this.approvalSubmitting = false
|
||||
})
|
||||
}
|
||||
.finally(() => {
|
||||
this.approvalSubmitting = false
|
||||
})
|
||||
})
|
||||
},
|
||||
handleApprovalDialogClose() {
|
||||
// 关闭弹窗,重置表单
|
||||
this.approvalDialogVisible = false
|
||||
this.approvalActionType = ''
|
||||
this.approvalDialogTitle = '审批'
|
||||
this.approvalFormData = {
|
||||
operator: '同意',
|
||||
comment: ''
|
||||
|
||||
@ -88,14 +88,14 @@
|
||||
clearable
|
||||
class="tree-search"
|
||||
></el-input>
|
||||
<div class="tree-actions">
|
||||
<!-- <div class="tree-actions">
|
||||
<el-button size="mini" @click="handleExpandAllSecondLevel">
|
||||
一键展开
|
||||
</el-button>
|
||||
<el-button size="mini" @click="handleCollapseAllSecondLevel">
|
||||
一键收起
|
||||
</el-button>
|
||||
</div>
|
||||
</div> -->
|
||||
<el-tree
|
||||
ref="paramTree"
|
||||
:data="treeData"
|
||||
@ -1450,9 +1450,9 @@ export default {
|
||||
|
||||
// 如果是批量修改填写人,直接更新页面数据
|
||||
if (this.dispatchType === 'update_param') {
|
||||
const { subsystem, partsName, userId, userNumber, username } = change
|
||||
console.log(change, 'change', subsystem, partsName, userId, userNumber, username)
|
||||
if (!subsystem || !partsName || !userId) {
|
||||
const { subsystem, partsName, department, userId, userNumber, username } = change
|
||||
console.log(change, 'change', subsystem, partsName, department, userId, userNumber, username)
|
||||
if (!subsystem || !partsName || !department || !userId) {
|
||||
this.$message({
|
||||
type: 'warning',
|
||||
message: '缺少必要参数'
|
||||
@ -1480,11 +1480,12 @@ export default {
|
||||
// 获取参数的零部件名称(优先使用param.partsName,否则使用dataPartsName)
|
||||
const paramPartsName = param.partsName || dataPartsName
|
||||
|
||||
// 检查参数是否匹配子系统和零部件名称(不再匹配部门)
|
||||
// 检查参数是否匹配子系统、零部件名称和部门
|
||||
// 当 partsName 为 '/' 时,匹配所有子系统为选中子系统且 partsName 为 '/' 的参数
|
||||
if (
|
||||
param.subsystemName === subsystem &&
|
||||
paramPartsName === partsName
|
||||
paramPartsName === partsName &&
|
||||
param.department === department
|
||||
) {
|
||||
// 更新填写人信息
|
||||
param.filledBy = userId // 填写人ID(userId,用于提交)
|
||||
|
||||
@ -49,14 +49,14 @@
|
||||
下载导入模板
|
||||
</el-button>
|
||||
<el-button
|
||||
|
||||
v-if="shouldShowButtons"
|
||||
class="right-button"
|
||||
@click="handleMaintainParams"
|
||||
>
|
||||
维护参数
|
||||
</el-button>
|
||||
<el-button
|
||||
|
||||
v-if="shouldShowButtonsNew"
|
||||
class="right-button-primary"
|
||||
type="primary"
|
||||
@click="handleInitiateApproval"
|
||||
|
||||
@ -120,23 +120,18 @@
|
||||
<el-tree
|
||||
ref="permissionTree"
|
||||
:key="'permission-tree-' + dialogVisible"
|
||||
:data="[]"
|
||||
:data="treeData"
|
||||
node-key="id"
|
||||
:props="{ children: 'children', label: 'label', isLeaf: 'isLeaf' }"
|
||||
:props="{ children: 'children', label: 'label' }"
|
||||
:filter-node-method="filterTreeNode"
|
||||
:default-expand-all="false"
|
||||
:lazy="true"
|
||||
:load="loadNode"
|
||||
class="permission-tree"
|
||||
>
|
||||
<span slot-scope="{ node, data }" class="custom-tree-node">
|
||||
<span class="node-label">
|
||||
{{ node.label }}
|
||||
<!-- <span v-if="data.type === 'menu'" class="type-tag menu-tag">菜单</span>
|
||||
<span v-if="data.type === 'subsystem'" class="type-tag subsystem-tag">子系统</span>
|
||||
<span v-if="data.type === 'parameter'" class="type-tag parameter-tag">参数类型</span> -->
|
||||
</span>
|
||||
<span v-if="data.type === 'subsystem' || data.type === 'parameter'" class="permission-checkboxes">
|
||||
<span v-if="data.type === 'subsystem' || data.type === 'parts'" class="permission-checkboxes">
|
||||
<el-checkbox
|
||||
v-model="data.permissions.view"
|
||||
size="small"
|
||||
@ -335,7 +330,7 @@ export default {
|
||||
formData: {
|
||||
roleName: '',
|
||||
rowId: '',
|
||||
permissions: [] // 权限数据 [{ menuId, menuName, subsystem, parameter, view, edit }]
|
||||
permissions: [] // 权限数据 [{ roleId, subsystem, parameterName, parameterId, parameterPer, userId }]
|
||||
},
|
||||
formRules: {
|
||||
roleName: [
|
||||
@ -362,21 +357,11 @@ export default {
|
||||
{ required: true, message: '请输入角色描述', trigger: 'blur' }
|
||||
]
|
||||
},
|
||||
// 菜单树数据
|
||||
menuTreeData: [],
|
||||
// 子系统列表(数组格式)
|
||||
subsystemList: [],
|
||||
// 树数据(两级结构:子系统 -> 零部件名称)
|
||||
treeData: [],
|
||||
treeFilterText: '',
|
||||
// 节点映射,用于快速查找
|
||||
nodeMap: {},
|
||||
// 待应用的权限数据(用于懒加载模式下延迟应用权限)
|
||||
pendingPermissions: [],
|
||||
// 固定的父级菜单列表
|
||||
menuList: [
|
||||
'模板管理',
|
||||
'玉柴发动机数据',
|
||||
'竞品发动机数据'
|
||||
],
|
||||
// 人员配置相关
|
||||
personConfigDialogVisible: false,
|
||||
personConfigSubmitting: false,
|
||||
@ -442,31 +427,6 @@ export default {
|
||||
computed: {
|
||||
dialogTitle() {
|
||||
return this.dialogMode === 'add' ? '新增' : '修改'
|
||||
},
|
||||
// 获取所有参数节点,用于表格显示(只有参数类型,没有第四级)
|
||||
// 在懒加载模式下,从 nodeMap 中收集所有已加载的参数节点
|
||||
allParameterNodes() {
|
||||
const nodes = []
|
||||
// 遍历 nodeMap,收集所有参数类型的节点
|
||||
Object.keys(this.nodeMap).forEach(nodeId => {
|
||||
const node = this.nodeMap[nodeId]
|
||||
if (node && node.type === 'parameter') {
|
||||
// 确保权限对象存在
|
||||
if (!node.permissions) {
|
||||
this.$set(node, 'permissions', { view: false, edit: false })
|
||||
}
|
||||
nodes.push({
|
||||
id: node.id,
|
||||
menuName: node.menuName || '',
|
||||
subsystem: node.subsystem || '',
|
||||
parameter: node.parameter || node.label || '',
|
||||
parameterType: node.parameterType || node.label || '',
|
||||
parameterId: node.parameterId || '', // 保存参数ID
|
||||
permissions: node.permissions // 直接引用,保持响应式
|
||||
})
|
||||
}
|
||||
})
|
||||
return nodes
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
@ -476,7 +436,6 @@ export default {
|
||||
},
|
||||
mounted() {
|
||||
this.loadPermissionData()
|
||||
this.loadParamList()
|
||||
this.loadDepartmentList()
|
||||
this.getUserSelfRole()
|
||||
},
|
||||
@ -507,9 +466,11 @@ export default {
|
||||
},
|
||||
// 验证权限
|
||||
validatePermissions(rule, value, callback) {
|
||||
// 检查是否有参数节点被选中
|
||||
const hasParameterPermission = this.allParameterNodes.some(node => {
|
||||
return node.permissions.view || node.permissions.edit
|
||||
// 检查是否有零部件节点被选中
|
||||
const hasPartsPermission = Object.keys(this.nodeMap).some(nodeId => {
|
||||
const node = this.nodeMap[nodeId]
|
||||
return node && node.type === 'parts' && node.permissions &&
|
||||
(node.permissions.view || node.permissions.edit)
|
||||
})
|
||||
|
||||
// 检查是否有子系统节点被选中
|
||||
@ -519,240 +480,162 @@ export default {
|
||||
(node.permissions.view || node.permissions.edit)
|
||||
})
|
||||
|
||||
if (!hasParameterPermission && !hasSubsystemPermission) {
|
||||
if (!hasPartsPermission && !hasSubsystemPermission) {
|
||||
callback(new Error('请至少分配一个权限'))
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
},
|
||||
// 加载子系统列表
|
||||
loadParamList() {
|
||||
// 加载树数据(两级结构:子系统 -> 零部件名称)
|
||||
loadTreeData() {
|
||||
const request = {
|
||||
...api.GET_ALL_SYSTEM_ROLE_LIST,
|
||||
...api.GET_ENGINE_DETAIL_QUERY,
|
||||
disableSuccessMsg: true
|
||||
}
|
||||
this.$request(request)
|
||||
.asyncThen((resp) => {
|
||||
// 处理接口返回的数据
|
||||
if (resp && resp.data) {
|
||||
// 返回所有子系统名,可能是数组或对象
|
||||
let subsystemList = []
|
||||
if (Array.isArray(resp.data)) {
|
||||
subsystemList = resp.data
|
||||
} else if (typeof resp.data === 'object') {
|
||||
// 如果是对象,可能是 { result: [...] } 或 { data: [...] }
|
||||
subsystemList = resp.data.result || resp.data.data || Object.keys(resp.data) || []
|
||||
}
|
||||
// 存储为数组格式
|
||||
this.subsystemList = subsystemList
|
||||
// 接口返回的是对象格式:{ "子系统名": ["零部件1", "零部件2", ...] }
|
||||
const data = resp.data
|
||||
let treeDataResult = []
|
||||
if (typeof data === 'object' && !Array.isArray(data)) {
|
||||
treeDataResult = this.convertObjectToTree(data)
|
||||
} else if (Array.isArray(data)) {
|
||||
// 如果已经是数组格式,尝试格式化
|
||||
treeDataResult = this.formatTreeData(data)
|
||||
} else {
|
||||
this.subsystemList = []
|
||||
treeDataResult = []
|
||||
}
|
||||
this.treeData = treeDataResult
|
||||
} else {
|
||||
this.treeData = []
|
||||
}
|
||||
this.buildMenuTree()
|
||||
})
|
||||
.asyncErrorCatch((err) => {
|
||||
console.error('加载子系统列表失败:', err)
|
||||
this.subsystemList = []
|
||||
this.buildMenuTree()
|
||||
console.error('获取树数据失败:', err)
|
||||
this.$message.error('获取树数据失败')
|
||||
this.treeData = []
|
||||
})
|
||||
},
|
||||
// 构建菜单树(菜单 -> 子系统)
|
||||
// 参数类型在展开子系统节点时动态加载
|
||||
buildMenuTree() {
|
||||
// 重置节点映射
|
||||
this.nodeMap = {}
|
||||
|
||||
// 构建菜单树结构
|
||||
// 结构:菜单(固定6个) -> 子系统(从接口获取) -> 参数类型(展开时动态加载)
|
||||
// 将对象格式转换为树形结构
|
||||
// 输入格式: { "子系统名": ["零部件1", "零部件2", ...] }
|
||||
convertObjectToTree(data) {
|
||||
const treeData = []
|
||||
this.nodeMap = {} // 重置节点映射
|
||||
|
||||
// 遍历固定的菜单列表,即使子系统列表为空,也要构建菜单节点
|
||||
this.menuList.forEach((menuName, menuIdx) => {
|
||||
const menuId = `menu-${menuIdx}`
|
||||
const menuNode = {
|
||||
id: menuId,
|
||||
label: menuName,
|
||||
type: 'menu',
|
||||
children: null, // 初始为 null,懒加载时加载
|
||||
isLeaf: false // 明确标记为非叶子节点,让 el-tree 显示展开按钮
|
||||
Object.keys(data).forEach((subsystemName, subsystemIdx) => {
|
||||
const subsystemId = `subsystem-${subsystemIdx}`
|
||||
const children = []
|
||||
const seenLabels = new Set() // 用于去重,记录已处理的子节点 label
|
||||
|
||||
// 保存子系统节点映射
|
||||
this.nodeMap[subsystemId] = {
|
||||
id: subsystemId,
|
||||
label: subsystemName,
|
||||
type: 'subsystem',
|
||||
subsystem: subsystemName,
|
||||
permissions: {
|
||||
view: false,
|
||||
edit: false
|
||||
}
|
||||
}
|
||||
|
||||
// 保存菜单节点映射
|
||||
this.nodeMap[menuId] = menuNode
|
||||
treeData.push(menuNode)
|
||||
// 处理子节点数组,去重(根据 label),过滤掉值为 `/` 的子节点
|
||||
if (Array.isArray(data[subsystemName])) {
|
||||
data[subsystemName].forEach((partsName, partsIdx) => {
|
||||
// 过滤掉值为 `/` 的子节点
|
||||
if (partsName === '/') {
|
||||
return
|
||||
}
|
||||
// 如果该 label 已经处理过,跳过
|
||||
if (seenLabels.has(partsName)) {
|
||||
return
|
||||
}
|
||||
seenLabels.add(partsName)
|
||||
|
||||
const partsId = `${subsystemId}-parts-${partsIdx}`
|
||||
const partsNode = {
|
||||
id: partsId,
|
||||
label: partsName,
|
||||
type: 'parts',
|
||||
subsystem: subsystemName,
|
||||
partsName: partsName,
|
||||
permissions: {
|
||||
view: false,
|
||||
edit: false
|
||||
}
|
||||
}
|
||||
children.push(partsNode)
|
||||
// 保存零部件节点映射
|
||||
this.nodeMap[partsId] = {
|
||||
id: partsId,
|
||||
label: partsName,
|
||||
type: 'parts',
|
||||
subsystem: subsystemName,
|
||||
partsName: partsName,
|
||||
permissions: {
|
||||
view: false,
|
||||
edit: false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
treeData.push({
|
||||
id: subsystemId,
|
||||
label: subsystemName,
|
||||
type: 'subsystem',
|
||||
subsystem: subsystemName,
|
||||
permissions: {
|
||||
view: false,
|
||||
edit: false
|
||||
},
|
||||
children: children
|
||||
})
|
||||
})
|
||||
|
||||
this.menuTreeData = treeData
|
||||
return treeData
|
||||
},
|
||||
// 格式化树数据,确保每个节点有 id 和 label 属性,并对子节点去重(根据 label)
|
||||
formatTreeData(data) {
|
||||
return data.map((item, index) => {
|
||||
const node = {
|
||||
id: item.id || item.key || `node-${index}`,
|
||||
label: item.label || item.name || item.title || '',
|
||||
type: item.type || 'subsystem',
|
||||
subsystem: item.subsystem || item.label || '',
|
||||
permissions: item.permissions || { view: false, edit: false }
|
||||
}
|
||||
if (item.children && item.children.length > 0) {
|
||||
// 对子节点去重(根据 label)
|
||||
const seenLabels = new Set()
|
||||
const uniqueChildren = []
|
||||
item.children.forEach((child) => {
|
||||
const childLabel = child.label || child.name || child.title || ''
|
||||
if (childLabel !== '/' && !seenLabels.has(childLabel)) {
|
||||
seenLabels.add(childLabel)
|
||||
uniqueChildren.push({
|
||||
id: child.id || `${node.id}-parts-${uniqueChildren.length}`,
|
||||
label: childLabel,
|
||||
type: 'parts',
|
||||
subsystem: node.subsystem,
|
||||
partsName: childLabel,
|
||||
permissions: child.permissions || { view: false, edit: false }
|
||||
})
|
||||
}
|
||||
})
|
||||
// 递归处理子节点
|
||||
node.children = uniqueChildren
|
||||
}
|
||||
return node
|
||||
})
|
||||
},
|
||||
// 树节点过滤
|
||||
filterTreeNode(value, data) {
|
||||
if (!value) return true
|
||||
return data.label && data.label.indexOf(value) !== -1
|
||||
},
|
||||
// 懒加载节点数据
|
||||
loadNode(node, resolve) {
|
||||
// 根节点(level === 0),返回第一级菜单数据
|
||||
if (node.level === 0) {
|
||||
// 如果菜单树数据为空,先构建它
|
||||
if (!this.menuTreeData || this.menuTreeData.length === 0) {
|
||||
this.buildMenuTree()
|
||||
}
|
||||
resolve(this.menuTreeData || [])
|
||||
return
|
||||
}
|
||||
// 如果节点是菜单类型,加载其子系统(第二级)
|
||||
if (node.data.type === 'menu') {
|
||||
this.loadMenuSubsystemsForLazy(node.data, resolve)
|
||||
return
|
||||
}
|
||||
// 如果节点是子系统类型,加载其参数类型(第三级)
|
||||
if (node.data.type === 'subsystem') {
|
||||
this.loadSubsystemParametersForLazy(node.data, resolve)
|
||||
return
|
||||
}
|
||||
// 其他节点(参数类型)都是叶子节点,不需要加载
|
||||
resolve([])
|
||||
},
|
||||
// 懒加载方式加载菜单下的子系统
|
||||
loadMenuSubsystemsForLazy(menuNode, resolve) {
|
||||
// 如果没有子系统数据,返回空数组
|
||||
if (!Array.isArray(this.subsystemList) || this.subsystemList.length === 0) {
|
||||
resolve([])
|
||||
return
|
||||
}
|
||||
|
||||
// 构建子系统节点(第二级)
|
||||
const subsystemNodes = []
|
||||
this.subsystemList.forEach((subsystemName, subIdx) => {
|
||||
// 处理子系统名称,可能是字符串或对象
|
||||
const subsystemNameStr = typeof subsystemName === 'string'
|
||||
? subsystemName
|
||||
: (subsystemName.name || subsystemName.subsystemName || subsystemName.label || '')
|
||||
|
||||
if (!subsystemNameStr) {
|
||||
return
|
||||
}
|
||||
|
||||
const subsystemId = `${menuNode.id}-subsystem-${subIdx}`
|
||||
const subsystemNode = {
|
||||
id: subsystemId,
|
||||
label: subsystemNameStr,
|
||||
type: 'subsystem',
|
||||
menuName: menuNode.label,
|
||||
subsystem: subsystemNameStr,
|
||||
permissions: {
|
||||
view: false,
|
||||
edit: false
|
||||
},
|
||||
children: null, // 初始为 null,懒加载时加载
|
||||
isLeaf: false // 明确标记为非叶子节点,让 el-tree 显示展开按钮
|
||||
}
|
||||
|
||||
subsystemNodes.push(subsystemNode)
|
||||
// 保存节点映射
|
||||
this.nodeMap[subsystemId] = subsystemNode
|
||||
})
|
||||
|
||||
// 通过 resolve 回调返回子节点数据
|
||||
resolve(subsystemNodes)
|
||||
},
|
||||
// 懒加载方式加载子系统下的参数类型
|
||||
loadSubsystemParametersForLazy(subsystemNode, resolve) {
|
||||
if (!subsystemNode.subsystem) {
|
||||
console.warn('子系统节点缺少子系统名称')
|
||||
resolve([])
|
||||
return
|
||||
}
|
||||
|
||||
const request = {
|
||||
...api.GET_SUB_SYSTEM_DATA_LIST,
|
||||
params: {
|
||||
subsystem: subsystemNode.subsystem
|
||||
},
|
||||
disableSuccessMsg: true
|
||||
}
|
||||
|
||||
this.$request(request)
|
||||
.asyncThen((resp) => {
|
||||
// 处理返回的数据,获取参数名称列表
|
||||
let parameterList = []
|
||||
if (resp && resp.data) {
|
||||
if (Array.isArray(resp.data)) {
|
||||
parameterList = resp.data
|
||||
} else if (resp.data.result && Array.isArray(resp.data.result)) {
|
||||
parameterList = resp.data.result
|
||||
} else if (resp.data.data && Array.isArray(resp.data.data)) {
|
||||
parameterList = resp.data.data
|
||||
}
|
||||
}
|
||||
|
||||
// 构建参数类型节点(第三级,没有子节点)
|
||||
const parameterNodes = []
|
||||
const seenTypes = new Set() // 用于去重
|
||||
parameterList.forEach((param, paramIdx) => {
|
||||
// 处理参数名称,可能是字符串或对象
|
||||
const paramName = typeof param === 'string'
|
||||
? param
|
||||
: (param.name || param.parameterName || param.parameterType || param.label || '')
|
||||
|
||||
// 处理参数ID,可能是 id 或 parameterId
|
||||
const parameterId = typeof param === 'object' && param !== null
|
||||
? (param.id || param.parameterId || '')
|
||||
: ''
|
||||
|
||||
if (!paramName || seenTypes.has(paramName)) {
|
||||
return
|
||||
}
|
||||
seenTypes.add(paramName)
|
||||
|
||||
const paramTypeId = `${subsystemNode.id}-param-${paramIdx}`
|
||||
const paramTypeNode = {
|
||||
id: paramTypeId,
|
||||
label: paramName,
|
||||
type: 'parameter',
|
||||
menuName: subsystemNode.menuName,
|
||||
subsystem: subsystemNode.subsystem,
|
||||
parameter: paramName,
|
||||
parameterName: paramName, // 保存参数名称,用于权限匹配
|
||||
parameterType: paramName,
|
||||
parameterId: parameterId, // 保存参数ID,用于提交
|
||||
permissions: {
|
||||
view: false,
|
||||
edit: false
|
||||
},
|
||||
isLeaf: true, // 参数类型是叶子节点,没有第四级
|
||||
children: null // 没有子节点
|
||||
}
|
||||
|
||||
parameterNodes.push(paramTypeNode)
|
||||
// 保存节点映射
|
||||
this.nodeMap[paramTypeId] = paramTypeNode
|
||||
|
||||
// 如果有待应用的权限数据,立即应用
|
||||
this.applyPendingPermissionsToNode(paramTypeNode)
|
||||
})
|
||||
|
||||
// 通过 resolve 回调返回子节点数据
|
||||
resolve(parameterNodes)
|
||||
|
||||
// 使用 $nextTick 确保节点渲染后,权限状态能正确显示
|
||||
this.$nextTick(() => {
|
||||
// 再次应用权限,确保视图更新
|
||||
parameterNodes.forEach(node => {
|
||||
this.applyPendingPermissionsToNode(node)
|
||||
})
|
||||
// 更新子系统权限状态(如果有参数节点)
|
||||
if (parameterNodes.length > 0) {
|
||||
this.updateSubsystemPermissionFromChildren(parameterNodes[0])
|
||||
}
|
||||
})
|
||||
})
|
||||
.asyncErrorCatch((err) => {
|
||||
console.error('加载子系统参数失败:', err)
|
||||
this.$message.error('加载参数类型失败')
|
||||
// 返回空数组,避免重复请求
|
||||
resolve([])
|
||||
})
|
||||
},
|
||||
// 权限变更处理
|
||||
handlePermissionChange(data, permissionType) {
|
||||
// 同步更新节点映射中的权限
|
||||
@ -761,11 +644,11 @@ export default {
|
||||
this.$set(this.nodeMap[data.id].permissions, permissionType, data.permissions[permissionType])
|
||||
}
|
||||
|
||||
// 如果是子系统节点,全选/取消全选其下所有参数
|
||||
// 如果是子系统节点,全选/取消全选其下所有零部件节点
|
||||
if (data.type === 'subsystem') {
|
||||
this.updateSubsystemChildParameters(data, permissionType)
|
||||
} else if (data.type === 'parameter') {
|
||||
// 如果是参数节点,更新其父子系统节点的权限状态
|
||||
this.updateSubsystemChildParts(data, permissionType)
|
||||
} else if (data.type === 'parts') {
|
||||
// 如果是零部件节点,更新其父子系统节点的权限状态
|
||||
this.updateSubsystemPermissionFromChildren(data)
|
||||
}
|
||||
|
||||
@ -776,32 +659,32 @@ export default {
|
||||
}
|
||||
})
|
||||
},
|
||||
// 更新子系统下所有参数的权限
|
||||
updateSubsystemChildParameters(subsystemNode, permissionType) {
|
||||
// 更新子系统下所有零部件的权限
|
||||
updateSubsystemChildParts(subsystemNode, permissionType) {
|
||||
const subsystemId = subsystemNode.id
|
||||
const newValue = subsystemNode.permissions[permissionType]
|
||||
|
||||
// 查找该子系统下的所有参数节点
|
||||
// 查找该子系统下的所有零部件节点
|
||||
Object.keys(this.nodeMap).forEach(nodeId => {
|
||||
const node = this.nodeMap[nodeId]
|
||||
if (node && node.type === 'parameter' && node.id && node.id.startsWith(subsystemId + '-param-')) {
|
||||
if (node && node.type === 'parts' && node.id && node.id.startsWith(subsystemId + '-parts-')) {
|
||||
// 确保权限对象存在
|
||||
if (!node.permissions) {
|
||||
this.$set(node, 'permissions', { view: false, edit: false })
|
||||
}
|
||||
// 更新参数节点的权限
|
||||
// 更新零部件节点的权限
|
||||
this.$set(node.permissions, permissionType, newValue)
|
||||
}
|
||||
})
|
||||
},
|
||||
// 根据子参数节点的权限状态更新子系统节点的权限状态
|
||||
updateSubsystemPermissionFromChildren(parameterNode) {
|
||||
if (!parameterNode || !parameterNode.id) {
|
||||
// 根据子零部件节点的权限状态更新子系统节点的权限状态
|
||||
updateSubsystemPermissionFromChildren(partsNode) {
|
||||
if (!partsNode || !partsNode.id) {
|
||||
return
|
||||
}
|
||||
|
||||
// 查找该参数节点的父子系统节点
|
||||
const subsystemId = parameterNode.id.split('-param-')[0]
|
||||
// 查找该零部件节点的父子系统节点
|
||||
const subsystemId = partsNode.id.split('-parts-')[0]
|
||||
const subsystemNode = this.nodeMap[subsystemId]
|
||||
|
||||
if (!subsystemNode || subsystemNode.type !== 'subsystem') {
|
||||
@ -813,26 +696,26 @@ export default {
|
||||
this.$set(subsystemNode, 'permissions', { view: false, edit: false })
|
||||
}
|
||||
|
||||
// 查找该子系统下的所有参数节点
|
||||
const childParameterNodes = []
|
||||
// 查找该子系统下的所有零部件节点
|
||||
const childPartsNodes = []
|
||||
Object.keys(this.nodeMap).forEach(nodeId => {
|
||||
const node = this.nodeMap[nodeId]
|
||||
if (node && node.type === 'parameter' && node.id && node.id.startsWith(subsystemId + '-param-')) {
|
||||
childParameterNodes.push(node)
|
||||
if (node && node.type === 'parts' && node.id && node.id.startsWith(subsystemId + '-parts-')) {
|
||||
childPartsNodes.push(node)
|
||||
}
|
||||
})
|
||||
|
||||
if (childParameterNodes.length === 0) {
|
||||
if (childPartsNodes.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// 计算查看权限状态:如果所有参数都有查看权限,则子系统也选中;如果都没有,则不选中;否则保持当前状态
|
||||
const allViewSelected = childParameterNodes.every(node => node.permissions && node.permissions.view)
|
||||
const noneViewSelected = childParameterNodes.every(node => !node.permissions || !node.permissions.view)
|
||||
// 计算查看权限状态:如果所有零部件都有查看权限,则子系统也选中;如果都没有,则不选中;否则保持当前状态
|
||||
const allViewSelected = childPartsNodes.every(node => node.permissions && node.permissions.view)
|
||||
const noneViewSelected = childPartsNodes.every(node => !node.permissions || !node.permissions.view)
|
||||
|
||||
// 计算编辑权限状态
|
||||
const allEditSelected = childParameterNodes.every(node => node.permissions && node.permissions.edit)
|
||||
const noneEditSelected = childParameterNodes.every(node => !node.permissions || !node.permissions.edit)
|
||||
const allEditSelected = childPartsNodes.every(node => node.permissions && node.permissions.edit)
|
||||
const noneEditSelected = childPartsNodes.every(node => !node.permissions || !node.permissions.edit)
|
||||
|
||||
// 更新子系统权限
|
||||
if (allViewSelected) {
|
||||
@ -945,10 +828,8 @@ export default {
|
||||
}
|
||||
// 重置所有权限复选框
|
||||
this.resetAllPermissions()
|
||||
// 确保菜单树已构建(如果还没有构建)
|
||||
if (!this.menuTreeData || this.menuTreeData.length === 0) {
|
||||
this.buildMenuTree()
|
||||
}
|
||||
// 加载树数据
|
||||
this.loadTreeData()
|
||||
// 打开弹窗(key 属性会强制重新渲染树组件)
|
||||
this.dialogVisible = true
|
||||
// 加载权限详情
|
||||
@ -973,7 +854,7 @@ export default {
|
||||
}
|
||||
this.$request(request)
|
||||
.asyncThen((resp) => {
|
||||
// 处理返回的权限数据,格式应该是数组:[{ roleId, menuName, parameterId, parameterPer, userId }]
|
||||
// 处理返回的权限数据,格式应该是数组:[{ roleId, subsystem, parameterName, parameterId, parameterPer, userId }]
|
||||
let permissions = []
|
||||
if (resp && resp.data) {
|
||||
if (Array.isArray(resp.data)) {
|
||||
@ -988,9 +869,6 @@ export default {
|
||||
// 设置权限数据
|
||||
if (permissions.length > 0) {
|
||||
this.setPermissionsFromData(permissions)
|
||||
} else {
|
||||
// 如果没有权限数据,清空待应用的权限
|
||||
this.pendingPermissions = []
|
||||
}
|
||||
})
|
||||
.asyncErrorCatch((err) => {
|
||||
@ -1427,26 +1305,28 @@ export default {
|
||||
if (node && node.permissions) {
|
||||
node.permissions.view = false
|
||||
node.permissions.edit = false
|
||||
} else if (node && (node.type === 'subsystem' || node.type === 'parameter')) {
|
||||
} else if (node && (node.type === 'subsystem' || node.type === 'parts')) {
|
||||
// 如果节点没有权限对象,创建一个
|
||||
this.$set(node, 'permissions', { view: false, edit: false })
|
||||
}
|
||||
})
|
||||
},
|
||||
// 从 menuPath 中提取第一级菜单名
|
||||
// menuPath 格式: "数据录入/模板管理" -> 提取 "模板管理"
|
||||
// 根据 menuList 中的菜单名来匹配 menuPath 中的内容
|
||||
extractMenuNameFromPath(menuPath) {
|
||||
if (!menuPath) return ''
|
||||
// 首先尝试从 menuList 中匹配
|
||||
for (const menuName of this.menuList) {
|
||||
if (menuPath.includes(menuName)) {
|
||||
return menuName
|
||||
// 同时重置树数据中的权限
|
||||
const resetNodePermissions = (nodes) => {
|
||||
if (Array.isArray(nodes)) {
|
||||
nodes.forEach(node => {
|
||||
if (node.permissions) {
|
||||
node.permissions.view = false
|
||||
node.permissions.edit = false
|
||||
} else if (node.type === 'subsystem' || node.type === 'parts') {
|
||||
this.$set(node, 'permissions', { view: false, edit: false })
|
||||
}
|
||||
if (node.children && Array.isArray(node.children)) {
|
||||
resetNodePermissions(node.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
// 如果没有匹配到,按 "/" 分割,取最后一部分作为菜单名
|
||||
const parts = menuPath.split('/')
|
||||
return parts.length > 0 ? parts[parts.length - 1].trim() : menuPath.trim()
|
||||
resetNodePermissions(this.treeData)
|
||||
},
|
||||
// 从数据设置权限
|
||||
setPermissionsFromData(permissions) {
|
||||
@ -1458,14 +1338,8 @@ export default {
|
||||
// 先重置所有权限
|
||||
this.resetAllPermissions()
|
||||
|
||||
// 保存权限数据,用于懒加载模式下延迟应用
|
||||
this.pendingPermissions = permArray
|
||||
|
||||
// 处理权限数据,提取第一级菜单名并转换权限类型
|
||||
// 处理权限数据,转换权限类型
|
||||
const processedPerms = permArray.map(perm => {
|
||||
// 根据 menuPath 提取第一级菜单名(匹配 menuList 中的菜单)
|
||||
const menuName = this.extractMenuNameFromPath(perm.menuPath || '')
|
||||
|
||||
// 处理 parameterPer:支持字符串和数字格式
|
||||
let isView = false
|
||||
let isEdit = false
|
||||
@ -1480,153 +1354,93 @@ export default {
|
||||
|
||||
return {
|
||||
...perm,
|
||||
menuName: menuName, // 提取的第一级菜单名
|
||||
view: isView,
|
||||
edit: isEdit
|
||||
}
|
||||
})
|
||||
|
||||
// 根据 menuName、subsystem、parameterName 匹配节点并设置权限(只设置已加载的节点)
|
||||
// 先按参数分组,合并同一个参数的所有权限记录
|
||||
const parameterPermMap = new Map()
|
||||
// 根据 subsystem 和 parameterName 匹配节点并设置权限
|
||||
// 先按子系统分组,再按零部件名称分组,合并同一个零部件的所有权限记录
|
||||
const subsystemPermMap = new Map()
|
||||
processedPerms.forEach(perm => {
|
||||
const key = `${perm.menuName || ''}_${perm.subsystem || ''}_${perm.parameterName || ''}`
|
||||
if (!parameterPermMap.has(key)) {
|
||||
parameterPermMap.set(key, {
|
||||
menuName: perm.menuName,
|
||||
subsystem: perm.subsystem,
|
||||
parameterName: perm.parameterName,
|
||||
const subsystem = perm.subsystem || ''
|
||||
const parameterName = perm.parameterName || ''
|
||||
|
||||
if (!subsystemPermMap.has(subsystem)) {
|
||||
subsystemPermMap.set(subsystem, new Map())
|
||||
}
|
||||
const partsPermMap = subsystemPermMap.get(subsystem)
|
||||
|
||||
// 使用 parameterName 作为零部件名称的标识
|
||||
const key = parameterName
|
||||
if (!partsPermMap.has(key)) {
|
||||
partsPermMap.set(key, {
|
||||
subsystem: subsystem,
|
||||
partsName: parameterName,
|
||||
view: false,
|
||||
edit: false
|
||||
})
|
||||
}
|
||||
const paramPerm = parameterPermMap.get(key)
|
||||
const partsPerm = partsPermMap.get(key)
|
||||
if (perm.view) {
|
||||
paramPerm.view = true
|
||||
partsPerm.view = true
|
||||
}
|
||||
if (perm.edit) {
|
||||
paramPerm.edit = true
|
||||
partsPerm.edit = true
|
||||
}
|
||||
})
|
||||
|
||||
// 设置已加载节点的权限
|
||||
parameterPermMap.forEach((paramPerm, key) => {
|
||||
subsystemPermMap.forEach((partsPermMap, subsystem) => {
|
||||
partsPermMap.forEach((partsPerm, partsName) => {
|
||||
Object.keys(this.nodeMap).forEach(nodeId => {
|
||||
const node = this.nodeMap[nodeId]
|
||||
if (node && node.type === 'parameter') {
|
||||
// 匹配第一级:menuPath 中包含第一级菜单名
|
||||
const menuMatch = paramPerm.menuName && node.menuName && paramPerm.menuName === node.menuName
|
||||
// 匹配第二级:subsystem
|
||||
const subsystemMatch = paramPerm.subsystem && node.subsystem && paramPerm.subsystem === node.subsystem
|
||||
// 匹配第三级:parameterName
|
||||
const parameterNameMatch = paramPerm.parameterName && (node.parameterName || node.label) &&
|
||||
paramPerm.parameterName === (node.parameterName || node.label)
|
||||
if (node && node.type === 'parts') {
|
||||
// 匹配子系统
|
||||
const subsystemMatch = partsPerm.subsystem && node.subsystem && partsPerm.subsystem === node.subsystem
|
||||
// 匹配零部件名称(使用 parameterName 作为零部件名称)
|
||||
const partsNameMatch = partsPerm.partsName && (node.partsName || node.label) &&
|
||||
partsPerm.partsName === (node.partsName || node.label)
|
||||
|
||||
if (menuMatch && subsystemMatch && parameterNameMatch) {
|
||||
if (subsystemMatch && partsNameMatch) {
|
||||
// 确保权限对象存在
|
||||
if (!node.permissions) {
|
||||
this.$set(node, 'permissions', { view: false, edit: false })
|
||||
}
|
||||
// 合并权限:如果已有权限,则合并(取或运算)
|
||||
const newPermissions = {
|
||||
view: node.permissions.view || paramPerm.view,
|
||||
edit: node.permissions.edit || paramPerm.edit
|
||||
view: node.permissions.view || partsPerm.view,
|
||||
edit: node.permissions.edit || partsPerm.edit
|
||||
}
|
||||
this.$set(node, 'permissions', newPermissions)
|
||||
console.log('设置已加载节点权限:', node.id, node.label, {
|
||||
menuName: node.menuName,
|
||||
console.log('设置零部件节点权限:', node.id, node.label, {
|
||||
subsystem: node.subsystem,
|
||||
parameterName: node.parameterName || node.label
|
||||
partsName: node.partsName || node.label
|
||||
}, newPermissions)
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
// 更新所有子系统权限状态
|
||||
this.$nextTick(() => {
|
||||
Object.keys(this.nodeMap).forEach(nodeId => {
|
||||
const node = this.nodeMap[nodeId]
|
||||
if (node && node.type === 'subsystem') {
|
||||
// 查找该子系统下的任意一个参数节点来触发更新
|
||||
const childParameterNode = Object.keys(this.nodeMap).find(id => {
|
||||
// 查找该子系统下的任意一个零部件节点来触发更新
|
||||
const childPartsNode = Object.keys(this.nodeMap).find(id => {
|
||||
const childNode = this.nodeMap[id]
|
||||
return childNode && childNode.type === 'parameter' && childNode.id && childNode.id.startsWith(nodeId + '-param-')
|
||||
return childNode && childNode.type === 'parts' && childNode.id && childNode.id.startsWith(nodeId + '-parts-')
|
||||
})
|
||||
if (childParameterNode) {
|
||||
this.updateSubsystemPermissionFromChildren(this.nodeMap[childParameterNode])
|
||||
if (childPartsNode) {
|
||||
this.updateSubsystemPermissionFromChildren(this.nodeMap[childPartsNode])
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
console.log('权限数据已保存,待应用权限数量:', this.pendingPermissions.length, '处理后的权限:', processedPerms)
|
||||
},
|
||||
// 将待应用的权限应用到新加载的节点
|
||||
applyPendingPermissionsToNode(node) {
|
||||
if (!node || node.type !== 'parameter' || !this.pendingPermissions || this.pendingPermissions.length === 0) {
|
||||
return
|
||||
}
|
||||
|
||||
// 查找匹配的权限数据
|
||||
const matchingPerms = this.pendingPermissions.filter(perm => {
|
||||
// 从 menuPath 中提取第一级菜单名
|
||||
const permMenuName = this.extractMenuNameFromPath(perm.menuPath || '')
|
||||
// 匹配第一级:menuPath 中包含第一级菜单名
|
||||
const menuMatch = permMenuName && node.menuName && permMenuName === node.menuName
|
||||
// 匹配第二级:subsystem
|
||||
const subsystemMatch = perm.subsystem && node.subsystem && perm.subsystem === node.subsystem
|
||||
// 匹配第三级:parameterName
|
||||
const parameterNameMatch = perm.parameterName && (node.parameterName || node.label) &&
|
||||
perm.parameterName === (node.parameterName || node.label)
|
||||
|
||||
return menuMatch && subsystemMatch && parameterNameMatch
|
||||
})
|
||||
|
||||
if (matchingPerms.length > 0) {
|
||||
// 确保权限对象存在
|
||||
if (!node.permissions) {
|
||||
this.$set(node, 'permissions', { view: false, edit: false })
|
||||
}
|
||||
|
||||
// 应用权限:parameterPer 可能是字符串 "查看" 或 "编辑",也可能是数字 1(查看)或 2(编辑)
|
||||
let hasView = false
|
||||
let hasEdit = false
|
||||
matchingPerms.forEach(perm => {
|
||||
const parameterPer = perm.parameterPer
|
||||
if (typeof parameterPer === 'string') {
|
||||
if (parameterPer === '查看') {
|
||||
hasView = true
|
||||
} else if (parameterPer === '编辑') {
|
||||
hasEdit = true
|
||||
}
|
||||
} else if (typeof parameterPer === 'number') {
|
||||
if (parameterPer === 1) {
|
||||
hasView = true
|
||||
} else if (parameterPer === 2) {
|
||||
hasEdit = true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 使用 $set 确保响应式更新,直接替换整个权限对象
|
||||
const newPermissions = {
|
||||
view: hasView,
|
||||
edit: hasEdit
|
||||
}
|
||||
// 更新 nodeMap 中的节点
|
||||
if (this.nodeMap[node.id]) {
|
||||
this.$set(this.nodeMap[node.id], 'permissions', newPermissions)
|
||||
}
|
||||
// 同时更新节点本身的权限
|
||||
this.$set(node, 'permissions', newPermissions)
|
||||
|
||||
console.log('应用权限到节点:', node.id, node.label, {
|
||||
menuName: node.menuName,
|
||||
subsystem: node.subsystem,
|
||||
parameterName: node.parameterName || node.label
|
||||
}, newPermissions, '匹配的权限:', matchingPerms)
|
||||
}
|
||||
console.log('权限数据已设置,处理后的权限:', processedPerms)
|
||||
},
|
||||
// 收集选中的权限
|
||||
collectPermissions() {
|
||||
@ -1634,48 +1448,51 @@ export default {
|
||||
const roleId = this.formData.rowId || ''
|
||||
const userId = getUserId()
|
||||
|
||||
// 收集所有参数节点的权限
|
||||
// 如果子系统权限被选中,其下所有参数都会被收集(无论参数是否单独选中)
|
||||
// 收集所有零部件节点的权限
|
||||
// 如果子系统权限被选中,其下所有零部件都会被收集(无论零部件是否单独选中)
|
||||
Object.keys(this.nodeMap).forEach(nodeId => {
|
||||
const node = this.nodeMap[nodeId]
|
||||
if (node && node.type === 'parameter') {
|
||||
if (node && node.type === 'parts') {
|
||||
// 确保权限对象存在
|
||||
const nodePermissions = node.permissions || { view: false, edit: false }
|
||||
|
||||
// 检查该参数所属的子系统权限状态
|
||||
const subsystemId = node.id.split('-param-')[0]
|
||||
// 检查该零部件所属的子系统权限状态
|
||||
const subsystemId = node.id.split('-parts-')[0]
|
||||
const subsystemNode = this.nodeMap[subsystemId]
|
||||
const subsystemPermissions = subsystemNode && subsystemNode.permissions
|
||||
? subsystemNode.permissions
|
||||
: { view: false, edit: false }
|
||||
|
||||
// 如果子系统权限被选中,或者参数本身被选中,都需要收集
|
||||
// 如果子系统权限被选中,或者零部件本身被选中,都需要收集
|
||||
const shouldCollectView = nodePermissions.view || subsystemPermissions.view
|
||||
const shouldCollectEdit = nodePermissions.edit || subsystemPermissions.edit
|
||||
|
||||
// 如果选中了查看权限,添加一条记录(parameterPer = 1)
|
||||
// 使用 partsName 作为 parameterName
|
||||
if (shouldCollectView) {
|
||||
permissions.push({
|
||||
roleId: roleId,
|
||||
menuName: node.menuName || '',
|
||||
parameterId: node.parameterId || '',
|
||||
subsystem: node.subsystem || '',
|
||||
parameterName: node.partsName || node.label || '',
|
||||
parameterId: '',
|
||||
parameterPer: 1, // 1是查看
|
||||
userId: userId
|
||||
})
|
||||
}
|
||||
// 如果选中了控制权限,添加一条记录(parameterPer = 2)
|
||||
// 如果选中了编辑权限,添加一条记录(parameterPer = 2)
|
||||
if (shouldCollectEdit) {
|
||||
permissions.push({
|
||||
roleId: roleId,
|
||||
menuName: node.menuName || '',
|
||||
parameterId: node.parameterId || '',
|
||||
parameterPer: 2, // 2是控制
|
||||
subsystem: node.subsystem || '',
|
||||
parameterName: node.partsName || node.label || '',
|
||||
parameterId: '',
|
||||
parameterPer: 2, // 2是编辑
|
||||
userId: userId
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
console.log('收集到的权限:', permissions, 'nodeMap中的参数节点数量:', Object.keys(this.nodeMap).filter(id => this.nodeMap[id] && this.nodeMap[id].type === 'parameter').length)
|
||||
console.log('收集到的权限:', permissions, 'nodeMap中的零部件节点数量:', Object.keys(this.nodeMap).filter(id => this.nodeMap[id] && this.nodeMap[id].type === 'parts').length)
|
||||
return permissions
|
||||
},
|
||||
// 关闭对话框
|
||||
@ -1688,7 +1505,6 @@ export default {
|
||||
}
|
||||
this.treeFilterText = ''
|
||||
this.resetAllPermissions()
|
||||
this.pendingPermissions = [] // 清空待应用的权限数据
|
||||
if (this.$refs.form) {
|
||||
this.$refs.form.clearValidate()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user