From 3ca91a731665962918a026f521c556f4745ebf35 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 16 十一月 2020 19:20:19 +0800
Subject: [PATCH] 2020-11-16

---
 src/tabviews/formtab/index.jsx |  137 ++++++++++++++++-----------------------------
 1 files changed, 49 insertions(+), 88 deletions(-)

diff --git a/src/tabviews/formtab/index.jsx b/src/tabviews/formtab/index.jsx
index 719b1c0..89ab064 100644
--- a/src/tabviews/formtab/index.jsx
+++ b/src/tabviews/formtab/index.jsx
@@ -11,11 +11,12 @@
 import Utils from '@/utils/utils.js'
 import options from '@/store/options.js'
 import asyncComponent from '@/utils/asyncLoadComponent'
+import MKEmitter from '@/utils/events.js'
 
 import FormGroup from './formgroup'
 import FormAction from './actionList'
 import NotFount from '@/components/404'
-import {refreshTabView, modifyTabview} from '@/store/action'
+import {modifyTabview} from '@/store/action'
 import './index.scss'
 
 const { TabPane } = Tabs
@@ -25,7 +26,6 @@
   static propTpyes = {
     MenuID: PropTypes.string,       // 鑿滃崟Id
     param: PropTypes.any,           // 涓昏〃浼犻�掑弬鏁�
-    refresh: PropTypes.any          // 鍒锋柊涓昏〃椤甸潰
   }
 
   state = {
@@ -40,14 +40,8 @@
     arr_field: '',        // 浣跨敤 sPC_Get_TableData 鏃剁殑鏌ヨ瀛楁闆�
     setting: null,        // 椤甸潰鍏ㄥ眬璁剧疆锛氭暟鎹簮銆佹寜閽強鏄剧ず鍒楀浐瀹氥�佷富閿瓑
     data: null,           // 鍒楄〃鏁版嵁闆�
-    configMap: {},        // 椤甸潰閰嶇疆淇℃伅锛氫笅鎷夈�佹寜閽瓑
     BIDs: {},             // 涓婄骇琛╥d
-    setsingle: false,     // 涓昏〃鍗曢�夊閫夊垏鎹�
-    pickup: false,        // 涓昏〃鏁版嵁闅愯棌鏄剧ず鍒囨崲
-    popData: false,       // 寮规椤甸潰锛屾墍閫夌殑琛ㄦ牸鏁版嵁
-    visible: false,       // 寮规鏄剧ず闅愯棌鎺у埗
     primaryId: null,
-    refreshtabs: null
   }
 
   /**
@@ -503,7 +497,7 @@
       this.setState({
         primaryId: primaryId
       }, () => {
-        if (btn.execSuccess === 'refresh') {
+        if (btn.execSuccess === 'refresh' || btn.execSuccess === 'grid') {
           this.loadmaindata()
         } else {
           let data = {}
@@ -524,53 +518,39 @@
         }
       })
     } else if (type === 'success' && btn.afterExecSuccess === 'close') {
-      if (this.props.refresh) {
-        this.props.refresh(btn.execSuccess)
-      } else {
-        if (btn.execSuccess !== 'never') {
-          let PMenu = {
-            MenuID: this.props.param.parentId || ''
-          }
-          this.props.refreshTabView(PMenu)
+      if (btn.execSuccess !== 'never') {
+        MKEmitter.emit('reloadData', this.props.param.parentId, 'formtab', btn)
+      }
+
+      let tabs = this.props.tabviews.filter(tab => {
+        tab.selected = false
+        if (tab.MenuID === this.props.param.parentId) {
+          tab.selected = true
         }
 
-        let tabs = this.props.tabviews.filter(tab => {
-          tab.selected = false
-          if (tab.MenuID === this.props.param.parentId) {
-            tab.selected = true
-          }
+        return tab.MenuID !== this.props.MenuID
+      })
 
-          return tab.MenuID !== this.props.MenuID
-        })
-
-        this.props.modifyTabview(tabs)
-      }
+      this.props.modifyTabview(tabs)
     } else if (type === 'error' && btn.afterExecError === 'notclose') {
       if (btn.execError === 'refresh') {
         this.loadmaindata()
       }
     } else if (type === 'error' && btn.afterExecError === 'close') {
-      if (this.props.refresh) {
-        this.props.refresh(btn.execError)
-      } else {
-        if (btn.execError !== 'never') {
-          let PMenu = {
-            MenuID: this.props.param.parentId || '',
-          }
-          this.props.refreshTabView(PMenu)
+      if (btn.execError !== 'never') {
+        MKEmitter.emit('reloadData', this.props.param.parentId, 'formtab', btn)
+      }
+
+      let tabs = this.props.tabviews.filter(tab => {
+        tab.selected = false
+        if (tab.MenuID === this.props.param.parentId) {
+          tab.selected = true
         }
 
-        let tabs = this.props.tabviews.filter(tab => {
-          tab.selected = false
-          if (tab.MenuID === this.props.param.parentId) {
-            tab.selected = true
-          }
+        return tab.MenuID !== this.props.MenuID
+      })
 
-          return tab.MenuID !== this.props.MenuID
-        })
-
-        this.props.modifyTabview(tabs)
-      }
+      this.props.modifyTabview(tabs)
     }
   }
 
@@ -590,31 +570,6 @@
   }
 
   /**
-   * @description 瀛愯〃鎿嶄綔瀹屾垚鍚庡埛鏂颁富琛�
-   */
-  handleMainTable = (type, tab) => {
-    if ((type === 'maingrid' || type === 'mainline') && tab.supMenu === 'mainTable') {
-      this.loadmaindata()
-    } else if ((type === 'maingrid' || type === 'mainline') && tab.supMenu) {
-      this.setState({
-        refreshtabs: [type, tab.supMenu]
-      }, () => {
-        this.setState({
-          refreshtabs: null
-        })
-      })
-    } else if (type === 'equaltab' && tab.equalTab && tab.equalTab.length > 0) {
-      this.setState({
-        refreshtabs: tab.equalTab
-      }, () => {
-        this.setState({
-          refreshtabs: null
-        })
-      })
-    }
-  }
-
-  /**
    * @description 鑾峰彇琛ㄥ崟鍙傛暟
    */
   getFormData = () => {
@@ -629,20 +584,29 @@
       config: {},
       groups: null,
       actions: null,
-      arr_field: '',
       setting: null,
       data: null,
-      configMap: {},
       BIDs: {},
-      setsingle: false,
-      pickup: false,
-      popData: false,
-      visible: false,
       primaryId: null,
-      refreshtabs: null
     }, () => {
       this.loadconfig()
     })
