From 6afdec0062dacbded57e166230eb22cc55ced0c1 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 08 五月 2021 14:30:21 +0800
Subject: [PATCH] 2021-05-08

---
 src/tabviews/custom/components/share/normalTable/index.jsx |  269 +++++++++++++++++++++++++++++------------------------
 1 files changed, 146 insertions(+), 123 deletions(-)

diff --git a/src/tabviews/custom/components/share/normalTable/index.jsx b/src/tabviews/custom/components/share/normalTable/index.jsx
index e203f3d..2d53eb5 100644
--- a/src/tabviews/custom/components/share/normalTable/index.jsx
+++ b/src/tabviews/custom/components/share/normalTable/index.jsx
@@ -15,14 +15,18 @@
 
 const { Paragraph } = Typography
 const CardCellComponent = asyncComponent(() => import('@/tabviews/custom/components/card/cardcellList'))
-
+const PicRadio = {
+  '4:3': '75%', '3:2': '66.67%', '16:9': '56.25%', '2:1': '50%', '3:1': '33.33%', '4:1': '25%',
+  '5:1': '20%', '6:1': '16.67%', '7:1': '14.29%', '8:1': '12.5%', '9:1': '11.11%',
+  '10:1': '10%', '3:4': '133.33%', '2:3': '150%', '9:16': '177.78%'
+}
 class BodyRow extends React.Component {
   shouldComponentUpdate (nextProps, nextState) {
     return !is(fromJS(this.props.data), fromJS(nextProps.data)) || !is(fromJS(this.props.className), fromJS(nextProps.className))
   }
 
   render() {
-    let { lineMarks, data, className, ...resProps } = this.props
+    let { lineMarks, onDoubleClick, data, className, ...resProps } = this.props
     let style = {}
 
     if (lineMarks && lineMarks.length > 0) {
@@ -89,7 +93,7 @@
       })
     }
 
-    return <tr {...resProps} className={className} style={style}/>
+    return <tr {...resProps} onDoubleClick={onDoubleClick} className={className} style={style}/>
   }
 }
 
