diff --git a/packages/console-utils/xconsole-service/src/hooks/useAsync.ts b/packages/console-utils/xconsole-service/src/hooks/useAsync.ts index fb255bf..f68d74e 100644 --- a/packages/console-utils/xconsole-service/src/hooks/useAsync.ts +++ b/packages/console-utils/xconsole-service/src/hooks/useAsync.ts @@ -75,7 +75,11 @@ export interface ReturnValue { error?: Error; data?: T; cancel: noop; + /**当次执行的 service 的参数数组*/ + params?: any[]; run: promiseReturn; + /**使用上一次的 params,重新调用 run */ + refresh: () => void; timer: { stop: noop; resume: noop; @@ -92,6 +96,8 @@ export default function useAsync

( loading: false, cancel: noop, run: promiseReturn, + params: [], + refresh:noop, timer: { stop: noop, resume: promiseReturn, @@ -113,7 +119,7 @@ export default function useAsync

( const run = useCallback((...args: any[]): Promise => { // 确保不会返回被取消的结果 const runCount = count.current; - set((s) => ({ ...s, loading: true })); + set((s) => ({ ...s, loading: true,params:args })); return fn(...args) .then((data) => { if (runCount === count.current) { @@ -139,6 +145,11 @@ export default function useAsync

( }); }, deps); + + const refresh = useCallback(() => { + run(state.params||[]); + }, []); + const stop = useCallback(() => { count.current += 1; // 清除计时器 @@ -248,7 +259,9 @@ export default function useAsync

( loading: state.loading, error: state.error, data: state.data, + params:state.params, cancel, + refresh, run: options.manual && options.pollingInterval ? start : reload, timer: { stop,