提交 b28f8c7f 作者: 郁骅焌

提交

上级 ca6810f8
......@@ -42,7 +42,7 @@ const SageTable = React.forwardRef((props, ref) => {
const [selectedRows, setSelectedRows] = useState([]);
// 展开keys
const [expandedRowKeys, setExpandedRowKeys] = useState([])
const [expandedRowKeys, setExpandedRowKeys] = useState([]);
const {
request,
......@@ -140,9 +140,9 @@ const SageTable = React.forwardRef((props, ref) => {
delete newSearchParams.pageSize;
}
let lastDataSource = res.data ? res.data.slice() : []
let lastDataSource = res.data ? res.data.slice() : [];
if (renderData) {
lastDataSource = renderData(lastDataSource)
lastDataSource = renderData(lastDataSource);
}
setTableState({
......@@ -159,18 +159,18 @@ const SageTable = React.forwardRef((props, ref) => {
});
if (defaultExpandAllRowsProps) {
const allKeys = []
const allData = lastDataSource.slice()
const allKeys = [];
const allData = lastDataSource.slice();
const filterExpandRowKeys = (list) => {
list.forEach(item => {
list.forEach((item) => {
if (item.children && item.children.length !== 0) {
allKeys.push(item[props.rowKey])
filterExpandRowKeys(item.children)
allKeys.push(item[props.rowKey]);
filterExpandRowKeys(item.children);
}
})
}
filterExpandRowKeys(allData)
setExpandedRowKeys(allKeys)
});
};
filterExpandRowKeys(allData);
setExpandedRowKeys(allKeys);
}
}
}
......@@ -250,23 +250,25 @@ const SageTable = React.forwardRef((props, ref) => {
columnsState.unshift({
title: '序号',
render: (text, record, index) => {
let serialNumber = 0
let serialNumber = 0;
if (paginationState) {
serialNumber = `${(paginationState.current - 1) * paginationState.pageSize + index + 1}`
serialNumber = `${
(paginationState.current - 1) * paginationState.pageSize + index + 1
}`;
} else {
serialNumber = index + 1
serialNumber = index + 1;
}
return serialNumber
return serialNumber;
},
align: 'center',
width: 60,
});
}
// 隐藏hidden属性列
columnsState = columnsState.filter(item => !item.hidden)
return columnsState
}
const latestColumnsState = useMemo(() => getLatestColumnsState(), [props.columns, tableState])
columnsState = columnsState.filter((item) => !item.hidden);
return columnsState;
};
const latestColumnsState = useMemo(() => getLatestColumnsState(), [props.columns, tableState]);
const tableSearchFormProps = {
searchFields: searchFieldsProps,
......@@ -298,56 +300,84 @@ const SageTable = React.forwardRef((props, ref) => {
const getExpandedRowKeys = () => {
return expandedRowKeys;
}
};
const getAllExpandedRowKeys = () => {
const allKeys = []
const allData = dataSourceState.slice()
const allKeys = [];
const allData = dataSourceState.slice();
const filterExpandRowKeys = (list) => {
list.forEach(item => {
list.forEach((item) => {
if (item.children && item.children.length !== 0) {
allKeys.push(item[props.rowKey])
filterExpandRowKeys(item.children)
allKeys.push(item[props.rowKey]);
filterExpandRowKeys(item.children);
}
})
}
filterExpandRowKeys(allData)
});
};
filterExpandRowKeys(allData);
return allKeys;
}
};
if (expandableProps) {
lastTableState.expandable = {
expandedRowKeys,
onExpand: (expanded, record) => {
const lastExpandedRowKeys = expandedRowKeys.slice()
const lastExpandedRowKeys = expandedRowKeys.slice();
if (expanded) {
lastExpandedRowKeys.push(record[props.rowKey])
setExpandedRowKeys(lastExpandedRowKeys)
lastExpandedRowKeys.push(record[props.rowKey]);
setExpandedRowKeys(lastExpandedRowKeys);
} else {
const deleteIndex = lastExpandedRowKeys.findIndex(item => item === record[props.rowKey])
lastExpandedRowKeys.splice(deleteIndex, 1)
const deleteIndex = lastExpandedRowKeys.findIndex(
(item) => item === record[props.rowKey],
);
lastExpandedRowKeys.splice(deleteIndex, 1);
}
setExpandedRowKeys(lastExpandedRowKeys)
}
}
setExpandedRowKeys(lastExpandedRowKeys);
},
};
}
// 获取当前列表的数据
const getDataSource = () => {
return dataSourceState
}
return dataSourceState;
};
// 给列表赋值
const setDataSource = (data) => {
const tableStateTemp = Object.assign({}, tableState)
let lastDataSource = data.slice()
const tableStateTemp = Object.assign({}, tableState);
let lastDataSource = data.slice();
if (renderData) {
lastDataSource = renderData(lastDataSource)
lastDataSource = renderData(lastDataSource);
}
tableStateTemp.dataSource = lastDataSource
setTableState(tableStateTemp)
}
tableStateTemp.dataSource = lastDataSource;
setTableState(tableStateTemp);
};
// 根据某个属性修改值
const setDataSourceByMapKey = (
fieldKeyName,
fieldKeyValue,
changeFieldKeyName,
changeFieldKeyValue,
) => {
const dataSourceTemp = tableState.dataSource ? tableState.dataSource.slice() : [];
const loopDataSource = (list) => {
for (let i = 0; i < list.length; i++) {
if (list[i].children && list[i].children.length !== 0) {
loopDataSource(list[i].children);
}
if (list[i][fieldKeyName] === fieldKeyValue) {
list[i][changeFieldKeyName] = changeFieldKeyValue;
break;
}
}
};
loopDataSource(dataSourceTemp);
const tableStateTemp = Object.assign({}, tableState);
tableStateTemp.dataSource = dataSourceTemp;
setTableState(tableStateTemp);
};
// 暴露给外部的方法
useImperativeHandle(ref, () => ({
......@@ -363,6 +393,7 @@ const SageTable = React.forwardRef((props, ref) => {
getAllExpandedRowKeys,
getExpandedRowKeys,
setExpandedRowKeys,
setDataSourceByMapKey,
}));
return (
......@@ -381,9 +412,9 @@ const SageTable = React.forwardRef((props, ref) => {
<TableSearchForm ref={tableSearchFormRef} {...tableSearchFormProps} />
)}
{
!hiddeTool ? <TableTool tableSize={tableSizeState} isFullscreen={isFullscreen} {...tableToolProps} /> : null
}
{!hiddeTool ? (
<TableTool tableSize={tableSizeState} isFullscreen={isFullscreen} {...tableToolProps} />
) : null}
<Table
size={tableSizeState}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论