From 31ec63f0419895876cbaba99637a884a32d33d0d Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 01 九月 2021 10:31:45 +0800
Subject: [PATCH] 2021-09-01

---
 src/templates/sharecomponent/tablecomponent/index.jsx |   80 +++++++++++++++++++++++++--------------
 1 files changed, 51 insertions(+), 29 deletions(-)

diff --git a/src/templates/sharecomponent/tablecomponent/index.jsx b/src/templates/sharecomponent/tablecomponent/index.jsx
index b91c630..8c8f4b4 100644
--- a/src/templates/sharecomponent/tablecomponent/index.jsx
+++ b/src/templates/sharecomponent/tablecomponent/index.jsx
@@ -5,6 +5,7 @@
 import moment from 'moment'
 
 import Api from '@/api'
+import options from '@/store/options.js'
 import Utils from '@/utils/utils.js'
 import zhCN from '@/locales/zh-CN/model.js'
 import enUS from '@/locales/en-US/model.js'
@@ -22,12 +23,10 @@
   }
 
   state = {
-    dict: localStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
     tables: [],          // 绯荤粺琛�
-    tableFields: [],    // 宸查�夎〃瀛楁闆�
+    tableFields: [],     // 宸查�夎〃瀛楁闆�
     selectedTables: [],  // 宸查�夎〃
-    searchlist: null,    // 鎼滅储鏉′欢闆�
-    visible: false       // 妯℃�佹鎺у埗
   }
 
   /**
@@ -59,12 +58,17 @@
     }
 
     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) // 浜戠鏁版嵁楠岃瘉
 
-    param.open_key = Utils.encrypt(param.secretkey, param.timestamp, true) // 浜戠鏁版嵁楠岃瘉
+    if (options.cloudServiceApi) { // 涓斿瓨鍦ㄤ簯绔湴鍧�
+      param.rduri = options.cloudServiceApi
+      param.userid = sessionStorage.getItem('CloudUserID') || ''
+      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
+    }
 
-    Api.getSystemConfig(param).then(res => {
+    Api.getSystemCacheConfig(param).then(res => {
       if (res.status) {
         this.setState({
           tables: res.data
@@ -82,7 +86,14 @@
   gettableFields = () => {
     let deffers = this.state.selectedTables.map(item => {
       return new Promise(resolve => {
-        Api.getSystemConfig({func: 'sPC_Get_FieldName', TBName: item.TbName}).then(res => {
+        let param = {func: 'sPC_Get_FieldName', TBName: item.TbName}
+        if (options.cloudServiceApi) { // 涓斿瓨鍦ㄤ簯绔湴鍧�
+          param.rduri = options.cloudServiceApi
+          param.userid = sessionStorage.getItem('CloudUserID') || ''
+          param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
+        }
+
+        Api.getSystemCacheConfig(param).then(res => {
           res.TBName = item.TbName
           resolve(res)
         })
@@ -97,23 +108,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 (e) {
+                  _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'
@@ -124,11 +131,13 @@
               }
   
               return {
-                field: item.FieldName,
+                field: item.FieldName || '',
                 label: item.FieldDec,
                 type: _type,
                 datatype: _type,
-                decimal: _decimal
+                decimal: _decimal,
+                length: _length,
+                $datatype: item.FieldType.toLowerCase()
               }
             })
           }
@@ -145,8 +154,7 @@
       this.setState({
         tableFields: _columns
       })
-
-      this.props.updatetable(this.props.config, _columns)
+      window.GLOB.tableFields = _columns
     })
   }
 
@@ -165,15 +173,21 @@
       })
 
       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)) {
+                try { // 瀛樺湪max
+                  _length = +_type.match(/\d+/)[0] || 50
+                } catch (e) {
+                  _length = 2048
+                }
                 _type = 'text'
               } else if (/^int/.test(_type)) {
                 _type = 'number'
@@ -194,15 +208,21 @@
                 label: item.FieldDec,
                 type: _type,
                 datatype: _type,
-                decimal: _decimal
+                decimal: _decimal,
+                length: _length
               }
             })
           }
+
+          let _columns = [...tableFields, tabmsg]
+
           this.setState({
-            tableFields: [...tableFields, tabmsg]
+            tableFields: _columns
           })
 
-          this.props.updatetable(_config, [...tableFields, tabmsg])
+          window.GLOB.tableFields = _columns
+
+          this.props.updatetable(_config)
         } else {
           notification.warning({
             top: 92,
@@ -229,7 +249,9 @@
       tableFields: _fields
     })
 
-    this.props.updatetable({...config, tables: _tables}, _fields)
+    window.GLOB.tableFields = _fields
+
+    this.props.updatetable({...config, tables: _tables})
   }
 
   /**
@@ -264,7 +286,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