From 76427d51a079a5fd1f45bf7188249e7a4647ae05 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 14 九月 2020 10:37:25 +0800
Subject: [PATCH] 2020-09-14

---
 src/templates/sharecomponent/tablecomponent/index.jsx |  228 ++++++++-------------------------------------------------
 1 files changed, 32 insertions(+), 196 deletions(-)

diff --git a/src/templates/sharecomponent/tablecomponent/index.jsx b/src/templates/sharecomponent/tablecomponent/index.jsx
index 4a17396..72431bb 100644
--- a/src/templates/sharecomponent/tablecomponent/index.jsx
+++ b/src/templates/sharecomponent/tablecomponent/index.jsx
@@ -14,7 +14,6 @@
 
 const { Option } = Select
 
-// **鎮茶鑰呭線寰�姝g‘锛屼箰瑙傝�呭線寰�鎴愬姛
 class TablesComponent extends Component {
   static propTpyes = {
     config: PropTypes.object,        // 瀹瑰櫒Id
@@ -23,7 +22,7 @@
   }
 
   state = {
-    dict: (!localStorage.getItem('lang') || localStorage.getItem('lang') === 'zh-CN') ? zhCN : enUS,
+    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     tables: [],          // 绯荤粺琛�
     tableFields: [],    // 宸查�夎〃瀛楁闆�
     selectedTables: [],  // 宸查�夎〃
@@ -60,8 +59,9 @@
     }
 
     param.LText = Utils.formatOptions(param.LText)
-    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss') + '.000'
+    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
     param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+    param.open_key = Utils.encryptOpenKey(param.secretkey, param.timestamp) // 浜戠鏁版嵁楠岃瘉
 
     Api.getSystemConfig(param).then(res => {
       if (res.status) {
@@ -96,23 +96,19 @@
             columns: res.FDName.map(item => {
               let _type = item.FieldType.toLowerCase()
               let _decimal = 0
+              let _length = 50
               if (/^nvarchar/.test(_type)) {
+                try { // 瀛樺湪max
+                  _length = +_type.match(/\d+/)[0] || 50
+                } catch {
+                  _length = 2048
+                }
                 _type = 'text'
               } else if (/^int/.test(_type)) {
                 _type = 'number'
               } else if (/^decimal/.test(_type)) {
                 _decimal = _type.split(',')[1]
                 _decimal = parseInt(_decimal)
-                if (_decimal > 4) {
-                  _decimal = 4
-                }
-                _type = 'number'
-              } else if (/^decimal/.test(_type)) {
-                _decimal = _type.split(',')[1]
-                _decimal = parseInt(_decimal)
-                if (_decimal > 4) {
-                  _decimal = 4
-                }
                 _type = 'number'
               } else if (/^datetime/.test(_type)) {
                 _type = 'datetime'
@@ -127,7 +123,8 @@
                 label: item.FieldDec,
                 type: _type,
                 datatype: _type,
-                decimal: _decimal
+                decimal: _decimal,
+                length: _length,
               }
             })
           }
@@ -149,179 +146,9 @@
     })
   }
 
