From e1cee96b38805bcccf48e7bcb9d296f2bc54c720 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 24 一月 2025 11:10:32 +0800
Subject: [PATCH] 2025-01-24

---
 src/tabviews/custom/components/share/normalTable/index.jsx |  300 ++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 234 insertions(+), 66 deletions(-)

diff --git a/src/tabviews/custom/components/share/normalTable/index.jsx b/src/tabviews/custom/components/share/normalTable/index.jsx
index 9631dcc..4bfb15a 100644
--- a/src/tabviews/custom/components/share/normalTable/index.jsx
+++ b/src/tabviews/custom/components/share/normalTable/index.jsx
@@ -2,7 +2,8 @@
 import PropTypes from 'prop-types'
 import md5 from 'md5'
 import { is, fromJS } from 'immutable'
-import { Table, Typography, Col, Switch, message } from 'antd'
+import { Table, Typography, Col, Switch, message, Pagination } from 'antd'
+import { CaretRightOutlined, CaretDownOutlined } from '@ant-design/icons'
 
 import asyncComponent from '@/utils/asyncComponent'
 import { getMark } from '@/utils/utils.js'
@@ -31,7 +32,7 @@
     }
 
     if (item.field) {
-      __param.$searchkey = item.field.toLowerCase()
+      __param.$searchkey = item.field
       __param.$searchval = record[item.field] || ''
     }
 
@@ -152,7 +153,7 @@
   }
 
   render() {
-    let { col, config, record, className, style, ...resProps } = this.props
+    let { col, config, record, className, style, openChange, ...resProps } = this.props
 
     if (!col) return (<td {...resProps} className={className} style={style}/>)
 
@@ -210,6 +211,21 @@
       if (col.rowspan === 'true') {
         resProps.rowSpan = record['$$' + col.field]
       }
+
+      if (col.$tree && record.$mk_floor) {
+        className += ' mk-tree-td'
+        if (record.$open) {
+          content = <>
+            <span className="mk-tree-node" style={{width: `calc(var(--tree-node-width) * ${record.$mk_floor})`}}><CaretRightOutlined onClick={(e) => openChange(e, record.$key)} /><CaretDownOutlined onClick={(e) => openChange(e, record.$key)}/></span>
+            {content}
+          </>
+        } else {
+          content = <>
+            <span className="mk-tree-node" style={{width: `calc(var(--tree-node-width) * ${record.$mk_floor})`}}></span>
+            {content}
+          </>
+        }
+      }
       
       resProps.children = content
 
@@ -236,6 +252,9 @@
         }
         if (col.format === 'percent') {
           content = content * 100
+          if (!col.round) {
+            content = +content.toFixed(2)
+          }
         } else if (col.format === 'abs') {
           content = Math.abs(content)
         }
@@ -415,6 +434,15 @@
           content = ''
         }
       } else {
+        if (col.eval === 'false' && col.noValue === 'hide') { // 绌哄�奸殣钘�
+          Object.keys(record).forEach(key => {
+            if (/^\$/.test(key)) return
+            if (record[key]) return
+
+            content = content.replace(new RegExp('[^@]*@' + key + '@', 'ig'), '')
+          })
+        }
+        
         Object.keys(record).forEach(key => {
           let reg = new RegExp('@' + key + '@', 'ig')
           content = content.replace(reg, record[key])
@@ -527,11 +555,12 @@
     orderfields: {},      // 鎺掑簭id涓巉ield杞崲
     pageOptions: [],
     allColumns: null,
-    reseting: false
+    reseting: false,
+    openkeys: []
   }
 
   UNSAFE_componentWillMount () {
-    const { setting, columns, fields, colsCtrls } = this.props
+    const { setting, columns, fields, colsCtrls, data } = this.props
     let radio = 5          // 铏氬寲姣斾緥
     let _format = false    // 鏄惁铏氬寲澶勭悊
     let rowspans = []
@@ -582,6 +611,7 @@
                 record,
                 col: item,
                 config: item.type === 'custom' ? {setting, columns: fields} : null,
+                openChange: item.$tree ? this.openChange : null,
               })
             }
           }
@@ -641,6 +671,10 @@
       _columns = this.getCurColumns(_columns, this.props.allSearch)
     }
 
