From c34bcb0a3054bdab29fbaff17e587c19d7b5de28 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 16 九月 2020 23:39:28 +0800
Subject: [PATCH] 2020-09-16

---
 src/menu/components/chart/antv-bar/index.jsx |  101 +++++++++++++++++++++-----------------------------
 1 files changed, 42 insertions(+), 59 deletions(-)

diff --git a/src/menu/components/chart/antv-bar/index.jsx b/src/menu/components/chart/antv-bar/index.jsx
index d6c61c0..6c216a0 100644
--- a/src/menu/components/chart/antv-bar/index.jsx
+++ b/src/menu/components/chart/antv-bar/index.jsx
@@ -4,6 +4,7 @@
 import { Chart } from '@antv/g2'
 import DataSet from '@antv/data-set'
 
+import MKEmitter from '@/utils/events.js'
 import asyncComponent from '@/utils/asyncComponent'
 
 import Utils from '@/utils/utils.js'
@@ -18,18 +19,19 @@
 
 class antvBarLineChart extends Component {
   static propTpyes = {
-    config: PropTypes.object,
+    menu: PropTypes.object,
     card: PropTypes.object,
     updateConfig: PropTypes.func,
   }
 
   state = {
     dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
-    card: null
+    card: null,
+    eventListener: null
   }
 
   UNSAFE_componentWillMount () {
-    const { card, config } = this.props
+    const { card, menu } = this.props
 
     if (card.isNew) {
       let _plot = {
@@ -51,27 +53,14 @@
         _plot.shape = 'hv'
       }
 
-      let name = ''
-      let names = {
-        bar: '鏌辩姸鍥�',
-        line: '鎶樼嚎鍥�',
-      }
-      let i = 1
-      
-      while (!name) {
-        let _name = names[card.type] + i
-        if (config.components.filter(com => com.setting && com.setting.name === _name).length === 0) {
-          name = _name
-        }
-        i++
-      }
-
       let dataName = ''
 
-      while (!dataName) {
-        let _dataName = Utils.getdataName()
-        if (config.components.filter(com => com.dataName === _dataName).length === 0) {
-          dataName = _dataName
+      if (card.floor === 1) {
+        while (!dataName) {
+          let _dataName = Utils.getdataName()
+          if (menu.components.filter(com => com.dataName === _dataName).length === 0) {
+            dataName = _dataName
+          }
         }
       }
 
@@ -79,12 +68,13 @@
         uuid: card.uuid,
         type: card.type,
         floor: card.floor,
+        parentId: card.parentId || '',
         format: 'array',   // 缁勪欢灞炴�� - 鏁版嵁鏍煎紡
         pageable: false,   // 缁勪欢灞炴�� - 鏄惁鍙垎椤�
         switchable: false, // 缁勪欢灞炴�� - 鏁版嵁鏄惁鍙垏鎹�
         dataName: dataName,
         subtype: card.subtype,
-        setting: {span: 12, height: 400, interType: 'system', name},
+        setting: {span: card.floor === 1 ? 12 : 24, height: 400, interType: 'system', name: card.name},
         columns: [],
         scripts: [],
         search: [],
@@ -104,11 +94,33 @@
 
   componentDidMount () {
     this.viewrender()
+    MKEmitter.addListener('tabsChange', this.handleTabsChange)
   }
 
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    if (!is(fromJS(this.props.plot), fromJS(nextProps.plot))) {
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
+  }
 
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
+    MKEmitter.removeListener('tabsChange', this.handleTabsChange)
+  }
+
+  handleTabsChange = (parentId) => {
+    const { card } = this.state
+
+    if (parentId === card.parentId) {
+      let _element = document.getElementById(card.uuid)
+      if (_element) {
+        _element.innerHTML = ''
+      }
+
+      setTimeout(this.viewrender, 100)
     }
   }
 
@@ -510,35 +522,6 @@
     }
   }
 
-  plotChange = (_plot) => {
-    const { config } = this.props
-
-    if (_plot.datatype === 'statistics') {
-      _plot.Yaxis = [_plot.InfoValue]
-    }
-    
-    let _charts = fromJS(config.charts).toJS()
-
-    _charts = _charts.map(item => {
-      if (item.uuid === _plot.uuid) {
-        if (!is(fromJS(item), fromJS(_plot))) {
-          let _element = document.getElementById(_plot.uuid)
-          if (_element) {
-            _element.innerHTML = ''
-          }
-        }
-        return _plot
-      }
-      return item
-    })
-
-    this.props.plotchange({...config, charts: _charts})
-  }
-
-  shouldComponentUpdate (nextProps, nextState) {
-    return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
-  }
-
   updateComponent = (component) => {
     const card = fromJS(this.state.card).toJS()
     let refresh = false
@@ -564,28 +547,28 @@
 
   render() {
     const { card } = this.state
-    const { config } = this.props
+    const { menu } = this.props
 
     return (
       <div className="menu-line-chart-edit-box" style={{height: card.setting.height || 400}}>
         <SettingComponent
           config={card}
-          menu={config}
+          menu={menu}
           updateConfig={this.updateComponent}
         />
         <div className="chart-header">
           <span className="chart-title">{card.setting.title || ''}</span>
           <SearchComponent
-            menu={config}
+            menu={menu}
             config={card}
-            sysRoles={config.sysRoles}
+            sysRoles={menu.sysRoles}
             optionLibs={null}
             updatesearch={this.updateComponent}
           />
         </div>
         <ActionComponent
           type="chart"
-          menu={config}
+          menu={menu}
           config={card}
           tabs={[]}
           // setSubConfig={(_btn) => this.setSubConfig(_btn, 'button')}

--
Gitblit v1.8.0