From 871597aaf2c838946723ee44fc7fa12487b56d34 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期三, 22 一月 2025 15:14:25 +0800
Subject: [PATCH] 2025-01-22

---
 src/templates/sharecomponent/fieldscomponent/index.jsx |  164 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 142 insertions(+), 22 deletions(-)

diff --git a/src/templates/sharecomponent/fieldscomponent/index.jsx b/src/templates/sharecomponent/fieldscomponent/index.jsx
index 4d8d96f..4bbf651 100644
--- a/src/templates/sharecomponent/fieldscomponent/index.jsx
+++ b/src/templates/sharecomponent/fieldscomponent/index.jsx
@@ -3,6 +3,7 @@
 import { is, fromJS } from 'immutable'
 import { Button, Modal, Empty, notification } from 'antd'
 
+import Api from '@/api'
 import Utils from '@/utils/utils.js'
 import EditCard from './editcard'
 
@@ -11,8 +12,8 @@
 
 class FieldsComponent extends Component {
   static propTpyes = {
-    type: PropTypes.string,          // 鎼滅储鏉′欢娣诲姞銆佹樉绀哄垪娣诲姞
-    config: PropTypes.object,        // 瀹瑰櫒Id
+    type: PropTypes.string,
+    config: PropTypes.object,
     updatefield: PropTypes.func
   }
 
@@ -23,10 +24,8 @@
     selectCards: []
   }
 
