From d5d39e40736b3b07cfba1773c7ea5b237f9a3d0b Mon Sep 17 00:00:00 2001
From: sunFlower <787203167@qq.com>
Date: Sun, 9 Oct 2022 09:49:31 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=A6=85=E9=81=93=E5=B7=B2?=
=?UTF-8?q?=E7=9F=A5bug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../components/PersonnelSelection/index.vue | 608 ++++++++++--------
.../components/virtualNodeTree/mixin/node.js | 9 +-
.../virtualNodeTree/model/tree-store.js | 1 -
.../virtualNodeTree/tree-virtual-node.vue | 4 +-
4 files changed, 329 insertions(+), 293 deletions(-)
diff --git a/jero-web/src/components/PersonnelSelection/index.vue b/jero-web/src/components/PersonnelSelection/index.vue
index 43b6f4b88..3d8bc49f8 100644
--- a/jero-web/src/components/PersonnelSelection/index.vue
+++ b/jero-web/src/components/PersonnelSelection/index.vue
@@ -32,40 +32,39 @@
v-model="searchModel" @search="onSearch"/>
{{$t('dataLoading')}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ ref="virtualNodeTreeRef"
+ :keeps="40"
+ show-checkbox
+ v-model="checkboxList"
+ class="treeWrap"
+ :defaultCheckedKeys="defaultCheckedKeys"
+ :defaultExpandAll="defaultExpandAll"
+ :check-strictly="false"
+ node-key="id"
+ @check="handleCheckChange"
+ @check-change="checkChange"
+ :data.sync="gData">
+
+
+ {{ data.title }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
{{$t('cancel')}}
@@ -107,109 +106,145 @@
defaultCheckedKeysName: [],
content: [],
dataList: [],
- defaultExpandAll: false
+ defaultExpandAll: false,
+ searchData: ''
}
},
mounted() {
},
methods: {
- // handleCheckChange(val, checked, indeterminate) {
- // if (checked) {
- // this.userName.push(val.title)
- // this.userIds.push(val.id)
- // } else {
- // for (let i = 0; i < this.userName.length; i++) {
- // if (this.userName[i] == val.title) {
- // this.userName.splice(i, 1)
- // i--
- // }
- // }
- // for (let i = 0; i < this.userIds.length; i++) {
- // if (this.userIds[i] == val.id) {
- // this.userIds.splice(i, 1)
- // i--
- // }
- // }
- // }
- // },
+ checkChange(val, checked, indeterminate) {
+ if (!checked && this.searchData) {
+ this.userName = this.userName.filter(res => {
+ return res != val.title
+ })
+ this.userIds = this.userIds.filter(res => {
+ return res != val.id
+ })
+ for (let i = 0; i < this.userIds.length; i++) {
+ if (this.userIds[i] == val.parentId) {
+ this.userIds.splice(i, 1)
+ this.userName.splice(i, 1)
+ i--
+ }
+ }
+ } else if (checked && this.searchData) {
+ this.userName.push(val.title)
+ this.userIds.push(val.id)
+ }
+ },
+ handleCheckChange(val, data, checked) {
+ if (!this.searchData) {
+ this.userName = []
+ this.userIds = []
+ if (data.checkedNodes && data.checkedNodes.length > 0) {
+ data.checkedNodes.forEach(res => {
+ this.userName.push(res.title)
+ this.userIds.push(res.id)
+ })
+ }
+ }
+ },
standardClick() {
this.treeVisible = false
- this.departId = ''
+ // this.departId = ''
this.searchModel = ''
- this.userIds = []
- this.userName = []
- this.queryDepartUserTreeList(1)
+ this.searchData = ''
+ // this.userIds = []
+ // this.userName = []
+ // this.queryDepartUserTreeList(1)
this.visible = true
- // let gData = localStorage.getItem('gData')
- // if (gData) {
- // let dataList = JSON.parse(gData)
- // if (!this.selectDepartment) {
- // dataList.forEach(res => {
- // if (res.type == 'Depart') {
- // res.disabled = true
- // }
- // })
- // }
- // this.dataList = this.toTree(dataList)
- // }
- // setTimeout(() => {
- // if (gData) {
- // this.gData = this.dataList
- // this.gData = [...this.gData]
- // // this.treeVisible = true
- // if (this.personneQuery[this.query.db_field_name + 'Name']) {
- // this.userName = this.personneQuery[this.query.db_field_name + 'Name'].split(',')
- // } else if (this.personneQuery[this.query.db_field_name]) {
- // this.userName = this.personneQuery[this.query.db_field_name].split(',')
- // } else {
- // this.userName = []
- // }
- // if (this.personneQuery[this.query.db_field_name + '_id']) {
- // this.userIds = this.personneQuery[this.query.db_field_name + '_id'].split(',')
- // } else if (this.personneQuery[this.query.db_field_name]) {
- // this.userIds = this.personneQuery[this.query.db_field_name].split(',')
- // } else {
- // this.userIds = []
- // }
- // this.defaultCheckedKeys = this.userIds
- // this.defaultCheckedKeys = [...this.defaultCheckedKeys]
- // this.defaultExpandAll = false
- // this.treeVisible = true
- // } else {
- // this.queryDepartUserTreeList(1)
- // }
- // }, 200)
+ let gData = localStorage.getItem('gData')
+ if (gData) {
+ let dataList = JSON.parse(gData)
+ if (!this.selectDepartment) {
+ dataList.forEach(res => {
+ if (res.type == 'Depart') {
+ res.disabled = true
+ }
+ })
+ }
+ this.dataList = this.toTree(dataList)
+ }
+ setTimeout(() => {
+ if (gData) {
+ this.gData = this.dataList
+ this.gData = [...this.gData]
+ // this.treeVisible = true
+ if (this.personneQuery[this.query.db_field_name + 'Name']) {
+ this.userName = this.personneQuery[this.query.db_field_name + 'Name'].split(',')
+ } else if (this.personneQuery[this.query.db_field_name]) {
+ this.userName = this.personneQuery[this.query.db_field_name].split(',')
+ } else {
+ this.userName = []
+ }
+ if (this.personneQuery[this.query.db_field_name + '_id']) {
+ this.userIds = this.personneQuery[this.query.db_field_name + '_id'].split(',')
+ } else if (this.personneQuery[this.query.db_field_name]) {
+ this.userIds = this.personneQuery[this.query.db_field_name].split(',')
+ } else {
+ this.userIds = []
+ }
+ this.defaultCheckedKeys = this.userIds
+ this.defaultCheckedKeys = [...this.defaultCheckedKeys]
+ this.defaultExpandAll = false
+ this.treeVisible = true
+ } else {
+ this.queryDepartUserTreeList(1)
+ }
+ }, 200)
+ },
+ deleteChildren(value, arr) {
+ let newarr = []
+ arr.forEach(element => {
+ if (element.title.indexOf(value) > -1) { // 判断条件
+ newarr.push(element)
+ } else {
+ if (element.children && element.children.length > 0) {
+ let redata = this.deleteChildren(value, element.children)
+ if (redata && redata.length > 0) {
+ let obj = {
+ ...element,
+ children: redata
+ }
+ newarr.push(obj)
+ }
+ }
+ }
+ })
+ return newarr
},
//将数据拼成树形结构
- // toTree(config) {
- // // 删除 所有 children,以防止多次调用
- // config.forEach(function(item) {
- // delete item.children
- // })
- // // 将数据存储为 以 id 为 KEY 的 map 索引数据列
- // let map = {}
- // config.forEach((item) => {
- // item.label = item.name
- // item.key = item.id
- //
- // item.title = item.name + (item.itemName ? ' ' + item.itemName : '')
- // map[item.id] = item
- // })
- // let val = []
- // config.forEach((item) => {
- // // 以当前遍历项,的pid,去map对象中找到索引的id
- // let parent = map[item.parentId]
- // // 如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
- // if (parent) {
- // (parent.children || (parent.children = [])).push(item)
- // } else {
- // //如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
- // val.push(item)
- // }
- // })
- // return val
- // },
+ toTree(config, num) {
+ // 删除 所有 children,以防止多次调用
+ config.forEach(function(item) {
+ delete item.children
+ })
+ // 将数据存储为 以 id 为 KEY 的 map 索引数据列
+ let map = {}
+ config.forEach((item) => {
+ item.label = item.name
+ item.key = item.id
+
+ item.title = item.name + (item.itemName ? ' ' + item.itemName : '')
+ map[item.id] = item
+ })
+ let val = []
+ config.forEach((item) => {
+ // 以当前遍历项,的pid,去map对象中找到索引的id
+ let parent = map[item.parentId]
+
+ // 如果找到索引,那么说明此项不在顶级当中,那么需要把此项添加到,他对应的父级中
+ if (parent) {
+ (parent.children || (parent.children = [])).push(item)
+ } else {
+ //如果没有在map中找到对应的索引ID,那么直接把 当前的item添加到 val结果集中,作为顶级
+ val.push(item)
+ }
+ })
+ return val
+ },
standardDelete() {
this.$emit('input', null)
this.$forceUpdate()
@@ -220,61 +255,61 @@
// this.selectedKey = selectedKeys
// },
- onCheck(checkedKeys, info) {
- this.userIds = checkedKeys.checked
- this.userName = []
- if (this.userIds.length > 0) {
- for (let i = 0; i < this.userIds.length; i++) {
- for (let j = 0; j < this.defaultCheckedKeysName.length; j++) {
- if (this.userIds[i] == this.defaultCheckedKeysName[j].id) {
- this.userName.push(this.defaultCheckedKeysName[j].name)
- }
- }
- }
- }
- if (info.checkedNodes && info.checkedNodes.length > 0) {
- info.checkedNodes.forEach(res => {
- if (res.data.props.dataRef.key) {
- this.content.push({
- id: res.data.props.dataRef.key,
- title: res.data.props.dataRef.title
- })
- } else {
- this.content.push({
- id: res.data.props.id,
- title: res.data.props.title
- })
- }
- })
- }
- if (this.content && this.content.length > 0) {
- for (let i = 0; i < this.content.length; i++) {
- for (let j = i + 1; j < this.content.length; j++) {
- if (this.content[i].id == this.content[j].id) {
- this.content.splice(j, 1)
- j--
- }
- }
- }
- this.userIds.forEach(res => {
- this.content.forEach(val => {
- if (res == val.id) {
- this.userName.push(val.title)
- }
- })
- })
- }
- if (this.userName.length > 0) {
- for (let i = 0; i < this.userName.length; i++) {
- for (let j = i + 1; j < this.userName.length; j++) {
- if (this.userName[i] == this.userName[j]) {
- this.userName.splice(j, 1)
- j--
- }
- }
- }
- }
- },
+ // onCheck(checkedKeys, info) {
+ // this.userIds = checkedKeys.checked
+ // this.userName = []
+ // if (this.userIds.length > 0) {
+ // for (let i = 0; i < this.userIds.length; i++) {
+ // for (let j = 0; j < this.defaultCheckedKeysName.length; j++) {
+ // if (this.userIds[i] == this.defaultCheckedKeysName[j].id) {
+ // this.userName.push(this.defaultCheckedKeysName[j].name)
+ // }
+ // }
+ // }
+ // }
+ // if (info.checkedNodes && info.checkedNodes.length > 0) {
+ // info.checkedNodes.forEach(res => {
+ // if (res.data.props.dataRef.key) {
+ // this.content.push({
+ // id: res.data.props.dataRef.key,
+ // title: res.data.props.dataRef.title
+ // })
+ // } else {
+ // this.content.push({
+ // id: res.data.props.id,
+ // title: res.data.props.title
+ // })
+ // }
+ // })
+ // }
+ // if (this.content && this.content.length > 0) {
+ // for (let i = 0; i < this.content.length; i++) {
+ // for (let j = i + 1; j < this.content.length; j++) {
+ // if (this.content[i].id == this.content[j].id) {
+ // this.content.splice(j, 1)
+ // j--
+ // }
+ // }
+ // }
+ // this.userIds.forEach(res => {
+ // this.content.forEach(val => {
+ // if (res == val.id) {
+ // this.userName.push(val.title)
+ // }
+ // })
+ // })
+ // }
+ // if (this.userName.length > 0) {
+ // for (let i = 0; i < this.userName.length; i++) {
+ // for (let j = i + 1; j < this.userName.length; j++) {
+ // if (this.userName[i] == this.userName[j]) {
+ // this.userName.splice(j, 1)
+ // j--
+ // }
+ // }
+ // }
+ // }
+ // },
handleCancel() {
this.visible = false
this.treeVisible = false
@@ -289,12 +324,12 @@
}
let userIds = JSON.parse(JSON.stringify(this.userIds))
let userName = JSON.parse(JSON.stringify(this.userName))
- // userName = userName.filter(function(item, index) {
- // return userName.indexOf(item) === index // 因为indexOf 只能查找到第一个
- // })
- // userIds = userIds.filter(function(item, index) {
- // return userIds.indexOf(item) === index // 因为indexOf 只能查找到第一个
- // })
+ userName = userName.filter(function(item, index) {
+ return userName.indexOf(item) === index // 因为indexOf 只能查找到第一个
+ })
+ userIds = userIds.filter(function(item, index) {
+ return userIds.indexOf(item) === index // 因为indexOf 只能查找到第一个
+ })
this.$emit('input', userName.join(','))
this.$emit('change', this.query.db_field_name, userIds.join(','), this.query.subscript)
this.visible = false
@@ -312,116 +347,119 @@
this.defaultCheckedKeys = []
},
onSearch(e) {
- // this.loading = true
- // this.treeVisible = false
- // let p = new Promise((resolve, reject) => {
- // resolve()
- // })
- // p.then(() => {
- // let gData = localStorage.getItem('gData')
- // let content = []
- // if (gData) {
- // if (e) {
- // JSON.parse(gData).forEach(res => {
- // if (res.type == 'User') {
- // if (res.name.includes(e)) {
- // res.color = true
- // content.push(res)
- // }
- // } else if (res.type == 'Depart') {
- // if (!this.selectDepartment) {
- // res.disabled = true
- // }
- // content.push(res)
- // }
- // })
- // this.defaultExpandAll = true
- // this.gData = this.toTree(content)
- // } else {
- // let content = JSON.parse(gData)
- // if (!this.selectDepartment) {
- // content.forEach(res => {
- // if (res.type == 'Depart') {
- // res.disabled = true
- // }
- // })
- // }
- // this.gData = this.toTree(content)
- // this.defaultExpandAll = false
- // }
- // }
- // this.defaultCheckedKeys = this.userIds
- // this.defaultCheckedKeys = [...this.defaultCheckedKeys]
- // this.treeVisible = true
- // this.loading = false
- // })
- this.gData = []
- this.departId = ''
- this.visibleTree = false
- if (e) {
- this.getUserAndDepart()
- } else {
- this.treeVisible = false
- this.queryDepartUserTreeList(2)
- }
- },
- getUserAndDepart() {
- getAction('sys/user/getUserAndDepart', { name: this.searchModel }).then((res) => {
- if (res) {
- this.gData = res.filter(ele => ele.flag === 'DEPART')
- } else {
- this.gData = []
- }
- this.visibleTree = true
+ this.treeVisible = false
+ let p = new Promise((resolve, reject) => {
+ resolve()
})
- },
- onExpand(selectedKeys, val) {
- if (this.searchModel == '' || !this.searchModel) {
- if (val.expanded) {
- if (this.departId == val.node.value) {
+ p.then(() => {
+ this.searchData = e
+ let gData = localStorage.getItem('gData')
+ let content = []
+ if (gData) {
+ if (e) {
+ JSON.parse(gData).forEach(res => {
+ if (res.type == 'User') {
+ if (res.name.includes(e)) {
+ res.color = true
+ content.push(res)
+ }
+ }
+ // else if(res.type == 'Depart'){
+ // content.push(res)
+ // }
+ })
+ let gDataAdmin = this.toTree(content)
+ this.gData = this.deleteChildren(e, gDataAdmin)
+ this.defaultExpandAll = true
+ this.treeVisible = true
+ this.defaultCheckedKeys = this.userIds
+ this.defaultCheckedKeys = [...this.defaultCheckedKeys]
+ this.loading = false
} else {
- this.departId = val.node.value
- this.queryDepartUserTreeList(2)
+ let content = JSON.parse(gData)
+ if (!this.selectDepartment) {
+ content.forEach(res => {
+ if (res.type == 'Depart') {
+ res.disabled = true
+ }
+ })
+ }
+ this.gData = this.toTree(content)
+ this.defaultExpandAll = false
+ this.defaultCheckedKeys = this.userIds
+ this.defaultCheckedKeys = [...this.defaultCheckedKeys]
+ this.treeVisible = true
+ this.loading = false
}
}
- }
+ })
+ // this.gData = []
+ // this.departId = ''
+ // this.visibleTree = false
+ // if (e) {
+ // this.getUserAndDepart()
+ // } else {
+ // this.treeVisible = false
+ // this.queryDepartUserTreeList(2)
+ // }
},
+ // getUserAndDepart() {
+ // getAction('sys/user/getUserAndDepart', { name: this.searchModel }).then((res) => {
+ // if (res) {
+ // this.gData = res.filter(ele => ele.flag === 'DEPART')
+ // } else {
+ // this.gData = []
+ // }
+ // this.visibleTree = true
+ // })
+ // },
+ // onExpand(selectedKeys, val) {
+ // if (this.searchModel == '' || !this.searchModel) {
+ // if (val.expanded) {
+ // if (this.departId == val.node.value) {
+ // } else {
+ // this.departId = val.node.value
+ // this.queryDepartUserTreeList(2)
+ // }
+ // }
+ // }
+ // },
queryDepartUserTreeList(num) {
- let gData = JSON.parse(JSON.stringify(this.gData))
- if (gData && gData.length > 0) {
- gData = JSON.stringify(gData)
- } else {
- gData = ''
- }
+ // let gData = JSON.parse(JSON.stringify(this.gData))
+ // if (gData && gData.length > 0) {
+ // gData = JSON.stringify(gData)
+ // } else {
+ // gData = ''
+ // }
this.confirmLoading = true
this.loading = true
//queryDepartUserTreeList
//queryUserTreeList
- postAction('sys/user/queryDepartUserTreeList', {
- departId: this.departId,
- json: gData,
- flag: '1'
+ postAction('sys/user/queryUserTreeList', {
+ // departId: this.departId,
+ // json: gData,
+ // flag: '1'
}).then((res) => {
this.confirmLoading = false
if (res.success) {
this.loading = false
// localStorage.setItem('gData', JSON.stringify(res.result))
// this.toTree(dataList)
- // let content = JSON.parse(JSON.stringify(res.result))
- // if (!this.selectDepartment) {
- // res.result.forEach(res => {
- // if (res.type == 'Depart') {
- // res.disabled = true
- // }
- // })
- // }
- // localStorage.removeItem('gData')
- // localStorage.setItem('gData', JSON.stringify(content))
- // this.gData = this.toTree(res.result)
- this.gData = res.result
+ let content = JSON.parse(JSON.stringify(res.result))
+ if (!this.selectDepartment) {
+ res.result.forEach(res => {
+ if (res.type == 'Depart') {
+ res.disabled = true
+ }
+ })
+ }
+ localStorage.removeItem('gData')
+ localStorage.setItem('gData', JSON.stringify(content))
+ this.gData = this.toTree(res.result)
+ // this.gData = res.result
this.gData = [...this.gData]
// this.gData[0].isLeaf = false
- this.defaultExpandedKeys = [this.departId]
+ // this.defaultExpandedKeys = [this.departId]
if (num == 1) {
if (this.userName && this.userName.length == 0) {
if (this.personneQuery[this.query.db_field_name + 'Name']) {
@@ -444,14 +482,14 @@
this.defaultCheckedKeys = this.userIds
this.defaultCheckedKeys = [...this.defaultCheckedKeys]
this.defaultCheckedKeysName = []
- if (this.defaultCheckedKeys.length > 0) {
- for (let i = 0; i < this.defaultCheckedKeys.length; i++) {
- this.defaultCheckedKeysName.push({
- id: this.defaultCheckedKeys[i],
- name: this.userName[i]
- })
- }
- }
+ // if (this.defaultCheckedKeys.length > 0) {
+ // for (let i = 0; i < this.defaultCheckedKeys.length; i++) {
+ // this.defaultCheckedKeysName.push({
+ // id: this.defaultCheckedKeys[i],
+ // name: this.userName[i]
+ // })
+ // }
+ // }
}
this.defaultExpandAll = false
this.treeVisible = true
diff --git a/jero-web/src/components/virtualNodeTree/mixin/node.js b/jero-web/src/components/virtualNodeTree/mixin/node.js
index 9c7850718..efeea4ce4 100644
--- a/jero-web/src/components/virtualNodeTree/mixin/node.js
+++ b/jero-web/src/components/virtualNodeTree/mixin/node.js
@@ -41,9 +41,8 @@ export default {
return getNodeKey(this.tree.nodeKey, node.data);
},
- handleSelectChange(checked, indeterminate) {
+ handleSelectChange(checked, indeterminate,source) {
const node = this.node || this.source;
-
if (this.oldChecked !== checked && this.oldIndeterminate !== indeterminate) {
this.tree.$emit('check-change', node.data, checked, indeterminate);
}
@@ -95,7 +94,6 @@ export default {
handleCheckChange(_, ev) {
const node = this.node || this.source;
-
node.setChecked(ev.target.checked, !this.tree.checkStrictly);
this.$nextTick(() => {
const store = this.tree.store;
@@ -103,8 +101,9 @@ export default {
checkedNodes: store.getCheckedNodes(),
checkedKeys: store.getCheckedKeys(),
halfCheckedNodes: store.getHalfCheckedNodes(),
- halfCheckedKeys: store.getHalfCheckedKeys()
- });
+ halfCheckedKeys: store.getHalfCheckedKeys(),
+ getCurrentNode:store.getCurrentNode()
+ },this.source.checked);
});
},
diff --git a/jero-web/src/components/virtualNodeTree/model/tree-store.js b/jero-web/src/components/virtualNodeTree/model/tree-store.js
index c9df39c83..760ea8980 100644
--- a/jero-web/src/components/virtualNodeTree/model/tree-store.js
+++ b/jero-web/src/components/virtualNodeTree/model/tree-store.js
@@ -57,7 +57,6 @@ export default class TreeStore {
if (node.visible && !node.isLeaf && !lazy) node.expand();
};
-
traverse(this);
}
diff --git a/jero-web/src/components/virtualNodeTree/tree-virtual-node.vue b/jero-web/src/components/virtualNodeTree/tree-virtual-node.vue
index acc2ba88e..2f0925b40 100644
--- a/jero-web/src/components/virtualNodeTree/tree-virtual-node.vue
+++ b/jero-web/src/components/virtualNodeTree/tree-virtual-node.vue
@@ -115,11 +115,11 @@
},
watch: {
'source.indeterminate'(val) {
- this.handleSelectChange(this.source.checked, val);
+ this.handleSelectChange(this.source.checked, val,this.source);
},
'source.checked'(val) {
- this.handleSelectChange(val, this.source.indeterminate);
+ this.handleSelectChange(val, this.source.indeterminate,this.source);
},
'source.expanded'(val) {