From 1da6506bf58270bacc2a4345002c6b082835580e Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 21 十月 2021 23:17:08 +0800
Subject: [PATCH] 2021-10-21

---
 src/tabviews/zshare/normalTable/index.jsx |  435 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 272 insertions(+), 163 deletions(-)

diff --git a/src/tabviews/zshare/normalTable/index.jsx b/src/tabviews/zshare/normalTable/index.jsx
index 21feaa5..2db7a13 100644
--- a/src/tabviews/zshare/normalTable/index.jsx
+++ b/src/tabviews/zshare/normalTable/index.jsx
@@ -5,7 +5,6 @@
 import { is, fromJS } from 'immutable'
 import { Table, Affix, Typography, Icon } from 'antd'
 
-import { modifyTabview } from '@/store/action'
 import asyncComponent from '@/utils/asyncComponent'
 import MKEmitter from '@/utils/events.js'
 import '@/assets/css/table.scss'
@@ -17,6 +16,17 @@
 const PopupButton = asyncComponent(() => import('@/tabviews/zshare/actionList/popupbutton'))
 const TabButton = asyncComponent(() => import('@/tabviews/zshare/actionList/tabbutton'))
 const NewPageButton = asyncComponent(() => import('@/tabviews/zshare/actionList/newpagebutton'))
