nieyuge 1 nedēļu atpakaļ
vecāks
revīzija
624c9c1994

+ 22 - 11
src/views/publishContent/weGZH/components/publishPlanModal/index.tsx

@@ -6,6 +6,7 @@ import EditTitleCoverModal from '../editTitleCoverModal';
 import { VideoItem } from '../types'; // Import from common types
 import { GzhPlanDataType, GzhPlanType } from '../../hooks/useGzhPlanList';
 import { useAccountOptions } from '../../hooks/useAccountOptions';
+import { VideoLibraryType } from '@src/views/publishContent/weCom/components/videoSelectModal';
 
 const { Option } = Select;
 const { Paragraph } = Typography;
@@ -18,17 +19,10 @@ interface AddPunlishPlanModalProps {
 	planType: GzhPlanType;
 	editPlanData?: GzhPlanDataType;
 	isSubmiting?: boolean;
+	videoId?: string;
 }
 
-const AddPunlishPlanModal: React.FC<AddPunlishPlanModalProps> = ({
-	visible,
-	isSubmiting,
-	onCancel,
-	onOk,
-	actionType,
-	planType,
-	editPlanData
-}) => {
+const AddPunlishPlanModal: React.FC<AddPunlishPlanModalProps> = ({ visible, isSubmiting, onCancel, onOk, actionType, planType, editPlanData, videoId }) => {
 	const [form] = Form.useForm();
 	const type = Form.useWatch('type', form);
 	const selectVideoType = Form.useWatch('selectVideoType', form);
@@ -36,6 +30,7 @@ const AddPunlishPlanModal: React.FC<AddPunlishPlanModalProps> = ({
 	const [isVideoSelectVisible, setIsVideoSelectVisible] = useState(false);
 	const [playingVideo, setPlayingVideo] = useState<VideoItem | null>(null); // State for video player modal
 	const [editingVideo, setEditingVideo] = useState<VideoItem | null>(null); // State for editing modal
+	const [initialSelectedVideoId, setInitialSelectedVideoId] = useState<string | null>(null); // State for initial video selection
 	const { accountOptions, getAccountList } = useAccountOptions();
 
 	useEffect(() => {
@@ -60,6 +55,21 @@ const AddPunlishPlanModal: React.FC<AddPunlishPlanModalProps> = ({
 		getAccountList({accountType: planType});
 	}, [planType]);
 
+	// 处理videoId参数
+	useEffect(() => {
+		if (visible && videoId) {
+			setInitialSelectedVideoId(videoId);
+			setIsVideoSelectVisible(true);
+		}
+	}, [visible, videoId]);
+
+	// 重置状态
+	useEffect(() => {
+		if (!visible) {
+			setInitialSelectedVideoId(null);
+		}
+	}, [visible]);
+
 	const onTypeChange = (value: string) => {
 		form.setFieldsValue({ accountId: undefined });
 		getAccountList({ accountType: value });
@@ -308,12 +318,13 @@ const AddPunlishPlanModal: React.FC<AddPunlishPlanModalProps> = ({
 
 			{/* Video Selection Drawer */}
 			<VideoSelectModal
-				planType={type}
+				planType={planType}
 				visible={isVideoSelectVisible}
 				onClose={handleVideoSelectionCancel}
 				onOk={handleVideoSelectionOk}
 				selectedVideos={selectedVideos}
-				initialSelectedIds={selectedVideos.map(v => v.videoId)} // Pass current selection IDs
+				initialSelectedIds={initialSelectedVideoId ? [Number(initialSelectedVideoId)] : selectedVideos.map(v => v.videoId)}
+				defaultVideoLibraryType={VideoLibraryType.我的上传}
 			/>
 
 			{/* Video Player Modal */}

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

@@ -30,9 +30,10 @@ interface VideoSelectModalProps {
 	onOk: (selectedVideos: VideoItem[]) => void;
 	initialSelectedIds?: number[];
 	selectedVideos?: VideoItem[];
+	defaultVideoLibraryType?: VideoLibraryType;
 }
 
-const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible, onClose, onOk, initialSelectedIds = [], selectedVideos = [] }) => {
+const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible, onClose, onOk, initialSelectedIds = [], selectedVideos = [], defaultVideoLibraryType }) => {
 	const { videoCategoryOptions } = useVideoCategoryOptions();
 	const [category, setCategory] = useState<string>();
 	const [sort, setSort] = useState<VideoSortType>(VideoSortType.平台推荐);
@@ -45,9 +46,16 @@ const VideoSelectModal: React.FC<VideoSelectModalProps> = ({ planType, visible,
 	const [videoListAll, setVideoListAll] = useState<VideoItem[]>([]);
 	const [selectedVideoIds, setSelectedVideoIds] = useState<Set<number>>(new Set(initialSelectedIds));
 	const [playingVideo, setPlayingVideo] = useState<VideoItem | null>(null);
-	const [videoLibraryType, setVideoLibraryType] = useState<VideoLibraryType>(VideoLibraryType.平台视频库);
+	const [videoLibraryType, setVideoLibraryType] = useState<VideoLibraryType>(defaultVideoLibraryType || VideoLibraryType.平台视频库);
 	const MAX_SELECTION = 3;
 
+	// 当默认视频来源变化时更新状态
+	useEffect(() => {
+		if (defaultVideoLibraryType) {
+			setVideoLibraryType(defaultVideoLibraryType);
+		}
+	}, [defaultVideoLibraryType]);
+
 	const getVideoListType = (planType: GzhPlanType) => {
 		if (planType === GzhPlanType.自动回复) {
 			return VideoSearchPlanType.自动回复;

+ 24 - 13
src/views/publishContent/weGZH/index.tsx

@@ -1,5 +1,5 @@
 import React, { useEffect, useState } from 'react';
-// import { useParams } from 'react-router-dom';
+import { useParams } from 'react-router-dom';
 import { Space, Table, Button, Input, Select, DatePicker, Tabs, message, Typography, Spin, Popconfirm } from 'antd';
 import type { TableProps } from 'antd';
 import dayjs, { Dayjs } from 'dayjs';
@@ -16,7 +16,7 @@ const TableHeight = window.innerHeight - 380;
 
 const WeGZHContent: React.FC = () => {
 	const [planType, setPlanType] = useState<GzhPlanType>(GzhPlanType.自动回复);
-	// const { code } = useParams<{ code?: string }>();
+	const { code } = useParams<{ code?: string }>();
 	// 状态管理
 	const [selectedAccount, setSelectedAccount] = useState<string>();
 	const [videoTitle, setVideoTitle] = useState<string>('');
@@ -33,6 +33,15 @@ const WeGZHContent: React.FC = () => {
 	const [pageNum, setPageNum] = useState<number>(1);
 	const [pageSize, setPageSize] = useState<number>(10);
 	const [isShowAddPunlishDetailPlan, setIsShowAddPunlishDetailPlan] = useState<boolean>(false);
+	const [videoId, setVideoId] = useState<string | undefined>(undefined);
+
+	// 处理code参数
+	useEffect(() => {
+		if (code) {
+			setVideoId(code);
+			setIsShowAddPunlishPlan(true);
+		}
+	}, [code]);
 
 	// 表格列配置
 	const columns: TableProps<GzhPlanDataType>['columns'] = [
@@ -340,17 +349,19 @@ const WeGZHContent: React.FC = () => {
 					}}
 				/>
 				<PunlishPlanModal
-					visible={isShowAddPunlishPlan}
-					onCancel={() => {
-						setEditPlanData(undefined);
-						setIsShowAddPunlishPlan(false);
-					}}
-					onOk={handleAddPunlishPlan}
-					actionType={actionType}
-					editPlanData={editPlanData}
-					isSubmiting={isSubmiting}
-					planType={ planType}
-				/>
+			visible={isShowAddPunlishPlan}
+			onCancel={() => {
+				setEditPlanData(undefined);
+				setIsShowAddPunlishPlan(false);
+				setVideoId(undefined);
+			}}
+			onOk={handleAddPunlishPlan}
+			actionType={actionType}
+			editPlanData={editPlanData}
+			isSubmiting={isSubmiting}
+			planType={ planType}
+			videoId={videoId}
+		/>
 				<PunlishPlanDetailModal
 					visible={isShowAddPunlishDetailPlan}
 					onCancel={() => {