From cb9ade2afd2a367ad767bc605ab7086c695dd010 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 09 十二月 2022 15:53:32 +0800
Subject: [PATCH] 2022-12-09

---
 src/tabviews/custom/components/card/balcony/index.jsx |  194 +++++++++++++++++++++++++-----------------------
 1 files changed, 101 insertions(+), 93 deletions(-)

diff --git a/src/tabviews/custom/components/card/balcony/index.jsx b/src/tabviews/custom/components/card/balcony/index.jsx
index c92528f..dde04a1 100644
--- a/src/tabviews/custom/components/card/balcony/index.jsx
+++ b/src/tabviews/custom/components/card/balcony/index.jsx
@@ -1,24 +1,21 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Spin, notification, Checkbox } from 'antd'
-import moment from 'moment'
+import { Spin, notification, Checkbox, Modal } from 'antd'
 
 import Api from '@/api'
-import Utils from '@/utils/utils.js'
 import UtilsDM from '@/utils/utils-datamanage.js'
 import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
+import TimerTask from '@/utils/timer-task.js'
 import './index.scss'
 
 const CardCellComponent = asyncComponent(() => import('../cardcellList'))
 
 class BalconyComponent extends Component {
   static propTpyes = {
-    BID: PropTypes.any,
     data: PropTypes.array,
     config: PropTypes.object,
-    menuType: PropTypes.any,
   }
 
   state = {
@@ -35,19 +32,31 @@
   }
 
   UNSAFE_componentWillMount () {
-    const { data, BID, initdata } = this.props
+    const { data, initdata } = this.props
     let _config = fromJS(this.props.config).toJS()
 
     let _data = { $$empty: true }
     let _sync = false
+
+    let BID = ''
+    let BData = ''
+
+    if (_config.setting.supModule) {
+      BData = window.GLOB.CacheData.get(_config.setting.supModule)
+    } else {
+      BData = window.GLOB.CacheData.get(_config.$pageId)
+    }
+    if (BData) {
+      BID = BData.$BID || ''
+    }
     
-    if (_config.setting && _config.wrap.datatype !== 'static') {
+    if (_config.wrap.datatype === 'dynamic') {
       _sync = _config.setting.sync === 'true'
 
       if (_sync && data) {
-        _data = data[_config.dataName] || {}
+        _data = data[_config.dataName] || {$$empty: true}
         if (_data && Array.isArray(_data)) {
-          _data = _data[0] || {}
+          _data = _data[0] || {$$empty: true}
         }
         _sync = false
       } else if (_sync && initdata) {
@@ -57,15 +66,20 @@
         }
         _sync = false
       }
+    } else if (_config.wrap.datatype === 'public' && window.GLOB.CacheData.get(_config.wrap.publicId)) {
+      _data = window.GLOB.CacheData.get(_config.wrap.publicId)
+      _data = fromJS(_data).toJS()
     }
 
-    if (_data) {
-      _data.$$BID = BID || ''
+    _data.$$BID = BID || ''
+    _data.$$BData = BData || ''
+    if (_config.setting.primaryKey) {
+      _data.$$uuid = _data[_config.setting.primaryKey] || ''
     }
 
     if (_config.wrap.position === 'fixed' || _config.wrap.position === 'absolute') {
       _config.style.position = _config.wrap.position
-      _config.style.zIndex = 2
+      _config.style.zIndex = 3
       _config.style.left = _config.wrap.left || ''
       _config.style.right = _config.wrap.right || ''
       _config.style.top = _config.wrap.top || ''
@@ -73,7 +87,7 @@
       _config.style.transform = _config.wrap.transform || ''
       _config.style.width = _config.wrap.realwidth || ''
     } else {
-      _config.style.zIndex = 2
+      _config.style.zIndex = 3
       _config.style.left = _config.wrap.left || ''
       _config.style.right = _config.wrap.right || ''
       _config.style.top = _config.wrap.top || ''
@@ -91,11 +105,8 @@
         }
         return item
       })
-    } else if (_config.wrap.linkType === 'sup') {
-      _config.wrap.supModule = _config.wrap.supModule.pop()
-      if (_config.wrap.supControl === 'hidden') {
-        show = false
-      }
+    } else if (_config.wrap.linkType === 'sup' && _config.wrap.supControl === 'hidden') {
+      show = false
     }
 
     this.setState({
@@ -107,7 +118,7 @@
       config: _config,
       arr_field: _config.columns.map(col => col.field).join(','),
     }, () => {
-      if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true') {
+      if (_config.wrap.datatype === 'dynamic' && _config.setting && _config.setting.sync !== 'true') {
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
@@ -116,11 +127,22 @@
   }
 
   componentDidMount () {
+    const { config } = this.state
+
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('syncBalconyData', this.syncBalconyData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
-    this.handleTimer()
+
+    if (config.wrap.datatype === 'public') {
+      MKEmitter.addListener('mkPublicData', this.mkPublicData)
+    }
+    
+    if (config.timer && config.wrap.datatype === 'dynamic') {
+      this.timer = new TimerTask()
+      this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData(true)})
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -128,87 +150,54 @@
   }
 
   componentWillUnmount () {
-    clearTimeout(this.timer)
     this.setState = () => {
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('mkPublicData', this.mkPublicData)
     MKEmitter.removeListener('syncBalconyData', this.syncBalconyData)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
+
+    this.timer && this.timer.stop()
   }
 
   /**
    * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
    */
   UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config, BID } = this.state
+    const { sync, config, BID, BData } = this.state
 
     if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
       let _data = {$$empty: true}
       if (nextProps.data && nextProps.data[config.dataName]) {
         _data = nextProps.data[config.dataName]
         if (_data && Array.isArray(_data)) {
-          _data = _data[0]
+          _data = _data[0] || {$$empty: true}
         }
       }
 
-      if (_data) {
-        _data.$$BID = BID || ''
-      }
+      _data.$$BID = BID || ''
+      _data.$$BData = BData || ''
+      _data.$$uuid = _data[config.setting.primaryKey] || ''
 
       this.setState({sync: false, data: _data})
     }
   }
 
