From 9e60fb89a8b1c8a1d16b557b20b6d0a509f37983 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 04 六月 2021 19:22:39 +0800
Subject: [PATCH] 2021-06-04

---
 src/templates/zshare/editTable/index.jsx |   36 ++++++++++++++++++++++--------------
 1 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/src/templates/zshare/editTable/index.jsx b/src/templates/zshare/editTable/index.jsx
index 2caf0cc..da3ee13 100644
--- a/src/templates/zshare/editTable/index.jsx
+++ b/src/templates/zshare/editTable/index.jsx
@@ -171,6 +171,7 @@
   UNSAFE_componentWillMount () {
     const { data, actions } = this.props
     let columns = fromJS(this.props.columns).toJS()
+    let operation = null
 
     if (actions && (actions.includes('edit') || actions.includes('copy') || actions.includes('del'))) {
       let _operation = null
@@ -181,7 +182,7 @@
         return item.dataIndex !== 'operation'
       })
 
-      let operation = {
+      operation = {
         title: (<div>
           {eTDict['model.operation']}
           {actions.includes('copy') ? (
@@ -233,7 +234,7 @@
 
     this.setState({
       data: data || [],
-      oricolumns: fromJS(this.props.columns).toJS(),
+      operation,
       columns
     })
   }
@@ -241,19 +242,26 @@
   UNSAFE_componentWillReceiveProps (nextProps) {
     if (!is(fromJS(this.state.data), fromJS(nextProps.data))) {
       this.setState({data: nextProps.data, editingKey: ''})
-    } else if (!is(fromJS(this.state.oricolumns), fromJS(nextProps.columns))) {
-      let cols = {}
-      nextProps.columns.forEach(col => {cols[col.dataIndex] = col})
-
-      this.setState({
-        oricolumns: fromJS(nextProps.columns).toJS(),
-        columns: this.state.columns.map(col => {
-          if (cols[col.dataIndex]) {
-            return cols[col.dataIndex]
-          }
-          return col
+    } else if (!is(fromJS(this.props.columns), fromJS(nextProps.columns))) {
+      if (nextProps.columns.length === this.props.columns.length) {
+        let cols = {}
+        nextProps.columns.forEach(col => {cols[col.dataIndex] = col})
+  
+        this.setState({
+          columns: this.state.columns.map(col => {
+            if (cols[col.dataIndex]) {
+              return cols[col.dataIndex]
+            }
+            return col
+          })
         })
-      })
+      } else {
+        let columns = fromJS(nextProps.columns).toJS()
+        if (this.state.operation) {
+          columns.push(this.state.operation)
+        }
+        this.setState({columns})
+      }
     }
   }
 

--
Gitblit v1.8.0