From 4cf3c14e6cd5ababdc6c7fddad1726395ed083b7 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 16 三月 2021 12:21:16 +0800
Subject: [PATCH] 2021-03-16

---
 src/tabviews/custom/components/chart/antv-bar-line/index.jsx |  317 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 241 insertions(+), 76 deletions(-)

diff --git a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
index 23f1f6a..1d2ba36 100644
--- a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
@@ -5,16 +5,18 @@
 import { connect } from 'react-redux'
 import DataSet from '@antv/data-set'
 import { Spin, Empty, Select, notification } from 'antd'
+import moment from 'moment'
 
 import asyncComponent from './asyncButtonComponent'
 import { chartColors } from '@/utils/option.js'
-// import searchLine from '../../share/searchLine'
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import { modifyTabview } from '@/store/action'
+import MKEmitter from '@/utils/events.js'
 import './index.scss'
 
+const NormalHeader = asyncComponent(() => import('@/tabviews/custom/components/share/normalheader'))
 const ExcelOutButton = asyncComponent(() => import('@/tabviews/zshare/actionList/exceloutbutton'))
 const ExcelInButton = asyncComponent(() => import('@/tabviews/zshare/actionList/excelInbutton'))
 
@@ -25,16 +27,15 @@
     config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
     mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
     menuType: PropTypes.any,         // 鑿滃崟绫诲瀷
-    dataManager: PropTypes.any,      // 鏁版嵁鏉冮檺
   }
 
   state = {
+    BID: '',                   // 涓昏〃ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     empty: true,               // 鍥捐〃鏁版嵁涓虹┖
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
     chartId: Utils.getuuid(),  // 鍥捐〃Id
     transfield: {},            // 瀛楁鍚嶇О缈昏瘧
-    title: '',                 // 缁勪欢鏍囬
     sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     plot: null,                // 鍥捐〃璁剧疆
     data: null,                // 鏁版嵁
@@ -44,13 +45,11 @@
     chartData: [],             // 鍥捐〃鏁版嵁
     chartFields: [],           // 缁熻鍥捐〃鐢熸垚瀛楁闆�
     selectFields: [],          // 缁熻鍥捐〃閫夋嫨瀛楁
-    showHeader: false          // 瀛樺湪鏍囬銆佹悳绱€�佹垨缁熻鏁版嵁鏃舵樉绀�
   }
 
   UNSAFE_componentWillMount () {
-    const { config, data, initdata } = this.props
+    const { config, data, initdata, BID } = this.props
     let _config = fromJS(config).toJS()
-
     let _data = null
     let _sync = config.setting.sync === 'true'
 
@@ -99,9 +98,7 @@
       })
     }
 
