From 10f5efae1624c89d9a8f04ac331e07c895ea282a Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 25 五月 2024 18:22:58 +0800
Subject: [PATCH] 2024-05-25

---
 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx |  281 +++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 186 insertions(+), 95 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 ed634a0..762b303 100644
--- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -55,7 +55,7 @@
 
     this.node.blur()
     
-    if (config.enter === '$noAct') return
+    if (/\$noAct/.test(config.enter)) return
 
     if (/\$next/.test(config.enter)) {
       MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', ''))
@@ -191,7 +191,7 @@
 
     this.props.onChange(values)
 
-    if (config.enter === '$noAct') return
+    if (/\$noAct/.test(config.enter)) return
 
     if (/\$next/.test(config.enter)) {
       MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', ''))
@@ -283,9 +283,11 @@
 
     this.props.onChange(values, val)
 
+    if (config.enter === '$noActX') return
+
     this.node.blur()
     
-    if (config.enter === '$noAct') return
+    if (/\$noAct/.test(config.enter)) return
 
     setTimeout(() => {
       if (/\$next/.test(config.enter)) {
@@ -308,7 +310,7 @@
     const { config, lineId } = this.props
 
     if (config.$ctrl) {
-      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid)
+      MKEmitter.emit('colBlur' + config.tableId, lineId, config.uuid, true)
     }
 
     setTimeout(() => {
@@ -408,7 +410,7 @@
 
     this.node.blur()
     
-    if (config.enter === '$noAct') return
+    if (/\$noAct/.test(config.enter)) return
 
     if (/\$next/.test(config.enter)) {
       MKEmitter.emit('nextLine' + config.tableId, lineId, config.enter.replace('$next_', ''))
@@ -536,7 +538,7 @@
 
     this.node.blur()
     
-    if (config.enter === '$noAct') return
+    if (/\$noAct/.test(config.enter)) return
 
     setTimeout(() => {
       if (/\$next/.test(config.enter)) {
@@ -560,6 +562,10 @@
 
       if (config.noValue === 'hide' && !value) {
         value = 0
+      }
+
+      if (config.required === 'true' && !value) {
+        err = `${config.label}涓嶅彲涓�${config.noValue === 'hide' ? '绌�' : '0'}`
       } else {
         if (typeof(config.max) === 'number' && value > config.max) {
           err = config.label + '鏈�澶т负' + config.max
@@ -725,7 +731,7 @@
   }
 
   render() {
-    let { col, config, record, style, className, ...resProps } = this.props
+    let { col, record, style, className, ...resProps } = this.props
     const { editing } = this.state
 
     if (!col) return (<td {...resProps} className={className} style={style}/>)
@@ -745,10 +751,14 @@
       if (col.editType === 'select' && col.options.length > 0) {
         content = col.map.get(content) || content
       } else if (col.editType === 'switch') {
-        if (content === config.openVal) {
-          content = config.openText
-        } else if (content === config.closeVal) {
-          content = config.closeText
+        if (content === col.openVal) {
+          content = col.openText
+        } else if (content === col.closeVal) {
+          content = col.closeText
+        }
+      } else if (col.editType === 'popSelect') {
+        if (col.showField) {
+          content = record[col.showField] || content
         }
       }
 
@@ -759,6 +769,10 @@
           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>
+        }
+
+        if (col.noValue === 'hide' && content < '1949-10-02') {
+          content = ''
         }
 
         if (col.textFormat !== 'encryption') {
@@ -807,8 +821,13 @@
               <MkDatePicker config={col} lineId={record.$$uuid} defaultValue={_value || null} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/>
             </td>)
           } else if (col.editType === 'popSelect') {
+            let showValue = ''
+            if (col.showField) {
+              showValue = record[col.showField] || ''
+            }
+
             return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell">
-              <MKPopSelect config={col} lineId={record.$$uuid} defaultValue={_value} BID={record.$$BID} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/>
+              <MKPopSelect config={col} lineId={record.$$uuid} defaultValue={_value} showValue={showValue} BID={record.$$BID} autoFocus={true} onChange={this.onColChange} onBlur={() => this.setState({editing: false})}/>
             </td>)
           } else {
             return (<td onClick={(e) => e.stopPropagation()} className="editing_table_cell">
@@ -851,6 +870,7 @@
         }
   
         if (col.format === 'thdSeparator') {
+          content = content + ''
           content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
         }
   
@@ -994,7 +1014,7 @@
       }
 
       children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements}/>
+        <CardCellComponent data={record} cards={col.config} elements={col.elements}/>
       )
     }
 
@@ -1025,7 +1045,7 @@
   }
 
   render() {
-    let { col, config, record, style, className, ...resProps } = this.props
+    let { col, record, style, className, ...resProps } = this.props
 
     if (!col) return (<td {...resProps} className={className} style={style}/>)
 
@@ -1054,8 +1074,13 @@
             <MkDatePicker config={col} lineId={record.$$uuid} defaultValue={_value || null} autoFocus={false} onChange={this.onColChange}/>
           )
         } else if (col.editType === 'popSelect') {
+          let showValue = ''
+          if (col.showField) {
+            showValue = record[col.showField] || ''
+          }
+          
           children = (
-            <MKPopSelect config={col} lineId={record.$$uuid} defaultValue={_value} BID={record.$$BID} autoFocus={false} onChange={this.onColChange}/>
+            <MKPopSelect config={col} lineId={record.$$uuid} defaultValue={_value} showValue={showValue} BID={record.$$BID} autoFocus={false} onChange={this.onColChange}/>
           )
         } else {
           children = (
@@ -1071,10 +1096,14 @@
         if (col.editType === 'select' && col.options.length > 0) {
           content = col.map.get(content) || content
         } else if (col.editType === 'switch') {
-          if (content === config.openVal) {
-            content = config.openText
-          } else if (content === config.closeVal) {
-            content = config.closeText
+          if (content === col.openVal) {
+            content = col.openText
+          } else if (content === col.closeVal) {
+            content = col.closeText
+          }
+        } else if (col.editType === 'popSelect') {
+          if (col.showField) {
+            content = record[col.showField] || content
           }
         }
 
@@ -1085,6 +1114,10 @@
             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>
+          }
+
+          if (col.noValue === 'hide' && content < '1949-10-02') {
+            content = ''
           }
 
           if (col.textFormat !== 'encryption') {
@@ -1162,6 +1195,7 @@
           }
     
           if (col.format === 'thdSeparator') {
+            content = content + ''
             content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
           }
     
@@ -1294,7 +1328,7 @@
       }
 
       children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements}/>
+        <CardCellComponent data={record} cards={col.config} elements={col.elements}/>
       )
     }
 
@@ -1345,6 +1379,7 @@
   timer = null
   focusId = ''
   blurId = ''
+  colId = ''
 
   UNSAFE_componentWillMount () {
     const { setting, fields, columns, BID, colsCtrls } = this.props
@@ -1354,7 +1389,6 @@
     let deForms = []
     let _forms = {}
     let hasBid = false
-    let index = 0
     let checkForms = []
     let allForms = []
 
@@ -1367,29 +1401,16 @@
           cell.children = getColumns(item.subcols, sk || item.uuid)
         } else {
           if (item.editable === 'true') {
-            item.$sort = index
-            index++
             _forms[item.field] = item
 
             allForms.push({uuid: sk || item.uuid, field: item.field})
             checkForms.push(item.field)
 
-            if (item.ctrlField) {
-              item.ctrlValue = item.ctrlValue.split(',')
-            }
-            
-            if (item.type === 'number' && item.clearField) {
-              fields.forEach(cell => {
-                if (cell.field === item.clearField) {
-                  item.clearName = cell.label
-                }
-              })
-            } else if (item.type === 'text' && item.editType === 'select') {
-              item.map = new Map()
+            if (item.type === 'text' && item.editType === 'select') {
               if (item.resourceType === '1') {
                 let _option = Utils.getSelectQueryOptions(item)
   
-                if (/@BID@/ig.test(_option.sql)) {
+                if (/@BID@/ig.test(_option.sql) && setting.supModule) {
                   hasBid = true
                 }
         
@@ -1397,20 +1418,6 @@
                 item.arr_field = _option.field
         
                 deForms.push(item)
-              } else {
-                item.options.forEach(cell => {
-                  item.map.set(cell.value, cell.label)
-                })
-              }
-            } else if (item.type === 'text' && item.editType === 'date') {
-              item.format = 'YYYY-MM-DD'
-  
-              if (item.precision === 'hour') {
-                item.format = 'YYYY-MM-DD HH'
-              } else if (item.precision === 'minute') {
-                item.format = 'YYYY-MM-DD HH:mm'
-              } else if (item.precision === 'second') {
-                item.format = 'YYYY-MM-DD HH:mm:ss'
               }
             }
           }
@@ -1430,8 +1437,7 @@
             $key: item.uuid,
             onCell: record => ({
               record,
-              col: item,
-              config: item.type === 'custom' ? {setting, columns: fields} : null,
+              col: item
             })
           }
         }
@@ -1470,6 +1476,10 @@
       pageOptions = pageOptions.sort((a, b) => a - b)
     }
 
+    if (setting.maxPageSize) {
+      pageOptions = pageOptions.filter(item => item <= setting.maxPageSize)
+    }
+
     let allColumns = null
     if (colsCtrls) {
       allColumns = [..._columns]
@@ -1490,14 +1500,11 @@
       pageOptions,
       columns: _columns,
       tableId: setting.tableId,
-      orderfields
+      orderfields,
+      deForms: hasBid ? deForms : null
     }, () => {
-      if (deForms.length > 0) {
-        if (hasBid && setting.supModule && !BID) {
-          this.setState({ deForms })
-        } else {
-          this.improveActionForm(deForms, BID)
-        }
+      if (deForms.length > 0 && (!hasBid || BID)) {
+        this.improveActionForm(deForms, BID)
       }
     })
   }
@@ -1507,11 +1514,44 @@
   }
 
   UNSAFE_componentWillReceiveProps(nextProps) {
-    const { BID } = this.props
+    const { BID, parCtrl } = this.props
     const { deForms } = this.state
 
     if (deForms && nextProps.BID !== BID) {
       this.improveActionForm(deForms, nextProps.BID)
+    }
+    if (parCtrl && !is(fromJS(this.props.columns), fromJS(nextProps.columns))) {
+      let getColumns = (cols, sk) => {
+        return cols.map(item => {
+          let cell = null
+    
+          if (item.type === 'colspan') {
+            cell = { title: item.label, align: item.Align, $key: item.uuid }
+            cell.children = getColumns(item.subcols, sk || item.uuid)
+          } else {
+            cell = {
+              align: item.Align,
+              dataIndex: item.uuid,
+              title: item.editable === 'true' ? <span>{item.label}<EditOutlined className="system-color mk-edit-sign"/></span> : item.label,
+              sorter: (item.field || item.sortField) && item.IsSort === 'true',
+              width: item.Width || 120,
+              $key: item.uuid,
+              onCell: record => ({
+                record,
+                col: item
+              })
+            }
+          }
+    
+          return cell
+        })
+      }
+  
+      let _columns = getColumns(nextProps.columns)
+
+      this.setState({
+        columns: _columns
+      })
     }
   }
 
@@ -1552,7 +1592,11 @@
     MKEmitter.removeListener('changeRecord' + tableId, this.changeRecord)
   }
 
