From e9353e9639ac50735713eb85a8fe0ef7e06afa4f Mon Sep 17 00:00:00 2001 From: zhaowei <zhaowei> Date: 星期一, 10 三月 2025 13:41:25 +0800 Subject: [PATCH] 1、产品和设备结构树选择节点时可以连续点击相同节点且不会取消选中当前节点 2、产品结构树接口调整,产品结构树节点实体信息通过点击后调取接口获取(仍有bug,点击一次会出现多次重复请求) --- src/views/dnc/base/modules/DeviceStructure/DeviceStructureTree.vue | 76 ++++++++++++++++++++++---------------- 1 files changed, 44 insertions(+), 32 deletions(-) diff --git a/src/views/dnc/base/modules/DeviceStructure/DeviceStructureTree.vue b/src/views/dnc/base/modules/DeviceStructure/DeviceStructureTree.vue index 1b86a5b..a930ddd 100644 --- a/src/views/dnc/base/modules/DeviceStructure/DeviceStructureTree.vue +++ b/src/views/dnc/base/modules/DeviceStructure/DeviceStructureTree.vue @@ -41,8 +41,7 @@ </template> <script> - import { mapActions } from 'vuex' - import { deleteAction } from '@/api/manage' + import dncApi from '@/api/dnc' import DeviceStructureTreeContextMenu from './DeviceStructureTreeContextMenu' import AssignPermissionModal from './Permission/AssignPermissionModal' @@ -60,6 +59,7 @@ treeDataSource: [], selectedKeys: [], expandedKeys: [], + beforeSearchExpandedKeys: [], searchValue: '', dataList: [], autoExpandParent: true, @@ -79,26 +79,26 @@ this.$bus.$on('handleSwitchDeviceDocClassCode', this.setCurrentDeviceDocClassCode) }, methods: { - ...mapActions(['QueryProduction']), - getTreeDataByApi() { this.loading = true this.cardLoading = true - this.QueryProduction('DNC').then(res => { - if (res.success) { - this.dataList = [] - this.allTreeKeys = [] - this.treeDataSource = res.result - this.generateList(this.treeDataSource) - this.expandedKeys = this.allTreeKeys - this.$bus.$emit('sendCurrentTreeNodeInfo', this.treeDataSource[0]) - } else { - this.$message.warn(res.message) - } - }).finally(() => { - this.loading = false - this.cardLoading = false - }) + dncApi.getDeviceTreeDataApi() + .then(res => { + if (res.success) { + this.dataList = [] + this.allTreeKeys = [] + this.treeDataSource = res.result + this.generateList(this.treeDataSource) + this.expandedKeys = this.beforeSearchExpandedKeys = this.allTreeKeys + this.$bus.$emit('sendDeviceTreeNodeInfo', this.treeDataSource[0]) + } else { + this.$message.warn(res.message) + } + }) + .finally(() => { + this.loading = false + this.cardLoading = false + }) }, setCurrentDeviceDocClassCode(documentActiveTabKey) { @@ -114,9 +114,11 @@ handleTreeSelect(selectedKeys, { node }) { let record = node.dataRef this.currentSelected = Object.assign({}, record) - this.selectedKeys = selectedKeys // 鍚戝彸渚х埗绾х粍浠跺彂閫佸綋鍓嶉�変腑鏍戣妭鐐逛俊鎭� - this.$bus.$emit('sendCurrentTreeNodeInfo', this.currentSelected) + this.$bus.$emit('sendDeviceTreeNodeInfo', this.currentSelected) + if (selectedKeys.length === 0) return + this.selectedKeys = selectedKeys + }, /** @@ -136,27 +138,37 @@ * @param expandedKeys 灞曞紑椤筴ey */ handleTreeExpand(expandedKeys) { - this.expandedKeys = expandedKeys + this.expandedKeys = this.beforeSearchExpandedKeys = expandedKeys + console.log('beforeSearchExpandedKeys', this.beforeSearchExpandedKeys) this.autoExpandParent = false }, /* 杈撳叆鏌ヨ鍐呭鍙樺寲鏃惰Е鍙� */ handleSearchInputChange() { let search = this.searchInput - let expandedKeys = this.dataList - .map(item => { - if (item.title != null) { - if (item.title.indexOf(search) > -1) { - return this.getParentKey(item.key, this.treeDataSource) + let expandedKeys + let autoExpandParent + if (search !== '') { + expandedKeys = this.dataList + .map(item => { + if (item.title != null) { + if (item.title.indexOf(search) > -1) { + return this.getParentKey(item.key, this.treeDataSource) + } + return null } - return null - } - }) - .filter((item, i, self) => item && self.indexOf(item) === i) + }) + .filter((item, i, self) => item && self.indexOf(item) === i) + autoExpandParent = true + } else { + expandedKeys = this.beforeSearchExpandedKeys + autoExpandParent = false + } + Object.assign(this, { expandedKeys, searchValue: search, - autoExpandParent: true + autoExpandParent }) }, -- Gitblit v1.9.3