fix:填写人功能

This commit is contained in:
大黑 2025-12-23 14:05:23 +08:00
parent 0b25c98276
commit df23f924e0
11 changed files with 1916 additions and 2435 deletions

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

View File

@ -20,10 +20,16 @@
<div class="header-right"> <div class="header-right">
<el-button <el-button
v-if="flowStatus === 'APPROVING'" v-if="flowStatus === 'APPROVING'"
type="primary" @click="handleReject"
@click="handleApprove"
> >
审批 退回
</el-button>
<el-button
v-if="flowStatus === 'APPROVING'"
type="primary"
@click="handleSubmit"
>
提交
</el-button> </el-button>
</div> </div>
</div> </div>
@ -156,30 +162,23 @@
<!-- 审批弹窗 --> <!-- 审批弹窗 -->
<el-dialog <el-dialog
title="审核" :title="approvalDialogTitle"
:visible.sync="approvalDialogVisible" :visible.sync="approvalDialogVisible"
width="500px" width="500px"
:close-on-click-modal="false" :close-on-click-modal="false"
append-to-body append-to-body
@close="handleApprovalDialogClose" @close="handleApprovalDialogClose"
> >
<el-form ref="approvalForm" :model="approvalFormData" label-width="80px"> <el-form ref="approvalForm" :model="approvalFormData" :rules="approvalFormRules" label-width="80px">
<el-form-item label="审核"> <el-form-item
<el-radio-group v-model="approvalFormData.result"> :label="approvalActionType === 'reject' ? '退回意见:' : '提交意见:'"
<el-radio label="PASS"> prop="opinion"
通过 >
</el-radio>
<el-radio label="REJECT">
退回
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="备注">
<el-input <el-input
v-model="approvalFormData.opinion" v-model="approvalFormData.opinion"
type="textarea" type="textarea"
:rows="4" :rows="4"
placeholder="请输入备注" :placeholder="approvalActionType === 'reject' ? '请输入退回意见' : '请输入提交意见'"
/> />
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -221,11 +220,18 @@ export default {
changeTablePageNumber: 1, changeTablePageNumber: 1,
changeTablePageSize: 10, changeTablePageSize: 10,
approvalDialogVisible: false, approvalDialogVisible: false,
approvalActionType: '', // 'reject' 'submit'
approvalDialogTitle: '审核',
approvalFormData: { approvalFormData: {
result: '', result: '',
opinion: '' opinion: ''
}, },
approvalSubmitting: false approvalSubmitting: false,
approvalFormRules: {
opinion: [
{ required: true, message: '请输入意见', trigger: 'blur' }
]
}
} }
}, },
computed: { computed: {
@ -543,9 +549,26 @@ export default {
return formattedStep return formattedStep
}) })
}, },
handleApprove() { handleReject() {
this.approvalActionType = 'reject'
this.approvalDialogTitle = '退回'
this.approvalFormData = { 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: '' opinion: ''
} }
this.approvalDialogVisible = true this.approvalDialogVisible = true
@ -558,6 +581,8 @@ export default {
}, },
handleApprovalDialogClose() { handleApprovalDialogClose() {
this.approvalDialogVisible = false this.approvalDialogVisible = false
this.approvalActionType = ''
this.approvalDialogTitle = '审核'
this.approvalFormData = { this.approvalFormData = {
result: '', result: '',
opinion: '' opinion: ''
@ -568,10 +593,10 @@ export default {
} }
}, },
handleApprovalSubmit() { handleApprovalSubmit() {
// //
if (!this.approvalFormData.result) { this.$refs.approvalForm.validate((valid) => {
this.$message.warning('请选择审核结果(通过或退回)') if (!valid) {
return return false
} }
if (!this.detail || !this.detail.flowId) { if (!this.detail || !this.detail.flowId) {
@ -611,6 +636,7 @@ export default {
.finally(() => { .finally(() => {
this.approvalSubmitting = false this.approvalSubmitting = false
}) })
})
} }
} }
} }

View File