-  queryField = (type) => {
-    const {selectedTables, tableFields, config} = this.state
-    // 鍒ゆ柇鏄惁宸查�夋嫨琛ㄥ悕
-    if (selectedTables.length === 0) {
-      notification.warning({
-        top: 92,
-        message: '璇烽�夋嫨琛ㄥ悕锛�',
-        duration: 5
-      })
-      return
-    }
-
-    // 琛ㄥ瓧娈甸泦杞负map鏁版嵁
-    let columns = new Map()
-    tableFields.forEach(table => {
-      table.columns.forEach(column => {
-        columns.set(column.field, 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})
-        }
-      })
-    } 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})
-        }
-      })
-    }
-
-    // 鏄剧ず瀛楁闆嗗脊绐�
-    this.setState({
-      addType: type,
-      tableVisible: true,
-      fields: [...columns.values()]
-    })
-  }
-
-  addFieldSubmit = () => {
-    // 瀛楁闆嗕负绌猴紝鍏抽棴寮圭獥
-    if (!this.state.fields || this.state.fields.length === 0) {
-      this.setState({
-        tableVisible: false,
-        addType: ''
-      })
-    }
-
-    const {addType, config} = this.state
-
-    // 鑾峰彇宸查�夊瓧娈甸泦鍚�
-    let cards = this.refs.searchcard.state.selectCards
-    let columnsMap = new Map()
-    cards.forEach(card => {
-      columnsMap.set(card.field, card)
-    })
-
-    let items = []
-    if (addType === 'search') {
-      config.search.forEach(item => {
-        if (columnsMap.has(item.field)) {
-          let cell = columnsMap.get(item.field)
-
-          if (cell.selected && cell.type === item.type) { // 鏁版嵁鏈慨鏀�
-            items.push(item)
-          } else if (cell.selected) { // 鏁版嵁绫诲瀷淇敼
-            if (cell.type === 'select') {
-              item.match = '='
-            } else if (cell.type === 'daterange') {
-              item.match = 'between'
-            } else {
-              cell.type = 'text'
-              item.match = 'like'
-            }
-            
-            item.type = cell.type
-            item.initval = ''
-            items.push(item)
-          }
-          columnsMap.delete(item.field)
-        } else if (!item.origin) {
-          items.push(item)
-        }
-      })
-
-      let _columns = [...columnsMap.values()]
-
-      _columns.forEach(item => {
-        if (item.selected) {
-          let _match = ''
-          if (item.type === 'select') {
-            _match = '='
-          } else if (item.type === 'daterange') {
-            _match = 'between'
-          } else {
-            item.type = 'text'
-            _match = 'like'
-          }
-
-          let newcard = {
-            uuid: Utils.getuuid(),
-            label: item.label,
-            field: item.field,
-            initval: '',
-            type: item.type,
-            resourceType: '0',
-            setAll: 'false',
-            options: [],
-            dataSource: '',
-            linkField: '',
-            valueField: '',
-            valueText: '',
-            orderBy: '',
-            orderType: 'asc',
-            match: _match,
-            display: 'dropdown'
-          }
-
-          items.push(newcard)
-        }
-      })
-    } else {
-      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 if (!item.origin) {
-          items.push(item)
-        }
-      })
-
-      let _columns = [...columnsMap.values()]
-
-      _columns.forEach(item => {
-        if (item.selected) {
-          let newcard = {
-            uuid: Utils.getuuid(),
-            Align: 'left',
-            label: item.label,
-            field: item.field,
-            Hide: 'false',
-            IsSort: item.type === 'picture' ? 'false' : 'true',
-            type: item.type,
-            Width: 120
-          }
-
-          items.push(newcard)
-        }
-      })
-    }
-
-    this.setState({
-      config: {...config, [addType]: items}
-    })
-
-    notification.success({
-      top: 92,
-      message: '鎿嶄綔鎴愬姛',
-      duration: 2
-    })
-  }
-
+  /**
+   * @description 娣诲姞琛ㄥ悕
+   */
   onTableChange = (value) => {
     const { config } = this.props
     const { tables, tableFields, selectedTables } = this.state
@@ -334,15 +161,17 @@
       })
 
       let _config = {...config, tables: [...selectedTables, _table]}
-
+      
       Api.getSystemConfig({func: 'sPC_Get_FieldName', TBName: value}).then(res => {
         if (res.status) {
           let tabmsg = {
-            tableName: _table.name,
+            tableName: _table.TbName,
             columns: res.FDName.map(item => {
               let _type = item.FieldType.toLowerCase()
               let _decimal = 0
+              let _length = 50
               if (/^nvarchar/.test(_type)) {
+                _length = +_type.match(/\d+/)[0] || 50
                 _type = 'text'
               } else if (/^int/.test(_type)) {
                 _type = 'number'
@@ -363,7 +192,8 @@
                 label: item.FieldDec,
                 type: _type,
                 datatype: _type,
-                decimal: _decimal
+                decimal: _decimal,
+                length: _length
               }
             })
           }
@@ -383,9 +213,12 @@
     }
   }
 
+  /**
+   * @description 鍒犻櫎琛ㄥ悕
+   */
   deleteTable = (table) => {
     const { config } = this.props
-    const {selectedTables, tableFields} = this.state
+    const { selectedTables, tableFields } = this.state
 
     let _tables = selectedTables.filter(item => item.TbName !== table.TbName)
     let _fields = tableFields.filter(item => item.tableName !== table.TbName)
@@ -398,10 +231,13 @@
     this.props.updatetable({...config, tables: _tables}, _fields)
   }
 
-  changeSetting = () => {
-    this.setState({
-      settingVisible: true
-    })
+  /**
+   * @description 缁勪欢閿�姣侊紝娓呴櫎state鏇存柊
+   */
+  componentWillUnmount () {
+    this.setState = () => {
+      return
+    }
   }
 
   render() {
@@ -427,7 +263,7 @@
           value={dict['header.menu.table.placeholder']}
           onChange={this.onTableChange}
           showArrow={false}
-          getPopupContainer={() => document.getElementById(containerId)}
+          getPopupContainer={() => containerId ? document.getElementById(containerId) : document.body}
           filterOption={(input, option) => {
             return option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0 ||
               option.props.value.toLowerCase().indexOf(input.toLowerCase()) >= 0

--
Gitblit v1.8.0