From 6dd965723be9dc245105296198c25a80cfe51b54 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 27 四月 2023 10:51:50 +0800
Subject: [PATCH] 2023-04-27

---
 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx |  286 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 180 insertions(+), 106 deletions(-)

diff --git a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
index 9d7eaf9..2efbd4e 100644
--- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -6,7 +6,6 @@
 import moment from 'moment'
 
 import Api from '@/api'
-import options from '@/store/options.js'
 import asyncComponent from '@/utils/asyncComponent'
 import Utils, { getEditTableSql, getMark } from '@/utils/utils.js'
 import MkIcon from '@/components/mk-icon'
@@ -14,7 +13,7 @@
 import zhCN from '@/locales/zh-CN/main.js'
 import enUS from '@/locales/en-US/main.js'
 import CusSwitch from './cusSwitch'
-import '@/assets/css/table.scss'
+import Encrypts from '@/components/encrypts'
 import './index.scss'
 
 const { Paragraph } = Typography
@@ -127,6 +126,9 @@
     const { col, record } = this.props
 
     if (id !== col.uuid + record.$$uuid) return
+
+    if (col.ctrlField && col.ctrlValue.includes(record[col.ctrlField])) return
+
     this.focus()
   }
 
@@ -289,6 +291,11 @@
 
     if (!col) return (<td {...resProps} className={className} style={style}/>)
 
+    let disabled = false
+    if (col.ctrlField) {
+      disabled = col.ctrlValue.includes(record[col.ctrlField])
+    }
+
     let children = null
     if (col.type === 'text') {
       let content = ''
@@ -301,9 +308,13 @@
           content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)}`
         } else if (col.textFormat === 'YYYY-MM-DD HH:mm:ss' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1]).([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/.test(content)) {
           content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)} ${content.substr(11, 2)}:${content.substr(14, 2)}:${content.substr(17, 2)}`
+        } else if (col.textFormat === 'encryption') {
+          content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span>
         }
 
