Commit fec5c75e by lijiabin

【需求 20331】 perf: 优化查询hook,增加成功回调,可用于对响应数据处理

parent 96bad3c0
...@@ -33,6 +33,8 @@ export interface PageSearchConfig<T extends PageSearchParams = PageSearchParams> ...@@ -33,6 +33,8 @@ export interface PageSearchConfig<T extends PageSearchParams = PageSearchParams>
pageSizeField?: keyof T pageSizeField?: keyof T
/** 格式化列表数据 */ /** 格式化列表数据 */
formatList?: (list: any[]) => any[] formatList?: (list: any[]) => any[]
/** 成功回调 */
success?: (list: Ref<any[]>) => void
} }
/** /**
...@@ -57,6 +59,7 @@ export function usePageSearch< ...@@ -57,6 +59,7 @@ export function usePageSearch<
pageField = 'current' as keyof TParams, pageField = 'current' as keyof TParams,
pageSizeField = 'size' as keyof TParams, pageSizeField = 'size' as keyof TParams,
formatList = (list: any[]) => list, formatList = (list: any[]) => list,
success = () => {},
} = config } = config
const loading = shallowRef(false) const loading = shallowRef(false)
...@@ -79,6 +82,7 @@ export function usePageSearch< ...@@ -79,6 +82,7 @@ export function usePageSearch<
list.value = formatList(data.list || []) list.value = formatList(data.list || [])
total.value = data.total || 0 total.value = data.total || 0
success?.(list)
} catch (error) { } catch (error) {
console.log('分页搜索失败:', error) console.log('分页搜索失败:', error)
list.value = [] list.value = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment