From fcdfdc9670866fecd2d239d75a6ec28391175e9f Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期四, 10 四月 2025 11:13:51 +0800
Subject: [PATCH] 2025-04-10
---
src/tabviews/custom/components/share/normalTable/index.jsx | 217 +++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 191 insertions(+), 26 deletions(-)
diff --git a/src/tabviews/custom/components/share/normalTable/index.jsx b/src/tabviews/custom/components/share/normalTable/index.jsx
index dc47705..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}/>)
@@ -209,6 +210,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
@@ -539,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 = []
@@ -594,6 +611,7 @@
record,
col: item,
config: item.type === 'custom' ? {setting, columns: fields} : null,
+ openChange: item.$tree ? this.openChange : null,
})
}
}
@@ -653,6 +671,10 @@
_columns = this.getCurColumns(_columns, this.props.allSearch)
}
+ if (setting.$tree) {
+ this.resetOpenKeys(data)
+ }
+
this.setState({
pageSize: setting.pageSize || 10,
pageOptions,
@@ -669,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))) {
@@ -698,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,
})
}
}
@@ -709,6 +732,10 @@
this.setState({
columns: getColumns(nextProps.columns)
})
+ }
+
+ if (setting.$tree && !is(fromJS(data), fromJS(nextProps.data))) {
+ this.resetOpenKeys(nextProps.data)
}
}
@@ -738,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) => {
@@ -823,7 +927,7 @@
this.props.refreshdata({pageIndex})
}
- mkCheckTopLine = (menuId, id, selected) => {
+ mkCheckTopLine = (menuId, id, selected, orikeys) => {
const { MenuID, data, setting } = this.props
if (MenuID !== menuId) return
@@ -851,6 +955,16 @@
index = i
}
})
+ } 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
@@ -974,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) => {
@@ -1125,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
@@ -1152,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,
@@ -1210,7 +1349,7 @@
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} ${setting.empSign === 'hidden' ? 'mk-empty-hide' : ''}`} style={style}>
- {(setting.tableType === 'radio' || setting.tableType === 'checkbox') && data && data.length > 0 ?
+ {(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
@@ -1223,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)}
}
@@ -1235,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