@ -51,13 +51,13 @@
/> />
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item v-if="dispatchType !== 'update_param'" label="部门:" prop="department"> <el-form-item label="部门:" prop="department">
<el-select <el-select
v-model="formData.department" v-model="formData.department"
placeholder="请选择部门" placeholder="请选择部门"
clearable clearable
style="width: 100%" style="width: 100%"
:disabled="!formData.subsystem" :disabled="dispatchType === 'update_param' ? (!formData.subsystem || !formData.partsName) : !formData.subsystem"
@change="handleDepartmentChange" @change="handleDepartmentChange"
> >
<el-option <el-option
@ -77,22 +77,13 @@
style="width: 100%" style="width: 100%"
/> />
</el-form-item> </el-form-item>
<el-form-item v-if="dispatchType === 'update_param'" label="现填写人:"> <el-form-item :label="dispatchType === 'update_param' ? '人员:' : '责任人:'" prop="userId">
<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-select <el-select
v-model="formData.userId" v-model="formData.userId"
:placeholder="dispatchType === 'update_param' ? '请输入填写人姓名进行搜索' : '请输入责任人姓名进行搜索'" :placeholder="dispatchType === 'update_param' ? '请输入人员姓名进行搜索' : '请输入责任人姓名进行搜索'"
style="width: 100%" style="width: 100%"
clearable clearable
:disabled="dispatchType === 'update_param' ? !formData.partsName : !formData.department" :disabled="!formData.department"
filterable filterable
remote remote
reserve-keyword reserve-keyword
@ -190,19 +181,18 @@ export default {
{ required: true, message: '请选择子系统', trigger: 'change' } { required: true, message: '请选择子系统', trigger: 'change' }
], ],
userId: [ 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') { if (this.dispatchType === 'update_param') {
rules.partsName = [ rules.partsName = [
{ required: true, message: '请选择零部件名称', trigger: 'change' } { required: true, message: '请选择零部件名称', trigger: 'change' }
] ]
} else {
//
rules.department = [
{ required: true, message: '请选择部门', trigger: 'change' }
]
} }
return rules return rules
} }
@ -355,8 +345,8 @@ export default {
partsNameSet.add(paramPartsName) partsNameSet.add(paramPartsName)
} }
} }
// //
if (this.dispatchType !== 'update_param' && param.department) { if (param.department) {
departmentSet.add(param.department) departmentSet.add(param.department)
} }
} }
@ -371,11 +361,10 @@ export default {
partsNamesArray.unshift('/') partsNamesArray.unshift('/')
} }
this.availablePartsNames = partsNamesArray this.availablePartsNames = partsNamesArray
} //
this.availableDepartments = []
// } else {
if (this.dispatchType !== 'update_param') { //
//
this.availableDepartments = Array.from(departmentSet).map((dept) => ({ this.availableDepartments = Array.from(departmentSet).map((dept) => ({
department: dept department: dept
})) }))
@ -387,32 +376,29 @@ export default {
}, },
// //
handlePartsNameChange(partsName) { handlePartsNameChange(partsName) {
// //
this.formData.department = ''
this.formData.currentFillerId = '' this.formData.currentFillerId = ''
this.formData.currentFillerName = '' this.formData.currentFillerName = ''
this.formData.userId = '' this.formData.userId = ''
this.formData.userNumber = '' this.formData.userNumber = ''
this.formData.username = '' this.formData.username = ''
this.availableDepartments = []
this.userOptions = [] this.userOptions = []
// //
if (partsName && this.formData.subsystem) { if (partsName && this.formData.subsystem) {
this.findCurrentFiller() this.filterDepartmentsByPartsName()
} else {
this.formData.currentFillerId = ''
this.formData.currentFillerName = ''
} }
}, },
// //
findCurrentFiller() { filterDepartmentsByPartsName() {
if (!this.formData.subsystem || !this.formData.partsName) { if (!this.formData.subsystem || !this.formData.partsName) {
this.formData.currentFillerId = '' this.availableDepartments = []
this.formData.currentFillerName = ''
return return
} }
// versionData
const currentVersionData = this.versionData[this.currentVersionId] || {} const currentVersionData = this.versionData[this.currentVersionId] || {}
let foundFiller = null const departmentSet = new Set()
// partsName // partsName
Object.keys(currentVersionData).forEach((dataPartsName) => { Object.keys(currentVersionData).forEach((dataPartsName) => {
@ -424,36 +410,17 @@ export default {
if ( if (
param.subsystemName === this.formData.subsystem && param.subsystemName === this.formData.subsystem &&
paramPartsName === this.formData.partsName && paramPartsName === this.formData.partsName &&
param.filledByUserId param.department
) { ) {
// 使 departmentSet.add(param.department)
if (!foundFiller) {
foundFiller = {
userId: param.filledByUserId,
username: param.filledBy || ''
}
}
} }
}) })
}) })
if (foundFiller) { //
// fillerPersons this.availableDepartments = Array.from(departmentSet).map((dept) => ({
const fillerPerson = this.fillerPersons.find( department: dept
(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 = ''
}
}, },
// //
handleDepartmentChange(department) { handleDepartmentChange(department) {
@ -494,19 +461,11 @@ export default {
}, },
// / // /
handleRemoteSearch(query) { handleRemoteSearch(query) {
// //
if (this.dispatchType === 'update_param') {
if (!this.formData.partsName) {
this.userOptions = []
return
}
} else {
//
if (!this.formData.department) { if (!this.formData.department) {
this.userOptions = [] this.userOptions = []
return return
} }
}
if (!query || query.trim() === '') { if (!query || query.trim() === '') {
if (this.formData.userId) { if (this.formData.userId) {
const selectedOptions = this.userOptions.filter((opt) => opt.userId === this.formData.userId) const selectedOptions = this.userOptions.filter((opt) => opt.userId === this.formData.userId)
@ -609,7 +568,7 @@ export default {
return return
} }
if (!this.formData.userId) { if (!this.formData.userId) {
const fieldName = this.dispatchType === 'update_param' ? '填写人' : '责任人' const fieldName = this.dispatchType === 'update_param' ? '' : '责任人'
this.$message.warning(`请选择${fieldName}`) this.$message.warning(`请选择${fieldName}`)
return return
} }
@ -626,6 +585,7 @@ export default {
const confirmData = { const confirmData = {
subsystem: this.formData.subsystem, subsystem: this.formData.subsystem,
partsName: this.formData.partsName, partsName: this.formData.partsName,
department: this.formData.department,
userId: this.formData.userId, // userId userId: this.formData.userId, // userId
userNumber: this.formData.userNumber || this.formData.userId, // userNumber使 userId userNumber: this.formData.userNumber || this.formData.userId, // userNumber使 userId
username: this.formData.username || '' username: this.formData.username || ''

View File

@ -19,8 +19,11 @@
</div> </div>
</div> </div>
<div class="header-right"> <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> </el-button>
</div> </div>
</div> </div>
@ -137,7 +140,7 @@
<!-- 审批弹窗 --> <!-- 审批弹窗 -->
<el-dialog <el-dialog
title="审批" :title="approvalDialogTitle"
:visible.sync="approvalDialogVisible" :visible.sync="approvalDialogVisible"
width="500px" width="500px"
:close-on-click-modal="false" :close-on-click-modal="false"
@ -150,22 +153,15 @@
:rules="approvalFormRules" :rules="approvalFormRules"
label-width="80px" label-width="80px"
> >
<el-form-item label="审批结果" prop="operator"> <el-form-item
<el-radio-group v-model="approvalFormData.operator"> :label="approvalActionType === 'reject' ? '退回意见:' : '提交意见:'"
<el-radio label="同意"> prop="comment"
同意 >
</el-radio>
<el-radio label="拒绝">
拒绝
</el-radio>
</el-radio-group>
</el-form-item>
<el-form-item label="说明" prop="comment">
<el-input <el-input
v-model="approvalFormData.comment" v-model="approvalFormData.comment"
type="textarea" type="textarea"
:rows="4" :rows="4"
placeholder="请输入审批说明" :placeholder="approvalActionType === 'reject' ? '请输入退回意见' : '请输入提交意见'"
/> />
</el-form-item> </el-form-item>
</el-form> </el-form>
@ -214,6 +210,8 @@ export default {
changeTablePageSize: 10, changeTablePageSize: 10,
activitiRecordDTOS: [], // activitiRecordDTOS: [], //
approvalDialogVisible: false, approvalDialogVisible: false,
approvalActionType: '', // 'reject' 'submit'
approvalDialogTitle: '审批',
approvalFormData: { approvalFormData: {
operator: '同意', operator: '同意',
comment: '' comment: ''
@ -329,8 +327,7 @@ export default {
}, },
approvalFormRules() { approvalFormRules() {
return { 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() { handleBack() {
this.$emit('close') 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 = { this.approvalFormData = {
operator: '同意', operator: '同意',
comment: '' comment: ''
@ -589,7 +602,10 @@ export default {
handleApprovalSubmit() { handleApprovalSubmit() {
// //
this.$refs.approvalForm.validate((valid) => { this.$refs.approvalForm.validate((valid) => {
if (valid) { if (!valid) {
return false
}
if (!this.detail || !this.detail.id) { if (!this.detail || !this.detail.id) {
this.$message.error('缺少审批数据') this.$message.error('缺少审批数据')
return return
@ -602,8 +618,8 @@ export default {
} }
// //
// """PASS""""REJECT" // operator退 'REJECT' 'PASS'
const operator = this.approvalFormData.operator === '同意' ? 'PASS' : 'REJECT' const operator = this.approvalActionType === 'reject' ? 'REJECT' : 'PASS'
const submitData = { const submitData = {
approvalId: approvalId, approvalId: approvalId,
operator: operator, operator: operator,
@ -622,22 +638,28 @@ export default {
.asyncThen((resp) => { .asyncThen((resp) => {
console.log('审批提交成功') console.log('审批提交成功')
this.approvalDialogVisible = false this.handleApprovalDialogClose()
this.approvalSubmitting = false
// //
this.getApprovalDetail() this.getApprovalDetail()
//
this.$emit('refresh')
this.approvalSubmitting = false
}) })
.asyncErrorCatch((err) => { .asyncErrorCatch((err) => {
console.error('审批提交失败:', err) console.error('审批提交失败:', err)
this.$message.error(err.message || '审批提交失败,请重试') this.$message.error(err.message || '审批提交失败,请重试')
this.approvalSubmitting = false this.approvalSubmitting = false
}) })
} .finally(() => {
this.approvalSubmitting = false
})
}) })
}, },
handleApprovalDialogClose() { handleApprovalDialogClose() {
// //
this.approvalDialogVisible = false this.approvalDialogVisible = false
this.approvalActionType = ''
this.approvalDialogTitle = '审批'
this.approvalFormData = { this.approvalFormData = {
operator: '同意', operator: '同意',
comment: '' comment: ''

View File

@ -88,14 +88,14 @@
clearable clearable
class="tree-search" class="tree-search"
></el-input> ></el-input>
<div class="tree-actions"> <!-- <div class="tree-actions">
<el-button size="mini" @click="handleExpandAllSecondLevel"> <el-button size="mini" @click="handleExpandAllSecondLevel">
一键展开 一键展开
</el-button> </el-button>
<el-button size="mini" @click="handleCollapseAllSecondLevel"> <el-button size="mini" @click="handleCollapseAllSecondLevel">
一键收起 一键收起
</el-button> </el-button>
</div> </div> -->
<el-tree <el-tree
ref="paramTree" ref="paramTree"
:data="treeData" :data="treeData"
@ -1450,9 +1450,9 @@ export default {
// //
if (this.dispatchType === 'update_param') { if (this.dispatchType === 'update_param') {
const { subsystem, partsName, userId, userNumber, username } = change const { subsystem, partsName, department, userId, userNumber, username } = change
console.log(change, 'change', subsystem, partsName, userId, userNumber, username) console.log(change, 'change', subsystem, partsName, department, userId, userNumber, username)
if (!subsystem || !partsName || !userId) { if (!subsystem || !partsName || !department || !userId) {
this.$message({ this.$message({
type: 'warning', type: 'warning',
message: '缺少必要参数' message: '缺少必要参数'
@ -1480,11 +1480,12 @@ export default {
// 使param.partsName使dataPartsName // 使param.partsName使dataPartsName
const paramPartsName = param.partsName || dataPartsName const paramPartsName = param.partsName || dataPartsName
// //
// partsName '/' partsName '/' // partsName '/' partsName '/'
if ( if (
param.subsystemName === subsystem && param.subsystemName === subsystem &&
paramPartsName === partsName paramPartsName === partsName &&
param.department === department
) { ) {
// //
param.filledBy = userId // IDuserId param.filledBy = userId // IDuserId

View File

@ -49,14 +49,14 @@
下载导入模板 下载导入模板
</el-button> </el-button>
<el-button <el-button
v-if="shouldShowButtons"
class="right-button" class="right-button"
@click="handleMaintainParams" @click="handleMaintainParams"
> >
维护参数 维护参数
</el-button> </el-button>
<el-button <el-button
v-if="shouldShowButtonsNew"
class="right-button-primary" class="right-button-primary"
type="primary" type="primary"
@click="handleInitiateApproval" @click="handleInitiateApproval"

View File

@ -120,23 +120,18 @@
<el-tree <el-tree
ref="permissionTree" ref="permissionTree"
:key="'permission-tree-' + dialogVisible" :key="'permission-tree-' + dialogVisible"
:data="[]" :data="treeData"
node-key="id" node-key="id"
:props="{ children: 'children', label: 'label', isLeaf: 'isLeaf' }" :props="{ children: 'children', label: 'label' }"
:filter-node-method="filterTreeNode" :filter-node-method="filterTreeNode"
:default-expand-all="false" :default-expand-all="false"
:lazy="true"
:load="loadNode"
class="permission-tree" class="permission-tree"
> >
<span slot-scope="{ node, data }" class="custom-tree-node"> <span slot-scope="{ node, data }" class="custom-tree-node">
<span class="node-label"> <span class="node-label">
{{ 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>
<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 <el-checkbox
v-model="data.permissions.view" v-model="data.permissions.view"
size="small" size="small"
@ -335,7 +330,7 @@ export default {
formData: { formData: {
roleName: '', roleName: '',
rowId: '', rowId: '',
permissions: [] // [{ menuId, menuName, subsystem, parameter, view, edit }] permissions: [] // [{ roleId, subsystem, parameterName, parameterId, parameterPer, userId }]
}, },
formRules: { formRules: {
roleName: [ roleName: [
@ -362,21 +357,11 @@ export default {
{ required: true, message: '请输入角色描述', trigger: 'blur' } { required: true, message: '请输入角色描述', trigger: 'blur' }
] ]
}, },
// // ->
menuTreeData: [], treeData: [],
//
subsystemList: [],
treeFilterText: '', treeFilterText: '',
// //
nodeMap: {}, nodeMap: {},
//
pendingPermissions: [],
//
menuList: [
'模板管理',
'玉柴发动机数据',
'竞品发动机数据'
],
// //
personConfigDialogVisible: false, personConfigDialogVisible: false,
personConfigSubmitting: false, personConfigSubmitting: false,
@ -442,31 +427,6 @@ export default {
computed: { computed: {
dialogTitle() { dialogTitle() {
return this.dialogMode === 'add' ? '新增' : '修改' 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: { watch: {
@ -476,7 +436,6 @@ export default {
}, },
mounted() { mounted() {
this.loadPermissionData() this.loadPermissionData()
this.loadParamList()
this.loadDepartmentList() this.loadDepartmentList()
this.getUserSelfRole() this.getUserSelfRole()
}, },
@ -507,9 +466,11 @@ export default {
}, },
// //
validatePermissions(rule, value, callback) { validatePermissions(rule, value, callback) {
// //
const hasParameterPermission = this.allParameterNodes.some(node => { const hasPartsPermission = Object.keys(this.nodeMap).some(nodeId => {
return node.permissions.view || node.permissions.edit 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) (node.permissions.view || node.permissions.edit)
}) })
if (!hasParameterPermission && !hasSubsystemPermission) { if (!hasPartsPermission && !hasSubsystemPermission) {
callback(new Error('请至少分配一个权限')) callback(new Error('请至少分配一个权限'))
} else { } else {
callback() callback()
} }
}, },
// // ->
loadParamList() { loadTreeData() {
const request = { const request = {
...api.GET_ALL_SYSTEM_ROLE_LIST, ...api.GET_ENGINE_DETAIL_QUERY,
disableSuccessMsg: true disableSuccessMsg: true
} }
this.$request(request) this.$request(request)
.asyncThen((resp) => { .asyncThen((resp) => {
//
if (resp && resp.data) { if (resp && resp.data) {
// // { "": ["1", "2", ...] }
let subsystemList = [] const data = resp.data
if (Array.isArray(resp.data)) { let treeDataResult = []
subsystemList = resp.data if (typeof data === 'object' && !Array.isArray(data)) {
} else if (typeof resp.data === 'object') { treeDataResult = this.convertObjectToTree(data)
// { result: [...] } { data: [...] } } else if (Array.isArray(data)) {
subsystemList = resp.data.result || resp.data.data || Object.keys(resp.data) || [] //
} treeDataResult = this.formatTreeData(data)
//
this.subsystemList = subsystemList
} else { } else {
this.subsystemList = [] treeDataResult = []
}
this.treeData = treeDataResult
} else {
this.treeData = []
} }
this.buildMenuTree()
}) })
.asyncErrorCatch((err) => { .asyncErrorCatch((err) => {
console.error('加载子系统列表失败:', err) console.error('获取树数据失败:', err)
this.subsystemList = [] this.$message.error('获取树数据失败')
this.buildMenuTree() this.treeData = []
}) })
}, },
// -> //
// // : { "": ["1", "2", ...] }
buildMenuTree() { convertObjectToTree(data) {
//
this.nodeMap = {}
//
// 6 -> ->
const treeData = [] const treeData = []
this.nodeMap = {} //
// 使 Object.keys(data).forEach((subsystemName, subsystemIdx) => {
this.menuList.forEach((menuName, menuIdx) => { const subsystemId = `subsystem-${subsystemIdx}`
const menuId = `menu-${menuIdx}` const children = []
const menuNode = { const seenLabels = new Set() // label
id: menuId,
label: menuName, //
type: 'menu', this.nodeMap[subsystemId] = {
children: null, // null id: subsystemId,
isLeaf: false // el-tree label: subsystemName,
type: 'subsystem',
subsystem: subsystemName,
permissions: {
view: false,
edit: false
}
} }
// // label `/`
this.nodeMap[menuId] = menuNode if (Array.isArray(data[subsystemName])) {
treeData.push(menuNode) 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) { filterTreeNode(value, data) {
if (!value) return true if (!value) return true
return data.label && data.label.indexOf(value) !== -1 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) { handlePermissionChange(data, permissionType) {
// //
@ -761,11 +644,11 @@ export default {
this.$set(this.nodeMap[data.id].permissions, permissionType, data.permissions[permissionType]) this.$set(this.nodeMap[data.id].permissions, permissionType, data.permissions[permissionType])
} }
// / // /
if (data.type === 'subsystem') { if (data.type === 'subsystem') {
this.updateSubsystemChildParameters(data, permissionType) this.updateSubsystemChildParts(data, permissionType)
} else if (data.type === 'parameter') { } else if (data.type === 'parts') {
// //
this.updateSubsystemPermissionFromChildren(data) this.updateSubsystemPermissionFromChildren(data)
} }
@ -776,32 +659,32 @@ export default {
} }
}) })
}, },
// //
updateSubsystemChildParameters(subsystemNode, permissionType) { updateSubsystemChildParts(subsystemNode, permissionType) {
const subsystemId = subsystemNode.id const subsystemId = subsystemNode.id
const newValue = subsystemNode.permissions[permissionType] const newValue = subsystemNode.permissions[permissionType]
// //
Object.keys(this.nodeMap).forEach(nodeId => { Object.keys(this.nodeMap).forEach(nodeId => {
const node = this.nodeMap[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) { if (!node.permissions) {
this.$set(node, 'permissions', { view: false, edit: false }) this.$set(node, 'permissions', { view: false, edit: false })
} }
// //
this.$set(node.permissions, permissionType, newValue) this.$set(node.permissions, permissionType, newValue)
} }
}) })
}, },
// //
updateSubsystemPermissionFromChildren(parameterNode) { updateSubsystemPermissionFromChildren(partsNode) {
if (!parameterNode || !parameterNode.id) { if (!partsNode || !partsNode.id) {
return return
} }
// //
const subsystemId = parameterNode.id.split('-param-')[0] const subsystemId = partsNode.id.split('-parts-')[0]
const subsystemNode = this.nodeMap[subsystemId] const subsystemNode = this.nodeMap[subsystemId]
if (!subsystemNode || subsystemNode.type !== 'subsystem') { if (!subsystemNode || subsystemNode.type !== 'subsystem') {
@ -813,26 +696,26 @@ export default {
this.$set(subsystemNode, 'permissions', { view: false, edit: false }) this.$set(subsystemNode, 'permissions', { view: false, edit: false })
} }
// //
const childParameterNodes = [] const childPartsNodes = []
Object.keys(this.nodeMap).forEach(nodeId => { Object.keys(this.nodeMap).forEach(nodeId => {
const node = this.nodeMap[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-')) {
childParameterNodes.push(node) childPartsNodes.push(node)
} }
}) })
if (childParameterNodes.length === 0) { if (childPartsNodes.length === 0) {
return return
} }
// //
const allViewSelected = childParameterNodes.every(node => node.permissions && node.permissions.view) const allViewSelected = childPartsNodes.every(node => node.permissions && node.permissions.view)
const noneViewSelected = childParameterNodes.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 allEditSelected = childPartsNodes.every(node => node.permissions && node.permissions.edit)
const noneEditSelected = childParameterNodes.every(node => !node.permissions || !node.permissions.edit) const noneEditSelected = childPartsNodes.every(node => !node.permissions || !node.permissions.edit)
// //
if (allViewSelected) { if (allViewSelected) {
@ -945,10 +828,8 @@ export default {
} }
// //
this.resetAllPermissions() this.resetAllPermissions()
// //
if (!this.menuTreeData || this.menuTreeData.length === 0) { this.loadTreeData()
this.buildMenuTree()
}
// key // key
this.dialogVisible = true this.dialogVisible = true
// //
@ -973,7 +854,7 @@ export default {
} }
this.$request(request) this.$request(request)
.asyncThen((resp) => { .asyncThen((resp) => {
// [{ roleId, menuName, parameterId, parameterPer, userId }] // [{ roleId, subsystem, parameterName, parameterId, parameterPer, userId }]
let permissions = [] let permissions = []
if (resp && resp.data) { if (resp && resp.data) {
if (Array.isArray(resp.data)) { if (Array.isArray(resp.data)) {
@ -988,9 +869,6 @@ export default {
// //
if (permissions.length > 0) { if (permissions.length > 0) {
this.setPermissionsFromData(permissions) this.setPermissionsFromData(permissions)
} else {
//
this.pendingPermissions = []
} }
}) })
.asyncErrorCatch((err) => { .asyncErrorCatch((err) => {
@ -1427,26 +1305,28 @@ export default {
if (node && node.permissions) { if (node && node.permissions) {
node.permissions.view = false node.permissions.view = false
node.permissions.edit = 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 }) this.$set(node, 'permissions', { view: false, edit: false })
} }
}) })
}, //
// menuPath const resetNodePermissions = (nodes) => {
// menuPath : "/" -> "" if (Array.isArray(nodes)) {
// menuList menuPath nodes.forEach(node => {
extractMenuNameFromPath(menuPath) { if (node.permissions) {
if (!menuPath) return '' node.permissions.view = false
// menuList node.permissions.edit = false
for (const menuName of this.menuList) { } else if (node.type === 'subsystem' || node.type === 'parts') {
if (menuPath.includes(menuName)) { this.$set(node, 'permissions', { view: false, edit: false })
return menuName }
if (node.children && Array.isArray(node.children)) {
resetNodePermissions(node.children)
}
})
} }
} }
// "/" resetNodePermissions(this.treeData)
const parts = menuPath.split('/')
return parts.length > 0 ? parts[parts.length - 1].trim() : menuPath.trim()
}, },
// //
setPermissionsFromData(permissions) { setPermissionsFromData(permissions) {
@ -1458,14 +1338,8 @@ export default {
// //
this.resetAllPermissions() this.resetAllPermissions()
// //
this.pendingPermissions = permArray
//
const processedPerms = permArray.map(perm => { const processedPerms = permArray.map(perm => {
// menuPath menuList
const menuName = this.extractMenuNameFromPath(perm.menuPath || '')
// parameterPer // parameterPer
let isView = false let isView = false
let isEdit = false let isEdit = false
@ -1480,153 +1354,93 @@ export default {
return { return {
...perm, ...perm,
menuName: menuName, //
view: isView, view: isView,
edit: isEdit edit: isEdit
} }
}) })
// menuNamesubsystemparameterName // subsystem parameterName
// //
const parameterPermMap = new Map() const subsystemPermMap = new Map()
processedPerms.forEach(perm => { processedPerms.forEach(perm => {
const key = `${perm.menuName || ''}_${perm.subsystem || ''}_${perm.parameterName || ''}` const subsystem = perm.subsystem || ''
if (!parameterPermMap.has(key)) { const parameterName = perm.parameterName || ''
parameterPermMap.set(key, {
menuName: perm.menuName, if (!subsystemPermMap.has(subsystem)) {
subsystem: perm.subsystem, subsystemPermMap.set(subsystem, new Map())
parameterName: perm.parameterName, }
const partsPermMap = subsystemPermMap.get(subsystem)
// 使 parameterName
const key = parameterName
if (!partsPermMap.has(key)) {
partsPermMap.set(key, {
subsystem: subsystem,
partsName: parameterName,
view: false, view: false,
edit: false edit: false
}) })
} }
const paramPerm = parameterPermMap.get(key) const partsPerm = partsPermMap.get(key)
if (perm.view) { if (perm.view) {
paramPerm.view = true partsPerm.view = true
} }
if (perm.edit) { 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 => { Object.keys(this.nodeMap).forEach(nodeId => {
const node = this.nodeMap[nodeId] const node = this.nodeMap[nodeId]
if (node && node.type === 'parameter') { if (node && node.type === 'parts') {
// menuPath //
const menuMatch = paramPerm.menuName && node.menuName && paramPerm.menuName === node.menuName const subsystemMatch = partsPerm.subsystem && node.subsystem && partsPerm.subsystem === node.subsystem
// subsystem // 使 parameterName
const subsystemMatch = paramPerm.subsystem && node.subsystem && paramPerm.subsystem === node.subsystem const partsNameMatch = partsPerm.partsName && (node.partsName || node.label) &&
// parameterName partsPerm.partsName === (node.partsName || node.label)
const parameterNameMatch = paramPerm.parameterName && (node.parameterName || node.label) &&
paramPerm.parameterName === (node.parameterName || node.label)
if (menuMatch && subsystemMatch && parameterNameMatch) { if (subsystemMatch && partsNameMatch) {
// //
if (!node.permissions) { if (!node.permissions) {
this.$set(node, 'permissions', { view: false, edit: false }) this.$set(node, 'permissions', { view: false, edit: false })
} }
// //
const newPermissions = { const newPermissions = {
view: node.permissions.view || paramPerm.view, view: node.permissions.view || partsPerm.view,
edit: node.permissions.edit || paramPerm.edit edit: node.permissions.edit || partsPerm.edit
} }
this.$set(node, 'permissions', newPermissions) this.$set(node, 'permissions', newPermissions)
console.log('设置已加载节点权限:', node.id, node.label, { console.log('设置零部件节点权限:', node.id, node.label, {
menuName: node.menuName,
subsystem: node.subsystem, subsystem: node.subsystem,
parameterName: node.parameterName || node.label partsName: node.partsName || node.label
}, newPermissions) }, newPermissions)
} }
} }
}) })
}) })
})
// //
this.$nextTick(() => { this.$nextTick(() => {
Object.keys(this.nodeMap).forEach(nodeId => { Object.keys(this.nodeMap).forEach(nodeId => {
const node = this.nodeMap[nodeId] const node = this.nodeMap[nodeId]
if (node && node.type === 'subsystem') { 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] 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) { if (childPartsNode) {
this.updateSubsystemPermissionFromChildren(this.nodeMap[childParameterNode]) this.updateSubsystemPermissionFromChildren(this.nodeMap[childPartsNode])
} }
} }
}) })
}) })
console.log('权限数据已保存,待应用权限数量:', this.pendingPermissions.length, '处理后的权限:', processedPerms) console.log('权限数据已设置,处理后的权限:', 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)
}
}, },
// //
collectPermissions() { collectPermissions() {
@ -1634,48 +1448,51 @@ export default {
const roleId = this.formData.rowId || '' const roleId = this.formData.rowId || ''
const userId = getUserId() const userId = getUserId()
// //
// //
Object.keys(this.nodeMap).forEach(nodeId => { Object.keys(this.nodeMap).forEach(nodeId => {
const node = this.nodeMap[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 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 subsystemNode = this.nodeMap[subsystemId]
const subsystemPermissions = subsystemNode && subsystemNode.permissions const subsystemPermissions = subsystemNode && subsystemNode.permissions
? subsystemNode.permissions ? subsystemNode.permissions
: { view: false, edit: false } : { view: false, edit: false }
// //
const shouldCollectView = nodePermissions.view || subsystemPermissions.view const shouldCollectView = nodePermissions.view || subsystemPermissions.view
const shouldCollectEdit = nodePermissions.edit || subsystemPermissions.edit const shouldCollectEdit = nodePermissions.edit || subsystemPermissions.edit
// parameterPer = 1 // parameterPer = 1
// 使 partsName parameterName
if (shouldCollectView) { if (shouldCollectView) {
permissions.push({ permissions.push({
roleId: roleId, roleId: roleId,
menuName: node.menuName || '', subsystem: node.subsystem || '',
parameterId: node.parameterId || '', parameterName: node.partsName || node.label || '',
parameterId: '',
parameterPer: 1, // 1 parameterPer: 1, // 1
userId: userId userId: userId
}) })
} }
// parameterPer = 2 // parameterPer = 2
if (shouldCollectEdit) { if (shouldCollectEdit) {
permissions.push({ permissions.push({
roleId: roleId, roleId: roleId,
menuName: node.menuName || '', subsystem: node.subsystem || '',
parameterId: node.parameterId || '', parameterName: node.partsName || node.label || '',
parameterPer: 2, // 2 parameterId: '',
parameterPer: 2, // 2
userId: userId 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 return permissions
}, },
// //
@ -1688,7 +1505,6 @@ export default {
} }
this.treeFilterText = '' this.treeFilterText = ''
this.resetAllPermissions() this.resetAllPermissions()
this.pendingPermissions = [] //
if (this.$refs.form) { if (this.$refs.form) {
this.$refs.form.clearValidate() this.$refs.form.clearValidate()
} }