@@ -170,7 +174,7 @@
   }
 
   render() {
-    let { col, config, record, className, style, triggerLink, updateStatus, ...resProps } = this.props
+    let { col, config, record, className, style, triggerLink, ...resProps } = this.props
 
     if (!col) return (<td {...resProps} className={className} style={style}/>)
     
@@ -187,7 +191,7 @@
           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)}`
         }
   
-        content = col.prefix + content + col.postfix
+        content = (col.prefix || '') + content + (col.postfix || '')
       }
 
       if (col.marks) {
@@ -201,11 +205,11 @@
       if (col.rowspan === 'true') {
         resProps.rowSpan = record['$$' + col.field]
       }
-
+      
       if (col.linkThdMenu || col.linkurl) {
         content = (
           <div>
-            <div className="link-menu" onDoubleClick={() => this.triggerLink(col, record)}></div>
+            <div className="link-menu" onDoubleClick={(e) => triggerLink(e, col, record)}></div>
             {content}
           </div>
         )
@@ -248,10 +252,14 @@
         content = md5(content)
       }
 
+      if (col.rowspan === 'true') {
+        resProps.rowSpan = record['$$' + col.field]
+      }
+
       if (col.linkThdMenu || col.linkurl) {
         content = (
           <div>
-            <div className="link-menu" onDoubleClick={() => this.triggerLink(col, record)}></div>
+            <div className="link-menu" onDoubleClick={(e) => triggerLink(e, col, record)}></div>
             {content}
           </div>
         )
@@ -268,12 +276,8 @@
       let cols = 24 / (col.picSort || 1)
       let paddingTop = '100%'
 
-      if (col.lenWidRadio === '16:9') {
-        paddingTop = '56.25%'
-      } else if (col.lenWidRadio === '3:2') {
-        paddingTop = '66.67%'
-      } else if (col.lenWidRadio === '4:3') {
-        paddingTop = '75%'
+      if (PicRadio[col.lenWidRadio]) {
+        paddingTop = PicRadio[col.lenWidRadio]
       }
 
       resProps.children = (
@@ -347,12 +351,12 @@
     } else if (col.type === 'custom') {
       style.padding = '0px'
       resProps.children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements} updateStatus={this.props.updateStatus}/>
+        <CardCellComponent data={record} cards={config} elements={col.elements}/>
       )
     } else if (col.type === 'action') {
       style.padding = '0px 5px'
       resProps.children = (
-        <CardCellComponent data={record} cards={config} elements={col.elements} updateStatus={this.props.updateStatus}/>
+        <CardCellComponent data={record} cards={config} elements={col.elements}/>
       )
     }
 
@@ -376,27 +380,27 @@
     loading: PropTypes.bool,         // 琛ㄦ牸鍔犺浇涓�
     refreshdata: PropTypes.func,     // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂�
     chgSelectData: PropTypes.func,   // 鏁版嵁鍒囨崲
-    refreshbyaction: PropTypes.func, // 鎸夐挳鎵ц瀹屾垚鍚庡埛鏂�
   }
 
   state = {
     dict: sessionStorage.getItem('lang') !== 'en-US' ? zhCN : enUS,
+    tableId: '',          // 琛ㄦ牸ID
     selectedRowKeys: [],  // 琛ㄦ牸涓�変腑琛�
     pageIndex: 1,         // 鍒濆椤甸潰绱㈠紩
     pageSize: 10,         // 姣忛〉鏁版嵁鏉℃暟
     columns: null,        // 鏄剧ず鍒�
     activeIndex: null,    // 鏍囪褰撳墠閫変腑琛�
     rowspans: null,       // 琛屽悎骞跺瓧娈典俊鎭�
-    pickup: false
+    pickup: false,        // 鏀惰捣鏈�夋嫨椤�
+    orderfields: {}       // 鎺掑簭id涓巉ield杞崲
   }
 
   UNSAFE_componentWillMount () {
-    const { menuType, memberLevel, setting, fields } = this.props
-    let columns = fromJS(this.props.columns).toJS()
-    let _columns = []
+    const { menuType, memberLevel, setting, fields, columns } = this.props
     let radio = 5          // 铏氬寲姣斾緥
     let _format = false    // 鏄惁铏氬寲澶勭悊
     let rowspans = []
+    let orderfields = {}
 
     if (window.GLOB.dataFormat && menuType !== 'HS' && memberLevel) {
       _format = true
@@ -408,78 +412,78 @@
       }
     }
 
-    columns.forEach(item => {
-      if (item.hidden === true || item.Hide === 'true') return
-      let cell = null
-
-      if (item.type === 'colspan') {
-        cell = {title: item.label, children: []}
-
-        item.subcols.forEach(col => {
-          if (col.rowspan === 'true') {
-            rowspans.push(col.field)
+    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.rowspan === 'true') {
+            rowspans.push(item.field)
           }
-          if (_format && !Math.floor(Math.random() * radio)) {
-            col.blur = true
+          if (item.type === 'index') {
+            item.field = '$Index'
+            item.type = 'text'
+          } else if (_format && !Math.floor(Math.random() * radio)) {
+            item.blur = true
+          }
+  
+          if (item.marks && item.marks.length === 0) {
+            item.marks = ''
           }
 
-          if (col.marks && col.marks.length === 0) {
-            col.marks = ''
+          if (item.field) {
+            orderfields[item.uuid] = item.field
           }
 
-          cell.children.push({
-            align: col.Align,
-            title: col.label,
-            dataIndex: col.field || col.uuid,
-            key: col.uuid,
-            width: col.Width || 120,
+          cell = {
+            align: item.Align,
+            dataIndex: item.uuid,
+            title: item.label,
+            sorter: item.field && item.IsSort === 'true',
+            width: item.Width || 120,
             onCell: record => ({
               record,
-              col,
-              config: col.type === 'custom' ? {setting, columns: fields} : null,
-              triggerLink: this.triggerLink,
-              updateStatus: this.updateStatus
+              col: item,
+              config: item.type === 'custom' || item.type === 'action' ? {setting, columns: fields} : null,
+              triggerLink: this.triggerLink
             })
-          })
-        })
-      } else {
-        if (item.rowspan === 'true') {
-          rowspans.push(item.field)
+          }
         }
-        if (_format && !Math.floor(Math.random() * radio)) {
-          item.blur = true
-        }
+  
+        return cell
+      })
+    }
 
-        if (item.marks && item.marks.length === 0) {
-          item.marks = ''
-        }
-
-        cell = {
-          align: item.Align,
-          dataIndex: item.field || 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,
-            triggerLink: this.triggerLink,
-            updateStatus: this.updateStatus
-          })
-        }
-      }
-
-      _columns.push(cell)
-    })
+    let _columns = getColumns(columns)
 
     if (rowspans.length === 0) {
       rowspans = null
     }
 
+    let tableId = (() => {
+      let uuid = []
+      let _options = 'abcdefghigklmnopqrstuv'
+      for (let i = 0; i < 19; i++) {
+        uuid.push(_options.substr(Math.floor(Math.random() * 0x20), 1))
+      }
+      return uuid.join('')
+    }) ()
+
+    if (setting.borderColor) { // 杈规棰滆壊
+      let style = `#${tableId} table, #${tableId} tr, #${tableId} th, #${tableId} td {border-color: ${setting.borderColor}}`
+      let ele = document.createElement('style')
+      ele.innerHTML = style
+      document.getElementsByTagName('head')[0].appendChild(ele)
+    }
+
     this.setState({
       columns: _columns,
-      rowspans
+      rowspans,
+      tableId,
+      orderfields
     })
   }
 
