提交 b28f8c7f 作者: 郁骅焌

提交

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