From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 08 五月 2021 14:30:21 +0800
Subject: [PATCH] 2021-05-08

---
 src/templates/sharecomponent/fieldscomponent/index.jsx |  178 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 132 insertions(+), 46 deletions(-)

diff --git a/src/templates/sharecomponent/fieldscomponent/index.jsx b/src/templates/sharecomponent/fieldscomponent/index.jsx
index e83eded..f6a6609 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,25 +10,23 @@
 
 import './index.scss'
 
-// **鎮茶鑰呭線寰�姝g‘锛屼箰瑙傝�呭線寰�鎴愬姛
 class FieldsComponent extends Component {
   static propTpyes = {
     type: PropTypes.string,          // 鎼滅储鏉′欢娣诲姞銆佹樉绀哄垪娣诲姞
     config: PropTypes.object,        // 瀹瑰櫒Id
-    tableFields: PropTypes.string,   // 宸查�夎〃瀛楁闆�
     updatefield: PropTypes.func
   }
 
   state = {
-    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     fields: [],          // 瀛楁闆�
     tableVisible: false,    // 妯℃�佹鎺у埗
   }
 
   queryField = () => {
-    const { type, config, tableFields } = this.props
+    const { type, config } = this.props
     // 鍒ゆ柇鏄惁宸查�夋嫨琛ㄥ悕
-    if (!config.tables || config.tables.length === 0) {
+    if (!window.GLOB.tableFields || window.GLOB.tableFields.length === 0) {
       notification.warning({
         top: 92,
         message: '璇烽�夋嫨琛ㄥ悕锛�',
@@ -39,26 +37,40 @@
 
     // 琛ㄥ瓧娈甸泦杞负map鏁版嵁
     let columns = new Map()
-    tableFields.forEach(table => {
+    window.GLOB.tableFields.forEach(table => {
       table.columns.forEach(column => {
-        columns.set(column.field, column)
+        columns.set(column.field.toLowerCase(), column)
       })
     })
 
     if (type === 'search') {
       // 娣诲姞鎼滅储鏉′欢锛屽瓧娈甸泦涓瓨鍦ㄦ悳绱㈡潯浠跺瓧娈碉紝浣跨敤鎼滅储鏉′欢瀵硅薄鏇挎崲瀛楁闆嗭紝璁剧疆鏁版嵁绫诲瀷
       config.search.forEach(item => {
-        if (columns.has(item.field)) {
-          let _datatype = columns.get(item.field).datatype
-          columns.set(item.field, {...item, selected: true, datatype: _datatype})
+        if (columns.has(item.field.toLowerCase())) {
+          let _datatype = columns.get(item.field.toLowerCase()).datatype
+          columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
         }
       })
     } 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})
+        if (item.field && columns.has(item.field.toLowerCase())) {
+          let _datatype = columns.get(item.field.toLowerCase()).datatype
+          columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
+        }
+      })
+    } else if (type === 'fields') {
+      config.columns.forEach(item => {
+        if (columns.has(item.field.toLowerCase())) {
+          let _datatype = columns.get(item.field.toLowerCase()).datatype
+          columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
+        }
+      })
+    } else if (type === 'form') {
+      config.fields.forEach(item => {
+        if (item.field && columns.has(item.field.toLowerCase())) {
+          let _datatype = columns.get(item.field.toLowerCase()).datatype
+          columns.set(item.field.toLowerCase(), {...item, selected: true, datatype: _datatype})
         }
       })
     }
@@ -85,14 +97,14 @@
     let cards = this.refs.searchcard.state.selectCards
     let columnsMap = new Map()
     cards.forEach(card => {
-      columnsMap.set(card.field, card)
+      columnsMap.set(card.field.toLowerCase(), card)
     })
 
     let items = []
     if (type === 'search') {
       config.search.forEach(item => {
-        if (columnsMap.has(item.field)) {
-          let cell = columnsMap.get(item.field)
+        if (columnsMap.has(item.field.toLowerCase())) {
+          let cell = columnsMap.get(item.field.toLowerCase())
 
           if (cell.selected && cell.type === item.type) { // 鏁版嵁鏈慨鏀�
             items.push(item)
@@ -110,7 +122,7 @@
             item.initval = ''
             items.push(item)
           }
-          columnsMap.delete(item.field)
+          columnsMap.delete(item.field.toLowerCase())
         } else if (!item.origin) {
           items.push(item)
         }
@@ -139,11 +151,6 @@
             resourceType: '0',
             setAll: 'false',
             options: [],
-            dataSource: '',
-            linkField: '',
-            valueField: '',
-            valueText: '',
-            orderBy: '',
             orderType: 'asc',
             match: _match,
             display: 'dropdown'
@@ -152,15 +159,16 @@
           items.push(newcard)
         }
       })
+      config.search = items
     } else if (type === 'columns') {
       config.columns.forEach(item => {
-        if (columnsMap.has(item.field)) {
-          let cell = columnsMap.get(item.field)
+        if (item.field && columnsMap.has(item.field.toLowerCase())) {
+          let cell = columnsMap.get(item.field.toLowerCase())
 
           if (cell.selected) {
             items.push(item)
           }
-          columnsMap.delete(item.field)
+          columnsMap.delete(item.field.toLowerCase())
         } else if (!item.origin) {
           items.push(item)
         }
@@ -181,21 +189,103 @@
             Width: 120
           }
 
+          if (item.type === 'number') {
+            newcard.decimal = item.decimal
+          } else {
+            newcard.fieldlength = item.length || 50
+          }
+
           items.push(newcard)
         }
       })
+      config.columns = items
+    } else if (type === 'fields') {
+      config.columns.forEach(item => {
+        if (columnsMap.has(item.field.toLowerCase())) {
+          let cell = columnsMap.get(item.field.toLowerCase())
+
+          if (cell.selected) {
+            items.push(item)
+          }
+          columnsMap.delete(item.field.toLowerCase())
+        } 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)
+        }
+      })
+    } else if (type === 'form') {
+      config.fields.forEach(item => {
+        if (item.field && columnsMap.has(item.field.toLowerCase())) {
+          let cell = columnsMap.get(item.field.toLowerCase())
+  
+          if (cell.selected && cell.type === item.type) { // 鏁版嵁閫夋嫨鐘舵�佸強绫诲瀷鏈慨鏀规椂锛岀洿鎺ユ坊鍔�
+            items.push(item)
+          } else if (cell.selected) {                     // 鏁版嵁绫诲瀷淇敼鏃讹紝閲嶇疆绫诲瀷鍙婂垵濮嬪��
+            item.type = cell.type
+            item.initval = ''
+            items.push(item)
+          }
+          columnsMap.delete(item.field.toLowerCase())
+        } else if (!item.origin) {                        // 杩囨护绀轰緥椤�
+          items.push(item)
+        }
+      })
+  
+      let _columns = [...columnsMap.values()]
+      let lastItem = config.fields[config.fields.length - 1]
+      let span = lastItem ? lastItem.span || 12 : 12
+
+      _columns.forEach(item => { // 寰幆娣诲姞鏂板瀛楁
+        if (item.selected) {
+          let newcard = {
+            uuid: Utils.getuuid(),
+            label: item.label,
+            field: item.field,
+            initval: '',
+            type: item.type,
+            resourceType: '0',
+            setAll: 'false',
+            span: span,
+            labelwidth: 33.3,
+            options: [],
+            dataSource: '',
+            decimal: item.decimal,
+            orderType: 'asc',
+            readonly: 'false',
+            required: 'true'
+          }
+  
+          items.push(newcard)
+        }
+      })
+  
+      config.fields = items
     }
 
-    let _config = null
+    if (type === 'search' || type === 'columns' || type === 'form') {
+      this.props.updatefield(config)
 
-    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({
+        top: 92,
+        message: '鎿嶄綔鎴愬姛',
+        duration: 2
+      })
+    } else if (type === 'fields') {
+      this.props.updatefield(items)
 
       notification.success({
         top: 92,
@@ -203,6 +293,10 @@
         duration: 2
       })
     }
+  }
+
+  shouldComponentUpdate (nextProps, nextState) {
+    return !is(fromJS(this.state), fromJS(nextState))
   }
 
   /**
@@ -218,16 +312,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"
@@ -235,8 +322,7 @@
           visible={this.state.tableVisible}
           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