From 71e3da644eca32a5aa40503e903efb0640748093 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 21 七月 2023 17:00:59 +0800
Subject: [PATCH] 2023-07-21

---
 src/tabviews/custom/components/editor/braft-editor/index.jsx |  162 ++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 104 insertions(+), 58 deletions(-)

diff --git a/src/tabviews/custom/components/editor/braft-editor/index.jsx b/src/tabviews/custom/components/editor/braft-editor/index.jsx
index 5c41173..38f0382 100644
--- a/src/tabviews/custom/components/editor/braft-editor/index.jsx
+++ b/src/tabviews/custom/components/editor/braft-editor/index.jsx
@@ -1,7 +1,7 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { Spin, notification } from 'antd'
+import { Spin, notification, Modal } from 'antd'
 
 import asyncComponent from '@/utils/asyncComponent'
 import Api from '@/api'
@@ -14,25 +14,21 @@
 
 class BraftEditorContent extends Component {
   static propTpyes = {
-    data: PropTypes.array,           // 缁熶竴鏌ヨ鏁版嵁
-    config: PropTypes.object,        // 缁勪欢閰嶇疆淇℃伅
-    mainSearch: PropTypes.any,       // 澶栧眰鎼滅储鏉′欢
+    config: PropTypes.object
   }
 
   state = {
     BID: '',                   // 涓婄骇ID
     config: null,              // 鍥捐〃閰嶇疆淇℃伅
     loading: false,            // 鏁版嵁鍔犺浇鐘舵��
-    sync: false,               // 鏄惁缁熶竴璇锋眰鏁版嵁
     data: {}                   // 鏁版嵁
   }
 
   UNSAFE_componentWillMount () {
-    const { data, initdata } = this.props
-    let _config = fromJS(this.props.config).toJS()
+    const { config } = this.props
 
-    let _data = {}
-    let _sync = false
+    let _config = fromJS(config).toJS()
+    let _data = { $$empty: true }
 
     let BID = ''
     let BData = ''
@@ -46,24 +42,15 @@
       BID = BData.$BID || ''
     }
     
-    if (_config.setting && _config.wrap.datatype !== 'static') {
-      _sync = _config.setting.sync === 'true'
+    if (_config.wrap.datatype === 'dynamic') {
+      if (_config.setting.sync === 'true' && window.GLOB.SyncData.has(_config.dataName)) {
+        _data = window.GLOB.SyncData.get(_config.dataName) || []
+        _data = _data[0] || {$$empty: true}
 
-      if (_sync && data) {
-        _data = data[_config.dataName] || {}
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0] || {}
-        }
-        _sync = false
-      } else if (_sync && initdata) {
-        _data = initdata || {}
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0] || {}
-        }
-        _sync = false
+        _config.setting.sync = 'false'
+  
+        window.GLOB.SyncData.delete(_config.dataName)
       }
