添加流程实例切换查询函数
This commit is contained in:
parent
816b46744a
commit
03ae984b83
@ -64,7 +64,10 @@ export default function useHookTable<A extends ApiFn, T, C>(config: TableConfig<
|
|||||||
const { loading, startLoading, endLoading } = useLoading();
|
const { loading, startLoading, endLoading } = useLoading();
|
||||||
const { bool: empty, setBool: setEmpty } = useBoolean();
|
const { bool: empty, setBool: setEmpty } = useBoolean();
|
||||||
|
|
||||||
const { apiFn, apiParams, transformer, immediate = true, getColumnChecks, getColumns } = config;
|
const { transformer, immediate = true, getColumnChecks, getColumns } = config;
|
||||||
|
|
||||||
|
let currentApiFn = config.apiFn;
|
||||||
|
const apiParams = config.apiParams;
|
||||||
|
|
||||||
const searchParams: NonNullable<Parameters<A>[0]> = reactive(jsonClone({ ...apiParams }));
|
const searchParams: NonNullable<Parameters<A>[0]> = reactive(jsonClone({ ...apiParams }));
|
||||||
|
|
||||||
@ -94,7 +97,7 @@ export default function useHookTable<A extends ApiFn, T, C>(config: TableConfig<
|
|||||||
|
|
||||||
const formattedParams = formatSearchParams(searchParams);
|
const formattedParams = formatSearchParams(searchParams);
|
||||||
|
|
||||||
const response = await apiFn(formattedParams);
|
const response = await currentApiFn(formattedParams);
|
||||||
|
|
||||||
const transformed = transformer(response as Awaited<ReturnType<A>>);
|
const transformed = transformer(response as Awaited<ReturnType<A>>);
|
||||||
|
|
||||||
@ -119,6 +122,10 @@ export default function useHookTable<A extends ApiFn, T, C>(config: TableConfig<
|
|||||||
return formattedParams;
|
return formattedParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateApiFn(newApiFn: A) {
|
||||||
|
currentApiFn = newApiFn;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update search params
|
* update search params
|
||||||
*
|
*
|
||||||
@ -148,6 +155,7 @@ export default function useHookTable<A extends ApiFn, T, C>(config: TableConfig<
|
|||||||
getData,
|
getData,
|
||||||
searchParams,
|
searchParams,
|
||||||
updateSearchParams,
|
updateSearchParams,
|
||||||
resetSearchParams
|
resetSearchParams,
|
||||||
|
updateApiFn
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,7 +32,8 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
|
|||||||
getData,
|
getData,
|
||||||
searchParams,
|
searchParams,
|
||||||
updateSearchParams,
|
updateSearchParams,
|
||||||
resetSearchParams
|
resetSearchParams,
|
||||||
|
updateApiFn
|
||||||
} = useHookTable<A, GetTableData<A>, TableColumn<NaiveUI.TableDataWithIndex<GetTableData<A>>>>({
|
} = useHookTable<A, GetTableData<A>, TableColumn<NaiveUI.TableDataWithIndex<GetTableData<A>>>>({
|
||||||
apiFn,
|
apiFn,
|
||||||
apiParams,
|
apiParams,
|
||||||
@ -147,8 +148,8 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
|
|||||||
},
|
},
|
||||||
...(showTotal
|
...(showTotal
|
||||||
? {
|
? {
|
||||||
prefix: page => $t('datatable.itemCount', { total: page.itemCount })
|
prefix: page => $t('datatable.itemCount', { total: page.itemCount })
|
||||||
}
|
}
|
||||||
: {})
|
: {})
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -212,7 +213,8 @@ export function useTable<A extends NaiveUI.TableApiFn>(config: NaiveUI.NaiveTabl
|
|||||||
getDataByPage,
|
getDataByPage,
|
||||||
searchParams,
|
searchParams,
|
||||||
updateSearchParams,
|
updateSearchParams,
|
||||||
resetSearchParams
|
resetSearchParams,
|
||||||
|
updateApiFn
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user