-    let showHeader = false
-    if (config.plot.title || _config.plot.datatype === 'statistics' || config.search.length > 0) {
-      showHeader = true
+    if (config.plot.title || config.search.length > 0) {
       _config.plot.height = _config.plot.height - 80
     } else {
       _config.plot.height = _config.plot.height - 30
@@ -190,15 +187,14 @@
     this.setState({
       config: _config,
       data: _data,
+      BID: BID || '',
       vFields: vFields,
       vstFields: vstFields,
       arr_field: _config.columns.map(col => col.field).join(','),
       plot: _config.plot,
       sync: _sync,
-      title: config.plot.title,
       search: Utils.initMainSearch(config.search),
-      transfield,
-      showHeader
+      transfield
     }, () => {
       if (config.setting.sync !== 'true' && config.setting.onload === 'true') {
         this.loadData()
@@ -223,7 +219,7 @@
       this.setState({sync: false, data: _data}, () => {
         this.handleData()
       })
-    } else if (!is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+    } else if (nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       if (config.setting.syncRefresh === 'true') {
         this.setState({}, () => {
           this.loadData()
@@ -236,6 +232,217 @@
     return !is(fromJS(this.state), fromJS(nextState))
   }
 
+  componentDidMount () {
+    MKEmitter.addListener('reloadData', this.reloadData)
+    MKEmitter.addListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.addListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
+    this.handleTimer()
+  }
+
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
+   */
+  componentWillUnmount () {
+    clearTimeout(this.timer)
+    this.setState = () => {
+      return
+    }
+    MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.removeListener('getexceloutparam', this.getexceloutparam)
+    MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
+  }
+
+  handleTimer = () => {
+    const { config } = this.state
+
+    if (!config.timer) return
+
+    const _change = {
+      '15s': 15000,
+      '30s': 30000,
+      '1min': 60000,
+      '5min': 300000,
+      '10min': 600000,
+      '15min': 900000,
+      '30min': 1800000,
+      '1hour': 3600000
+    }
+
+    let timer = _change[config.timer]
+
+    if (!timer) return
+
+    let _param = {
+      func: 's_get_timers_role',
+      LText: `select '${window.GLOB.appkey || ''}','${config.uuid}'`,
+      timer_type: config.timer,
+      component_id: config.uuid
+    }
+    
+    _param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')          // 鏃堕棿鎴�
+    _param.LText = Utils.formatOptions(_param.LText)                   // 鍏抽敭瀛楃鏇挎崲锛宐ase64鍔犲瘑
+    _param.secretkey = Utils.encrypt(_param.LText, _param.timestamp)   // md5瀵嗛挜
+
+    Api.getSystemConfig(_param).then(result => {
+      if (!result.status) {
+        notification.warning({
+          top: 92,
+          message: result.message,
+          duration: 5
+        })
+        return
+      } else if (result.run_type) {
+        this.setState({timer})
+        this.timer = setTimeout(() => {
+          this.timerTask()
+        }, timer)
+      }
+    })
+  }
+
+  timerTask = () => {
+    const { timer } = this.state
+    if (!timer) return
+    
+    this.loadData(true)
+    
+    this.timer = setTimeout(() => {
+      this.timerTask()
+    }, timer)
+  }
+
+  /**
+   * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂�
+   * @param {*} menuId     // 鑿滃崟Id
+   * @param {*} position   // 鍒锋柊浣嶇疆
+   * @param {*} btn        // 鎵ц鐨勬寜閽�
+   */
+  refreshByButtonResult = (menuId, position, btn) => {
+    const { config, BID } = this.state
+
+    if (config.uuid !== menuId) return
+
+    this.loadData()                                                            // 鏁版嵁鍒锋柊
+
+    if (btn.syncComponentId && btn.syncComponentId !== config.uuid && btn.syncComponentId !== config.setting.supModule) {
+      MKEmitter.emit('reloadData', btn.syncComponentId)                        // 鍚岀骇鏍囩鍒锋柊
+    }
+
+    if (position === 'mainline' && config.setting.supModule) {                 // 涓昏〃琛屽埛鏂�
+      MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
+    } else if (position === 'popclose') {                                      // 鏍囩鍏抽棴鍒锋柊
+      config.setting.supModule && MKEmitter.emit('reloadData', config.setting.supModule, (BID || 'empty'))
+      btn.$tabId && MKEmitter.emit('refreshPopButton', btn.$tabId)
+    }
+  }
+
+  reloadData = (menuId) => {
+    const { config } = this.state
+
+    if (config.uuid !== menuId) return
+
+    this.loadData()
+  }
+
+  resetParentParam = (MenuID, id) => {
+    const { config } = this.state
+
+    if (!config.setting.supModule || config.setting.supModule !== MenuID) return
+    if (id !== this.state.BID) {
+      this.setState({ BID: id }, () => {
+        this.loadData()
+      })
+    }
+  }
+
+  /**
+   * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
+   */
+  getexceloutparam = (menuId, btnId) => {
+    const { mainSearch } = this.props
+    const { arr_field, config, search } = this.state
+
+    if (config.uuid !== menuId) return
+
+    let searches = search ? fromJS(search).toJS() : []
+    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
+      let keys = searches.map(item => item.key.toLowerCase())
+      mainSearch.forEach(item => {
+        if (!keys.includes(item.key.toLowerCase())) {
+          searches.push(item)
+        }
+      })
+    }
+
+    MKEmitter.emit('execExcelout', config.uuid, btnId, {
+      arr_field: arr_field,
+      orderBy: config.setting.order || '',
+      search: searches,
+      menuName: config.name
+    })
+  }
+
+  /**
+   * @description 鏁版嵁鍔犺浇
+   */
+  async loadData (hastimer) {
+    const { mainSearch, menuType } = this.props
+    const { config, arr_field, BID, search } = this.state
+
+    if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
+      this.setState({
+        data: []
+      }, () => {
+        this.handleData()
+      })
+      return
+    }
+
+    let searches = search ? fromJS(search).toJS() : []
+    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
+      let keys = searches.map(item => item.key)
+      mainSearch.forEach(item => {
+        if (!keys.includes(item.key)) {
+          searches.push(item)
+        }
+      })
+    }
+
+    if (!hastimer) {
+      this.setState({
+        loading: true
+      })
+    }
+
+    let _orderBy = config.setting.order || ''
+    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, '', '', BID, menuType)
+
+    let result = await Api.genericInterface(param)
+    if (result.status) {
+      this.setState({
+        data: result.data,
+        loading: false
+      }, () => {
+        this.handleData()
+      })
+    } else {
+      this.setState({
+        loading: false,
+        timer: null
+      })
+      notification.error({
+        top: 92,
+        message: result.message,
+        duration: 10
+      })
+    }
+  }
+
+  /**
+   * @description 鏁版嵁棰勫鐞嗭紝缁熻鏁版嵁闇�瑕侀噸缃�
+   */
   handleData = () => {
     const { data, plot } = this.state
 
@@ -259,47 +466,6 @@
         _element.innerHTML = ''
       }
       this.viewrender()
-    }
-  }
-
-  async loadData () {
-    const { mainSearch, BID, menuType, dataManager } = this.props
-    const { config, arr_field, search } = this.state
-
-    let searches = fromJS(search).toJS()
-    if (mainSearch && mainSearch.length > 0) { // 涓昏〃鎼滅储鏉′欢
-      let keys = searches.map(item => item.key)
-      mainSearch.forEach(item => {
-        if (!keys.includes(item.key)) {
-          searches.push(item)
-        }
-      })
-    }
-
-    this.setState({
-      loading: true
-    })
-
-    let _orderBy = config.setting.order || ''
-    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, '', '', BID, menuType, dataManager)
-
-    let result = await Api.genericInterface(param)
-    if (result.status) {
-      this.setState({
-        data: result.data,
-        loading: false
-      }, () => {
-        this.handleData()
-      })
-    } else {
-      this.setState({
-        loading: false
-      })
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 10
-      })
     }
   }
 