@@ -501,68 +505,72 @@
     MKEmitter.removeListener('resetTable', this.resetTable)
   }
 
-  updateStatus = (type, positon, btn) => {
-    if (type === 'refresh') {
-      this.props.refreshbyaction(positon, btn)
-    }
-  }
-
   // 瀛楁閫忚
-  triggerLink = (item, record) => {
-    const { tabviews, MenuID } = this.props
+  triggerLink = (e, item, record) => {
+    const { tabviews } = this.props
+    e.stopPropagation()
+
+    let __param = {
+      $searchkey: item.field,
+      $searchval: record[item.field] || '',
+      $BID: record.$$uuid
+    }
+
+    if (item.linkfields && item.linkfields.length > 0) {
+      item.linkfields.forEach(field => {
+        __param[field] = record[field] || ''
+      })
+    }
 
     if (item.linkThdMenu) {
       let tabmenu = item.linkThdMenu
 
-      tabmenu.param = {
-        searchkey: item.field,
-        searchval: record[item.field] || '',
-        BID: record.$$uuid
-      }
-  
+      tabmenu.param = __param
       tabmenu.selected = true
   
-      let index = 0
-      let isexit = false
-      let tabs = tabviews.map((tab, i) => {
+      let tabs = tabviews.filter((tab, i) => {
         tab.selected = false
-  
-        if (tab.MenuID === MenuID) {
-          index = i
-        } else if (tab.MenuID === tabmenu.MenuID) {
-          tab.param = tabmenu.param
-          tab.selected = true
-          isexit = true
-        }
-  
-        return tab
+        return tab.MenuID !== tabmenu.MenuID
       })
   
-      if (!isexit) {
-        tabs.splice(index + 1, 0, tabmenu)
+      if (tabviews.length > tabs.length) {
+        this.props.modifyTabview(fromJS(tabs).toJS())
       }
   
-      this.props.modifyTabview(tabs)
-    } else {
+      this.setState({}, () => {
+        tabs.push(tabmenu)
+        this.props.modifyTabview(tabs)
+      })
+    } else if (item.linkurl) {
       let src = item.linkurl
 
-      if (item.linkurl.indexOf('paramsmain/') > -1) {
+      if (src.indexOf('paramsmain/') > -1) {
         try {
           let _url = item.linkurl.split('paramsmain/')[0] + 'paramsmain/'
           let _param = JSON.parse(window.decodeURIComponent(window.atob(item.linkurl.split('paramsmain/')[1])))
-          let dataparam = {
-            searchkey: item.field,
-            searchval: record[item.field] || '',
-            BID: record.$$uuid
-          }
           _param.UserID = sessionStorage.getItem('UserID')
           _param.LoginUID = sessionStorage.getItem('LoginUID')
           _param.User_Name = sessionStorage.getItem('User_Name')
-          _param.param = dataparam
+          _param.param = __param
           src = _url + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
         } catch {
           console.warn('鑿滃崟鍙傛暟瑙f瀽閿欒锛�')
         }
+      } else {
+        let con = '?'
+
+        if (/\?/ig.test(src)) {
+          con = '&'
+        }
+
+        if (item.linkfields && item.linkfields.length > 0) {
+          item.linkfields.forEach(field => {
+            if (field.toLowerCase() === 'id') return
+            con += `${field}=${record[field] || ''}&`
+          })
+        }
+        
+        src = src + `${con}id=${record.$$uuid}&appkey=${window.GLOB.appkey}&userid=${sessionStorage.getItem('UserID')}&LoginUID=${sessionStorage.getItem('LoginUID') || ''}`
       }
 
       window.open(src)
@@ -581,7 +589,7 @@
       index = selectedRowKeys.slice(-1)[0]
     }
 
-    if (setting.tableType === 'checkbox') {
+    if (setting.tableType === 'checkbox' || setting.tableType === 'radio') {
       _activeIndex = index === '' ? null : index
     }
 
@@ -607,7 +615,7 @@
     if (setting.tableType === 'radio') {
       newkeys = [index]
       this.changedata(index)
-      this.setState({ selectedRowKeys: newkeys })
+      this.setState({ selectedRowKeys: newkeys, activeIndex: index })
     } else {
       let _index = ''
       if (newkeys.includes(index)) {
@@ -631,6 +639,8 @@
   }
 
   changeTable = (pagination, filters, sorter) => {
+    const { orderfields } = this.state
+
     this.setState({
       pageIndex: pagination.current,
       pageSize: pagination.pageSize,
@@ -638,6 +648,9 @@
       activeIndex: null,
       pickup: false
     })
+
+    sorter.field = orderfields[sorter.field] || ''
+
     this.props.refreshdata(pagination, filters, sorter)
   }
 
@@ -692,13 +705,13 @@
         let preItem = data[index - 1]
         rowspans.forEach((cell, i) => {
           if (i === 0) {
-            if ((item[cell] || item[cell] === 0) && preItem[cell] === item[cell]) {
+            if (preItem[cell] === item[cell]) {
               item['$' + cell] = preItem['$' + cell] + 1
             } else {
               item['$' + cell] = 1
             }
           } else {
-            if ((item[cell] || item[cell] === 0) && preItem[cell] === item[cell]) {
+            if (preItem[cell] === item[cell]) {
               item['$' + cell] = preItem['$' + cell] + 1
             } else {
               item['$' + cell] = 1
@@ -736,9 +749,17 @@
     })
   }
 
+  doubleClickLine = (record) => {
+    const { setting } = this.props
+
+    if (!setting.doubleClick) return
+
+    MKEmitter.emit('triggerBtnId', setting.doubleClick, [record])
+  }
+
   render() {
     const { setting, statFValue, lineMarks, data } = this.props
-    const { selectedRowKeys, activeIndex, pickup } = this.state
+    const { selectedRowKeys, activeIndex, pickup, tableId } = this.state
 
     // 璁剧疆琛ㄦ牸閫夋嫨灞炴�э細鍗曢�夈�佸閫夈�佷笉鍙��
     let rowSelection = null
@@ -785,13 +806,14 @@
     }
 
     return (
-      <div className="normal-custom-table">
+      <div className={`normal-custom-table ${setting.tableHeader || ''} ${setting.mode || ''}`} id={tableId}>
         {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && data && data.length > 0 ?
-          <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" defaultChecked={pickup} onChange={this.pickupChange} /> : null
+          <Switch title="鏀惰捣" className="main-pickup" checkedChildren="寮�" unCheckedChildren="鍏�" checked={pickup} onChange={this.pickupChange} /> : null
         }
         <Table
-          size="middle"
           components={components}
+          style={setting.style}
+          size={setting.size || 'middle'}
           bordered={setting.bordered !== 'false'}
           rowSelection={rowSelection}
           columns={this.state.columns}
@@ -803,7 +825,8 @@
               lineMarks,
               data: record,
               className: index === activeIndex ? ' mk-row-active ' : '',
-              onClick: () => {this.changeRow(record, index)}
+              onClick: () => {this.changeRow(record, index)},
+              onDoubleClick: () => {this.doubleClickLine(record)}
             }
           }}
           onChange={this.changeTable}

--
Gitblit v1.8.0