From fd71440db47f3205cccab84ddd77026cf1df579a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期日, 20 十一月 2022 22:35:17 +0800
Subject: [PATCH] 2022-11-20

---
 src/tabviews/custom/components/chart/antv-bar-line/index.jsx |  154 ++++++++++++++++++++-------------------------------
 1 files changed, 60 insertions(+), 94 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 b90d017..e9e806e 100644
--- a/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
+++ b/src/tabviews/custom/components/chart/antv-bar-line/index.jsx
@@ -3,7 +3,7 @@
 import { is, fromJS } from 'immutable'
 import { Chart } from '@antv/g2'
 import DataSet from '@antv/data-set'
-import { Spin, Empty, notification } from 'antd'
+import { Spin, Empty, notification, Modal } from 'antd'
 import { DownloadOutlined } from '@ant-design/icons'
 import moment from 'moment'
 
@@ -13,6 +13,7 @@
 import Utils from '@/utils/utils.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import MKEmitter from '@/utils/events.js'
+import TimerTask from '@/utils/timer-task.js'
 import NormalHeader from '@/tabviews/custom/components/share/normalheader'
 import './index.scss'
 
@@ -107,7 +108,13 @@
       })
     }
 
-    _config.style.height = config.plot.height || 400
+    _config.plot.height = Utils.getHeight(_config.plot.height)
+    _config.style.height = 'auto'
+    _config.style.minHeight = _config.plot.height + 30
+
+    if (_config.plot.title) {
+      _config.style.minHeight = _config.style.minHeight + 45
+    }
 
     let transfield = {}
     _config.columns.forEach(col => {
@@ -363,7 +370,7 @@
       this.setState({sync: false, data: _data}, () => {
         this.handleData()
       })
-    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({}, () => {
         this.loadData()
       })
@@ -375,18 +382,25 @@
   }
 
   componentDidMount () {
+    const { config } = this.state
+
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
-    this.handleTimer()
+    
+    if (config.timer) {
+      this.timer = new TimerTask()
+      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {
+        this.loadData(true)
+      })
+    }
   }
 
   /**
    * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊锛屾竻闄ゅ揩鎹烽敭璁剧疆
    */
   componentWillUnmount () {
-    clearTimeout(this.timer)
     this.setState = () => {
       return
     }
@@ -394,72 +408,8 @@
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
     MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
-  }
 
-  handleTimer = () => {
-    const { config } = this.state
-
-    if (!config.timer) return
-
-    const _change = { '2s': 2000, '5s': 5000, '15s': 15000, '30s': 30000, '1min': 60000, '5min': 300000, '10min': 600000, '15min': 900000, '30min': 1800000, '1hour': 3600000 }
-
-    let timer = _change[config.timer]
-    let repeats = config.timerRepeats || 0
-
-    if (!timer) return
-
-    if (repeats > 0 && repeats <=3) {
-      this.setState({timer, repeats})
-      this.timer = setTimeout(() => {
-        this.timerTask(repeats)
-      }, 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, repeats})
-        this.timer = setTimeout(() => {
-          this.timerTask(repeats)
-        }, timer)
-      }
-    })
-  }
-
-  timerTask = (times) => {
-    const { timer, repeats } = this.state
-    if (!timer) return
-    
-    this.loadData(true)
-
-    if (repeats) {
-      times = times - 1
-      if (times <= 0) {
-        clearTimeout(this.timer)
-        return
-      }
-    }
-    this.timer = setTimeout(() => {
-      this.timerTask(times)
-    }, timer)
+    this.timer && this.timer.stop()
   }
 
   /**
@@ -587,14 +537,21 @@
       })
     } else {
       this.setState({
-        loading: false,
-        timer: null
+        loading: false
       })
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 10
-      })
+      this.timer && this.timer.stop()
+      
+      if (result.ErrCode === 'N') {
+        Modal.error({
+          title: result.message,
+        })
+      } else {
+        notification.error({
+          top: 92,
+          message: result.message,
+          duration: 10
+        })
+      }
     }
   }
 
@@ -606,7 +563,9 @@
     if (_element) {
       _element.innerHTML = ''
     }
-    this.viewrender()
+    setTimeout(() => {
+      this.viewrender()
+    }, 100)
   }
 
   /**
@@ -952,7 +911,7 @@
     const chart = new Chart({
       container: this.state.chartId,
       autoFit: true,
-      height: this.wrap.offsetHeight - 25
+      height: plot.height
     })
 
     chart.data(_data)
@@ -1136,7 +1095,7 @@
     const chart = new Chart({
       container: this.state.chartId,
       autoFit: true,
-      height: this.wrap.offsetHeight - 25
+      height: plot.height
     })
     
     // 鍧愭爣杞存牸寮忓寲
@@ -1234,7 +1193,7 @@
       view1.scale('value', c)
       view1.axis('value', plot.$yc)
   
-      view1.legend(false)
+      // view1.legend(false)
 
       let colorIndex = 0
   
@@ -1368,7 +1327,7 @@
     }
 
     view2.data(dv.rows)
-    view2.legend(false)
+    // view2.legend(false)
 
     plot.customs.forEach(item => {
       if (item.chartType === 'bar' && !plot.Bar_axis) {
@@ -1546,7 +1505,7 @@
     const chart = new Chart({
       container: this.state.chartId,
       autoFit: true,
-      height: this.wrap.offsetHeight - 25
+      height: plot.height
     })
 
     chart.data(_data)
@@ -1766,8 +1725,6 @@
     chart.on('element:click', (ev) => {
       let data = ev.data.data
 
-      MKEmitter.emit('resetSelectLine', config.uuid, (data ? data.$$uuid : ''), data)
-
       if (plot.click === 'menus') {
         let menu = null
         
@@ -1796,16 +1753,23 @@
         } else {
           MKEmitter.emit('modifyTabs', newtab, 'plus', true)
         }
-      } else if (plot.click === 'menu' && plot.MenuID) {
-        let menu = {
-          MenuID: plot.MenuID,
-          MenuName: plot.MenuName,
-          MenuNo: plot.MenuNo,
-          type: plot.tabType
+      } else if (plot.click === 'menu') {
+        let menuId = plot.menu.slice(-1)[0]
+        let newtab = window.GLOB.mkThdMenus.filter(m => m.MenuID === menuId)[0]
+
+        if (!newtab && plot.MenuID) {
+          newtab = {
+            MenuID: plot.MenuID,
+            MenuName: plot.MenuName,
+            MenuNo: plot.MenuNo,
+            type: plot.tabType
+          }
+        } else if (!newtab) {
+          return
         }
   
-        let newtab = {
-          ...menu,
+        newtab = {
+          ...newtab,
           param: {}
         }
   
@@ -1818,6 +1782,8 @@
         } else {
           MKEmitter.emit('modifyTabs', newtab, 'plus', true)
         }
+      } else {
+        MKEmitter.emit('resetSelectLine', config.uuid, (data ? data.$$uuid : ''), data)
       }
     })
 
@@ -1895,7 +1861,7 @@
           </div> : null
         }
         <NormalHeader config={config} BID={BID} refresh={this.refreshSearch} />
-        <div className="canvas-wrap" ref={ref => this.wrap = ref}>
+        <div className="canvas-wrap">
           {config.plot.download === 'enable' && this.state.chart && !empty ? <DownloadOutlined onClick={this.downloadImage} className="system-color download"/> : null}
           <div className={'chart-action' + (config.plot.download === 'enable' ? ' downable' : '')}>
             {config.action.map(item => {

--
Gitblit v1.8.0