-  handleTimer = () => {
-    const { config } = this.state
+  mkPublicData = (publicId, data) => {
+    const { config, BID, BData } = this.state
 
-    if (!config.timer) return
+    if (config.wrap.datatype === 'public' && config.wrap.publicId === publicId) {
+      let _data = fromJS(data).toJS()
 
-    const _change = { '5s': 5000, '15s': 15000, '30s': 30000, '1min': 60000, '5min': 300000, '10min': 600000, '15min': 900000, '30min': 1800000, '1hour': 3600000 }
+      _data.$$BID = BID || ''
+      _data.$$BData = BData || ''
+      _data.$$uuid = _data[config.setting.primaryKey] || ''
 
-    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
+      this.setState({data: _data})
     }
-    
-    _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)
   }
 
   /**
@@ -227,20 +216,10 @@
 
       this.loadData()
     } else {
-      let supModule = config.wrap.supModule
-
-      btn.syncComponentId && MKEmitter.emit('reloadData', btn.syncComponentId)
-
-      if (!btn.syncComponentId || btn.syncComponentId !== supModule) {
-        if (position === 'mainline' || position === 'popclose') { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠�
-          if (supModule && BID) {
-            MKEmitter.emit('reloadData', supModule, BID)
-          } else {
-            this.loadData()
-          }
-        } else {
-          this.loadData()
-        }
+      if ((position === 'mainline' || position === 'popclose') && config.wrap.supModule && BID) { // 鍒锋柊婧愮粍浠舵椂锛岄檮甯﹀埛鏂颁笂绾ц涓庡綋鍓嶇粍浠�
+        MKEmitter.emit('reloadData', config.wrap.supModule, BID)
+      } else {
+        this.loadData()
       }
       
       if (position === 'popclose') {                                      // 鏍囩鍏抽棴鍒锋柊
@@ -283,6 +262,22 @@
     }
   }
 
+  /**
+   * @description 瀵煎嚭Excel鏃讹紝鑾峰彇椤甸潰鎼滅储鎺掑簭绛夊弬鏁�
+   */
+  queryModuleParam = (menuId, callback) => {
+    const { config } = this.state
+
+    if (config.uuid !== menuId) return
+
+    callback({
+      arr_field: '',
+      orderBy: '',
+      search: [],
+      menuName: config.name
+    })
+  }
+
   reloadData = (menuId) => {
     const { config } = this.state
 
@@ -292,9 +287,13 @@
   }
 
   async loadData (hastimer) {
-    const { menuType } = this.props
     const { config, arr_field, BID, BData } = this.state
 
+    if (config.wrap.datatype === 'public') {
+      MKEmitter.emit('reloadData', config.wrap.publicId)
+      return
+    }
+    
     if (config.wrap.datatype === 'static') {
       this.setState({
         data: {$$BID: BID || '', $$BData: BData, $$empty: true},
@@ -316,7 +315,7 @@
     }
 
     let _orderBy = config.setting.order || ''
-    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID, menuType)
+    let param = UtilsDM.getQueryDataParams(config.setting, arr_field, searches, _orderBy, 1, 1, BID)
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -340,18 +339,25 @@
       if (config.timer && config.clearField) {
         let vals = (config.clearValue || '').split(',')
         if (vals.includes(_data[config.clearField])) {
-          clearTimeout(this.timer)
+          this.timer && this.timer.stop()
         }
       }
     } else {
       this.setState({
-        loading: false,
+        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
+        })
+      }
     }
   }
 
@@ -364,6 +370,8 @@
   render() {
     const { config, loading, data, show, syncConfig, syncData, checked } = this.state
 
+    if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null
+    
     return (
       <div className={'custom-balcony-box' + (!show ? ' hidden' : '')} style={config.style}>
         {loading ?

--
Gitblit v1.8.0