From f4b9504cad034ddcdef21c2081d14a4984fcd2d3 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期一, 15 七月 2024 17:14:48 +0800
Subject: [PATCH] 2024-07-15

---
 src/tabviews/custom/components/table/edit-table/normalTable/index.jsx |  211 +++++++++++++++++++++++++++++++---------------------
 1 files changed, 124 insertions(+), 87 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 a7571dd..9529a8e 100644
--- a/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
+++ b/src/tabviews/custom/components/table/edit-table/normalTable/index.jsx
@@ -562,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
@@ -727,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}/>)
@@ -747,10 +751,10 @@
       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) {
@@ -866,6 +870,7 @@
         }
   
         if (col.format === 'thdSeparator') {
+          content = content + ''
           content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
         }
   
@@ -973,7 +978,12 @@
         content = <span dangerouslySetInnerHTML={{__html: content}}></span>
       } else if (content !== '') {
         content = `${col.prefix || ''}${content}${col.postfix || ''}`
-        content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, '&nbsp;')
+        if (!col.evalchars || col.evalchars.includes('enter')) {
+          content = content.replace(/\n/ig, '<br/>')
+        }
+        if (!col.evalchars || col.evalchars.includes('space')) {
+          content = content.replace(/\s/ig, '&nbsp;')
+        }
         content = <span dangerouslySetInnerHTML={{__html: content}}></span>
       }
 
@@ -1009,7 +1019,7 @@
       }
 
       children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements}/>
+        <CardCellComponent data={record} cards={col.config} elements={col.elements}/>
       )
     }
 
@@ -1040,7 +1050,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}/>)
 
@@ -1091,10 +1101,10 @@
         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) {
@@ -1190,6 +1200,7 @@
           }
     
           if (col.format === 'thdSeparator') {
+            content = content + ''
             content = content.replace(/\d{1,3}(?=(\d{3})+(\.\d*)?$)/g, '$&,')
           }
     
@@ -1286,7 +1297,12 @@
         content = <span dangerouslySetInnerHTML={{__html: content}}></span>
       } else if (content !== '') {
         content = `${col.prefix || ''}${content}${col.postfix || ''}`
-        content = content.replace(/\n/ig, '<br/>').replace(/\s/ig, '&nbsp;')
+        if (!col.evalchars || col.evalchars.includes('enter')) {
+          content = content.replace(/\n/ig, '<br/>')
+        }
+        if (!col.evalchars || col.evalchars.includes('space')) {
+          content = content.replace(/\s/ig, '&nbsp;')
+        }
         content = <span dangerouslySetInnerHTML={{__html: content}}></span>
       }
 
@@ -1322,7 +1338,7 @@
       }
 
       children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements}/>
+        <CardCellComponent data={record} cards={col.config} elements={col.elements}/>
       )
     }
 
@@ -1367,7 +1383,8 @@
     allColumns: null,
     checkForms: [],
     allForms: [],
-    reseting: false
+    reseting: false,
+    dict: window.GLOB.dict
   }
 
   timer = null
@@ -1383,7 +1400,6 @@
     let deForms = []
     let _forms = {}
     let hasBid = false
-    let index = 0
     let checkForms = []
     let allForms = []
 
@@ -1396,25 +1412,12 @@
           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)
   
@@ -1426,20 +1429,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'
               }
             }
           }
@@ -1459,8 +1448,7 @@
             $key: item.uuid,
             onCell: record => ({
               record,
-              col: item,
-              config: item.type === 'custom' ? {setting, columns: fields} : null,
+              col: item
             })
           }
         }
@@ -1537,11 +1525,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
+      })
     }
   }
 