-        content = (col.prefix || '') + content + (col.postfix || '')
+        if (col.textFormat !== 'encryption') {
+          content = (col.prefix || '') + content + (col.postfix || '')
+        }
       }
 
       if (col.marks) {
@@ -313,14 +324,16 @@
 
         if (mark.icon) {
           if (mark.position === 'front') {
-            content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span>
+            content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span>
           } else {
-            content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span>
+            content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span>
           }
+        } else if (mark.innerStyle) {
+          content = <span style={mark.innerStyle}>{content}</span>
         }
       }
 
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         if (editing) {
           if (!col.editType || col.editType === 'text') {
             return (<td className="editing_table_cell">
@@ -381,21 +394,23 @@
       }
 
       if (content !== '') {
-        let decimal = col.decimal || 0
+        if (col.round) {
+          content = Math.round(content * col.round) / col.round
+        }
         if (col.format === 'percent') {
           content = content * 100
-          decimal = decimal > 2 ? decimal - 2 : 0
         } else if (col.format === 'abs') {
           content = Math.abs(content)
         }
-  
-        content = content.toFixed(decimal)
+        if (col.round) {
+          content = content.toFixed(col.decimal)
+        }
   
         if (col.format === 'thdSeparator') {
           content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
         }
   
-        content = col.prefix + content + col.postfix
+        content = (col.prefix || '') + content + (col.postfix || '')
       }
 
       if (col.marks) {
@@ -405,14 +420,16 @@
 
         if (mark.icon) {
           if (mark.position === 'front') {
-            content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span>
+            content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span>
           } else {
-            content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span>
+            content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span>
           }
+        } else if (mark.innerStyle) {
+          content = <span style={mark.innerStyle}>{content}</span>
         }
       }
 
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         if (editing) {
           return (<td className="editing_table_cell">
             <InputNumber id={col.uuid + record.$$uuid} defaultValue={value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress} onBlur={this.onBlur}/>
@@ -435,7 +452,7 @@
       }
 
       if (content) {
-        content = col.prefix + content + col.postfix
+        content = (col.prefix || '') + content + (col.postfix || '')
       }
 
       children = (
@@ -477,10 +494,12 @@
 
         if (mark.icon) {
           if (mark.position === 'front') {
-            content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span>
+            content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span>
           } else {
-            content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span>
+            content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span>
           }
+        } else if (mark.innerStyle) {
+          content = <span style={mark.innerStyle}>{content}</span>
         }
       }
 
@@ -495,7 +514,10 @@
         <CardCellComponent data={record} cards={config} elements={col.elements}/>
       )
     } else if (col.type === 'action') {
-      style.padding = '0px 5px'
+      style.padding = '0px'
+      if (col.style) {
+        style = {...style, ...col.style}
+      }
       children = (
         <CardCellComponent data={record} cards={config} elements={col.elements}/>
       )
@@ -671,9 +693,14 @@
     let { col, config, record, style, className } = this.props
     const { err } = this.state
 
+    let disabled = false
+    if (col.ctrlField) {
+      disabled = col.ctrlValue.includes(record[col.ctrlField])
+    }
+
     let children = null
     if (col.type === 'text') {
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         let _value = ''
         if (col.editField) {
           _value = record[col.editField] !== undefined ? record[col.editField] : ''
@@ -716,9 +743,13 @@
             content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)}`
           } else if (col.textFormat === 'YYYY-MM-DD HH:mm:ss' && /^[1-9]\d{3}(-|\/)(0[1-9]|1[0-2])(-|\/)(0[1-9]|[1-2][0-9]|3[0-1]).([0-1][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]/.test(content)) {
             content = `${content.substr(0, 4)}-${content.substr(5, 2)}-${content.substr(8, 2)} ${content.substr(11, 2)}:${content.substr(14, 2)}:${content.substr(17, 2)}`
+          } else if (col.textFormat === 'encryption') {
+            content = <span>{col.prefix || ''}<Encrypts value={content} />{col.postfix || ''}</span>
           }
 
-          content = (col.prefix || '') + content + (col.postfix || '')
+          if (col.textFormat !== 'encryption') {
+            content = (col.prefix || '') + content + (col.postfix || '')
+          }
         }
 
         if (col.marks) {
@@ -728,16 +759,18 @@
 
           if (mark.icon) {
             if (mark.position === 'front') {
-              content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span>
+              content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span>
             } else {
-              content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span>
+              content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span>
             }
+          } else if (mark.innerStyle) {
+            content = <span style={mark.innerStyle}>{content}</span>
           }
         }
         children = content
       }
     } else if (col.type === 'number') {
-      if (col.editable === 'true') {
+      if (col.editable === 'true' && !disabled) {
         let _value = record[col.field] !== undefined ? record[col.field] : ''
         children = (<>
           <InputNumber id={col.uuid + record.$$uuid} defaultValue={_value} onChange={(val) => this.onChange(val)} onPressEnter={this.enterPress}/>
@@ -755,21 +788,23 @@
         }
 
         if (content !== '') {
-          let decimal = col.decimal || 0
+          if (col.round) {
+            content = Math.round(content * col.round) / col.round
+          }
           if (col.format === 'percent') {
             content = content * 100
-            decimal = decimal > 2 ? decimal - 2 : 0
           } else if (col.format === 'abs') {
             content = Math.abs(content)
           }
-    
-          content = content.toFixed(decimal)
+          if (col.round) {
+            content = content.toFixed(col.decimal)
+          }
     
           if (col.format === 'thdSeparator') {
             content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
           }
     
-          content = col.prefix + content + col.postfix
+          content = (col.prefix || '') + content + (col.postfix || '')
         }
 
         if (col.marks) {
@@ -779,10 +814,12 @@
 
           if (mark.icon) {
             if (mark.position === 'front') {
-              content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span>
+              content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span>
             } else {
-              content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span>
+              content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span>
             }
+          } else if (mark.innerStyle) {
+            content = <span style={mark.innerStyle}>{content}</span>
           }
         }
         children = content
@@ -794,7 +831,7 @@
       }
 
       if (content) {
-        content = col.prefix + content + col.postfix
+        content = (col.prefix || '') + content + (col.postfix || '')
       }
 
       children = (
@@ -836,10 +873,12 @@
 
         if (mark.icon) {
           if (mark.position === 'front') {
-            content = <span><MkIcon style={{color: mark.color}} type={mark.icon} /> {content}</span>
+            content = <span><MkIcon style={mark.innerStyle} type={mark.icon} /> {content}</span>
           } else {
-            content = <span>{content} <MkIcon style={{color: mark.color}} type={mark.icon} /></span>
+            content = <span>{content} <MkIcon style={mark.innerStyle} type={mark.icon} /></span>
           }
+        } else if (mark.innerStyle) {
+          content = <span style={mark.innerStyle}>{content}</span>
         }
       }
 
@@ -868,7 +907,7 @@
   static propTpyes = {
     statFValue: PropTypes.any,       // 鍚堣瀛楁鏁版嵁
     MenuID: PropTypes.string,        // 鑿滃崟Id
-    setting: PropTypes.object,       // 琛ㄦ牸鍏ㄥ眬璁剧疆锛歵ableType锛堣〃鏍兼槸鍚﹀彲閫夈�佸崟閫夈�佸閫夛級銆乧olumnfixed锛堝垪鍥哄畾锛夈�乤ctionfixed锛堟寜閽浐瀹氾級
+    setting: PropTypes.object,       // 琛ㄦ牸鍏ㄥ眬璁剧疆锛歵ableType锛堣〃鏍兼槸鍚﹀彲閫夈�佸崟閫夈�佸閫夛級銆乤ctionfixed锛堟寜閽浐瀹氾級
     columns: PropTypes.array,        // 琛ㄦ牸鍒�
     lineMarks: PropTypes.any,        // 琛屾爣璁�
     fields: PropTypes.array,         // 缁勪欢瀛楁闆�
@@ -890,7 +929,7 @@
     pageIndex: 1,         // 鍒濆椤甸潰绱㈠紩
     pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
     columns: null,        // 鏄剧ず鍒�
-    fields: [],
+    forms: [],
     pickup: false,        // 鏀惰捣鏈�夋嫨椤�
     orderfields: {},      // 鎺掑簭id涓巉ield杞崲
     loading: false,
@@ -906,47 +945,85 @@
 
     let _columns = []
     let deForms = []
-    columns.forEach(item => {
-      if (!initEditLine && item.editable === 'true') {
-        initEditLine = item
-      }
+    let _forms = {}
 
-      if (item.type === 'text' && item.editable === 'true' && item.editType === 'select' && item.resourceType === '1') {
-        let _option = Utils.getSelectQueryOptions(item)
+    let getColumns = (cols) => {
+      return cols.map(item => {
+        let cell = null
+  
+        if (item.type === 'colspan') {
+          cell = { title: item.label, align: item.Align }
+          cell.children = getColumns(item.subcols)
+        } else {
+          if (item.editable === 'true') {
+            _forms[item.field] = item
+            if (!initEditLine) {
+              initEditLine = item
+            }
 
-        item.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
-        item.arr_field = _option.field
+            if (item.ctrlField) {
+              item.ctrlValue = item.ctrlValue.split(',')
+            }
+          }
+    
+          if (item.type === 'text' && item.editable === 'true' && item.editType === 'select' && item.resourceType === '1') {
+            let _option = Utils.getSelectQueryOptions(item)
+    
+            if (window.GLOB.debugger === true || window.debugger === true) {
+              console.info(_option.sql)
+            }
+    
+            item.base_sql = window.btoa(window.encodeURIComponent(_option.sql))
+            item.arr_field = _option.field
+    
+            deForms.push(item)
+          }
+    
+          if (item.field) {
+            orderfields[item.uuid] = item.field
+          }
 
-        deForms.push(item)
-      }
-
-      if (item.field) {
-        orderfields[item.uuid] = item.field
-      }
-
-      let _item = {
-        align: item.Align,
-        dataIndex: item.uuid,
-        title: item.label,
-        sorter: item.field && item.IsSort === 'true',
-        width: item.Width || 120,
-        onCell: record => ({
-          record,
-          col: item,
-          config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
-        })
-      }
-
-      if (item.type !== 'action') {
-        let _copy = fromJS(_item).toJS()
-        _copy.sorter = false
-
-        if (item.editable === 'true') {
-          _copy.title = <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span>
+          cell = {
+            align: item.Align,
+            dataIndex: item.uuid,
+            title: item.label,
+            sorter: !!(item.field && item.IsSort === 'true'),
+            width: item.Width || 120,
+            $type: item.type,
+            onCell: record => ({
+              record,
+              col: item,
+              config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
+            })
+          }
         }
-        edColumns.push(_copy)
+  
+        return cell
+      })
+    }
+    _columns = getColumns(columns)
+
+    let forms = []
+    fields.forEach(item => {
+      if (item.field === setting.primaryKey) return
+
+      if (_forms[item.field]) {
+        forms.push({..._forms[item.field], datatype: item.datatype})
+      } else {
+        forms.push(item)
       }
-      _columns.push(_item)
+    })
+
+    _columns.forEach(item => {
+      if (item.$type === 'action') return
+
+      let _copy = fromJS(item).toJS()
+      _copy.sorter = false
+
+      if (item.editable === 'true') {
+        _copy.title = <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span>
+      }
+      edColumns.push(_copy)
     })
 
     if (setting.delable !== 'false' && setting.operType !== 'buoyMode') {
@@ -963,13 +1040,6 @@
       })
     }
 
-    if (setting.borderColor) { // 杈规棰滆壊
-      let style = `#${setting.tableId} table, #${setting.tableId} tr, #${setting.tableId} th, #${setting.tableId} td {border-color: ${setting.borderColor}}`
-      let ele = document.createElement('style')
-      ele.innerHTML = style
-      document.getElementsByTagName('head')[0].appendChild(ele)
-    }
-
     let size = (setting.pageSize || 10) + ''
     let pageOptions = ['10', '25', '50', '100', '500', '1000']
 
@@ -979,6 +1049,7 @@
     }
 
     this.setState({
+      forms,
       pageSize: setting.pageSize || 10,
       pageOptions,
       columns: _columns,
@@ -991,6 +1062,12 @@
       if (deForms.length > 0) {
         this.improveActionForm(deForms)
       }
+
+      const element = document.getElementById(setting.tableId)
+      element && element.style.setProperty('--mk-table-border-color', setting.borderColor || '#e8e8e8')
+      element && element.style.setProperty('--mk-table-color', setting.color || 'rgba(0, 0, 0, 0.65)')
+      element && element.style.setProperty('--mk-table-font-size', setting.fontSize || '14px')
+      element && element.style.setProperty('--mk-table-font-weight', setting.fontWeight || 'normal')
     })
   }
 
