From 638ecb9bb2b6a1866b36d6c9e997021d49e93c42 Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Tue, 23 Feb 2021 10:32:53 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=A7=A3=E5=86=B3=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E6=9C=BA=E6=9E=84=E6=A0=91=E6=87=92=E5=8A=A0=E8=BD=BD=E5=9B=9E?= =?UTF-8?q?=E6=98=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/components/settings/sys/dept.vue | 74 +++++++++++++++++-- 1 file changed, 67 insertions(+), 7 deletions(-) diff --git a/frontend/src/business/components/settings/sys/dept.vue b/frontend/src/business/components/settings/sys/dept.vue index 14ca915d61..13026b9144 100644 --- a/frontend/src/business/components/settings/sys/dept.vue +++ b/frontend/src/business/components/settings/sys/dept.vue @@ -87,7 +87,7 @@ :load-options="loadDepts" :options="depts" style="width: 370px;" - placeholder="选择上级类目" + placeholder="选择上级类目" /> @@ -139,9 +139,8 @@ export default { data() { return { rootNodeLoaded: false, - depts:null, - formType:"add", - + depts: null, + formType: "add", queryPath: '/api/dept/childNodes', deletePath: '/api/dept/delete', createPath: '/api/dept/create', @@ -184,17 +183,51 @@ export default { this.formType = "modify"; this.oldPid = row.pid; this.form = Object.assign({}, row); - // this.treeByRow(row); + this.treeByRow(row); listenGoBack(this.closeFunc); }, treeByRow(row){ !this.depts && (this.depts = []) - if (!this.depts.some(node => node.id==row.deptId)) { - this.depts.push(this.normalizer(row)); + if (!this.depts.some(node => node.id==row.pid) && row.pid!=0) { + const arr = this.mapToArray(); + const ids = arr.map(item => item.id); + const tempTreeNodes = this.treeByArr(arr); + const pnodes = this.tableData.filter(node => (node.pid==0) && (ids.indexOf(node.deptId)==-1)).map(node => this.normalizer(node)) + const showNodes = tempTreeNodes.concat(pnodes) + this.depts = this.depts.concat(showNodes); } }, + mapToArray() { + const result = new Array(); + + this.maps.forEach((value, key) => { + if(value.hasOwnProperty('row')){ + result.push(this.editNormalizer(value.row)) + } + }) + return result; + }, + treeByArr(arr){ + if(!Array.isArray(arr) || !arr.length) return; + let map = {}; + arr.forEach(item => map[item.id] = item); + + let roots = []; + arr.forEach(item => { + const parent = map[item.pid]; + if(parent){ + (parent.children || (parent.children=[])).push(item); + } + else{ + roots.push(item); + } + }) + return roots; + + }, + initTableData(row, treeNode, resolve) { let _self = this; @@ -222,6 +255,7 @@ export default { this.initTableData(); this.form = {}; this.oldPid = null; + this.depts = null; removeGoBackListener(this.closeFunc); this.dialogOrgAddVisible = false; @@ -258,6 +292,14 @@ export default { children:node.children } }, + editNormalizer(node) { + return { + id: node.deptId, + pid: node.pid, + label: node.name, + children: node.children + } + }, // 改变状态 changeEnabled(data, val) { this.$confirm('此操作将 "停用" ' + data.name + '部门, 是否继续?', '提示', { @@ -324,7 +366,25 @@ export default { this.$set(this.$refs.table.store.states.lazyTreeNodeMap, pid, []); this.initTableData(row, treeNode, resolve); } + }, + array2Tree(arr){ + if(!Array.isArray(arr) || !arr.length) return; + let map = {}; + arr.forEach(item => map[item.id] = item); + + let roots = []; + arr.forEach(item => { + const parent = map[item.pid]; + if(parent){ + (parent.children || (parent.children=[])).push(item); + } + else{ + roots.push(item); + } + }) + return roots; } + } }