+    if (setting.$tree) {
+      this.resetOpenKeys(data)
+    }
+
     this.setState({
       pageSize: setting.pageSize || 10,
       pageOptions,
@@ -657,7 +691,7 @@
   }
 
   UNSAFE_componentWillReceiveProps(nextProps) {
-    const { allSearch, parCtrl } = this.props
+    const { allSearch, parCtrl, setting, data } = this.props
     const { allColumns } = this.state
 
     if (allSearch && !is(fromJS(allSearch), fromJS(nextProps.allSearch))) {
@@ -686,6 +720,7 @@
                 record,
                 col: item,
                 config: item.type === 'custom' ? {setting: this.props.setting, columns: this.props.fields} : null,
+                openChange: item.$tree ? this.openChange : null,
               })
             }
           }
@@ -697,6 +732,10 @@
       this.setState({
         columns: getColumns(nextProps.columns)
       })
+    }
+
+    if (setting.$tree && !is(fromJS(data), fromJS(nextProps.data))) {
+      this.resetOpenKeys(nextProps.data)
     }
   }
 
@@ -726,6 +765,83 @@
     MKEmitter.removeListener('autoQueryData', this.autoQueryData)
     MKEmitter.removeListener('autoSelectData', this.autoSelectData)
     MKEmitter.removeListener('mkCheckTopLine', this.mkCheckTopLine)
+  }
+
+  resetOpenKeys = (data) => {
+    const { setting } = this.props
+
+    if (!data || data.length === 0 || !setting.defOpen) {
+      this.setState({openkeys: []})
+    } else if (setting.defOpen === 'topline') {
+      let keys = []
+
+      if (data[0].$open) {
+        keys = [data[0].$key]
+
+        data.forEach(item => {
+          if (item.$pkeys && item.$pkeys.length > 1 && item.$pkeys.includes(data[0].$key)) {
+            keys.push(...item.$pkeys)
+          }
+        })
+
+        keys = Array.from(new Set(keys))
+      }
+
+      this.setState({openkeys: keys})
+    } else {
+      this.setState({openkeys: data.filter(item => !!item.$open).map(item => item.$key)})
+    }
+  }
+
+  openChange = (e, key) => {
+    const { setting, MenuID, data } = this.props
+    const { openkeys, selectedRowKeys } = this.state
+
+    e.stopPropagation()
+
+    let _openkeys = []
+
+    if (openkeys.includes(key)) {
+      _openkeys = openkeys.filter(k => k !== key)
+    } else {
+      _openkeys = [...openkeys, key]
+    }
+
+    if (!setting.tableType || _openkeys.length > openkeys.length) {
+      this.setState({openkeys: _openkeys})
+      return
+    }
+    
+    let newkeys = fromJS(selectedRowKeys).toJS()
+
+    newkeys = newkeys.filter(k => {
+      if (!data[k]) return false
+      if (!data[k].$pkeys) return true
+
+      return data[k].$pkeys.every(key => _openkeys.includes(key))
+    })
+
+    if (newkeys.length === selectedRowKeys.length) {
+      this.setState({openkeys: _openkeys})
+      return
+    }
+
+    let _index = ''
+    if (newkeys.length > 0) {
+      _index = newkeys.slice(-1)[0]
+    }
+
+    this.changedata(_index)
+    
+    this.setState({ openkeys: _openkeys, selectedRowKeys: newkeys, activeIndex: _index !== '' ? _index : null })
+
+    let selects = data.filter((item, _index) => newkeys.includes(_index))
+
+    this.props.chgSelectData(selects)
+
+    if (setting.$hasSyncModule) {
+      MKEmitter.emit('syncBalconyData', MenuID, selects, false)
+    }
   }
 
   getCurColumns = (columns, allSearch) => {
@@ -811,15 +927,27 @@
     this.props.refreshdata({pageIndex})
   }
 