@@ -999,12 +1076,6 @@
   }
 
   componentDidMount () {
-    const { fields, setting } = this.props
-
-    this.setState({
-      fields: fields.filter(item => item.field !== setting.primaryKey),
-    })
-
     MKEmitter.addListener('subLine', this.subLine)
     MKEmitter.addListener('nextLine', this.nextLine)
     MKEmitter.addListener('addRecord', this.addLine)
@@ -1077,11 +1148,6 @@
         localItems.push(`select '${item.uuid}' as obj_name,'${item.arr_field}' as arr_field,'${item.base_sql}' as LText`)
       }
     })
-    
-    if (options.sysType !== 'local') {
-      localItems = [...localItems, ...mainItems]
-      mainItems = []
-    }
 
     // 鏈湴璇锋眰
     let param = {
@@ -1172,16 +1238,24 @@
       if (item.resourceType === '1' && result[item.uuid] && result[item.uuid].length > 0) {
         let options = []
         let _map = new Map()
+        let all = false
         result[item.uuid].forEach(cell => {
           let _cell = {key: Utils.getuuid()}
 
           _cell.value = cell[item.valueField]
           _cell.label = cell[item.valueText]
 
-          if (!_cell.label && _cell.label !== 0) return
+          if (!_cell.label && _cell.label !== 0) {
+            if (!all) {
+              _cell.label = '鍏ㄩ儴'
+              all = true
+            } else {
+              return
+            }
+          }
 
           if (_map.has(_cell.value)) return
-          _map.set(_cell.value, true)
+          _map.set(_cell.value, 0)
 
           if (item.linkSubField) {
             item.linkSubField.forEach(m => {
@@ -1247,7 +1321,7 @@
   }
 
   subLine = (col, record) => {
-    const { tableId, fields, edData } = this.state
+    const { tableId, forms, edData } = this.state
 
     if (col && col.tableId !== tableId) return
 
@@ -1261,7 +1335,7 @@
     setTimeout(() => {
       let item = fromJS(record).toJS()
       let line = []
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.editable !== 'true' || item.$deleted) {
           if (col.type === 'number') {
             item[col.field] = +item[col.field]
@@ -1318,7 +1392,7 @@
   }
 
   plusLine = () => {
-    const { edData, fields, initEditLine } = this.state
+    const { edData, forms, initEditLine } = this.state
 
     let item = {...edData[edData.length - 1]}
 
@@ -1326,7 +1400,7 @@
     item.$type = 'add'
     item.$Index = ''
 
-    fields.forEach(col => {
+    forms.forEach(col => {
       if (col.initval !== '$copy') {
         item[col.field] = col.initval
       }
@@ -1395,7 +1469,7 @@
 
   addLine = (id, record) => {
     const { BID } = this.props
-    const { edData, fields, tableId } = this.state
+    const { edData, forms, tableId } = this.state
 
     if (id) {
       if (id !== tableId) return
@@ -1409,7 +1483,7 @@
       item.$Index = ''
       item.$$BID = BID || ''
   
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.initval !== '$copy') {
           item[col.field] = col.initval
         }
@@ -1442,7 +1516,7 @@
         item.$$BID = BID || ''
       }
   
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.initval !== '$copy') {
           item[col.field] = col.initval
         }
@@ -1463,7 +1537,7 @@
   }
 
   checkData = () => {
-    const { edData, fields } = this.state
+    const { edData, forms } = this.state
 
     if (edData.length === 0) {
       notification.warning({
@@ -1477,7 +1551,7 @@
     let Index = 1
     let data = fromJS(edData).toJS().map(item => {
       let line = []
-      fields.forEach(col => {
+      forms.forEach(col => {
         if (col.editable !== 'true' || item.$deleted) {
           if (col.type === 'number') {
             item[col.field] = +item[col.field]
@@ -1542,7 +1616,7 @@
 
   submit = (data, type) => {
     const { submit, BID, setting } = this.props
-    const { fields } = this.state
+    const { forms } = this.state
 
     if (type !== 'simple' && (setting.commit === 'change' || setting.commit === 'simple')) {
       data = data.filter(item => !item.$origin)
@@ -1557,7 +1631,7 @@
       return
     }
 
-    let result = getEditTableSql(submit, data, fields)
+    let result = getEditTableSql(submit, data, forms)
 
     let param = {
       excel_in: result.lines,
@@ -1938,7 +2012,7 @@
         pageSizeOptions: pageOptions,
         showSizeChanger: true,
         total: this.props.total || 0,
-        showTotal: (total, range) => `${range[0]}-${range[1]} ${this.state.dict['main.pagination.of']} ${total} ${this.state.dict['main.pagination.items']}`
+        showTotal: (total, range) => `${range[0]}-${range[1]} 鍏� ${total} 鏉
       }
     }
 
@@ -1957,13 +2031,13 @@
         </div> : null}
         <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}>
           {!submit.hasAction && pickup ? <Button style={submit.style} onClick={() => setTimeout(() => {this.checkData()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button> : null}
-          <Switch title="缂栬緫" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} />
+          {setting.switchable !== 'false' ? <Switch title="缂栬緫" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" disabled={loading || this.props.loading} checked={pickup} onChange={this.pickupChange} /> : null}
         </div>
-        <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''}`} id={tableId}>
+        <div className={`edit-custom-table ${pickup ? 'editable' : ''} ${setting.tableHeader || ''} ${setting.operType || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} id={tableId}>
           <Table
             rowKey="$$uuid"
             components={components}
-            style={setting.style}
+            // style={setting.style}
             size={setting.size || 'middle'}
             bordered={setting.bordered !== 'false'}
             rowSelection={rowSelection}

--
Gitblit v1.8.0