-    } else {
-      _data = {}
     }
 
     if (_config.wrap.minHeight) {
@@ -71,13 +58,12 @@
     }
 
     this.setState({
-      sync: _sync,
       data: _data,
       BID: BID || '',
       config: _config,
       arr_field: _config.columns.map(col => col.field).join(','),
     }, () => {
-      if (_config.wrap.datatype !== 'static' && _config.setting && _config.setting.sync !== 'true' && _config.setting.onload === 'true') {
+      if (_config.wrap.datatype === 'dynamic' && config.setting.sync !== 'true' && _config.setting.onload === 'true') {
         setTimeout(() => {
           this.loadData()
         }, _config.setting.delay || 0)
@@ -86,8 +72,22 @@
   }
 
   componentDidMount () {
+    const { config } = this.state
+
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
+
+    if (config.setting.useMSearch) {
+      MKEmitter.addListener('searchRefresh', this.searchRefresh)
+    }
+
+    if (config.setting.sync === 'true') {
+      MKEmitter.addListener('transferSyncData', this.transferSyncData)
+    }
+
+    if (config.wrap.datatype === 'public') {
+      MKEmitter.addListener('mkPublicData', this.mkPublicData)
+    }
   }
 
   shouldComponentUpdate (nextProps, nextState) {
@@ -99,29 +99,44 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('mkPublicData', this.mkPublicData)
+    MKEmitter.removeListener('searchRefresh', this.searchRefresh)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
   }
 
-  /**
-   * @description 鍥捐〃鏁版嵁鏇存柊锛屽埛鏂板唴瀹�
-   */
-  UNSAFE_componentWillReceiveProps (nextProps) {
-    const { sync, config } = this.state
+  transferSyncData = (syncId) => {
+    const { config } = this.state
 
-    if (sync && !is(fromJS(this.props.data), fromJS(nextProps.data))) {
-      let _data = {}
-      if (nextProps.data && nextProps.data[config.dataName]) {
-        _data = nextProps.data[config.dataName]
-        if (_data && Array.isArray(_data)) {
-          _data = _data[0]
-        }
-      }
+    if (config.$syncId !== syncId) return
 
-      this.setState({sync: false, data: _data})
-    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
-      this.setState({}, () => {
-        this.loadData()
-      })
+    let _data = window.GLOB.SyncData.get(config.dataName) || []
+    _data = _data[0] || {$$empty: true}
+
+    this.setState({data: _data})
+
+    window.GLOB.SyncData.delete(config.dataName)
+
+    MKEmitter.removeListener('transferSyncData', this.transferSyncData)
+  }
+
+  searchRefresh = (searchId) => {
+    const { config } = this.state
+
+    if (config.$searchId !== searchId) return
+    
+    this.setState({}, () => {
+      this.loadData()
+    })
+  }
+
+  mkPublicData = (publicId, data) => {
+    const { config } = this.state
+
+    if (config.wrap.datatype === 'public' && config.wrap.publicId === publicId) {
+      let _data = fromJS(data).toJS()
+
+      this.setState({data: _data})
     }
   }
 
@@ -145,27 +160,33 @@
   }
 
   async loadData () {
-    const { mainSearch } = this.props
     const { config, arr_field, BID } = this.state
 
+    if (config.wrap.datatype === 'public') {
+      MKEmitter.emit('reloadData', config.wrap.publicId)
+      return
+    }
+    
     if (config.wrap.datatype === 'static') {
       this.setState({
-        data: {},
+        data: {$$empty: true},
         loading: false
       })
       return
     } else if (config.setting.supModule && !BID) { // BID 涓嶅瓨鍦ㄦ椂锛屼笉鍋氭煡璇�
       this.setState({
-        data: {},
+        data: {$$empty: true},
         loading: false
       })
       return
     }
 
-    let searches = config.setting.useMSearch && mainSearch ? mainSearch : []
+    let searches = []
+    if (config.setting.useMSearch) { // 涓昏〃鎼滅储鏉′欢
+      searches = window.GLOB.SearchBox.get(config.$searchId) || []
+    }
 
-    let requireFields = searches.filter(item => item.required && item.value === '')
-    if (requireFields.length > 0) {
+    if (config.$s_req && searches.filter(item => item.required && item.value === '').length > 0) {
       return
     }
 
@@ -178,29 +199,54 @@
 
     let result = await Api.genericInterface(param)
     if (result.status) {
-      let _data = result.data && result.data[0] ? result.data[0] : {}
+      let _data = result.data || []
+      _data = _data[0] || {$$empty: true}
 
       this.setState({
         data: _data,
         loading: false
       })
+
+      if (result.message) {
+        if (result.ErrCode === 'Y') {
+          Modal.success({
+            title: result.message
+          })
+        } else if (result.ErrCode === 'S') {
+          notification.success({
+            top: 92,
+            message: result.message,
+            duration: 2
+          })
+        }
+      }
     } else {
       this.setState({
         loading: false
       })
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 10
-      })
+      
+      if (!result.message) return
+      if (result.ErrCode === 'N') {
+        Modal.error({
+          title: result.message
+        })
+      } else if (result.ErrCode !== '-2') {
+        notification.error({
+          top: 92,
+          message: result.message,
+          duration: 10
+        })
+      }
     }
   }
 
   render() {
     const { config, loading, data } = this.state
 
+    if (config.wrap.empty === 'hidden' && (!data || data.$$empty)) return null
+
     return (
-      <div className="custom-braft-editor-box" id={'anchor' + config.uuid} style={config.style}>
+      <div className={'custom-braft-editor-box ' + (config.wrap.firstTr || '')} id={'anchor' + config.uuid} style={config.style}>
         {loading ?
           <div className="loading-mask">
             <div className="ant-spin-blur"></div>

--
Gitblit v1.8.0