fix: model instances update when tab active

This commit is contained in:
jialin
2025-01-17 23:16:38 +08:00
parent faa13f58e0
commit 1df3a0b8cb
5 changed files with 78 additions and 49 deletions
@@ -1,4 +1,6 @@
import useSetChunkRequest from '@/hooks/use-chunk-request';
import useSetChunkRequest, {
createAxiosToken
} from '@/hooks/use-chunk-request';
import useUpdateChunkedList from '@/hooks/use-update-chunk-list';
import { DownOutlined, RightOutlined } from '@ant-design/icons';
import { Button, Checkbox, Col, Empty, Row, Spin } from 'antd';
@@ -32,6 +34,7 @@ const TableRow: React.FC<
} = props;
const tableContext: any = React.useContext<{
allChildren?: any[];
allSubChildren?: any[];
}>(TableContext);
const { setChunkRequest } = useSetChunkRequest();
const [expanded, setExpanded] = useState(false);
@@ -43,6 +46,7 @@ const TableRow: React.FC<
const chunkRequestRef = useRef<any>(null);
const childrenDataRef = useRef<any[]>([]);
childrenDataRef.current = childrenData;
const axiosToken = useRef<any>(null);
const { updateChunkedList, cacheDataListRef } = useUpdateChunkedList({
dataList: childrenData,
@@ -68,6 +72,7 @@ const TableRow: React.FC<
clearInterval(pollTimer.current);
}
chunkRequestRef.current?.current?.cancel?.();
axiosToken.current?.cancel?.();
};
}, []);
@@ -88,8 +93,12 @@ const TableRow: React.FC<
const handleLoadChildren = async () => {
try {
axiosToken.current?.cancel?.();
axiosToken.current = createAxiosToken();
setLoading(true);
const data = await loadChildren?.(record);
const data = await loadChildren?.(record, {
token: axiosToken.current?.token
});
setChildrenData(data || []);
setLoading(false);
@@ -144,6 +153,7 @@ const TableRow: React.FC<
}
if (expanded) {
axiosToken.current?.cancel?.();
return;
}
@@ -208,6 +218,10 @@ const TableRow: React.FC<
};
}, [firstLoad, expanded, tableContext.allChildren]);
useEffect(() => {
console.log('allSubChildren===', tableContext.allSubChildren);
}, [tableContext.allSubChildren]);
const renderRowPrefix = () => {
if (expandable && rowSelection) {
return (
+1 -1
View File
@@ -53,7 +53,7 @@ export interface SealTableProps {
onSort?: (dataIndex: string, order: 'ascend' | 'descend') => void;
onExpand?: (expanded: boolean, record: any, rowKey: any) => void;
renderChildren?: (data: any, parent?: any) => React.ReactNode;
loadChildren?: (record: any) => Promise<any[]>;
loadChildren?: (record: any, options?: any) => Promise<any[]>;
loadChildrenAPI?: (record: any) => string;
contentRendered?: () => void;
rowKey: string;