Przeglądaj źródła

Merge branch 'feature_260509_replace_upload_new_datasource' of Web/contentCooper into master

liulidong 1 tydzień temu
rodzic
commit
0613c3d97e

+ 12 - 29
src/views/publishContent/weCom/components/videoSelectModal/index.tsx

@@ -3,7 +3,6 @@ import {
 	Drawer,
 	Button,
 	Select,
-	Input,
 	Card,
 	Typography,
 	Space,
@@ -125,7 +124,6 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 	const [category, setCategory] = useState<string>();
 	const sort = VideoSortType.平台推荐;
 	const PAGE_SIZE = 10;
-	const [searchTerm, setSearchTerm] = useState<string>('');
 	const [currentPage, setCurrentPage] = useState(1);
 	const [total, setTotal] = useState(0);
 	const [loading, setLoading] = useState(false);
@@ -176,13 +174,13 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 			planType: type,
 			subChannel: 'weCom',
 			category: category ?? '',
-			title: searchTerm,
+			title: '',
 			sortType: sort,
 		});
 
 		const requestParams = {
 			category,
-			title: searchTerm,
+			title: '',
 			sort,
 			type,
 			pageNum,
@@ -224,9 +222,17 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 
 	getVideoListRef.current = getVideoList;
 
+	// 首次挂载 + 品类切换时,重置列表并重新拉第一页
 	useEffect(() => {
-		getVideoList(1, 'replace');
-	}, []);
+		reqIdRef.current++;
+		setHasMore(true);
+		setVideoList([]);
+		setTotal(0);
+		setViewingPage(1);
+		setPageAnchors(new Map());
+		passedPagesRef.current.clear();
+		getVideoListRef.current?.(1, 'replace');
+	}, [category]);
 
 	useEffect(() => {
 		if (visible) {
@@ -303,17 +309,6 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 		getVideoList(page, 'jump');
 	};
 
-	const handleSearch = () => {
-		reqIdRef.current++;
-		setHasMore(true);
-		setVideoList([]);
-		setTotal(0);
-		setViewingPage(1);
-		setPageAnchors(new Map());
-		passedPagesRef.current.clear();
-		getVideoList(1, 'replace');
-	};
-
 	const handleChangeSource = (value: string) => {
 		reqIdRef.current++;
 		setSource(value);
@@ -464,18 +459,6 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ visible, onClose, o
 							options={videoCategoryOptions.map(option => ({ label: option, value: option }))}
 						/>
 					</div>
-					<div className="flex items-center gap-2">
-						<span className="text-gray-600">视频标题:</span>
-						<Input
-							placeholder="搜索视频标题"
-							style={{ width: 120 }}
-							value={searchTerm}
-							allowClear
-							onChange={e => setSearchTerm(e.target.value)}
-							onPressEnter={handleSearch}
-						/>
-					</div>
-					<Button type="primary" loading={loading} onClick={handleSearch}>搜索</Button>
 				</div>
 
 				<Spin spinning={loading}>

+ 20 - 27
src/views/publishContent/weGZH/components/videoSelectModal/index.tsx

@@ -3,7 +3,6 @@ import {
 	Drawer,
 	Button,
 	Select,
-	Input,
 	Card,
 	Typography,
 	Space,
@@ -123,7 +122,6 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 	const [category, setCategory] = useState<string>();
 	const sort = VideoSortType.平台推荐;
 	const PAGE_SIZE = 10;
-	const [searchTerm, setSearchTerm] = useState<string>('');
 	const [currentPage, setCurrentPage] = useState(1);
 	const [total, setTotal] = useState(0);
 	const [loading, setLoading] = useState(false);
@@ -181,13 +179,13 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 			planType: getVideoListType(planType),
 			subChannel: 'weGZH',
 			category: category ?? '',
-			title: searchTerm,
+			title: '',
 			sortType: sort,
 		});
 
 		const requestParams = {
 			category,
-			title: searchTerm,
+			title: '',
 			sort,
 			type: getVideoListType(planType),
 			pageNum,
@@ -246,6 +244,24 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 		}
 	}, [visible]);
 
+	// 品类切换时重置列表并重新拉第一页(仅在弹窗打开时生效)
+	const isCategoryFirstRunRef = useRef(true);
+	useEffect(() => {
+		if (isCategoryFirstRunRef.current) {
+			isCategoryFirstRunRef.current = false;
+			return;
+		}
+		if (!visible) return;
+		reqIdRef.current++;
+		setHasMore(true);
+		setVideoList([]);
+		setTotal(0);
+		setViewingPage(1);
+		setPageAnchors(new Map());
+		passedPagesRef.current.clear();
+		getVideoListRef.current?.(1, 'replace');
+	}, [category]);
+
 	useEffect(() => {
 		if (visible) {
 			setSelectedVideoIds(new Set(initialSelectedIds));
@@ -321,17 +337,6 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 		getVideoList(page, 'jump');
 	};
 
-	const handleSearch = () => {
-		reqIdRef.current++;
-		setHasMore(true);
-		setVideoList([]);
-		setTotal(0);
-		setViewingPage(1);
-		setPageAnchors(new Map());
-		passedPagesRef.current.clear();
-		getVideoList(1, 'replace');
-	};
-
 	const handleChangeSource = (value: string) => {
 		reqIdRef.current++;
 		setSource(value);
@@ -457,18 +462,6 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 							options={videoCategoryOptions.map(option => ({ label: option, value: option }))}
 						/>
 					</div>
-					<div className="flex items-center gap-2">
-						<span className="text-gray-600">视频标题:</span>
-						<Input
-							placeholder="搜索视频标题"
-							style={{ width: 120 }}
-							value={searchTerm}
-							onPressEnter={handleSearch}
-							allowClear
-							onChange={e => setSearchTerm(e.target.value)}
-						/>
-					</div>
-					<Button type="primary" loading={loading} onClick={handleSearch}>搜索</Button>
 				</div>
 
 				<Spin spinning={loading}>