From 474c68f0fea10cc62977c67d186732b3346cdd53 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 17 一月 2023 18:04:45 +0800
Subject: [PATCH] 2023-01-17

---
 src/tabviews/custom/components/table/normal-table/index.jsx |   66 +++++++++++++++++++++++++++++++--
 1 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/src/tabviews/custom/components/table/normal-table/index.jsx b/src/tabviews/custom/components/table/normal-table/index.jsx
index 87c85cb..0ffafaa 100644
--- a/src/tabviews/custom/components/table/normal-table/index.jsx
+++ b/src/tabviews/custom/components/table/normal-table/index.jsx
@@ -45,6 +45,8 @@
     statFValue: []        // 鍚堣鍊�
   }
 
+  loaded = false
+
   /**
    * @description 鍒濆鍖栧鐞�
    * 1銆� initdata 涓烘墦鍗版椂浣跨敤鐨勬暟鎹泦
@@ -84,15 +86,16 @@
       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] || ''
@@ -201,10 +204,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,6 +239,28 @@
 
     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, setting.selected)
@@ -644,6 +671,8 @@
         }
       }
 
+      this.loaded = true
+
       this.setState({sync: false, data: _data})
     } else if (config.setting.useMSearch && nextProps.mainSearch && !is(fromJS(this.props.mainSearch), fromJS(nextProps.mainSearch))) {
       this.setState({pageIndex: 1}, () => {
@@ -657,7 +686,7 @@
   }
 
   componentDidMount () {
-    const { config } = this.state
+    const { config, setting } = this.state
 
     MKEmitter.addListener('reloadData', this.reloadData)
     MKEmitter.addListener('resetSelectLine', this.resetParentParam)
@@ -675,6 +704,35 @@
         })
       })
     }
+
+    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
+        })})
+      })
+    }
   }
 
   /**

--
Gitblit v1.8.0