From 5df578ff69f6b02e821d59a8883bc75d78695a62 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期二, 10 十一月 2020 11:07:31 +0800
Subject: [PATCH] 2020-11-10

---
 src/templates/sharecomponent/fieldscomponent/index.jsx |   92 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 69 insertions(+), 23 deletions(-)

diff --git a/src/templates/sharecomponent/fieldscomponent/index.jsx b/src/templates/sharecomponent/fieldscomponent/index.jsx
index e83eded..2aefd5c 100644
--- a/src/templates/sharecomponent/fieldscomponent/index.jsx
+++ b/src/templates/sharecomponent/fieldscomponent/index.jsx
@@ -1,6 +1,6 @@
 import React, {Component} from 'react'
 import PropTypes from 'prop-types'
-import { fromJS } from 'immutable'
+import { is, fromJS } from 'immutable'
 import { Button, Modal, Empty, notification } from 'antd'
 
 import Utils from '@/utils/utils.js'
@@ -10,7 +10,6 @@
 
 import './index.scss'
 
-// **鎮茶鑰呭線寰�姝g‘锛屼箰瑙傝�呭線寰�鎴愬姛
 class FieldsComponent extends Component {
   static propTpyes = {
     type: PropTypes.string,          // 鎼滅储鏉′欢娣诲姞銆佹樉绀哄垪娣诲姞
@@ -20,7 +19,7 @@
   }
 
   state = {
-    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
+    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     fields: [],          // 瀛楁闆�
     tableVisible: false,    // 妯℃�佹鎺у埗
   }
@@ -28,7 +27,7 @@
   queryField = () => {
     const { type, config, tableFields } = this.props
     // 鍒ゆ柇鏄惁宸查�夋嫨琛ㄥ悕
-    if (!config.tables || config.tables.length === 0) {
+    if (!tableFields || tableFields.length === 0) {
       notification.warning({
         top: 92,
         message: '璇烽�夋嫨琛ㄥ悕锛�',
@@ -55,6 +54,13 @@
       })
     } else if (type === 'columns') {
       // 娣诲姞鏄剧ず鍒楋紝瀛楁闆嗕腑瀛樺湪鏄剧ず鍒楀瓧娈碉紝浣跨敤鏄剧ず鍒楀璞℃浛鎹㈠瓧娈甸泦锛岃缃暟鎹被鍨�
+      config.columns.forEach(item => {
+        if (columns.has(item.field)) {
+          let _datatype = columns.get(item.field).datatype
+          columns.set(item.field, {...item, selected: true, datatype: _datatype})
+        }
+      })
+    } else if (type === 'fields') {
       config.columns.forEach(item => {
         if (columns.has(item.field)) {
           let _datatype = columns.get(item.field).datatype
@@ -139,11 +145,6 @@
             resourceType: '0',
             setAll: 'false',
             options: [],
-            dataSource: '',
-            linkField: '',
-            valueField: '',
-            valueText: '',
-            orderBy: '',
             orderType: 'asc',
             match: _match,
             display: 'dropdown'
@@ -181,6 +182,40 @@
             Width: 120
           }
 
+          if (item.type === 'number') {
+            newcard.decimal = item.decimal
+          } else {
+            newcard.fieldlength = item.length || 50
+          }
+
+          items.push(newcard)
+        }
+      })
+    } else if (type === 'fields') {
+      config.columns.forEach(item => {
+        if (columnsMap.has(item.field)) {
+          let cell = columnsMap.get(item.field)
+
+          if (cell.selected) {
+            items.push(item)
+          }
+          columnsMap.delete(item.field)
+        } else {
+          items.push(item)
+        }
+      })
+
+      let _columns = [...columnsMap.values()]
+
+      _columns.forEach(item => {
+        if (item.selected) {
+          let newcard = {
+            uuid: Utils.getuuid(),
+            label: item.label,
+            field: item.field,
+            datatype: item.type === 'number' ? 'Decimal(18,0)' : 'Nvarchar(50)'
+          }
+
           items.push(newcard)
         }
       })
@@ -190,11 +225,7 @@
 
     if (type === 'search') {
       _config = {...this.props.config, search: items}
-    } else if (type === 'columns') {
-      _config = {...this.props.config, columns: items}
-    }
 
-    if (_config) {
       this.props.updatefield(_config)
 
       notification.success({
@@ -202,7 +233,29 @@
         message: '鎿嶄綔鎴愬姛',
         duration: 2
       })
+    } else if (type === 'columns') {
+      _config = {...this.props.config, columns: items}
+
+      this.props.updatefield(_config)
+
+      notification.success({
+        top: 92,
+        message: '鎿嶄綔鎴愬姛',
+        duration: 2
+      })
+    } else if (type === 'fields') {
+      this.props.updatefield(items)
+
+      notification.success({
+        top: 92,
+        message: '鎿嶄綔鎴愬姛',
+        duration: 2
+      })
     }
+  }
+
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
   }
 
   /**
@@ -218,16 +271,9 @@
     const { type } = this.props
     const { dict, fields } = this.state
 
-    let label = ''
-    if (type === 'search') {
-      label = dict['header.menu.search.add']
-    } else if (type === 'columns') {
-      label = dict['header.menu.column.add']
-    }
-
     return (
-      <div>
-        <Button type="primary" block onClick={this.queryField}>{label}</Button>
+      <div className="quickly-add">
+        <Button type="primary" block onClick={this.queryField}>{dict['model.batchAdd']}</Button>
         {/* 鏍规嵁瀛楁鍚嶆坊鍔犳樉绀哄垪鍙婃悳绱㈡潯浠� */}
         <Modal
           wrapClassName="model-table-fieldmanage-modal"
@@ -236,7 +282,7 @@
           width={'65vw'}
           maskClosable={false}
           style={{minWidth: '900px', maxWidth: '1200px'}}
-          cancelText={dict['header.close']}
+          cancelText={dict['model.close']}
           onOk={this.addFieldSubmit}
           onCancel={() => { // 鍙栨秷娣诲姞
             this.setState({

--
Gitblit v1.8.0