@@ -1605,7 +1626,7 @@
   }
 
   checkLine = () => {
-    const { edData, forms, checkForms } = this.state
+    const { edData, forms, checkForms, dict } = this.state
 
     let data = edData.filter(item => item.$$uuid === this.blurId)[0]
 
@@ -1648,7 +1669,7 @@
       if (col.type === 'text') {
         let val = record[col.field] !== undefined ? (record[col.field] + '') : ''
         if (col.required === 'true' && !val) {
-          err = `${col.label}涓嶅彲涓虹┖`
+          err = `${col.label}${dict['not_empty'] || '涓嶅彲涓虹┖'}`
         } else if (col.datatype === 'datetime' && !val) {
           val = '1949-10-01'
         }
@@ -1656,26 +1677,28 @@
       } 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' ? (dict['not_empty'] || '涓嶅彲涓虹┖') : dict['not_zero'] || '涓嶅彲涓�0'}`
+        } else if (col.noValue === 'hide' && !val) {
           if (col.clearField && checkForms.includes(col.clearField) && !record[col.clearField]) {
-            err = `璇峰~鍐� ${col.label} 鎴� ${col.clearName}`
+            err = `${dict['input_tip'] || '璇峰~鍐� '}${col.label} ${dict['or'] || '鎴�'} ${col.clearName}`
           }
           val = 0
         } else if (!val && val !== 0) {
-          err = `${col.label}涓嶅彲涓虹┖`
+          err = `${col.label}${dict['not_empty'] || '涓嶅彲涓虹┖'}`
         } else {
           val = +val
           if (isNaN(val)) {
-            err = `${col.label}鏁版嵁鏍煎紡閿欒`
+            err = `${col.label} ${dict['data_format'] || '鏁版嵁鏍煎紡閿欒'}`
             return
           }
   
           val = +val.toFixed(col.decimal || 0)
           
           if (typeof(col.max) === 'number' && val > col.max) {
-            err = `${col.label}涓嶅彲澶т簬${col.max}`
+            err = `${col.label}${dict['max_limit'] || ' 涓嶅彲澶т簬 '}${col.max}`
           } else if (typeof(col.min) === 'number' && val < col.min) {
-            err = `${col.label}涓嶅彲灏忎簬${col.min}`
+            err = `${col.label}${dict['less_limit'] || ' 涓嶅彲灏忎簬 '}${col.min}`
           }
         }
 
