diff --git a/jero-web/src/components/PersonnelSelection/index.vue b/jero-web/src/components/PersonnelSelection/index.vue index 755e08ff2..3586254e2 100644 --- a/jero-web/src/components/PersonnelSelection/index.vue +++ b/jero-web/src/components/PersonnelSelection/index.vue @@ -31,42 +31,45 @@
- - - - - - - - - - - - - - - - - {{$t('dataLoading')}} + - + :keeps="40" + show-checkbox + v-model="checkboxList" + class="treeWrap" + :props="{ + isLeaf: 'leaf' + }" + :defaultCheckedKeys="defaultCheckedKeys" + :check-strictly="false" + node-key="id" + @check-change="handleCheckChange" + :data.sync="gData"> + + {{ data.title }} + + + + + + + + + + + + + + +
-
{{$t('cancel')}} {{$t('submit')}}
+ @@ -78,13 +81,13 @@ export default { name: 'index', - props: ['query', 'value', 'personneQuery', 'isSingleChoice', 'isInput', 'isClass', 'isDelete', 'disabled'], + props: ['query', 'value', 'personneQuery', 'isSingleChoice', 'isInput', 'isClass', 'isDelete', 'disabled', 'selectDepartment'], components: { virtualNodeTree }, data() { return { - loading: true, + loading: false, gData: [], autoExpandParent: true, checkboxList: [], @@ -99,7 +102,8 @@ defaultExpandedKeys: [], defaultCheckedKeys: [], defaultCheckedKeysName: [], - content: [] + content: [], + dataList: [] } }, mounted() { @@ -107,23 +111,69 @@ }, methods: { handleCheckChange(val, checked, indeterminate) { - console.log(val) - console.log(this.checkboxList) + 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-- + } + } + } }, standardClick() { + this.visible = true this.treeVisible = false this.departId = '' this.searchModel = '' - this.userIds = [] this.userName = [] + this.userIds = [] let gData = localStorage.getItem('gData') - // if (gData) { - // this.gData = this.toTree(JSON.parse(gData)) - // this.treeVisible = true - // } else { - this.queryDepartUserTreeList(1) - // } - this.visible = true + 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.treeVisible = true + } else { + this.queryDepartUserTreeList(1) + } + }, 200) }, //将数据拼成树形结构 toTree(config) { @@ -233,6 +283,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 只能查找到第一个 + }) this.$emit('input', userName.join(',')) this.$emit('change', this.query.db_field_name, userIds.join(','), this.query.subscript) this.visible = false @@ -250,88 +306,132 @@ this.defaultCheckedKeys = [] }, onSearch(e) { - 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.loading = 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(() => { + 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)) { + content.push(res) + } + } else if (res.type == 'Depart') { + content.push(res) + } + }) + this.gData = this.toTree(content) } else { - this.departId = val.node.value - this.queryDepartUserTreeList(2) + this.gData = this.toTree(JSON.parse(gData)) } } - } + 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' + getAction('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.gData = 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) + console.log(this.gData) + 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']) { - 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.userName && this.userName.length == 0) { + 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.userIds && this.userIds.length == 0) { - 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 = [] - } + // } + // if (this.userIds && this.userIds.length == 0) { + 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.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] - }) - } - } + 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] + // }) + // } + // } } this.treeVisible = true } else { @@ -378,6 +478,7 @@ .drawer-content { height: calc(100% - 60px); overflow: auto; + position: relative; } .my-tree { diff --git a/jero-web/src/store/modules/user.js b/jero-web/src/store/modules/user.js index 81b44fd6b..c59903a89 100644 --- a/jero-web/src/store/modules/user.js +++ b/jero-web/src/store/modules/user.js @@ -142,6 +142,14 @@ const user = { //Vue.ls.set(USER_AUTH,authData); sessionStorage.setItem(USER_AUTH, JSON.stringify(authData)) sessionStorage.setItem(SYS_BUTTON_AUTH, JSON.stringify(allAuthData)) + let gData = localStorage.getItem('gData') + if (!gData) { + getAction('sys/user/queryUserTreeList', {}).then((res) => { + if (res.success) { + localStorage.setItem('gData', JSON.stringify(res.result)) + } + }) + } if (menuData && menuData.length > 0) { //update--begin--autor:qinfeng-----date:20200109------for:JEECG-63 一级菜单的子菜单全部是隐藏路由,则一级菜单不显示------ menuData.forEach((item, index) => { @@ -178,6 +186,7 @@ const user = { Vue.ls.remove(USER_NAME) Vue.ls.remove(UI_CACHE_DB_DICT_DATA) Vue.ls.remove(CACHE_INCLUDED_ROUTES) + localStorage.removeItem('gData') //console.log('logoutToken: '+ logoutToken) logout(logoutToken).then(() => { if (process.env.VUE_APP_SSO == 'true') {