From 9cacf4bf8339ebdfbf2fec7604b501a8dc32f9a4 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 18 一月 2023 23:06:42 +0800
Subject: [PATCH] 2023-01-18

---
 src/tabviews/custom/components/card/balcony/index.jsx |  113 ++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 92 insertions(+), 21 deletions(-)

diff --git a/src/tabviews/custom/components/card/balcony/index.jsx b/src/tabviews/custom/components/card/balcony/index.jsx
index c00e0fa..5336d0f 100644
--- a/src/tabviews/custom/components/card/balcony/index.jsx
+++ b/src/tabviews/custom/components/card/balcony/index.jsx
@@ -1,7 +1,7 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Spin, notification, Checkbox } from 'antd'
+import { Spin, notification, Checkbox, Modal } from 'antd'
 
 import Api from '@/api'
 import UtilsDM from '@/utils/utils-datamanage.js'
@@ -31,6 +31,8 @@
     checked: false
   }
 
+  loaded = false
+
   UNSAFE_componentWillMount () {
     const { data, initdata } = this.props
     let _config = fromJS(this.props.config).toJS()
@@ -50,26 +52,36 @@
       BID = BData.$BID || ''
     }
     
-    if (_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
+        this.loaded = true
       } else if (_sync && initdata) {
         _data = initdata
         if (Array.isArray(_data)) {
           _data = _data[0] || {$$empty: true}
         }
         _sync = false
+        this.loaded = true
       }
+    } 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()
+      this.loaded = true
+    } else if (_config.wrap.datatype === 'static') {
+      this.loaded = true
     }
 
-    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') {
@@ -113,7 +125,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)
@@ -129,10 +141,25 @@
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
+
+    if (config.wrap.datatype === 'public') {
+      MKEmitter.addListener('mkPublicData', this.mkPublicData)
+    }
     
-    if (config.timer) {
+    if (config.timer && config.wrap.datatype === 'dynamic') {
       this.timer = new TimerTask()
       this.timer.init(config.uuid, config.timer, config.timerRepeats, () => {this.loadData(true)})
+    }
+
+    if (config.$cache && !this.loaded) {
+      Api.getLCacheConfig(config.uuid).then(res => {
+        if (!res || this.loaded) return
+
+        let _data = res[0]
+        _data.$$uuid = _data[config.setting.primaryKey] || ''
+
+        this.setState({data: _data})
+      })
     }
   }
 
@@ -145,6 +172,7 @@
       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)
@@ -157,22 +185,40 @@
    * @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.loaded = true
 
       this.setState({sync: false, data: _data})
+    }
+  }
+
+  mkPublicData = (publicId, data) => {
+    const { config, BID, BData } = this.state
+
+    if (config.wrap.datatype === 'public' && config.wrap.publicId === publicId) {
+      let _data = fromJS(data).toJS()
+
+      _data.$$BID = BID || ''
+      _data.$$BData = BData || ''
+      _data.$$uuid = _data[config.setting.primaryKey] || ''
+
+      this.loaded = true
+
+      this.setState({data: _data})
     }
   }
 
@@ -265,6 +311,11 @@
   async loadData (hastimer) {
     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},
@@ -274,6 +325,7 @@
       this.setState({
         data: {$$BID: BID || '', $$BData: BData, $$empty: true},
       })
+      this.loaded = true
       return
     }
 
@@ -291,6 +343,11 @@
     let result = await Api.genericInterface(param)
     if (result.status) {
       let _data = {}
+
+      this.loaded = true
+      if (config.$cache) {
+        Api.writeCacheConfig(config.uuid, result.data || '')
+      }
 
       if (!result.data || !result.data[0]) {
         _data.$$empty = true
@@ -318,11 +375,17 @@
         loading: false
       })
       this.timer && this.timer.stop()
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 10
-      })
+      if (result.ErrCode === 'N') {
+        Modal.error({
+          title: result.message,
+        })
+      } else {
+        notification.error({
+          top: 92,
+          message: result.message,
+          duration: 10
+        })
+      }
     }
   }
 
@@ -332,20 +395,28 @@
     MKEmitter.emit('mkCheckAll', syncConfig.uuid, e.target.checked)
   }
 
+  triggerButton = () => {
+    const { config, data } = this.state
+
+    if (config.wrap.linkbtn) {
+      MKEmitter.emit('triggerBtnId', config.wrap.linkbtn, data.$$empty ? [] : [data])
+    }
+  }
+
   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}>
+      <div className={'custom-balcony-box' + (!show ? ' hidden' : '')} style={config.style} onClick={this.triggerButton}>
         {loading ?
-          <div className="loading-mask">
+          <div className="loading-mask" onClick={(e) => e.stopPropagation()}>
             <div className="ant-spin-blur"></div>
             <Spin />
           </div> : null
         }
-        {config.wrap.checkAll === 'show' ? <div className="check-all"><Checkbox checked={checked} onChange={this.checkAll}>鍏ㄩ��</Checkbox></div> : null}
+        {config.wrap.checkAll === 'show' ? <div className="check-all" onClick={(e) => e.stopPropagation()}><Checkbox checked={checked} onChange={this.checkAll}>鍏ㄩ��</Checkbox></div> : null}
         <CardCellComponent data={data} syncData={syncData || []} cards={syncConfig || config} cardCell={config} elements={config.elements}/>
       </div>
     )

--
Gitblit v1.8.0