@@ -1160,7 +1326,7 @@
     }
 
     if (plot.linkmenu && plot.linkmenu.length > 0) {
-      let menu_id = plot.linkmenu[plot.linkmenu.length - 1]
+      let menu_id = plot.linkmenu.slice(-1)[0]
       let menu = this.props.permMenus.filter(m => m.MenuID === menu_id)[0] || ''
 
       chart.on('element:dblclick', (ev) => {
@@ -1224,9 +1390,14 @@
     })
   }
 
+  refreshSearch = (list) => {
+    this.setState({search: list}, () => {
+      this.loadData()
+    })
+  }
+
   render() {
-    const { BID } = this.props
-    const { showHeader, config, loading, title, plot, empty, chartFields, selectFields } = this.state
+    const { config, loading, plot, empty, chartFields, selectFields, BID } = this.state
 
     return (
       <div className="custom-line-chart-plot-box" style={config.style}>
@@ -1236,23 +1407,9 @@
             <Spin />
           </div> : null
         }
-        {showHeader ? <div className="chart-header" style={config.headerStyle}>
-          <span className="chart-title">{title}</span>
-          {/* <searchLine /> */}
-          {plot.datatype === 'statistics' && chartFields.length > 0 ? <Select
-            mode="multiple"
-            showSearch
-            showArrow={true}
-            value={selectFields}
-            onChange={this.handleChange}
-            maxTagCount={0}
-            maxTagPlaceholder={(option) => <div className="type-label">{option.join('銆�')}</div>}
-          >
-            {chartFields.map((item, i) => <Select.Option key={i} value={item}>{item}</Select.Option>)}
-          </Select> : null}
-        </div> : null}
+        <NormalHeader config={config} BID={BID} menuType={this.props.menuType} refresh={this.refreshSearch} />
         <div className="canvas-wrap">
-          <div className={'chart-action ' + (plot.title ? 'with-title' : '')}>
+          <div className="chart-action">
             {config.action.map(item => {
               if (item.OpenType === 'excelOut') {
                 return (
@@ -1262,8 +1419,6 @@
                     btn={item}
                     show="icon"
                     setting={config.setting}
-                    getexceloutparam={this.props.getexceloutparam}
-                    updateStatus={() => {}}
                   />
                 )
               } else {
@@ -1274,11 +1429,21 @@
                     btn={item}
                     show="icon"
                     setting={config.setting}
-                    updateStatus={() => {}}
                   />
                 )
               }
             })}
+            {plot.datatype === 'statistics' && chartFields.length > 0 ? <Select
+              mode="multiple"
+              showSearch
+              showArrow={true}
+              value={selectFields}
+              onChange={this.handleChange}
+              maxTagCount={0}
+              maxTagPlaceholder={(option) => <div className="type-label">{option.join('銆�')}</div>}
+            >
+              {chartFields.map((item, i) => <Select.Option key={i} value={item}>{item}</Select.Option>)}
+            </Select> : null}
           </div>
           <div className={'canvas' + (empty ? ' empty' : '')} id={this.state.chartId}></div>
         </div>

--
Gitblit v1.8.0