From bd1dfc9e6c9b9f8076ca2783ce598e0936b4c664 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 22 十二月 2021 14:36:03 +0800
Subject: [PATCH] 2021-12-22

---
 src/tabviews/commontable/index.jsx |  240 ++++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 139 insertions(+), 101 deletions(-)

diff --git a/src/tabviews/commontable/index.jsx b/src/tabviews/commontable/index.jsx
index 7980e0c..9469b12 100644
--- a/src/tabviews/commontable/index.jsx
+++ b/src/tabviews/commontable/index.jsx
@@ -2,7 +2,7 @@
 import PropTypes from 'prop-types'
 import {connect} from 'react-redux'
 import { is, fromJS } from 'immutable'
-import { notification, Spin, Tabs, Icon, Switch, Row, Col } from 'antd'
+import { notification, Spin, Tabs, Switch, Row, Col } from 'antd'
 
 import Api from '@/api'
 import zhCN from '@/locales/zh-CN/main.js'
@@ -13,6 +13,7 @@
 import { updateCommonTable } from '@/utils/utils-update.js'
 import asyncComponent from '@/utils/asyncComponent'
 import asyncSpinComponent from '@/utils/asyncSpinComponent'
+import MkIcon from '@/components/mk-icon'
 import MKEmitter from '@/utils/events.js'
 import NotFount from '@/components/404'
 import './index.scss'
@@ -26,6 +27,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 +68,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,9 +90,10 @@
 
       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
       } catch (e) {
         console.warn('Parse Failure')
         config = ''
@@ -157,7 +161,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
+          })
         })
       }
       // 鍘婚櫎绌鸿鏍囩
@@ -176,16 +194,17 @@
       }
       let chartId = config.charts[0] ? config.charts[0].uuid : ''
 
