From b70376bd370f83e0087e629b664243f3a4bf191c Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 10 二月 2020 02:35:33 +0800
Subject: [PATCH] 2020-02-10

---
 src/templates/ushare/editable/index.jsx |   50 +++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 45 insertions(+), 5 deletions(-)

diff --git a/src/templates/ushare/editable/index.jsx b/src/templates/ushare/editable/index.jsx
index 4f10603..a3064ca 100644
--- a/src/templates/ushare/editable/index.jsx
+++ b/src/templates/ushare/editable/index.jsx
@@ -1,4 +1,5 @@
 import React, {Component} from 'react'
+import { is, fromJS } from 'immutable'
 import { Table, Input, Button, Popconfirm, Form, Icon } from 'antd'
 import Utils from '@/utils/utils.js'
 import './index.scss'
@@ -91,19 +92,38 @@
 class EditTable extends Component {
   constructor(props) {
     super(props)
+
+    let _width = '40%'
+    let fields = []
+
+    if (props.type === 'link') {
+      _width = '27%'
+    } else {
+      _width = Math.floor(80 / (props.linkSubFields.length + 2)) + '%'
+      fields = props.linkSubFields.map(field => {
+        return {
+          title: field.label,
+          dataIndex: field.field,
+          width: _width,
+          editable: true
+        }
+      })
+    }
+
     let columns = [
       {
         title: 'Value',
         dataIndex: 'Value',
-        width: props.type === 'link' ? '27%' : '40%',
+        width: _width,
         editable: true
       },
       {
         title: 'Text',
         dataIndex: 'Text',
-        width: props.type === 'link' ? '27%' : '40%',
+        width: _width,
         editable: true
       },
+      ...fields,
       {
         title: '鎿嶄綔',
         align: 'center',
@@ -166,20 +186,38 @@
     this.setState({ dataSource: newData })
   }
 
-  resetColumn = (type) => {
+  resetColumn = (type, linkSubFields) => {
+    let _width = '40%'
+    let fields = []
+
+    if (type === 'link') {
+      _width = '27%'
+    } else {
+      _width = Math.floor(80 / (linkSubFields.length + 2)) + '%'
+      fields = linkSubFields.map(field => {
+        return {
+          title: field.label,
+          dataIndex: field.field,
+          width: _width,
+          editable: true
+        }
+      })
+    }
+
     let columns = [
       {
         title: 'Value',
         dataIndex: 'Value',
-        width: type === 'link' ? '27%' : '40%',
+        width: _width,
         editable: true
       },
       {
         title: 'Text',
         dataIndex: 'Text',
-        width: type === 'link' ? '27%' : '40%',
+        width: _width,
         editable: true
       },
+      ...fields,
       {
         title: '鎿嶄綔',
         align: 'center',
@@ -211,6 +249,8 @@
   UNSAFE_componentWillReceiveProps (nextProps) {
     if (this.props.type !== nextProps.type) {
       this.resetColumn(nextProps.type)
+    } else if (!is(fromJS(this.props.linkSubFields), fromJS(nextProps.linkSubFields))) {
+      this.resetColumn(this.props.type, nextProps.linkSubFields)
     }
   }
 

--
Gitblit v1.8.0