From 1da6506bf58270bacc2a4345002c6b082835580e Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 21 十月 2021 23:17:08 +0800
Subject: [PATCH] 2021-10-21

---
 src/tabviews/commontable/index.jsx |  156 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 102 insertions(+), 54 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index fdaa284..d37f4be 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -26,6 +26,7 @@
 const CardComponent = asyncSpinComponent(() => import('@/tabviews/zshare/cardcomponent'))
 const ChartComponent = asyncSpinComponent(() => import('@/tabviews/zshare/chartcomponent'))
 const PagemsgComponent = asyncComponent(() => import('@/tabviews/zshare/pageMessage'))
+const AutoMatic = asyncComponent(() => import('@/tabviews/zshare/automatic'))
 
 const { TabPane } = Tabs
 
@@ -66,18 +67,19 @@
     statFValue: [],       // 鍚堣鍊�
     absFields: [],        // 缁濆鍊煎瓧娈�
     loadCustomApi: true,  // 鍔犺浇澶栭儴璧勬簮
-    hasReqFields: false
+    hasReqFields: false,
+    autoMatic: null
   }
 
   /**
    * @description 鑾峰彇椤甸潰閰嶇疆淇℃伅
    */
   async loadconfig () {
-    const { permAction, permMenus, param, MenuName } = this.props
+    const { permAction, permMenus, param, MenuName, MenuID } = this.props
 
     let _param = {
       func: 'sPC_Get_LongParam',
-      MenuID: this.props.MenuID
+      MenuID: MenuID
     }
     let result = await Api.getCacheConfig(_param)
 
@@ -87,7 +89,7 @@
 
       try { // 閰嶇疆淇℃伅瑙f瀽
         config = JSON.parse(window.decodeURIComponent(window.atob(result.LongParam)))
-        config.MenuID = this.props.MenuID
+        config.MenuID = MenuID
         config.MenuName = MenuName
         config.setting.MenuName = MenuName
         config.setting.$name = MenuName
@@ -158,7 +160,21 @@
       if (this.props.menuType !== 'HS') {
         config.action = config.action.filter(item => permAction[item.uuid])
         config.tabgroups.forEach(group => {
-          group.sublist = group.sublist.filter(tab => permAction[tab.linkTab])
+          group.sublist = group.sublist.filter(tab => {
+            if (tab.supMenu === 'mainTable') {
+              tab.supMenu = MenuID
+            }
+            return permAction[tab.linkTab]
+          })
+        })
+      } else {
+        config.tabgroups.forEach(group => {
+          group.sublist = group.sublist.map(tab => {
+            if (tab.supMenu === 'mainTable') {
+              tab.supMenu = MenuID
+            }
+            return tab
+          })
         })
       }
       // 鍘婚櫎绌鸿鏍囩
@@ -365,9 +381,28 @@
         _columns.push(config.gridBtn)
       }
 
+      if (config.setting.selected !== 'init' && config.setting.selected !== 'always') {
+        config.setting.selected = 'false'
+      } else if (config.setting.selected === 'init' && config.setting.onload === 'false') {
+        config.setting.selected = 'false'
+      }
+
+      let autoMatic = null
+      if (config.autoMatic && config.autoMatic.enable === 'true') {
+        _actions.forEach(item => {
+          if (item.uuid === config.autoMatic.action && (['pop', 'prompt', 'exec'].includes(item.OpenType) || (item.OpenType === 'funcbutton' && item.funcType === 'print'))) {
+            autoMatic = config.autoMatic
+            autoMatic.OpenType = item.execMode || item.OpenType
+            config.setting.selected = 'false'
+            item.autoMatic = true
+          }
+        })
+      }
+
       this.setState({
         loadingview: false,
         absFields,
+        autoMatic,
         chartId,
         config,
         statFields,
@@ -441,15 +476,12 @@
   }
 
   loadData = () => {
+    const { MenuID } = this.props
     const { setting, search, BIDs, loadCustomApi, hasReqFields } = this.state
 
     this.setState({
       selectedData: [],
-      BIDs: {
-        ...BIDs,
-        mainTable: '',
-        mainTabledata: ''
-      }
+      BIDs: { ...BIDs, [MenuID]: '', [MenuID + 'data']: '' }
     })
 
     if (hasReqFields) {
@@ -657,7 +689,7 @@
    * @description 涓昏〃鏁版嵁鍔犺浇
    */ 
   async loadmaindata () {
-    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields } = this.state
+    const { setting, arr_field, search, orderBy, BID, pageIndex, pageSize, absFields, autoMatic } = this.state
 
     this.setState({
       loading: true
@@ -674,6 +706,15 @@
       let start = 1
       if (setting.laypage) {
         start = pageSize * (pageIndex - 1) + 1
+      }
+
+      if (setting.selected !== 'false') {
+        setTimeout(() => {
+          MKEmitter.emit('mkTableCheckTopLine', this.props.MenuID)
+        }, 200)
+        if (setting.selected === 'init') {
+          this.setState({setting: {...setting, selected: 'false'}})
+        }
       }
 
       this.setState({
@@ -698,10 +739,21 @@
         loading: false,
         pickup: false
       })
+
+      if (autoMatic) {
+        if (result.data && result.data.length > 0) {
+          MKEmitter.emit('autoGetData', this.props.MenuID)
+        } else {
+          MKEmitter.emit('autoMaticOver', this.props.MenuID)
+        }
+      }
     } else {
       this.setState({
         loading: false
       })
+      if (autoMatic) {
+        MKEmitter.emit('autoMaticError', this.props.MenuID)
+      }
       notification.error({
         top: 92,
         message: result.message,
@@ -757,7 +809,7 @@
             }
             return item
           })
-        } catch {
+        } catch (e) {
           console.warn('鏁版嵁鏌ヨ閿欒')
         }
       }
@@ -839,7 +891,7 @@
         this.loadData()
       })
     } else {
-      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.MenuID) // 鍒楄〃閲嶇疆
       this.setState({
         pageIndex: 1,
         search: searches
@@ -853,6 +905,15 @@
    * @description 琛ㄦ牸鏉′欢鏀瑰彉鏃堕噸缃暟鎹紙鍒嗛〉鎴栨帓搴忥級
    */
   refreshbytable = (pagination, filters, sorter) => {
+    if (!sorter) {
+      this.setState({
+        pageIndex: pagination.pageIndex
+      }, () => {
+        this.loadData()
+      })
+      return
+    }
+
     if (sorter.order) {
       let _chg = {
         ascend: 'asc',
@@ -875,14 +936,14 @@
    */
   reloadtable = (btn) => {
     if (!btn || btn.resetPageIndex !== 'false') {
-      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.MenuID) // 鍒楄〃閲嶇疆
       this.setState({
         pageIndex: 1
       }, () => {
         this.loadData()
       })
     } else {
-      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable', 'false') // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.MenuID, 'false') // 鍒楄〃閲嶇疆
       this.loadData()
     }
   }
@@ -922,21 +983,6 @@
   changeSelectedData = (selectedData) => {
     this.setState({selectedData})
   }
-
-  /**
-   * @description 琛ㄦ牸Id鍙樺寲
-   */
-  handleTableId = (type, id, data) => {
-    const { BIDs } = this.state
-
-    this.setState({
-      BIDs: {
-        ...BIDs,
-        [type]: id,
-        [type + 'data']: data
-      }
-    })
-  }
   
   /**
    * @description 鏁版嵁灞曞紑鍚堝苟鍒囨崲
@@ -973,12 +1019,16 @@
     }
   }
 
-  reloadMenuView = (menuId) => {
+  reloadMenuView = (menuId, position) => {
     const { MenuID } = this.props
 
     if (MenuID !== menuId) return
 
-    this.reloadview()
+    if (position === 'table') {
+      this.reloadtable()
+    } else {
+      this.reloadview()
+    }
   }
 
   resetActiveMenu = (menuId) => {
@@ -987,6 +1037,14 @@
     if (MenuID !== menuId) return
 
     this.setShortcut()
+  }
+
+  changeTableLine = (ContainerId, tableId, id, data) => {
+    if (this.state.ContainerId !== ContainerId) return
+
+    this.setState({
+      BIDs: {...this.state.BIDs, [tableId]: id, [tableId + 'data']: data}
+    })
   }
 
   /**
@@ -1008,15 +1066,6 @@
     this.loadconfig()
   }
 
-  UNSAFE_componentWillReceiveProps(nextProps) {
-    if (!is(fromJS(this.props.tabviews), fromJS(nextProps.tabviews))) {
-      let selectTab = nextProps.tabviews.filter(tab => tab.selected)[0]
-      if (selectTab && selectTab.MenuID === this.props.MenuID) {
-        this.setShortcut()
-      }
-    }
-  }
-
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.props), fromJS(nextProps)) || !is(fromJS(this.state), fromJS(nextState))
   }
@@ -1024,6 +1073,7 @@
   componentDidMount () {
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.addListener('changeTableLine', this.changeTableLine)
     MKEmitter.addListener('resetActiveMenu', this.resetActiveMenu)
     MKEmitter.addListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.addListener('refreshByButtonResult', this.refreshByButtonResult)
@@ -1039,14 +1089,15 @@
     document.onkeydown = () => {}
     MKEmitter.removeListener('reloadData', this.reloadData)
     MKEmitter.removeListener('reloadMenuView', this.reloadMenuView)
+    MKEmitter.removeListener('changeTableLine', this.changeTableLine)
     MKEmitter.removeListener('resetActiveMenu', this.resetActiveMenu)
     MKEmitter.removeListener('queryModuleParam', this.queryModuleParam)
     MKEmitter.removeListener('refreshByButtonResult', this.refreshByButtonResult)
   }
 
   render() {
-    const { menuType } = this.props
-    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData, shortcuts } = this.state
+    const { menuType, MenuID } = this.props
+    const { BID, setting, searchlist, pageSize, actions, columns, loadingview, viewlost, pickup, config, chartId, search, selectedData, shortcuts, autoMatic } = this.state
 
     return (
       <div className="commontable" id={this.state.ContainerId}>
@@ -1075,7 +1126,7 @@
                       actions={actions}
                       columns={columns}
                       dict={this.state.dict}
-                      MenuID={this.props.MenuID}
+                      MenuID={MenuID}
                       selectedData={selectedData}
                       ContainerId={this.state.ContainerId}
                     />
@@ -1085,7 +1136,8 @@
                       <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" checked={pickup} onChange={this.pickupChange} /> : null
                     }
                     <MainTable
-                      tableId="mainTable"
+                      MenuID={MenuID}
+                      tableId={MenuID}
                       pickup={pickup}
                       setting={setting}
                       columns={columns}
@@ -1093,12 +1145,10 @@
                       dict={this.state.dict}
                       data={this.state.data}
                       total={this.state.total}
-                      MenuID={this.props.MenuID}
                       loading={this.state.loading}
                       statFValue={this.state.statFValue}
                       ContainerId={this.state.ContainerId}
                       refreshdata={this.refreshbytable}
-                      handleTableId={this.handleTableId}
                       chgSelectData={this.changeSelectedData}
                     />
                   </div>
@@ -1110,14 +1160,13 @@
                   <CardComponent
                     BID={BID}
                     plot={item}
+                    MenuID={MenuID}
                     config={config}
+                    tableId={MenuID}
                     columns={columns}
-                    tableId="mainTable"
                     data={this.state.data}
-                    MenuID={this.props.MenuID}
                     loading={this.state.loading}
                     ContainerId={this.state.ContainerId}
-                    handleTableId={this.handleTableId}
                   />
                 </Col>
               )
@@ -1148,20 +1197,20 @@
                 } key={_tab.uuid}>
                   <SubTable
                     Tab={_tab}
+                    SupMenuID={MenuID}
                     MenuID={_tab.linkTab}
                     mainSearch={_tab.searchPass === 'true' ? search : null}
-                    SupMenuID={this.props.MenuID}
                     ContainerId={this.state.ContainerId}
                     BID={this.state.BIDs[_tab.supMenu] || ''}
                     BData={this.state.BIDs[_tab.supMenu + 'data'] || ''}
-                    handleTableId={this.handleTableId}
                   />
                 </TabPane>
               )
             })}
           </Tabs>))
         }
-        {menuType !== 'HS' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
+        {menuType !== 'HS' && autoMatic ? <AutoMatic autoMatic={autoMatic} config={config} /> : null}
+        {menuType !== 'HS' && window.GLOB.systemType !== 'production' ? <PagemsgComponent menu={{MenuName: this.props.MenuName, MenuNo: this.props.MenuNo}} config={config} dict={this.state.dict} /> : null}
         {menuType !== 'HS' && shortcuts ? <SettingComponent config={config} dict={this.state.dict} shortcuts={shortcuts} permAction={this.props.permAction}/> : null}
         {viewlost ? <NotFount msg={this.state.lostmsg} /> : null}
       </div>
@@ -1172,7 +1221,6 @@
 const mapStateToProps = (state) => {
   return {
     menuType: state.editLevel,
-    tabviews: state.tabviews,
     permAction: state.permAction,
     permMenus: state.permMenus
   }

--
Gitblit v1.8.0