diff --git a/src/views/setting/rules/index.vue b/src/views/setting/rules/index.vue index 6ac9567..7a445aa 100644 --- a/src/views/setting/rules/index.vue +++ b/src/views/setting/rules/index.vue @@ -168,6 +168,7 @@ :options="personOptions" :normalizer="normalizer" placeholder="选择部门和人员" + value-consists-of="LEAF_PRIORITY" @input="handleSelect" /> @@ -601,8 +602,51 @@ export default { }); return data; }, - handleSelect(value, instanceId) { - console.log("Selected:", value); + handleSelect(selectedNodes, instanceId) { + const lastSelectedNodeId = selectedNodes[selectedNodes.length - 1] // 获取最后选择的节点 ID + const selectedNode = this.findNodeById(this.personOptions, lastSelectedNodeId) // 查找对应的节点 + if (selectedNode && selectedNode.children) { + let childIds = this.getAllIds(selectedNode.children); + // 当前选中的逻辑 ID + this.form.checkList = [...new Set([...this.form.checkList, ...childIds])]; + } else { + // 如果选择的是单个节点,则直接更新 selectedNodes + this.form.checkList = [...new Set([...this.form.checkList, ...selectedNodes])]; + } + this.form.checkList = this.form.checkList.filter(item => { + return item.indexOf('user') > -1; + }); + // console.error(this.form.checkList); + }, + findNodeById(nodes, id) { + for (const node of nodes) { + if (node.id === id) { + return node + } + if (node.children) { + const found = this.findNodeById(node.children, id) + if (found) { + return found + } + } + } + return null + }, + // 获取所有 ID + getAllIds(list) { + return this.collectIds(list); + }, + // 递归遍历树形结构并收集所有 ID + collectIds(nodes) { + let ids = []; + nodes.forEach((node) => { + ids.push(node.id); // 添加当前节点的 ID + if (node.children && node.children.length > 0) { + // 递归处理子节点 + ids = ids.concat(this.collectIds(node.children)); + } + }); + return ids; }, /** 转换部门数据结构 */ @@ -756,6 +800,7 @@ export default { this.personOptions = this.changeData(this.form.treeList); this.form.checkList = []; this.setCheck(this.form.treeList); + this.form.checkList = [...new Set([...this.form.checkList])]; // console.log(this.form) this.open = true; this.title = "编辑"; @@ -785,18 +830,20 @@ export default { this.form.attDay = arr.join(","); let arr2 = []; this.form.checkList.forEach((item) => { - if (item.indexOf("|") > -1) { + if (item.indexOf("|") > -1 && item.split('|')[0] === 'user') { let obj = { - orgId: item.split("|")[1], - userId: item.split("|")[0], + // orgId: item.split("|")[1], + // userId: item.split("|")[0], + orgId: '', + userId: item.split('|')[1] }; arr2.push(obj); } else { - let obj = { + /* let obj = { orgId: item, userId: "", - }; - arr2.push(obj); + }; */ + // arr2.push(obj); } }); this.form.checkOrgList = arr2;