From c2580fb8de3bdaabb4179b0ce0fcd2fbac802441 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 01 三月 2023 00:49:14 +0800
Subject: [PATCH] 2023-03-01

---
 src/tabviews/custom/components/table/normal-table/index.jsx |  132 ++++++++++++++++++++++++++++---------------
 1 files changed, 86 insertions(+), 46 deletions(-)

diff --git a/src/tabviews/custom/components/table/normal-table/index.jsx b/src/tabviews/custom/components/table/normal-table/index.jsx
index bf7d655..7f66256 100644
--- a/src/tabviews/custom/components/table/normal-table/index.jsx
+++ b/src/tabviews/custom/components/table/normal-table/index.jsx
@@ -1,7 +1,7 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
 import { is, fromJS } from 'immutable'
-import { notification, Collapse } from 'antd'
+import { notification, Collapse, Modal } from 'antd'
 
 import Api from '@/api'
 import Utils from '@/utils/utils.js'
@@ -45,6 +45,8 @@
     statFValue: []        // 鍚堣鍊�
   }
 
+  loaded = false
+
   /**
    * @description 鍒濆鍖栧鐞�
    * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
@@ -52,7 +54,6 @@
   UNSAFE_componentWillMount () {
     const { data, initdata } = this.props
     let _config = fromJS(this.props.config).toJS()
-    let _cols = new Map()
     let _data = null
     let _sync = _config.setting.sync === 'true'
 
@@ -78,21 +79,22 @@
 
     let setting = {..._config.setting, ..._config.wrap}
 
-    if (setting.selected !== 'always' && setting.selected !== 'init') {
+    if (setting.selected !== 'always' && setting.selected !== 'init' && setting.selected !== 'sign') {
       setting.selected = 'false'
     } else {
       setting.orisel = true
     }
 
-    if (_config.setting.sync === 'true' && data) {
+    if (_sync && data) {
       _data = data[_config.dataName] || []
       _sync = false
-    } else if (_config.setting.sync === 'true' && initdata) {
+    } else if (_sync && initdata) {
       _data = initdata || []
       _sync = false
     }
 
     if (_data) {
+      this.loaded = true
       _data = _data.map((item, index) => {
         item.key = index
         item.$$uuid = item[_config.setting.primaryKey] || ''
@@ -120,38 +122,13 @@
 
       if (setting.selected !== 'false' && _data && _data.length > 0) {
         setTimeout(() => {
-          MKEmitter.emit('mkCheckTopLine', _config.uuid)
+          MKEmitter.emit('mkCheckTopLine', _config.uuid, '', setting.selected)
         }, 200)
         if (setting.selected === 'init') {
           setting.selected = 'false'
         }
       }
     }
-
-    _config.columns.forEach(item => {
-      if (item.type !== 'number') return
-      _cols.set(item.field, item)
-    })
-
-    _config.cols.forEach(column => {
-      if (column.type === 'custom') {
-        column.elements = column.elements.map(item => {
-          if (item.eleType === 'number' && item.field && _cols.has(item.field) && typeof(item.decimal) !== 'number') {
-            item.decimal = _cols.get(item.field).decimal || 0
-          }
-          return item
-        })
-      } else if (column.type === 'action') {
-        column.operations = column.elements
-      }
-    })
-
-    // if (setting.color) {
-    //   setting.style.color = setting.color
-    // }
-    // if (setting.fontSize) {
-    //   setting.style.fontSize = setting.fontSize
-    // }
 
     if (_config.wrap.collapse === 'true') {
       _config.wrap.title = _config.wrap.title || ' '
@@ -201,10 +178,12 @@
       })
       
       MKEmitter.emit('resetSelectLine', config.uuid, '', '') // 骞挎挱鏁版嵁鍒囨崲
-      reset && MKEmitter.emit('resetTable', config.uuid, repage) // 鍒楄〃閲嶇疆
+      reset && MKEmitter.emit('resetTable', config.uuid, 'true') // 鍒楄〃閲嶇疆
       if (setting.$hasSyncModule) {
         MKEmitter.emit('syncBalconyData', config.uuid, [], false)
       }
+
+      this.loaded = true
       return
     }
 
@@ -234,9 +213,31 @@
 
     let result = await Api.genericInterface(param)
     if (result.status) {
+      this.loaded = true
+      if (config.$cache && pageIndex === 1) {
+        Api.writeCacheConfig(config.uuid, result.data || '')
+      }
+
+      if (repage === 'false' && result.data && result.data.length === 0 && result.total > 0 && pageIndex > 1) {
+        let _pageIndex = Math.ceil(result.total / pageSize)
+
+        if (_pageIndex < pageIndex) {
+          MKEmitter.emit('resetTable', config.uuid, 'repage', _pageIndex)
+          this.setState({
+            pageIndex: _pageIndex,
+            data: [],
+            selectedData: [],
+            total: result.total
+          }, () => {
+            this.loadmaindata()
+          })
+          return
+        }
+      }
+      
       if ((setting.selected !== 'false' || (setting.orisel && id)) && result.data && result.data.length > 0) {
         setTimeout(() => {
-          MKEmitter.emit('mkCheckTopLine', config.uuid, id)
+          MKEmitter.emit('mkCheckTopLine', config.uuid, id, setting.selected)
         }, 200)
         if (setting.selected === 'init') {
           this.setState({setting: {...setting, selected: 'false'}})
@@ -289,11 +290,18 @@
         loading: false
       })
       this.timer && this.timer.stop()
-      notification.error({
-        top: 92,
-        message: result.message,
-        duration: 10
-      })
+      
+      if (result.ErrCode === 'N') {
+        Modal.error({
+          title: result.message,
+        })
+      } else {
+        notification.error({
+          top: 92,
+          message: result.message,
+          duration: 10
+        })
+      }
     }
   }
 
@@ -554,6 +562,7 @@
     const { setting } = this.state
 
     if (!setting.supModule || setting.supModule !== MenuID) return
+
     if (id !== this.state.BID || id !== '') {
       this.setState({
         pageIndex: 1,
@@ -628,7 +637,7 @@
 
         if (setting.selected !== 'false' && _data && _data.length > 0) {
           setTimeout(() => {
-            MKEmitter.emit('mkCheckTopLine', config.uuid)
+            MKEmitter.emit('mkCheckTopLine', config.uuid, '', setting.selected)
           }, 200)
           if (setting.selected === 'init') {
             this.setState({setting: {...setting, selected: 'false'}})
@@ -636,8 +645,10 @@
         }
       }
 
+      this.loaded = true
+
       this.setState({sync: false, data: _data})
-    } else if (config.setting.syncRefresh && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
+    } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({pageIndex: 1}, () => {
         this.reloadtable()
       })
@@ -649,7 +660,7 @@
   }
 
   componentDidMount () {
-    const { config } = this.state
+    const { config, setting } = this.state
 
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
@@ -665,6 +676,35 @@
           this.loadmaindata(true, 'true', '', 'timer')
           this.getStatFieldsValue()
         })
+      })
+    }
+
+    if (config.$cache && !this.loaded) {
+      Api.getLCacheConfig(config.uuid).then(res => {
+        if (!res || this.loaded) return
+
+        this.setState({data: res.map((item, index) => {
+          item.key = index
+          item.$$uuid = item[config.setting.primaryKey] || ''
+          item.$$key = '' + item.key + item.$$uuid
+          item.$Index = index + 1 + ''
+
+          if (config.absFields) {
+            config.absFields.forEach(f => {
+              if (!isNaN(item[f])) {
+                item[f] = Math.abs(item[f])
+              }
+            })
+          }
+
+          if (setting.controlField) {
+            if (setting.controlVal.includes(item[setting.controlField])) {
+              item.$disabled = true
+            }
+          }
+          
+          return item
+        })})
       })
     }
   }
@@ -699,15 +739,15 @@
             {config.search && config.search.length ?
               <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
             }
-            <MainAction
+            {actions.length > 0 ? <MainAction
               BID={BID}
               setting={setting}
               actions={actions}
               BData={BData}
               columns={config.columns}
               selectedData={selectedData}
-            />
-            <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}>
+            /> : <div className="mk-action-space" style={{height: '25px'}}></div>}
+            <div className="main-table-box">
               <MainTable
                 setting={setting}
                 columns={columns}
@@ -728,14 +768,14 @@
           {config.search && config.search.length ?
             <MainSearch BID={BID} config={config} refreshdata={this.refreshbysearch}/> : null
           }
-          <MainAction
+          {actions.length > 0 ? <MainAction
             BID={BID}
             setting={setting}
             actions={actions}
             BData={BData}
             columns={config.columns}
             selectedData={selectedData}
-          />
+          /> : <div className="mk-action-space" style={{height: '25px'}}></div>}
           <div className={'main-table-box ' + (!actions || actions.length === 0 ? 'no-action' : '')}>
             <MainTable
               setting={setting}

--
Gitblit v1.8.0