@@ -1748,7 +1771,10 @@
   transferData = (data, type) => {
     const { edData, tableId } = this.state
 
-    if (type === 'delete') {
+    if (type === 'clear') {
+      this.setState({edData: [], midData: []})
+      return
+    } else if (type === 'delete') {
 
     } else if (type === 'line') {
       let value = ''
@@ -2205,7 +2231,7 @@
 
   checkData = () => {
     const { setting } = this.props
-    const { edData, forms, checkForms, selectedRowKeys } = this.state
+    const { edData, forms, checkForms, selectedRowKeys, dict } = this.state
 
     let data = fromJS(edData).toJS()
 
@@ -2219,7 +2245,7 @@
       if (data.length === 0) {
         notification.warning({
           top: 92,
-          message: '璇烽�夋嫨闇�瑕佹彁浜ょ殑鏁版嵁锛�',
+          message: dict['select_row'] || '璇烽�夋嫨闇�瑕佹彁浜ょ殑鏁版嵁锛�',
           duration: 5
         })
         return null
@@ -2229,7 +2255,7 @@
     if (data.length === 0) {
       notification.warning({
         top: 92,
-        message: '鏁版嵁鏈慨鏀癸紝涓嶅彲鎻愪氦锛�',
+        message: dict['un_modified'] || '鏁版嵁鏈慨鏀癸紝涓嶅彲鎻愪氦锛�',
         duration: 5
       })
       return null
@@ -2263,37 +2289,39 @@
         if (col.type === 'text') {
           let val = item[col.field] !== undefined ? (item[col.field] + '') : ''
           if (col.required === 'true' && !val) {
-            line.push(`${col.label}涓嶅彲涓虹┖`)
+            line.push(`${col.label}${dict['not_empty'] || '涓嶅彲涓虹┖'}`)
           } else if (col.datatype === 'datetime' && !val) {
             val = '1949-10-01'
           }
           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' ? (dict['not_empty'] || '涓嶅彲涓虹┖') : dict['not_zero'] || '涓嶅彲涓�0'}`
+          } else if (col.noValue === 'hide' && !val) {
             if (col.clearField && checkForms.includes(col.clearField) && !item[col.clearField]) {
-              let msg = `璇峰~鍐� ${col.label} 鎴� ${col.clearName}`
+              let msg = `${dict['input_tip'] || '璇峰~鍐� '}${col.label} ${dict['or'] || '鎴�'} ${col.clearName}`
               if (!line.includes(msg)) {
                 line.push(msg)
               }
             }
             val = 0
           } else if (!val && val !== 0) {
-            line.push(`${col.label}涓嶅彲涓虹┖`)
+            line.push(`${col.label}${dict['not_empty'] || '涓嶅彲涓虹┖'}`)
             return
           } else {
             val = +val
             if (isNaN(val)) {
-              line.push(`${col.label}鏁版嵁鏍煎紡閿欒`)
+              line.push(`${col.label} ${dict['data_format'] || '鏁版嵁鏍煎紡閿欒'}`)
               return
             }
   
             val = +val.toFixed(col.decimal || 0)
             
             if (typeof(col.max) === 'number' && val > col.max) {
-              line.push(`${col.label}涓嶅彲澶т簬${col.max}`)
+              line.push(`${col.label}${dict['max_limit'] || ' 涓嶅彲澶т簬 '}${col.max}`)
             } else if (typeof(col.min) === 'number' && val < col.min) {
-              line.push(`${col.label}涓嶅彲灏忎簬${col.min}`)
+              line.push(`${col.label}${dict['less_limit'] || ' 涓嶅彲灏忎簬 '}${col.min}`)
             }
           }
 
@@ -2302,7 +2330,7 @@
       })
 
       if (line.length > 0) {
-        err += `绗�${Index}琛岋細` + line.join('锛�') + '锛�'
+        err += (dict['line'] ? `${dict['line']} ${Index}锛歚 : `绗�${Index}琛岋細`) + line.join('锛�') + '锛�'
       }
       if (!item.$deleted) {
         Index++
@@ -2326,14 +2354,14 @@
 
   submit = (record) => {
     const { submit, BID, setting } = this.props
-    const { forms } = this.state
+    const { forms, dict } = this.state
 
     this.setState({visible: false, midData: null})
 
     if (setting.supModule && !BID) {
       notification.warning({
         top: 92,
-        message: '闇�瑕佷笂绾т富閿�硷紒',
+        message: dict['sup_key_req'] || '闇�瑕佷笂绾т富閿�硷紒',
         duration: 5
       })
 
@@ -2411,17 +2439,18 @@
 
   execSuccess = (res, record) => {
     const { submit } = this.props
-    const { edData } = this.state
+    const { edData, dict } = this.state
 
     if (res && res.ErrCode === 'S') { // 鎵ц鎴愬姛
       notification.success({
         top: 92,
-        message: res.message || '鎵ц鎴愬姛',
+        message: res.message || dict['exc_success'] || '鎵ц鎴愬姛',
         duration: submit.stime ? submit.stime : 2
       })
     } else if (res && res.ErrCode === 'Y') { // 鎵ц鎴愬姛
       Modal.success({
-        title: res.message || '鎵ц鎴愬姛'
+        title: res.message || dict['exc_success'] || '鎵ц鎴愬姛',
+        okText: dict['got_it'] || '鐭ラ亾浜�'
       })
     } else if (res && res.ErrCode === '-1') { // 瀹屾垚鍚庝笉鎻愮ず
 
@@ -2467,26 +2496,28 @@
 
   execError = (res, record) => {
     const { submit } = this.props
+    const { dict } = this.state
 
     if (res.ErrCode === 'E') {
       Modal.error({
-        title: res.message || '鎵ц澶辫触锛�',
+        title: res.message || dict['exc_fail'] || '鎵ц澶辫触锛�',
+        okText: dict['got_it'] || '鐭ラ亾浜�'
       })
     } else if (res.ErrCode === 'N') {
       notification.error({
         top: 92,
-        message: res.message || '鎵ц澶辫触锛�',
+        message: res.message || dict['exc_fail'] || '鎵ц澶辫触锛�',
         duration: submit.ntime ? submit.ntime : 10
       })
     } else if (res.ErrCode === 'F') {
       notification.error({
         className: 'notification-custom-error',
         top: 92,
-        message: res.message || '鎵ц澶辫触锛�',
+        message: res.message || dict['exc_fail'] || '鎵ц澶辫触锛�',
         duration: submit.ftime ? submit.ftime : 10
       })
     } else if (res.ErrCode === 'NM') {
-      message.error(res.message || '鎵ц澶辫触锛�')
+      message.error(res.message || dict['exc_fail'] || '鎵ц澶辫触锛�')
     }
     
     this.setState({
@@ -2600,7 +2631,7 @@
 
   render() {
     const { setting, lineMarks, submit } = this.props
-    const { edData, columns, loading, pageOptions, selectedRowKeys, visible, midData, reseting } = this.state
+    const { edData, columns, loading, pageOptions, selectedRowKeys, visible, midData, reseting, dict } = this.state
 
     if (reseting) return null
 
@@ -2631,13 +2662,19 @@
         pageSizeOptions: pageOptions,
         showSizeChanger: true,
         total: this.props.total || 0,
-        showTotal: (total, range) => `${range[0]}-${range[1]} 鍏� ${total} 鏉
+        showTotal: (total, range) => `${range[0]}-${range[1]} ${dict['of'] || '鍏�'} ${total} ${dict['items'] || '鏉�'}`
       }
     }
 
     let height = setting.height || false
-    if (height && height <= 100) {
-      height = height + 'vh'
+    if (height) {
+      if (height <= 100) {
+        if (height < 0) {
+          height = `calc(100vh - ${-height}px)`
+        } else {
+          height = height + 'vh'
+        }
+      }
     }
 
     let style = {
@@ -2650,9 +2687,9 @@
     return (
       <>
         {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>
+          <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-table" type="link">{dict['submit'] || '鎻愪氦'}</Button>
         </div> : null}
-        <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}>
+        <div className={`edit-custom-table ${setting.tableHeader || ''} ${setting.parity === 'true' ? 'mk-parity' : ''} ${height ? 'fixed-table-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || ''} mk-edit-${setting.editType || 'simple'}`} style={style}>
           <Table
             rowKey="$$uuid"
             components={components}
@@ -2674,7 +2711,7 @@
             onChange={this.changeTable}
             pagination={_pagination}
           />
-          {setting.hasSubmit && _data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-footer-table" type="link">鎻愪氦</Button> : null}
+          {setting.hasSubmit && _data.length > 10 ? <Button style={submit.style} onClick={() => setTimeout(() => {this.submit()}, 10)} loading={loading} className="submit-footer-table" type="link">{dict['submit'] || '鎻愪氦'}</Button> : null}
         </div>
         <Modal
           className="mk-user-confirm"
@@ -2683,13 +2720,13 @@
           maskClosable={false}
           closable={false}
           footer={[
-            <Button key="cancel" onClick={() => { this.setState({ visible: false, midData: null }) }}>鍙栨秷</Button>,
-            <Button key="refresh" className="table-refresh" onClick={() => { midData && this.updateMutil(midData) }}>鍒锋柊琛ㄦ牸</Button>,
-            <Button key="confirm" type="primary" onClick={() => setTimeout(() => {this.submit()}, 10)}>鎻愪氦鏁版嵁</Button>
+            <Button key="cancel" onClick={() => { this.setState({ visible: false, midData: null }) }}>{dict['cancel'] || '鍙栨秷'}</Button>,
+            <Button key="refresh" className="table-refresh" onClick={() => { midData && this.updateMutil(midData) }}>{dict['refresh'] || '鍒锋柊琛ㄦ牸'}</Button>,
+            <Button key="confirm" type="primary" onClick={() => setTimeout(() => {this.submit()}, 10)}>{dict['submit'] || '鎻愪氦鏁版嵁'}</Button>
           ]}
           destroyOnClose
         >
-          <div><QuestionCircleOutlined />琛ㄦ牸涓湁鏁版嵁灏氭湭鎻愪氦</div>
+          <div><QuestionCircleOutlined />{dict['data_not_sub'] || '琛ㄦ牸涓湁鏁版嵁灏氭湭鎻愪氦'}</div>
         </Modal>
       </>
     )

--
Gitblit v1.8.0