+
+class BodyRow extends React.Component {
+  shouldComponentUpdate (nextProps) {
+    return !is(fromJS(this.props.record), fromJS(nextProps.record)) || this.props.className !== nextProps.className
+  }
+
+  render() {
+    const { record, ...resProps } = this.props
+    return <tr {...resProps}/>
+  }
+}
 
 class NormalTable extends Component {
   static propTpyes = {
@@ -35,7 +45,6 @@
     total: PropTypes.any,            // 鎬绘暟
     loading: PropTypes.bool,         // 琛ㄦ牸鍔犺浇涓�
     refreshdata: PropTypes.func,     // 琛ㄦ牸涓帓搴忓垪銆侀〉鐮佺殑鍙樺寲鏃跺埛鏂�
-    handleTableId: PropTypes.func,   // 鏁版嵁鍒囨崲
     chgSelectData: PropTypes.func,   // 鏁版嵁鍒囨崲
   }
 
@@ -50,7 +59,7 @@
   }
 
   UNSAFE_componentWillMount () {
-    const { menuType, memberLevel, pageSize } = this.props
+    const { menuType, memberLevel, pageSize, setting } = this.props
     let columns = fromJS(this.props.columns).toJS()
     let lineMarks = []
     let _columns = []
@@ -58,122 +67,159 @@
     let _format = false    // 鏄惁铏氬寲澶勭悊
     let rowspans = []
 
-    if (window.GLOB.dataFormat && menuType !== 'HS' && memberLevel) {
-      _format = true
-
-      if (memberLevel >= 30) {
-        radio = 20
-      } else if (memberLevel >= 20) {
-        radio = 10
-      }
-    }
-
-    columns.forEach((item, index) => {
-      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)
-          }
-          if (_format && !Math.floor(Math.random() * radio)) {
-            col.blur = true
-          }
-
-          if (col.marks) { // 杩囨护琛屽拰鍗$墖鏍囪
-            col.marks = col.marks.filter(mark => {
-              if (mark.signType === 'line') {
-                lineMarks.push(mark)
-              }
-              return mark.signType !== 'line' && mark.signType !== 'card'
+    if (setting.tableMode === 'fast') {
+      rowspans = null
+      columns.forEach(item => {
+        if (item.hidden === true || item.Hide === 'true') return
+        let cell = null
+  
+        if (item.type === 'colspan' || item.type === 'old_colspan') {
+          cell = {title: item.label, children: []}
+  
+          item.subcols.forEach(col => {
+            cell.children.push({
+              align: col.Align,
+              title: col.label,
+              dataIndex: col.field || col.uuid,
+              key: col.uuid,
+              width: col.Width || 120
             })
-    
-            if (col.marks.length === 0) {
-              col.marks = ''
-            }
-          }
-
-          cell.children.push({
-            align: col.Align,
-            title: col.label,
-            dataIndex: col.field || col.uuid,
-            key: col.uuid,
-            width: col.Width || 120,
-            render: (text, record) => {
-              return this.getContent(col, record)
-            }
           })
-        })
-      } else if (item.type === 'old_colspan') {
-        item.subcols.forEach(col => {
-          if (col.marks) { // 杩囨护琛屽拰鍗$墖鏍囪
-            col.marks = col.marks.filter(mark => {
-              if (mark.signType === 'line') {
-                lineMarks.push(mark)
+        } else {
+          if (item.type === 'index') {
+            item.field = '$Index'
+            item.type = 'text'
+          }
+  
+          cell = {
+            align: item.Align,
+            dataIndex: item.field || item.uuid,
+            title: item.label,
+            sorter: item.field && item.IsSort === 'true',
+            width: item.Width || 120
+          }
+        }
+        
+        _columns.push(cell)
+      })
+    } else {
+      if (window.GLOB.dataFormat && menuType !== 'HS' && memberLevel) {
+        _format = true
+  
+        if (memberLevel >= 30) {
+          radio = 20
+        } else if (memberLevel >= 20) {
+          radio = 10
+        }
+      }
+  
+      columns.forEach((item, index) => {
+        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)
+            }
+            if (_format && !Math.floor(Math.random() * radio)) {
+              col.blur = true
+            }
+  
+            if (col.marks) { // 杩囨护琛屽拰鍗$墖鏍囪
+              col.marks = col.marks.filter(mark => {
+                if (mark.signType === 'line') {
+                  lineMarks.push(mark)
+                }
+                return mark.signType !== 'line' && mark.signType !== 'card'
+              })
+      
+              if (col.marks.length === 0) {
+                col.marks = ''
               }
-              return mark.signType !== 'line' && mark.signType !== 'card'
+            }
+  
+            cell.children.push({
+              align: col.Align,
+              title: col.label,
+              dataIndex: col.field || col.uuid,
+              key: col.uuid,
+              width: col.Width || 120,
+              render: (text, record) => {
+                return this.getContent(col, record)
+              }
             })
-    
-            if (col.marks.length === 0) {
-              col.marks = ''
+          })
+        } else if (item.type === 'old_colspan') {
+          item.subcols.forEach(col => {
+            if (col.marks) { // 杩囨护琛屽拰鍗$墖鏍囪
+              col.marks = col.marks.filter(mark => {
+                if (mark.signType === 'line') {
+                  lineMarks.push(mark)
+                }
+                return mark.signType !== 'line' && mark.signType !== 'card'
+              })
+      
+              if (col.marks.length === 0) {
+                col.marks = ''
+              }
             }
-          }
-        })
-
-        cell = {
-          align: item.Align,
-          dataIndex: item.field || item.uuid,
-          title: item.label,
-          sorter: item.field && item.IsSort === 'true',
-          width: item.Width || 120,
-          render: (text, record) => {
-            return this.getContent(item, record)
-          }
-        }
-      } else {
-        if (item.rowspan === 'true') {
-          rowspans.push(item.field)
-        }
-        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 = item.marks.filter(mark => {
-            if (mark.signType === 'line') {
-              lineMarks.push(mark)
-            }
-            return mark.signType !== 'line' && mark.signType !== 'card'
           })
   
-          if (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,
+            render: (text, record) => {
+              return this.getContent(item, record)
+            }
+          }
+        } else {
+          if (item.rowspan === 'true') {
+            rowspans.push(item.field)
+          }
+          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 = item.marks.filter(mark => {
+              if (mark.signType === 'line') {
+                lineMarks.push(mark)
+              }
+              return mark.signType !== 'line' && mark.signType !== 'card'
+            })
+    
+            if (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,
+            render: (text, record) => {
+              return this.getContent(item, record)
+            }
           }
         }
-
-        cell = {
-          align: item.Align,
-          dataIndex: item.field || item.uuid,
-          title: item.label,
-          sorter: item.field && item.IsSort === 'true',
-          width: item.Width || 120,
-          render: (text, record) => {
-            return this.getContent(item, record)
-          }
-        }
+        
+        _columns.push(cell)
+      })
+  
+      if (rowspans.length === 0) {
+        rowspans = null
       }
-      
-      _columns.push(cell)
-    })
-
-    if (rowspans.length === 0) {
-      rowspans = null
     }
     
     this.setState({
@@ -190,6 +236,9 @@
 
   componentDidMount () {
     MKEmitter.addListener('resetTable', this.resetTable)
+    MKEmitter.addListener('autoQueryData', this.autoQueryData)
+    MKEmitter.addListener('autoSelectData', this.autoSelectData)
+    MKEmitter.addListener('mkTableCheckTopLine', this.mkTableCheckTopLine)
   }
 
   /**
@@ -200,12 +249,60 @@
       return
     }
     MKEmitter.removeListener('resetTable', this.resetTable)
+    MKEmitter.removeListener('autoQueryData', this.autoQueryData)
+    MKEmitter.removeListener('autoSelectData', this.autoSelectData)
+    MKEmitter.removeListener('mkTableCheckTopLine', this.mkTableCheckTopLine)
+  }
+
+  mkTableCheckTopLine = (id) => {
+    if (id !== this.props.MenuID) return
+
+    if (this.props.data.length > 0) {
+      this.changeRow(null, 0)
+    }
+  }
+
+  autoSelectData = (id, index) => {
+    if (id !== this.props.MenuID) return
+
+    const { pageSize, pageIndex } = this.state
+
+    let i = index - (pageIndex - 1) * pageSize - 1
+
+    if (this.props.data[i]) {
+      this.changeRow(null, i)
+      MKEmitter.emit('autoTransSelectData', this.props.MenuID, this.props.data[i])
+    } else {
+      MKEmitter.emit('autoMaticOver', this.props.MenuID)
+    }
+  }
+
+  autoQueryData = (id, index) => {
+    if (id !== this.props.MenuID) return
+
+    const { total } = this.props
+    const { pageSize } = this.state
+
+    if (index !== 1 && (!total || index > total)) {
+      MKEmitter.emit('autoMaticOver', this.props.MenuID)
+      return
+    }
+
+    console.clear()
+
+    let pageIndex = Math.ceil(index / pageSize)
+
+    this.setState({
+      pageIndex: pageIndex,
+      selectedRowKeys: [],
+      activeIndex: null
+    })
+
+    this.props.refreshdata({pageIndex})
   }
 
   // 瀛楁閫忚
   triggerLink = (e, item, record) => {
-    const { tabviews, MenuID } = this.props
-
     e.stopPropagation()
 
     let __param = {
@@ -222,33 +319,13 @@
 
     if (item.linkThdMenu) {
       let tabmenu = item.linkThdMenu
-
       tabmenu.param = __param
-      tabmenu.selected = true
-  
-      let index = 0
-      let tabs = tabviews.filter((tab, i) => {
-        tab.selected = false
-  
-        if (tab.MenuID === MenuID) {
-          index = i
-        }
-  
-        return tab.MenuID !== tabmenu.MenuID
-      })
-  
-      if (tabviews.length > tabs.length) {
-        this.props.modifyTabview(fromJS(tabs).toJS())
+
+      if (['linkage_navigation', 'linkage', 'menu_board'].includes(window.GLOB.navBar)) {
+        MKEmitter.emit('modifyTabs', tabmenu, 'replace')
+      } else {
+        MKEmitter.emit('modifyTabs', tabmenu, 'plus', true)
       }
-  
-      this.setState({}, () => {
-        if (MenuID) {
-          tabs.splice(index + 1, 0, tabmenu)
-        } else {
-          tabs.push(tabmenu)
-        }
-        this.props.modifyTabview(tabs)
-      })
     } else if (item.linkurl) {
       let src = item.linkurl
 
@@ -261,7 +338,7 @@
           _param.User_Name = sessionStorage.getItem('User_Name')
           _param.param = __param
           src = _url + window.btoa(window.encodeURIComponent(JSON.stringify(_param)))
-        } catch {
+        } catch (e) {
           console.warn('鑿滃崟鍙傛暟瑙f瀽閿欒锛�')
         }
       } else {
@@ -310,7 +387,7 @@
         try {
           originVal = parseFloat(originVal)
           contrastVal = parseFloat(contrastVal)
-        } catch {
+        } catch (e) {
           originVal = NaN
         }
 
@@ -321,7 +398,7 @@
         try {
           originVal = parseFloat(originVal)
           contrastVal = parseFloat(contrastVal)
-        } catch {
+        } catch (e) {
           originVal = NaN
         }
 
@@ -452,7 +529,7 @@
           if (isNaN(content)) {
             content = ''
           }
-        } catch {
+        } catch (e) {
           content = ''
         }
       }
@@ -605,7 +682,7 @@
         
         try {
           _param = window.btoa(_quary)
-        } catch {
+        } catch (e) {
           _param = window.btoa(window.encodeURIComponent(_quary))
         }
         
@@ -691,7 +768,7 @@
             if (isNaN(content)) {
               content = ''
             }
-          } catch {
+          } catch (e) {
             content = ''
           }
     
@@ -735,7 +812,7 @@
           try {
             photos = record[col.field] + ''
             photos = photos.split(',').filter(Boolean)
-          } catch {
+          } catch (e) {
             photos = []
           }
 
@@ -790,7 +867,7 @@
 
             try {
               _param = window.btoa(_quary)
-            } catch {
+            } catch (e) {
               _param = window.btoa(window.encodeURIComponent(_quary))
             }
 
@@ -981,7 +1058,9 @@
   }
 
   changedata = (index) => {
-    const { data, setting } = this.props
+    const { data, setting, tableId, ContainerId } = this.props
+
+    if (!tableId || !ContainerId) return
 
     let _id = ''
     let _data = ''
@@ -991,13 +1070,13 @@
       _data = data[index] || ''
     }
 
-    this.props.handleTableId(this.props.tableId, _id, _data)
+    MKEmitter.emit('changeTableLine', ContainerId, tableId, _id, _data)
   }
 
   resetTable = (id, repage) => {
-    const { MenuID, tableId } = this.props
+    const { tableId } = this.props
 
-    if (id !== (MenuID + tableId)) return
+    if (id !== tableId) return
 
     if (repage === 'false') {
       this.setState({
@@ -1079,6 +1158,14 @@
     const { setting, pickup, statFValue } = this.props
     const { selectedRowKeys, lineMarks, activeIndex } = this.state
 
+    let components = {
+      body: {}
+    }
+
+    if (setting.tableMode === 'fast') {
+      components.body.row = BodyRow
+    }
+
     // 璁剧疆琛ㄦ牸閫夋嫨灞炴�э細鍗曢�夈�佸閫夈�佷笉鍙��
     let rowSelection = null
     if (setting.tableType) {
@@ -1131,11 +1218,26 @@
       _footer = statFValue.map(f => `${f.label}(鍚堣)锛�${f.value}`).join('锛�')
     }
 
+    let height = setting.height || false
+    let style = {}
+    if (setting.color) {
+      style.color = setting.color
+    }
+    if (setting.fontSize) {
+      style.fontSize = setting.fontSize
+    }
+
+    let loading = this.props.loading
+    if (setting.mask === 'hidden') {
+      loading = false
+    }
+
     return (
-      <div className="normal-data-table mingke-table">
+      <div className={'normal-data-table mingke-table ' + (height ? 'fixed-height' : '')}>
         {offset && <Affix offsetTop={offset} className="fix-header">
           <Table
-            size="middle"
+            size={setting.size || 'middle'}
+            style={style}
             bordered={setting.bordered !== 'false'}
             rowSelection={rowSelection}
             columns={this.state.columns.map(column => {
@@ -1149,7 +1251,9 @@
           />
         </Affix>}
         <Table
-          size="middle"
+          components={components}
+          size={setting.size || 'middle'}
+          style={style}
           bordered={setting.bordered !== 'false'}
           rowSelection={rowSelection}
           columns={this.state.columns}
@@ -1181,7 +1285,7 @@
                 try {
                   originVal = parseFloat(originVal)
                   contrastVal = parseFloat(contrastVal)
-                } catch {
+                } catch (e) {
                   originVal = NaN
                 }
         
@@ -1192,7 +1296,7 @@
                 try {
                   originVal = parseFloat(originVal)
                   contrastVal = parseFloat(contrastVal)
-                } catch {
+                } catch (e) {
                   originVal = NaN
                 }
         
@@ -1207,12 +1311,20 @@
 
             return className
           }}
-          loading={this.props.loading}
-          scroll={{ x: '100%', y: false }}
+          loading={loading}
+          scroll={{ x: '100%', y: height }}
           onRow={(record, index) => {
-            return {
-              onClick: () => {this.changeRow(record, index)},
-              onDoubleClick: () => {this.doubleClickLine(record)}
+            if (setting.tableMode === 'fast') {
+              return {
+                record,
+                onClick: () => {this.changeRow(record, index)},
+                onDoubleClick: () => {this.doubleClickLine(record)}
+              }
+            } else {
+              return {
+                onClick: () => {this.changeRow(record, index)},
+                onDoubleClick: () => {this.doubleClickLine(record)}
+              }
             }
           }}
           onChange={this.changeTable}
@@ -1227,15 +1339,12 @@
 const mapStateToProps = (state) => {
   return {
     menuType: state.editLevel,
-    tabviews: state.tabviews,
     memberLevel: state.memberLevel
   }
 }
 
-const mapDispatchToProps = (dispatch) => {
-  return {
-    modifyTabview: (tabviews) => dispatch(modifyTabview(tabviews))
-  }
+const mapDispatchToProps = () => {
+  return {}
 }
 
 export default connect(mapStateToProps, mapDispatchToProps)(NormalTable)
\ No newline at end of file

--
Gitblit v1.8.0