From 79e4981aa6cc9354276fc54cdf6d14eb08ab7fee Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期四, 22 六月 2023 15:59:04 +0800 Subject: [PATCH] Merge branch 'develop' of ssh://121.36.20.145:29418/~jinfei/pc-plat into develop --- src/tabviews/custom/components/chart/antv-G6/index.jsx | 107 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 91 insertions(+), 16 deletions(-) diff --git a/src/tabviews/custom/components/chart/antv-G6/index.jsx b/src/tabviews/custom/components/chart/antv-G6/index.jsx index ac96d6b..f481f2e 100644 --- a/src/tabviews/custom/components/chart/antv-G6/index.jsx +++ b/src/tabviews/custom/components/chart/antv-G6/index.jsx @@ -814,6 +814,8 @@ } data = [] + mkgraph = null + selectedId = '' UNSAFE_componentWillMount () { const { config, data, initdata } = this.props @@ -1183,9 +1185,20 @@ _options.push(_item) }) - - root = this.getTree(root, _options) + + root.nodeNumber = 0 + root = this.getTree(root, _options, root) root.children = root.children || [] + + if (root.selectedItem) { + let option = {...root.selectedItem} + setTimeout(() => { + MKEmitter.emit('resetSelectLine', config.uuid, option.id, option) + }, 20) + delete root.selectedItem + } else { + this.selectedId = '' + } if (plot.subtype === 'mindmap') { root.type = 'dice-mind-map-root' @@ -1248,13 +1261,22 @@ return root } - getTree = (parent, options) => { + getTree = (parent, options, root) => { parent.children = [] // 娣诲姞鑿滃崟鐨勫瓙鍏冪礌 options = options.filter(option => { if (option.$parentId === parent.id) { delete option.$parentId + + if (this.selectedId && option.id === this.selectedId) { + root.selectedItem = {...option} + option.selected = true + } + parent.children.push(option) + + root.nodeNumber++ + return false } return true @@ -1264,7 +1286,7 @@ parent.children = null } else { parent.children = parent.children.map(item => { - item = this.getTree(item, options) + item = this.getTree(item, options, root) return item }) @@ -1274,30 +1296,71 @@ } handleData = () => { - let _element = document.getElementById(this.state.chartId) - if (_element) { - _element.innerHTML = '' - } + const { config } = this.state - setTimeout(() => { + MKEmitter.emit('resetSelectLine', config.uuid, '', '') + + if (this.mkgraph) { + this.mkgraph.clear() + this.resetrender() + } else { this.viewrender() - }, 100) + } } viewrender = () => { const { plot } = this.state + this.selectedId = '' if (this.data.length === 0) { this.setState({empty: true}) } else { this.setState({empty: false}) if (plot.subtype === 'mindmap') { - this.ponitrender() + this.mindrender() } else if (plot.subtype === 'indentTree') { this.indentrender() } else if (plot.subtype === 'kapmap') { this.kapmaprender() + } + } + } + + resetrender = () => { + const { plot } = this.state + + if (this.data.length === 0) { + this.setState({empty: true}) + this.selectedId = '' + } else { + this.setState({empty: false}) + + const data = this.getdata() + if (plot.subtype === 'mindmap') { + this.mkgraph.data(data) + + this.mkgraph.render() + + const width = this.wrap.scrollWidth - 30 + + if (plot.collapsed === 'true' && plot.dirField) { + this.mkgraph.zoomTo(1, { x: width / 2, y: plot.height / 2 }) + } else if (plot.collapsed === 'true' || data.nodeNumber < 5) { + this.mkgraph.zoomTo(1, { x: 0, y: plot.height / 2 }) + } + } else if (plot.subtype === 'indentTree') { + this.mkgraph.data(dataIndTransform(data)) + + this.mkgraph.render() + } else if (plot.subtype === 'kapmap') { + this.mkgraph.data(data) + this.mkgraph.render() + this.mkgraph.fitView() + + if (plot.collapsed === 'true' || data.nodeNumber < 5) { + this.mkgraph.zoomTo(1, { x: 0, y: plot.height / 2 }) + } } } } @@ -1357,9 +1420,11 @@ graph.render() graph.fitView() - if (plot.collapsed === 'true') { + if (plot.collapsed === 'true' || data.nodeNumber < 5) { graph.zoomTo(1, { x: 0, y: plot.height / 2 }) } + + this.mkgraph = graph } indentrender = () => { @@ -1421,12 +1486,14 @@ tree.data(dataIndTransform(data)) tree.render() + + this.mkgraph = tree } /** - * @description 鏁g偣鍥� + * @description 鎬濈淮瀵煎浘 */ - ponitrender = () => { + mindrender = () => { const { config, plot, chartId } = this.state const data = this.getdata() const width = this.wrap.scrollWidth - 30 @@ -1480,9 +1547,11 @@ if (plot.collapsed === 'true' && plot.dirField) { tree.zoomTo(1, { x: width / 2, y: plot.height / 2 }) - } else if (plot.collapsed === 'true') { + } else if (plot.collapsed === 'true' || data.nodeNumber < 5) { tree.zoomTo(1, { x: 0, y: plot.height / 2 }) } + + this.mkgraph = tree } handleClick = (data = null) => { @@ -1551,7 +1620,13 @@ MKEmitter.emit('modifyTabs', newtab, true) } else { - MKEmitter.emit('resetSelectLine', config.uuid, (data ? data.$$uuid : ''), data) + if (data) { + this.selectedId = data.$$uuid || '' + MKEmitter.emit('resetSelectLine', config.uuid, data.$$uuid || '', data) + } else { + this.selectedId = '' + MKEmitter.emit('resetSelectLine', config.uuid, '', '') + } } } -- Gitblit v1.8.0