-      // 瀛楁鏉冮檺榛戝悕鍗�
+      config.search = Utils.initSearchVal(config.search)
+
+      // 瀛楁閫忚鍙婂繀濉爣蹇�
+      let hasReqFields = false
       config.search = config.search.map(item => {
-        item.oriInitval = item.initval
         if (['text', 'select', 'link'].includes(item.type) && param && param.$searchkey === item.field) {
           item.initval = param.$searchval
         }
 
-        if (!item.blacklist || item.blacklist.length === 0) return item
-        if (item.blacklist.filter(v => roleId.indexOf(v) > -1).length > 0) {
-          item.Hide = 'true'
+        if (item.required) {
+          hasReqFields = true
         }
 
         return item
@@ -363,19 +382,29 @@
         _columns.push(config.gridBtn)
       }
 
-      let valid = true // 鎼滅储鏉′欢蹇呭~楠岃瘉, 鍒濆鎼滅储鏉′欢, 濡傞�氳繃涓婄骇閫忚锛屽啓鍏ユ悳绱㈡潯浠�
-      let hasReqFields = false
-      config.search.forEach(item => {
-        if (item.required !== 'true') return
-        if (!item.initval) {
-          valid = false
-        }
-        hasReqFields = true
-      })
+      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({
+        pageSize: config.setting.pageSize || 10,
         loadingview: false,
         absFields,
+        autoMatic,
         chartId,
         config,
         statFields,
@@ -386,10 +415,10 @@
         columns: _columns,
         arr_field: _arrField.join(','),
         BID: param && param.$BID ? param.$BID : '',
-        search: Utils.initMainSearch(config.search), // 鎼滅储鏉′欢鍒濆鍖栵紙鍚湁鏃堕棿鏍煎紡锛岄渶瑕佽浆鍖栵級
+        search: Utils.initMainSearch(config.search),
         hasReqFields
       }, () => {
-        if (config.setting.onload !== 'false' && valid) { // 鍒濆鍖栧彲鍔犺浇
+        if (config.setting.onload !== 'false') { // 鍒濆鍖栧彲鍔犺浇
           this.loadData()
         }
         this.setShortcut()
@@ -449,28 +478,26 @@
   }
 
   loadData = () => {
-    const { setting, search, BIDs, loadCustomApi, hasReqFields } = this.state
-    let requireFields = []
-
-    if (hasReqFields) {
-      requireFields = search.filter(item => item.required && (!item.value || item.value.length === 0))
-    }
+    const { MenuID } = this.props
+    const { setting, search, loadCustomApi, hasReqFields, ContainerId } = this.state
 
     this.setState({
-      selectedData: [],
-      BIDs: {
-        ...BIDs,
-        mainTable: '',
-        mainTabledata: ''
-      }
+      selectedData: []
     })
+    MKEmitter.emit('changeTableLine', ContainerId, MenuID, '', '')
 
-    if (requireFields.length > 0) {
-      this.setState({
-        loading: false
-      })
-      return
-    } else if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
+    if (hasReqFields) {
+      let requireFields = search.filter(item => item.required && item.value === '')
+
+      if (requireFields.length > 0) {
+        this.setState({
+          loading: false
+        })
+        return
+      }
+    }
+
+    if (window.GLOB.systemType === 'production' && setting.interType === 'custom' && !setting.proInterface) {
       notification.warning({
         top: 92,
         message: '鏈缃寮忕郴缁熷湴鍧�!',
@@ -555,7 +582,7 @@
     })
 
     Api.directRequest(url, setting.method, param, setting.cross).then(res => {
-      if (typeof(res) !== 'object' || Array.isArray(res)) {
+      if (typeof(res) !== 'object') {
         let error = '鏈煡鐨勮繑鍥炵粨鏋滐紒'
 
         if (typeof(res) === 'string') {
@@ -570,6 +597,9 @@
 
         this.customCallbackRequest(_result)
       } else {
+        if (Array.isArray(res)) {
+          res = { data: res }
+        }
         res.mk_api_key = mkey
         this.customCallbackRequest(res)
       }
@@ -661,7 +691,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
@@ -669,10 +699,6 @@
 
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType)
-
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.MenuName || ''
-    }
 
     let result = await Api.genericInterface(param)
 
@@ -682,6 +708,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({
@@ -706,10 +741,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,
@@ -730,10 +776,6 @@
 
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getQueryDataParams(setting, arr_field, search, _orderBy, pageIndex, pageSize, BID, this.props.menuType, id)
-
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.MenuName || ''
-    }
 
     let result = await Api.genericInterface(param)
     if (result.status) {
@@ -769,7 +811,7 @@
             }
             return item
           })
-        } catch {
+        } catch (e) {
           console.warn('鏁版嵁鏌ヨ閿欒')
         }
       }
@@ -801,10 +843,6 @@
 
     let _orderBy = orderBy || setting.order
     let param = UtilsDM.getStatQueryDataParams(setting, statFields, search, _orderBy, BID, this.props.menuType)
-
-    if (param.func === 'sPC_Get_TableData') {
-      param.menuname = this.props.MenuName || ''
-    }
 
     Api.genericInterface(param).then(res => {
       if (res.status) {
@@ -855,7 +893,7 @@
         this.loadData()
       })
     } else {
-      MKEmitter.emit('resetTable', this.props.MenuID + 'mainTable') // 鍒楄〃閲嶇疆
+      MKEmitter.emit('resetTable', this.props.MenuID) // 鍒楄〃閲嶇疆
       this.setState({
         pageIndex: 1,
         search: searches
@@ -869,6 +907,15 @@
    * @description 琛ㄦ牸鏉′欢鏀瑰彉鏃堕噸缃暟鎹紙鍒嗛〉鎴栨帓搴忥級
    */
   refreshbytable = (pagination, filters, sorter) => {
+    if (!sorter) {
+      this.setState({
+        pageIndex: pagination.pageIndex
+      }, () => {
+        this.loadData()
+      })
+      return
+    }
+
     if (sorter.order) {
       let _chg = {
         ascend: 'asc',
@@ -891,14 +938,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()
     }
   }
@@ -938,21 +985,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 鏁版嵁灞曞紑鍚堝苟鍒囨崲
@@ -989,12 +1021,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) => {
@@ -1005,32 +1041,35 @@
     this.setShortcut()
   }
 
+  changeTableLine = (ContainerId, tableId, id, data) => {
+    if (this.state.ContainerId !== ContainerId) return
+
+    this.setState({
+      BIDs: {...this.state.BIDs, [tableId]: id, [tableId + 'data']: data}
+    })
+  }
+
   /**
    * @description 鎸夐挳鎵ц瀹屾垚鍚庨〉闈㈠埛鏂�
    * @param {*} menuId     // 鑿滃崟Id
    * @param {*} position   // 鍒锋柊浣嶇疆
    * @param {*} btn        // 鎵ц鐨勬寜閽�
    */
-  refreshByButtonResult = (menuId, position, btn) => {
+  refreshByButtonResult = (menuId, position, btn, id, lines) => {
     const { MenuID } = this.props
 
     if (MenuID !== menuId) return
 
-    this.reloadtable(btn)
+    if (position === 'line' && lines && lines.length === 1) {
+      this.loadmainLinedata(lines[0].$$uuid)
+    } else {
+      this.reloadtable(btn)
+    }
   }
 
   UNSAFE_componentWillMount () {
     // 缁勪欢鍔犺浇鏃讹紝鑾峰彇鑿滃崟鏁版嵁
     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) {
@@ -1040,6 +1079,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)
@@ -1055,14 +1095,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}>
@@ -1074,7 +1115,7 @@
           {/* 瑙嗗浘缁� */}
           {!config.expand ? <Tabs activeKey={chartId} onChange={this.changeChart}>
             {config.charts.map(item => (
-              <TabPane tab={<Icon type={item.icon} />} key={item.uuid}></TabPane>
+              <TabPane tab={<MkIcon type={item.icon} />} key={item.uuid}></TabPane>
             ))}
           </Tabs> : null}
           {config.charts.map(item => {
@@ -1091,7 +1132,7 @@
                       actions={actions}
                       columns={columns}
                       dict={this.state.dict}
-                      MenuID={this.props.MenuID}
+                      MenuID={MenuID}
                       selectedData={selectedData}
                       ContainerId={this.state.ContainerId}
                     />
@@ -1101,7 +1142,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}
@@ -1109,12 +1151,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>
@@ -1126,14 +1166,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>
               )
@@ -1158,26 +1197,26 @@
               return (
                 <TabPane tab={
                   <span id={_tab.uuid}>
-                    {_tab.icon ? <Icon type={_tab.icon} /> : null}
+                    {_tab.icon ? <MkIcon type={_tab.icon} /> : null}
                     {_tab.label}
                   </span>
                 } 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>
@@ -1188,7 +1227,6 @@
 const mapStateToProps = (state) => {
   return {
     menuType: state.editLevel,
-    tabviews: state.tabviews,
     permAction: state.permAction,
     permMenus: state.permMenus
   }

--
Gitblit v1.8.0