From 29027dd28467bb823758fbe6ae094600f3b8f7b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E5=B9=BF?= Date: Tue, 12 Sep 2023 19:39:45 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20loadmore=E7=BB=84=E4=BB=B6=E5=9C=A8?= =?UTF-8?q?=E6=9C=AA=E6=BB=A1=E4=B8=80=E5=B1=8F=E5=86=85=E5=AE=B9=E4=B8=94?= =?UTF-8?q?getDataAtFirst=E4=B8=BAfalse=E6=83=85=E5=86=B5=E4=B8=8B?= =?UTF-8?q?=E4=B8=8D=E5=8A=A0=E8=BD=BD=E5=86=85=E5=AE=B9=E7=9A=84case?= =?UTF-8?q?=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../arcodesign/components/load-more/index.tsx | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/arcodesign/components/load-more/index.tsx b/packages/arcodesign/components/load-more/index.tsx index aeb8aa9b..d0890c15 100644 --- a/packages/arcodesign/components/load-more/index.tsx +++ b/packages/arcodesign/components/load-more/index.tsx @@ -128,6 +128,12 @@ export interface LoadMoreProps { * @default true */ getDataAtFirst?: boolean; + /** + * 当 getDataAtFirst === false 且数据不满一屏时是否触发一次请求,trigger=scroll时有效 + * @en Whether to trigger a request when getDataAtFirst === false and the data is not full of one screen, valid when trigger=scroll + * @default false + */ + triggerGetDataWhenNoGetDataAtFirst?: boolean; /** * 状态改变时回调 * @en Callback when state changes @@ -189,6 +195,7 @@ const LoadMore = forwardRef((props: LoadMoreProps, ref: Ref) => { onStatusChange, onClick, onEndReached, + triggerGetDataWhenNoGetDataAtFirst = false, } = props; const domRef = useRef(null); const requestAtFirst = trigger === 'scroll' ? getDataAtFirst : false; @@ -238,8 +245,18 @@ const LoadMore = forwardRef((props: LoadMoreProps, ref: Ref) => { }, [nowStatus]); useEffect(() => { - if (requestAtFirst && !disabled) { - if (statusRef.current === 'prepare') { + if (requestAtFirst) { + if (statusRef.current === 'prepare' && !disabled) { + triggerGetData('requestAtFirst'); + } + } else { + if ( + trigger === 'scroll' && + nowStatus === 'prepare' && + checkNeedTrigger(0, threshold) && + !disabled && + triggerGetDataWhenNoGetDataAtFirst + ) { triggerGetData('requestAtFirst'); } }