From 0eb129a9beddbb86ae74d7106a8e60823206b8d5 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 14 十二月 2023 11:29:15 +0800
Subject: [PATCH] 2023-12-14

---
 src/tabviews/custom/components/form/simple-form/index.jsx |  106 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 92 insertions(+), 14 deletions(-)

diff --git a/src/tabviews/custom/components/form/simple-form/index.jsx b/src/tabviews/custom/components/form/simple-form/index.jsx
index 4491894..2968377 100644
--- a/src/tabviews/custom/components/form/simple-form/index.jsx
+++ b/src/tabviews/custom/components/form/simple-form/index.jsx
@@ -57,6 +57,13 @@
   
         window.GLOB.SyncData.delete(_config.dataName)
       }
+    } else if (_config.wrap.datatype === 'public') {
+      if (window.GLOB.CacheData.has(_config.wrap.publicId)) {
+        _data = window.GLOB.CacheData.get(_config.wrap.publicId)
+        _data = fromJS(_data).toJS()
+        _data.$$BID = BID || ''
+        _data.$$BData = BData || ''
+      }
     } else {
       _data = {$$empty: true}
     }
@@ -85,12 +92,14 @@
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
 
-    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)
+    } else if (config.setting.useMSearch) {
+      MKEmitter.addListener('searchRefresh', this.searchRefresh)
     }
 
     this.initExec()
@@ -105,6 +114,7 @@
       return
     }
     MKEmitter.removeListener('reloadData', this.reloadData)
+    MKEmitter.removeListener('mkPublicData', this.mkPublicData)
     MKEmitter.removeListener('mkFormSubmit', this.mkFormSubmit)
     MKEmitter.removeListener('searchRefresh', this.searchRefresh)
     MKEmitter.removeListener('resetSelectLine', this.resetParentParam)
@@ -138,6 +148,23 @@
     MKEmitter.removeListener('transferSyncData', this.transferSyncData)
   }
 
+  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 || ''
+
+      this.setState({
+        data: null
+      }, () => {
+        this.setState({data: _data})
+      })
+    }
+  }
+
   searchRefresh = (searchId) => {
     const { config } = this.state
 
@@ -149,11 +176,39 @@
   }
 
   reloadData = (menuId, id) => {
-    const { config } = this.state
+    const { config, group } = this.state
 
     if (config.uuid !== menuId) return
 
-    this.loadData()
+    if (id === 'focus-refresh' && config.wrap.refocus) {
+      let _group = fromJS(group).toJS()
+      _group.setting.focus = config.wrap.refocus
+
+      if (config.wrap.datatype === 'static') {
+        this.setState({
+          data: null,
+          group: _group
+        }, () => {
+          this.setState({data: {$$empty: true}})
+        })
+      } else {
+        this.setState({
+          group: _group
+        }, () => {
+          this.loadData(true)
+        })
+      }
+    } else if (id === 'focus-nofresh' && config.wrap.refocus) {
+      let formId = ''
+      group.fields.forEach(item => {
+        if (item.field === config.wrap.refocus) {
+          formId = item.uuid
+        }
+      })
+      MKEmitter.emit('mkFC', 'focus', formId)
+    } else {
+      this.loadData()
+    }
   }
 
   /**
@@ -165,7 +220,16 @@
   refreshByButtonResult = (menuId, position, btn, id) => {
     const { config, group, BID } = this.state
 
-    if (group.uuid !== menuId) return
+    if (config.uuid !== menuId) return
+
+    if (position === 'grid' && config.wrap.refocus) {
+      let _group = fromJS(group).toJS()
+      _group.setting.focus = config.wrap.refocus
+
+      this.setState({
+        group: _group
+      })
+    }
 
     if ((position === 'mainline' || position === 'popclose') && config.setting.supModule && BID) {
       MKEmitter.emit('reloadData', config.setting.supModule, BID)
@@ -176,7 +240,7 @@
         this.setState({data: {$$empty: true}})
       })
     } else {
-      this.loadData()
+      this.loadData(position === 'grid')
     }
 
     if (id) {
@@ -226,10 +290,22 @@
     }
   }
 
-  async loadData () {
-    const { config, BID } = this.state
+  async loadData (refocus) {
+    const { config, BID, group } = this.state
 
-    if (config.wrap.datatype === 'static') {
+    if (config.wrap.refocus && !refocus && group.setting.focus === config.wrap.refocus) {
+      let _group = fromJS(group).toJS()
+      _group.setting.focus = config.wrap.focus
+
+      this.setState({
+        group: _group
+      })
+    }
+
+    if (config.wrap.datatype === 'public') {
+      MKEmitter.emit('reloadData', config.wrap.publicId)
+      return
+    } else if (config.wrap.datatype === 'static') {
       this.setState({
         data: {$$empty: true}
       })
@@ -308,13 +384,15 @@
     }
   }
 
-  mkFormSubmit = (btnId) => {
+  mkFormSubmit = (btnId, callback, formId) => {
     const { group } = this.state
 
     if (group.uuid !== btnId) return
 
-    this.formRef.handleConfirm().then(res => {
+    this.formRef.handleConfirm(formId).then(res => {
       MKEmitter.emit('triggerFormSubmit', {menuId: btnId, form: res})
+    }, () => {
+      callback && callback()
     })
   }
 
@@ -355,7 +433,7 @@
           data={data}
           action={group}
           unload={config.setting.supModule && !BID}
-          inputSubmit={() => this.mkFormSubmit(group.uuid)}
+          inputSubmit={(id) => this.mkFormSubmit(group.uuid, null, id)}
           wrappedComponentRef={(inst) => this.formRef = inst}
         /> : null}
         {data ? <div className={'mk-form-action ' + (group.$button || '')}>

--
Gitblit v1.8.0