Преглед изворни кода

修复翻页后页码指示器被重置回 1

跳转/初次加载后,IntersectionObserver 因为锚点还没"越过"顶部,
passedPages 为空,fallback 写死的 1 会把刚跳到的页号覆盖掉。
改为以 pageAnchors 里的最小页号作为基准,初次=1、跳到第 N 页=N。

顺手关掉 antd Pagination 默认的 size changer(PAGE_SIZE 固定 40)。
刘立冬 пре 3 часа
родитељ
комит
71d4d62eb0

+ 6 - 2
src/views/publishContent/weCom/components/videoSelectModal/index.tsx

@@ -58,6 +58,7 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 	const observerRef = useRef<IntersectionObserver | null>(null);
 	const pageObserverRef = useRef<IntersectionObserver | null>(null);
 	const passedPagesRef = useRef<Set<number>>(new Set());
+	const basePageRef = useRef(1);
 	const drawerBodyRef = useRef<HTMLElement | null>(null);
 	const loadingMoreRef = useRef(false);
 	const hasMoreRef = useRef(true);
@@ -156,8 +157,8 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 				}
 			});
 			const passed = passedPagesRef.current;
-			const max = passed.size > 0 ? Math.max(...Array.from(passed)) : 1;
-			setViewingPage(prev => prev === max ? prev : max);
+			const next = passed.size > 0 ? Math.max(...Array.from(passed)) : basePageRef.current;
+			setViewingPage(prev => prev === next ? prev : next);
 		}, { root: body, threshold: [0, 1] });
 	}, []);
 
@@ -171,6 +172,8 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 	}, [ensureObserver]);
 
 	useEffect(() => {
+		const pages = Array.from(pageAnchors.values());
+		basePageRef.current = pages.length > 0 ? Math.min(...pages) : 1;
 		const obs = pageObserverRef.current;
 		const body = drawerBodyRef.current;
 		if (!obs || !body) return;
@@ -274,6 +277,7 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 							{total > PAGE_SIZE && (
 								<Pagination
 									simple
+									showSizeChanger={false}
 									current={viewingPage}
 									total={total}
 									pageSize={PAGE_SIZE}

+ 6 - 2
src/views/publishContent/weGZH/components/videoSelectModal/index.tsx

@@ -54,6 +54,7 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 	const observerRef = useRef<IntersectionObserver | null>(null);
 	const pageObserverRef = useRef<IntersectionObserver | null>(null);
 	const passedPagesRef = useRef<Set<number>>(new Set());
+	const basePageRef = useRef(1);
 	const drawerBodyRef = useRef<HTMLElement | null>(null);
 	const loadingMoreRef = useRef(false);
 	const hasMoreRef = useRef(true);
@@ -173,8 +174,8 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 				}
 			});
 			const passed = passedPagesRef.current;
-			const max = passed.size > 0 ? Math.max(...Array.from(passed)) : 1;
-			setViewingPage(prev => prev === max ? prev : max);
+			const next = passed.size > 0 ? Math.max(...Array.from(passed)) : basePageRef.current;
+			setViewingPage(prev => prev === next ? prev : next);
 		}, { root: body, threshold: [0, 1] });
 	}, []);
 
@@ -188,6 +189,8 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 	}, [ensureObserver]);
 
 	useEffect(() => {
+		const pages = Array.from(pageAnchors.values());
+		basePageRef.current = pages.length > 0 ? Math.min(...pages) : 1;
 		const obs = pageObserverRef.current;
 		const body = drawerBodyRef.current;
 		if (!obs || !body) return;
@@ -266,6 +269,7 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 							{total > PAGE_SIZE && (
 								<Pagination
 									simple
+									showSizeChanger={false}
 									current={viewingPage}
 									total={total}
 									pageSize={PAGE_SIZE}