Skip to content

Commit

Permalink
feat: parent child field
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Aug 15, 2024
1 parent 87d3e75 commit 68440db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/components/Table/src/hooks/useDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,8 @@ export function useDataSource(
if (!api || !isFunction(api)) return;
try {
setLoading(true);
const { pageField, sizeField, listField, totalField } = Object.assign(
{},
FETCH_SETTING,
fetchSetting,
);
const { pageField, sizeField, listField, totalField, parentField, childrenField } =
Object.assign({}, FETCH_SETTING, fetchSetting);
let pageParams: Recordable = {};

const { current = 1, pageSize = PAGE_SIZE } = unref(getPaginationInfo) as PaginationProps;
Expand Down Expand Up @@ -295,7 +292,11 @@ export function useDataSource(
const result = await api(params);
const res = result.data;
if (isTreeTable) {
const tree = array2tree(res.data);
const tree = array2tree(res.data, {
parentKey: parentField !== undefined && parentField !== '' ? parentField : 'parentId',
childrenKey:
childrenField !== undefined && childrenField !== '' ? childrenField : 'children',
});
rawDataSourceRef.value = tree;
isArrayResult = Array.isArray(tree);
resultItems = isArrayResult ? tree : get(tree, listField);
Expand Down
4 changes: 4 additions & 0 deletions src/components/Table/src/types/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ export interface FetchSetting {
listField: string;
// 请求结果总数字段 支持 a.b.c
totalField: string;
// 父级字段
parentField: string;
// 子级字段
childrenField: string;
}

export interface TableSetting {
Expand Down

0 comments on commit 68440db

Please sign in to comment.