-  colBlur = (lineId) => {
+  colBlur = (lineId, colId, defer) => {
+    if (defer && this.focusId === lineId && this.colId !== colId) {
+      return
+    }
+    
     this.blurId = lineId
     this.focusId = ''
 
@@ -1565,8 +1609,9 @@
     }, 150)
   }
 
-  colFocus = (lineId) => {
+  colFocus = (lineId, colId) => {
     this.focusId = lineId
+    this.colId = colId
   }
 
   checkLine = () => {
@@ -1621,7 +1666,9 @@
       } else if (col.type === 'number') {
         let val = record[col.field]
 
-        if (col.noValue === 'hide' && !val) {
+        if (col.required === 'true' && !val) {
+          err = `${col.label}涓嶅彲涓�${col.noValue === 'hide' ? '绌�' : '0'}`
+        } else if (col.noValue === 'hide' && !val) {
           if (col.clearField && checkForms.includes(col.clearField) && !record[col.clearField]) {
             err = `璇峰~鍐� ${col.label} 鎴� ${col.clearName}`
           }
@@ -1673,6 +1720,9 @@
         result = originVal === contrastVal
       } else if (item.match === '!=') {
         result = originVal !== contrastVal
+      } else if (item.match === 'regexp') {
+        let reg = new RegExp(item.contrastValue, 'ig')
+        result = reg.test(originVal)
       } else {
         originVal = isNaN(originVal) ? originVal : +originVal
         contrastVal = isNaN(contrastVal) ? contrastVal : +contrastVal
@@ -1708,9 +1758,14 @@
   }
 
   transferData = (data, type) => {
-    const { edData } = this.state
+    const { edData, tableId } = this.state
 
-    if (type === 'line') {
+    if (type === 'clear') {
+      this.setState({edData: [], midData: []})
+      return
+    } else if (type === 'delete') {
+
+    } else if (type === 'line') {
       let value = ''
       Object.keys(data).sort().forEach(key => {
         if (/^\$/.test(key)) return
@@ -1728,14 +1783,18 @@
       })
     }
 
-    if (type !== 'line') {
-      let index = edData.findIndex(item => !item.$origin && !item.$forbid)
+    if (type === 'delete') {
+      let _edData = this.state.edData.filter(item => item.$$uuid !== data)
 
-      if (index > -1) {
-        this.setState({visible: true, midData: data})
-      } else {
-        this.updateMutil(data)
-      }
+      this.setState({edData: _edData, reseting: true}, () => {
+        this.setState({reseting: false})
+
+        if (this.focusId) {
+          setTimeout(() => {
+            MKEmitter.emit('setFocus' + tableId, this.focusId, this.colId)
+          }, 10)
+        }
+      })
     } else if (type === 'line') {
       let _edData = this.state.edData.map(item => {
         if (item.$$uuid === data.$$uuid) {
@@ -1747,7 +1806,21 @@
 
       this.setState({edData: _edData, reseting: true}, () => {
         this.setState({reseting: false})
+
+        if (this.focusId) {
+          setTimeout(() => {
+            MKEmitter.emit('setFocus' + tableId, this.focusId, this.colId)
+          }, 10)
+        }
       })
+    } else {
+      let index = edData.findIndex(item => !item.$origin && !item.$forbid)
+
+      if (index > -1) {
+        this.setState({visible: true, midData: data})
+      } else {
+        this.updateMutil(data)
+      }
     }
   }
 
@@ -1793,12 +1866,9 @@
   }
 
   improveActionForm = (deForms, BID) => {
-    const { setting } = this.props
-
     let deffers = []
     let mainItems = []  // 浜戠鎴栧崟鐐规暟鎹�
     let localItems = [] // 鏈湴鏁版嵁
-    let cache = setting.cache !== 'false'
     let debug = window.GLOB.debugger === true
     let _sql = `Declare @mk_departmentcode nvarchar(512),@mk_organization nvarchar(512),@mk_user_type nvarchar(20)  select @mk_departmentcode='${sessionStorage.getItem('departmentcode') || ''}',@mk_organization='${sessionStorage.getItem('organization') || ''}',@mk_user_type='${sessionStorage.getItem('mk_user_type') || ''}'\n`
     let _sso = _sql
@@ -1844,13 +1914,17 @@
     }
 
     if (param.LText) {
-      param.LText = Utils.formatOptions(param.LText)
+      if (window.GLOB.execType === 'x') {
+        param.exec_type = 'x'
+      }
+      
+      param.LText = Utils.formatOptions(param.LText, param.exec_type)
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
-      param.secretkey = Utils.encrypt(param.LText, param.timestamp)
+      param.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : param.LText, param.timestamp)
 
       deffers.push(
         new Promise(resolve => {
-          Api.getSystemCacheConfig(param, cache).then(res => {
+          Api.getSystemCacheConfig(param, false).then(res => {
             if (!res.status) {
               notification.warning({
                 top: 92,
@@ -1875,9 +1949,13 @@
     }
 
     if (mainparam.LText) {
-      mainparam.LText = Utils.formatOptions(mainparam.LText)
+      if (window.GLOB.execType === 'x') {
+        mainparam.exec_type = 'x'
+      }
+
+      mainparam.LText = Utils.formatOptions(mainparam.LText, mainparam.exec_type)
       mainparam.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
-      mainparam.secretkey = Utils.encrypt(mainparam.LText, mainparam.timestamp)
+      mainparam.secretkey = Utils.encrypt(window.GLOB.execType === 'x' ? '' : mainparam.LText, mainparam.timestamp)
 
       if (window.GLOB.mainSystemApi) {
         mainparam.rduri = window.GLOB.mainSystemApi
@@ -1885,7 +1963,7 @@
 
       deffers.push(
         new Promise(resolve => {
-          Api.getSystemCacheConfig(mainparam, cache).then(res => {
+          Api.getSystemCacheConfig(mainparam, false).then(res => {
             if (!res.status) {
               notification.warning({
                 top: 92,
@@ -2001,7 +2079,7 @@
       setTimeout(() => {
         this.plusLine(colId)
       }, 10)
-    } else if (edData[index] && setting.commit !== 'change') {
+    } else if (edData[index] && (setting.commit === 'all' || setting.commit === 'amend')) {
       setTimeout(() => {
         this.submit()
       }, 10)
@@ -2142,7 +2220,7 @@
 
   checkData = () => {
     const { setting } = this.props
-    const { edData, forms, checkForms } = this.state
+    const { edData, forms, checkForms, selectedRowKeys } = this.state
 
     let data = fromJS(edData).toJS()
 
@@ -2150,6 +2228,17 @@
 
     if (setting.commit === 'amend') {
       data = data.filter(item => !item.$origin)
+    } else if (setting.commit === 'check') {
+      data = data.filter(item => selectedRowKeys.includes(item.$$uuid))
+
+      if (data.length === 0) {
+        notification.warning({
+          top: 92,
+          message: '璇烽�夋嫨闇�瑕佹彁浜ょ殑鏁版嵁锛�',
+          duration: 5
+        })
+        return null
+      }
     }
 
     if (data.length === 0) {
@@ -2196,7 +2285,9 @@
           item[col.field] = val
         } else if (col.type === 'number') {
           let val = item[col.field]
-          if (col.noValue === 'hide' && !val) {
+          if (col.required === 'true' && !val) {
+            err = `${col.label}涓嶅彲涓�${col.noValue === 'hide' ? '绌�' : '0'}`
+          } else if (col.noValue === 'hide' && !val) {
             if (col.clearField && checkForms.includes(col.clearField) && !item[col.clearField]) {
               let msg = `璇峰~鍐� ${col.label} 鎴� ${col.clearName}`
               if (!line.includes(msg)) {
@@ -2291,8 +2382,8 @@
       
       delete param.excel_in
 
-      param.exec_type = 'y'
-      param.LText = Utils.formatOptions(result.sql)
+      param.exec_type = window.GLOB.execType || 'y'
+      param.LText = Utils.formatOptions(result.sql, param.exec_type)
       param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
       param.secretkey = Utils.encrypt('', param.timestamp)
 
@@ -2304,9 +2395,9 @@
 
       Api.genericInterface(param).then((res) => {
         if (res.status) {
-          this.execSuccess(res)
+          this.execSuccess(res, record)
         } else {
-          this.execError(res)
+          this.execError(res, record)
         }
       }, (error) => {
         if (error && error.ErrCode === 'LoginError') return
@@ -2323,9 +2414,9 @@
 
       Api.genericInterface(param).then((res) => {
         if (res.status) {
-          this.execSuccess(res)
+          this.execSuccess(res, record)
         } else {
-          this.execError(res)
+          this.execError(res, record)
         }
       }, (error) => {
         if (error && error.ErrCode === 'LoginError') return
@@ -2335,7 +2426,7 @@
     }
   }
 
-  execSuccess = (res) => {
+  execSuccess = (res, record) => {
     const { submit } = this.props
     const { edData } = this.state
 
@@ -2385,13 +2476,13 @@
     }
 
     if (submit.execSuccess !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit)
+      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execSuccess, submit, '', record ? [record] : null)
     }
 
     submit.syncComponentId && MKEmitter.emit('reloadData', submit.syncComponentId)
   }
 
-  execError = (res) => {
+  execError = (res, record) => {
     const { submit } = this.props
 
     if (res.ErrCode === 'E') {
@@ -2420,7 +2511,7 @@
     })
 
     if (submit.execError !== 'never') {
-      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit)
+      MKEmitter.emit('refreshByButtonResult', submit.$menuId, submit.execError, submit, '', record ? [record] : null)
     }
   }
 
@@ -2578,7 +2669,7 @@
         {setting.hasSubmit && edData.length > 0 ? <div className="edit-custom-table-btn-wrap" style={submit.wrapStyle}>
           <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-table" type="link">鎻愪氦</Button>
         </div> : null}
-        <div className={`edit-custom-table ${setting.tableHeader || ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} style={style}>
+        <div className={`edit-custom-table ${setting.tableHeader || ''} ${setting.parity === 'true' ? 'mk-parity' : ''} ${height ? 'fixed-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} style={style}>
           <Table
             rowKey="$$uuid"
             components={components}

--
Gitblit v1.8.0