refactor(usagesummary): fetch data

This commit is contained in:
jialin
2026-06-14 19:14:18 +08:00
committed by jialin
parent 6cf512cccd
commit 08ef2ffa9a
7 changed files with 281 additions and 149 deletions
+7 -3
View File
@@ -18,6 +18,7 @@ export function useQueryDataList<
Response = Array<ListItem>
>(option: {
key: string;
manual?: boolean;
responseType?: 'array' | 'object';
fetchList: (
params: Params,
@@ -38,6 +39,7 @@ export function useQueryDataList<
fetchList,
getLabel,
getValue,
manual = true,
responseType = 'array',
errorMsg
} = option;
@@ -70,7 +72,7 @@ export function useQueryDataList<
return responseType === 'array' ? res.items || [] : res;
},
{
manual: true,
manual: manual,
debounceWait: option.debounceWait || 300,
onSuccess: () => {},
onError: (error) => {
@@ -105,16 +107,18 @@ export function useQueryDataList<
export function useQueryData<Detail, Params = any>(option: {
key: string;
delay?: number;
manual?: boolean;
fetchDetail: (params: Params, options?: any) => Promise<Detail>;
getData?: (response: Detail, params?: any) => any;
errorMsg?: string;
}): {
loading: boolean;
detailData: Detail;
manual?: boolean;
cancelRequest: () => void;
fetchData: (params: Params, extra?: any) => Promise<Detail>;
} {
const { key, fetchDetail, getData, errorMsg, delay } = option;
const { key, fetchDetail, getData, errorMsg, delay, manual = true } = option;
const axiosTokenRef = useRef<CancelTokenSource | null>(null);
const [detailData, setDetailData] = useState<Detail>({} as Detail);
@@ -142,7 +146,7 @@ export function useQueryData<Detail, Params = any>(option: {
return res;
},
{
manual: true,
manual: manual,
onSuccess: () => {},
onError: (error) => {
message.error(