| | |
| | | treeDataSource: [], |
| | | selectedKeys: [], |
| | | expandedKeys: [], |
| | | beforeSearchExpandedKeys: [], |
| | | searchValue: '', |
| | | dataList: [], |
| | | autoExpandParent: true, |
| | |
| | | getTreeDataByApi() { |
| | | this.loading = true |
| | | this.cardLoading = true |
| | | this.treeDataSource = [] |
| | | dncApi.getDeviceTreeDataApi() |
| | | .then(res => { |
| | | if (res.success) { |
| | |
| | | this.allTreeKeys = [] |
| | | this.treeDataSource = res.result |
| | | this.generateList(this.treeDataSource) |
| | | this.expandedKeys = this.allTreeKeys |
| | | this.$bus.$emit('sendCurrentTreeNodeInfo', this.treeDataSource[0]) |
| | | this.expandedKeys = this.beforeSearchExpandedKeys = this.allTreeKeys |
| | | this.$bus.$emit('sendDeviceTreeNodeInfo', this.treeDataSource[0]) |
| | | } else { |
| | | this.$message.warn(res.message) |
| | | } |
| | |
| | | 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 |
| | | |
| | | }, |
| | | |
| | | /** |
| | |
| | | * @param expandedKeys 展开项key |
| | | */ |
| | | 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 |
| | | }) |
| | | }, |
| | | |