-  mkCheckTopLine = (menuId, id, type) => {
+  mkCheckTopLine = (menuId, id, selected, orikeys) => {
     const { MenuID, data, setting } = this.props
 
-    if (MenuID !== menuId || !data || data.length === 0) return
+    if (MenuID !== menuId) return
+    if (!data || data.length === 0) {
+      MKEmitter.emit('resetSelectLine', menuId, '', '')
+      return
+    }
 
-    if (type === 'sign') {
-      let index = ''
-      let keys = []
-      let items = []
+    let index = -1
+    let keys = []
+    let items = []
+
+    if (id) {
+      index = data.findIndex(item => item.$$uuid === id && !item.$disabled)
+    }
+    
+    if (index !== -1) {
+      keys = [index]
+      items = [data[index]]
+    } else if (selected === 'sign') {
       data.forEach((item, i) => {
         if (!item.$disabled && item.selected === 'true') {
           items.push(item)
@@ -827,33 +955,35 @@
           index = i
         }
       })
-  
-      this.changedata(index)
-      this.setState({ selectedRowKeys: keys, activeIndex: index })
-      this.props.chgSelectData(items)
-
-      if (setting.$hasSyncModule) {
-        MKEmitter.emit('syncBalconyData', MenuID, items, data.length === keys.length)
+    } else if (selected === 'local') {
+      if (orikeys && orikeys.length) {
+        data.forEach((item, i) => {
+          if (!item.$disabled && orikeys.includes(item.$$uuid)) {
+            items.push(item)
+            keys.push(i)
+            index = i
+          }
+        })
       }
+    } else if (selected !== 'false') {
+      if (!data[0].$disabled) {
+        index = 0
+        keys = [index]
+        items = [data[index]]
+      }
+    }
+
+    if (index === -1) {
+      MKEmitter.emit('resetSelectLine', menuId, '', '')
       return
     }
 
-    let index = 0
-    if (id) {
-      index = data.findIndex(item => item.$$uuid === id)
-      if (index === -1) {
-        index = 0
-      }
-    }
-
-    if (data[index].$disabled) return
-
     this.changedata(index)
-    this.setState({ selectedRowKeys: [index], activeIndex: index })
-    this.props.chgSelectData([data[index]])
+    this.setState({ selectedRowKeys: keys, activeIndex: index })
+    this.props.chgSelectData(items)
 
     if (setting.$hasSyncModule) {
-      MKEmitter.emit('syncBalconyData', MenuID, [data[index]], data.length === 1)
+      MKEmitter.emit('syncBalconyData', MenuID, items, data.length === keys.length)
     }
   }
 
@@ -958,21 +1088,44 @@
   }
 
   changeTable = (pagination, filters, sorter) => {
-    const { orderfields } = this.state
-
-    this.setState({
-      pageIndex: pagination.current,
-      pageSize: pagination.pageSize,
-      selectedRowKeys: [],
-      activeIndex: null,
-      pickup: false
-    })
+    const { setting } = this.props
+    const { orderfields, pageSize } = this.state
 
     if (orderfields) {
       sorter.field = orderfields[sorter.field] || ''
     }
 
-    this.props.refreshdata(pagination, filters, sorter)
+    if (setting.$tree) {
+      this.setState({
+        pageIndex: 1,
+        selectedRowKeys: [],
+        activeIndex: null,
+        pickup: false
+      })
+  
+      this.props.refreshdata({current: 1, pageSize: pageSize}, sorter)
+    } else {
+      this.setState({
+        pageIndex: pagination.current,
+        pageSize: pagination.pageSize,
+        selectedRowKeys: [],
+        activeIndex: null,
+        pickup: false
+      })
+  
+      this.props.refreshdata(pagination, sorter)
+    }
+  }
+
+  onPaginationChange = (current, pageSize) => {
+    this.setState({
+      pageIndex: current,
+      pageSize: pageSize,
+      selectedRowKeys: [],
+      activeIndex: null
+    })
+
+    this.props.refreshdata({current: current, pageSize: pageSize, fixed: true}, {})
   }
 
   changedata = (index) => {
@@ -1028,22 +1181,9 @@
       if (setting.$hasSyncModule) {
         MKEmitter.emit('syncBalconyData', MenuID, selects, data.length === selects.length)
       }
-    } else if (type === 'false') {
-      this.setState({
-        selectedRowKeys: [],
-        activeIndex: null,
-        pickup: false
-      })
-    } else if (type === 'repage') {
-      this.setState({
-        pageIndex: Index,
-        selectedRowKeys: [],
-        activeIndex: null,
-        pickup: false
-      })
     } else {
       this.setState({
-        pageIndex: 1,
+        pageIndex: type === 'false' ? this.state.pageIndex : 1,
         selectedRowKeys: [],
         activeIndex: null,
         pickup: false
@@ -1122,7 +1262,7 @@
 
   render() {
     const { setting, statFValue, lineMarks, data } = this.props
-    const { selectedRowKeys, activeIndex, pickup, pageOptions, columns, reseting } = this.state
+    const { selectedRowKeys, activeIndex, pickup, pageOptions, columns, reseting, openkeys } = this.state
 
     if (reseting) return null
 
@@ -1149,14 +1289,16 @@
     // 鏁版嵁鏀惰捣鏃讹紝杩囨护宸查�夋暟鎹�
     let _data = data || []
 
-    if (pickup) {
-      _data = _data.filter((item, index) => selectedRowKeys.includes(index))
+    if (!setting.$tree) {
+      if (pickup) {
+        _data = _data.filter((item, index) => selectedRowKeys.includes(index))
+      }
+  
+      _data = this.handleRowspan(_data)
     }
-
-    _data = this.handleRowspan(_data)
     
     let _pagination = false
-    if (setting.laypage !== 'false' && setting.laypage !== false) {
+    if (setting.laypage && !setting.$tree) {
       _pagination = {
         current: this.state.pageIndex,
         pageSize: this.state.pageSize,
@@ -1206,8 +1348,8 @@
     }
 
     return (
-      <div className={`normal-custom-table ${setting.tableHeader || ''} ${setting.parity === 'true' ? 'mk-parity' : ''} ${height ? 'fixed-table-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || 'middle'} table-col-${columns.length} ${fixed}`} style={style}>
-        {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && data && data.length > 0 ?
+      <div className={`normal-custom-table ${setting.tableHeader || ''} ${setting.parity === 'true' ? 'mk-parity' : ''} ${height ? 'fixed-table-height' : ''} ${setting.mode || ''} table-vertical-${setting.vertical || 'middle'} table-col-${columns.length} ${fixed} ${setting.empSign === 'hidden' ? 'mk-empty-hide' : ''}`} style={style}>
+        {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && data && data.length > 0 && !setting.$tree ?
           <Switch title="鏀惰捣" className="main-pickup" checkedChildren={window.GLOB.dict['open'] || '寮�'} unCheckedChildren={window.GLOB.dict['shut'] || '鍏�'} checked={pickup} onChange={this.pickupChange} /> : null
         }
         <Table
@@ -1220,11 +1362,26 @@
           loading={loading}
           scroll={{ x: '100%', y: height }}
           onRow={(record, index) => {
+            let className = ''
+
+            if (index === activeIndex) {
+              className = ' mk-row-active '
+            }
+
+            if (setting.$tree) {
+              if (record.$open && openkeys.includes(record.$key)) {
+                className += ' mk-tree-open '
+              }
+              if (record.$pkeys && !record.$pkeys.every(key => openkeys.includes(key))) {
+                className += ' mk-tree-hide '
+              }
+            }
+
             return {
-              lineMarks: setting.tableMode !== 'fast' ? lineMarks : null,
+              lineMarks: lineMarks,
               data: record,
               title: setting.tipField ? record[setting.tipField] : '',
-              className: index === activeIndex ? ' mk-row-active ' : '',
+              className: className,
               onClick: () => {this.changeRow(record, index)},
               onDoubleClick: () => {this.doubleClickLine(record)}
             }
@@ -1232,6 +1389,17 @@
           onChange={this.changeTable}
           pagination={_pagination}
         />
+        {setting.laypage && setting.$tree ? <Pagination
+          showSizeChanger
+          className="mk-tree-pagination"
+          onChange={this.onPaginationChange}
+          onShowSizeChange={this.onPaginationChange}
+          current={this.state.pageIndex}
+          pageSize={this.state.pageSize}
+          pageSizeOptions={pageOptions}
+          total={this.props.total || 0}
+          showTotal={(total, range) => `${range[0]}-${range[1]} ${window.GLOB.dict['of'] || '鍏�'} ${total} ${window.GLOB.dict['items'] || '鏉�'}`}
+        /> : null}
         {_footer ? <div className={'normal-table-footer ' + (_pagination ? 'pagination' : '')}>{_footer}</div> : null}
       </div>
     )

--
Gitblit v1.8.0