+  }
+
+  reloadMenuView = (menuId) => {
+    const { MenuID } = this.props
+
+    if (MenuID !== menuId) return
+
+    this.reloadview()
+  }
+
+  reloadData = (menuId) => {
+    const { MenuID } = this.props
+
+    if (MenuID !== menuId) return
+    
+    this.loadmaindata()
   }
 
   UNSAFE_componentWillMount () {
@@ -650,15 +614,13 @@
     this.loadconfig()
   }
 
-  UNSAFE_componentWillReceiveProps(nextProps) {
-    if (nextProps.refreshTab && nextProps.refreshTab.MenuID === this.props.MenuID) {
-      this.reloadview()
-      this.props.refreshTabView('')
-    }
-  }
-
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
+  }
+
+  componentDidMount () {
+    MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.addListener('reloadData', this.reloadData)
   }
 
   /**
@@ -668,6 +630,9 @@
     this.setState = () => {
       return
     }
+
+    MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.removeListener('reloadData', this.reloadData)
   }
 
   render() {
@@ -722,12 +687,10 @@
                           Tab={_tab}
                           MenuID={_tab.linkTab}
                           SupMenuID={this.props.MenuID}
-                          refreshtabs={this.state.refreshtabs}
                           ContainerId={this.state.ContainerId}
                           BID={this.state.BIDs[_tab.supMenu] || ''}
                           BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
                           handleTableId={this.handleTableId}
-                          handleMainTable={(type) => this.handleMainTable(type, _tab)}
                         /> : null}
                     </TabPane>
                   )
@@ -746,7 +709,6 @@
   return {
     menuType: state.editLevel,
     tabviews: state.tabviews,
-    refreshTab: state.refreshTab,
     permAction: state.permAction,
     dataManager: state.dataManager,
     permRoles: state.permRoles
@@ -755,7 +717,6 @@
 
 const mapDispatchToProps = (dispatch) => {
   return {
-    refreshTabView: (refreshTab) => dispatch(refreshTabView(refreshTab)),
     modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
   }
 }

--
Gitblit v1.8.0