-  queryField = () => {
-    const { type, config } = this.props
-    // 鍒ゆ柇鏄惁宸查�夋嫨琛ㄥ悕
-    if (!window.GLOB.tableFields || window.GLOB.tableFields.length === 0) {
+  checkField = () => {
+    if (!window.GLOB.publicTables || window.GLOB.publicTables.length === 0) {
       notification.warning({
         top: 92,
         message: '璇烽�夋嫨琛ㄥ悕锛�',
@@ -35,9 +34,110 @@
       return
     }
 
+    window.GLOB.tableFields = window.GLOB.tableFields || []
+
+    let index = 0
+
+    let deffers = window.GLOB.publicTables.map(item => {
+      let tb = window.GLOB.tableFields.filter(tab => tab.tableName === item.TbName)[0]
+
+      if (tb) {
+        return Promise.resolve(fromJS(tb).toJS())
+      }
+
+      return new Promise(resolve => {
+        setTimeout(() => {
+          Api.getCloudConfig({func: 'sPC_Get_FieldName', TBName: item.TbName}).then(res => {
+            let tabmsg = {
+              status: res.status,
+              message: res.message,
+              tableName: item.TbName,
+              columns: []
+            }
+
+            if (res.FDName && res.FDName.length > 0) {
+              tabmsg.columns = res.FDName.map(item => {
+                let _type = item.FieldType.toLowerCase()
+                let _datatype = item.FieldType.toLowerCase()
+                let _decimal = 0
+                let _length = 50
+                if (/^nvarchar/.test(_type)) {
+                  try { // 瀛樺湪max
+                    _length = +_type.match(/\d+/)[0] || 50
+                  } catch (e) {
+                    _length = 4000
+                  }
+                  _type = 'text'
+                } else if (/^int/.test(_type)) {
+                  _type = 'number'
+                } else if (/^decimal/.test(_type)) {
+                  _decimal = _type.split(',')[1]
+                  _decimal = parseInt(_decimal)
+                  _type = 'number'
+                } else if (/^datetime/.test(_type)) {
+                  _type = 'datetime'
+                } else if (/^date/.test(_type)) {
+                  _type = 'date'
+                } else {
+                  _type = 'text'
+                }
+
+                if (/^nvarchar/.test(_datatype)) {
+                  _datatype = _datatype.replace(/^nvarchar/, 'Nvarchar')
+                } else if (/^decimal/.test(_datatype)) {
+                  _datatype = _datatype.replace(/^decimal/, 'Decimal')
+                } else if (/^int/.test(_datatype)) {
+                  _datatype = _datatype.replace(/^int/, 'Int')
+                }
+    
+                return {
+                  field: item.FieldName || '',
+                  label: item.FieldDec,
+                  type: _type,
+                  datatype: _type,
+                  decimal: _decimal,
+                  length: _length,
+                  $datatype: _datatype
+                }
+              })
+            }
+
+            resolve(tabmsg)
+          })
+        }, index * 50)
+
+        index++
+      })
+    })
+    Promise.all(deffers).then(response => {
+      let error = false
+      let _columns = response
+
+      response.forEach(item => {
+        if (!item.status) {
+          error = item.message || '瀛楁鏌ヨ澶辫触锛�'
+        }
+      })
+
+      if (error) {
+        notification.warning({
+          top: 92,
+          message: error,
+          duration: 5
+        })
+      } else {
+        window.GLOB.tableFields = _columns
+        this.queryField(_columns)
+      }
+    })
+  }
+
+  queryField = (tableFields) => {
+    const { type, config } = this.props
+
     // 琛ㄥ瓧娈甸泦杞负map鏁版嵁
     let columns = new Map()
-    window.GLOB.tableFields.forEach(table => {
+    tableFields.forEach(table => {
       table.columns.forEach(column => {
         columns.set(column.field.toLowerCase(), column)
       })
@@ -46,9 +146,20 @@
     if (type === 'search') {
       // 娣诲姞鎼滅储鏉′欢锛屽瓧娈甸泦涓瓨鍦ㄦ悳绱㈡潯浠跺瓧娈碉紝浣跨敤鎼滅储鏉′欢瀵硅薄鏇挎崲瀛楁闆嗭紝璁剧疆鏁版嵁绫诲瀷
       config.search.forEach(item => {
-        if (item.field && columns.has(item.field.toLowerCase())) {
-          let _datatype = columns.get(item.field.toLowerCase()).datatype
-          columns.set(item.field.toLowerCase(), {...item, origin: true, datatype: _datatype})
+        if (item.field) {
+          if (/,/.test(item.field)) {
+            item.field.split(',').forEach(n => {
+              if (columns.has(n.toLowerCase())) {
+                let _datatype = columns.get(n.toLowerCase()).datatype
+                columns.set(n.toLowerCase(), {...item, field: n, origin: true, datatype: _datatype})
+              }
+            })
+          } else {
+            if (columns.has(item.field.toLowerCase())) {
+              let _datatype = columns.get(item.field.toLowerCase()).datatype
+              columns.set(item.field.toLowerCase(), {...item, origin: true, datatype: _datatype})
+            }
+          }
         }
       })
     } else if (type === 'columns') {
@@ -93,13 +204,6 @@
 
     let config = fromJS(this.props.config).toJS()
 
-    // 鑾峰彇宸查�夊瓧娈甸泦鍚�
-    let cards = selectCards
-    let columnsMap = new Map()
-    cards.forEach(card => {
-      columnsMap.set(card.field.toLowerCase(), card)
-    })
-
     let items = []
     let keys = []
     if (type === 'search') {
@@ -140,8 +244,8 @@
           label: item.label,
           field: item.field,
           Hide: 'false',
-          IsSort: 'true',
-          type: item.type,
+          IsSort: 'false',
+          type: item.type === 'number' ? 'number' : 'text',
           Width: item.type === 'number' ? 80 : 120
         }
 
@@ -149,6 +253,12 @@
           newcard.decimal = item.decimal
         } else {
           newcard.fieldlength = item.length || 50
+        }
+
+        if (item.type === 'date') {
+          newcard.textFormat = 'YYYY-MM-DD'
+        } else if (item.type === 'datetime') {
+          newcard.textFormat = 'YYYY-MM-DD HH:mm:ss'
         }
 
         items.push(newcard)
@@ -166,6 +276,7 @@
           field: item.field,
           datatype: _t
         }
+
         items.unshift(newcard)
         keys.push(item.field.toLowerCase())
       })
@@ -194,10 +305,17 @@
           decimal: item.decimal,
           orderType: 'asc',
           readonly: 'false',
-          required: 'true'
+          required: 'true',
+          readin: 'top'
         }
 
-        if (item.type === 'text' && item.length >= 256) {
+        if (/^icon|images?$/ig.test(item.field)) {
+          newcard.type = 'fileupload'
+          newcard.fileType = 'picture-card'
+          newcard.fieldlength = item.length || 512
+          newcard.maxSize = 1
+          newcard.maxfile = 1
+        } else if (item.type === 'text' && item.length >= 256) {
           newcard.type = 'textarea'
           newcard.required = 'false'
           newcard.fieldlength = item.length
@@ -219,6 +337,8 @@
             newcard.span = 24
             newcard.labelwidth = 16.2
           }
+        } else if (item.type === 'text') {
+          newcard.fieldlength = item.length || 50
         }
 
         items.push(newcard)
@@ -275,7 +395,7 @@
 
     return (
       <div className="quickly-add">
-        <Button type="primary" block onClick={this.queryField}>{label}</Button>
+        <Button type="primary" block onClick={this.checkField}>{label}</Button>
         {/* 鏍规嵁瀛楁鍚嶆坊鍔犳樉绀哄垪鍙婃悳绱㈡潯浠� */}
         <Modal
           wrapClassName="model-table-fieldmanage-modal"

--
Gitblit v1.8.0