From 7b9b391adc393658ef63bd7827a3721bad2eadcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E5=B8=B8=E5=AF=8C?= Date: Mon, 13 Jun 2022 22:02:37 +0800 Subject: [PATCH] =?UTF-8?q?fix(function):=E4=BF=AE=E5=A4=8Dtable=E4=B8=ADh?= =?UTF-8?q?ook(useDataSource)=E4=B8=AD=E8=AF=B7=E6=B1=82=E5=89=8D=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=90=8E=E5=9B=9E=E8=B0=83=E6=9C=AA=E5=9C=A8prop?= =?UTF-8?q?=E4=B8=AD=E5=A3=B0=E6=98=8E=E3=80=81isFunction=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=99=AE=E9=80=9A=E3=80=81=E7=AE=AD=E5=A4=B4=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Table/src/hooks/useDataSource.ts | 5 +---- src/components/Table/src/props.ts | 10 +++++++++- src/utils/is/index.ts | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/Table/src/hooks/useDataSource.ts b/src/components/Table/src/hooks/useDataSource.ts index 4cd2e98..a588f17 100644 --- a/src/components/Table/src/hooks/useDataSource.ts +++ b/src/components/Table/src/hooks/useDataSource.ts @@ -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({ diff --git a/src/components/Table/src/props.ts b/src/components/Table/src/props.ts index ee263b2..10c0e1e 100644 --- a/src/components/Table/src/props.ts +++ b/src/components/Table/src/props.ts @@ -25,17 +25,25 @@ export const basicProps = { default: () => [], required: true, }, + beforeRequest: { + type: Function as PropType<(...arg: any[]) => void | Promise>, + default: null, + }, request: { type: Function as PropType<(...arg: any[]) => Promise>, default: null, }, + afterRequest: { + type: Function as PropType<(...arg: any[]) => void | Promise>, + default: null, + }, rowKey: { type: [String, Function] as PropType string)>, default: undefined, }, pagination: { type: [Object, Boolean], - default: () => {}, + default: () => { }, }, //废弃 showPagination: { diff --git a/src/utils/is/index.ts b/src/utils/is/index.ts index fb1f3ed..088c6e8 100644 --- a/src/utils/is/index.ts +++ b/src/utils/is/index.ts @@ -11,7 +11,7 @@ export function is(val: unknown, type: string) { * @description: 是否为函数 */ export function isFunction(val: unknown): val is T { - return is(val, 'Function'); + return is(val, 'Function') || is(val, 'AsyncFunction'); } /**