Merge pull request #136 from Zheng-Changfu/fix/table-fetch-interceptor-statement

fix(function):修复 useDataSource 中请求前请求后回调未在prop中声明、isFunction支持普通、箭头函数判断
This commit is contained in:
Ah jung
2022-06-14 08:52:55 +08:00
committed by GitHub
3 changed files with 11 additions and 6 deletions

View File

@@ -88,10 +88,7 @@ export function useDataSource(
let resultInfo = res[listField] ? res[listField] : [];
if (afterRequest && isFunction(afterRequest)) {
// can modify the data returned by the interface for processing
resultInfo = (await afterRequest(resultInfo));
if (!isArray(resultInfo)) {
resultInfo = []
}
resultInfo = (await afterRequest(resultInfo)) || resultInfo;
}
dataSourceRef.value = resultInfo;
setPagination({

View File

@@ -25,17 +25,25 @@ export const basicProps = {
default: () => [],
required: true,
},
beforeRequest: {
type: Function as PropType<(...arg: any[]) => void | Promise<any>>,
default: null,
},
request: {
type: Function as PropType<(...arg: any[]) => Promise<any>>,
default: null,
},
afterRequest: {
type: Function as PropType<(...arg: any[]) => void | Promise<any>>,
default: null,
},
rowKey: {
type: [String, Function] as PropType<string | ((record) => string)>,
default: undefined,
},
pagination: {
type: [Object, Boolean],
default: () => {},
default: () => { },
},
//废弃
showPagination: {

View File

@@ -11,7 +11,7 @@ export function is(val: unknown, type: string) {
* @description: 是否为函数
*/
export function isFunction<T = Function>(val: unknown): val is T {
return is(val, 'Function');
return is(val, 'Function') || is(val, 'AsyncFunction');
}
/**