diff --git a/nkebao/src/components/ContentLibrarySelection/api.ts b/nkebao/src/components/ContentSelection/api.ts similarity index 100% rename from nkebao/src/components/ContentLibrarySelection/api.ts rename to nkebao/src/components/ContentSelection/api.ts diff --git a/nkebao/src/components/ContentSelection/data.ts b/nkebao/src/components/ContentSelection/data.ts new file mode 100644 index 00000000..5ea44b90 --- /dev/null +++ b/nkebao/src/components/ContentSelection/data.ts @@ -0,0 +1,21 @@ +// 内容库接口类型 +export interface ContentItem { + id: number; + name: string; + [key: string]: any; +} + +// 组件属性接口 +export interface ContentSelectionProps { + selectedContent: ContentItem[]; + onSelect: (selectedItems: ContentItem[]) => void; + placeholder?: string; + className?: string; + visible?: boolean; + onVisibleChange?: (visible: boolean) => void; + selectedListMaxHeight?: number; + showInput?: boolean; + showSelectedList?: boolean; + readonly?: boolean; + onConfirm?: (selectedItems: ContentItem[]) => void; +} diff --git a/nkebao/src/components/ContentLibrarySelection/index.module.scss b/nkebao/src/components/ContentSelection/index.module.scss similarity index 100% rename from nkebao/src/components/ContentLibrarySelection/index.module.scss rename to nkebao/src/components/ContentSelection/index.module.scss diff --git a/nkebao/src/components/ContentLibrarySelection/index.tsx b/nkebao/src/components/ContentSelection/index.tsx similarity index 81% rename from nkebao/src/components/ContentLibrarySelection/index.tsx rename to nkebao/src/components/ContentSelection/index.tsx index b053f1d9..9c022e80 100644 --- a/nkebao/src/components/ContentLibrarySelection/index.tsx +++ b/nkebao/src/components/ContentSelection/index.tsx @@ -7,17 +7,7 @@ import Layout from "@/components/Layout/Layout"; import PopupHeader from "@/components/PopuLayout/header"; import PopupFooter from "@/components/PopuLayout/footer"; import { getContentLibraryList } from "./api"; - -// 内容库接口类型 -interface ContentLibraryItem { - id: string; - name: string; - description?: string; - sourceType?: number; // 1=文本 2=图片 3=视频 - creatorName?: string; - updateTime?: string; - [key: string]: any; -} +import { ContentItem, ContentSelectionProps } from "./data"; // 类型标签文本 const getTypeText = (type?: number) => { @@ -43,29 +33,9 @@ const formatDate = (dateStr?: string) => { .padStart(2, "0")}`; }; -// 组件属性接口 -interface ContentLibrarySelectionProps { - selectedLibraries: (string | number)[]; - onSelect: (libraries: string[]) => void; - onSelectDetail?: (libraries: ContentLibraryItem[]) => void; - placeholder?: string; - className?: string; - visible?: boolean; - onVisibleChange?: (visible: boolean) => void; - selectedListMaxHeight?: number; - showInput?: boolean; - showSelectedList?: boolean; - readonly?: boolean; - onConfirm?: ( - selectedIds: string[], - selectedItems: ContentLibraryItem[], - ) => void; -} - -export default function ContentLibrarySelection({ - selectedLibraries, +export default function ContentSelection({ + selectedContent, onSelect, - onSelectDetail, placeholder = "选择内容库", className = "", visible, @@ -75,24 +45,19 @@ export default function ContentLibrarySelection({ showSelectedList = true, readonly = false, onConfirm, -}: ContentLibrarySelectionProps) { +}: ContentSelectionProps) { const [popupVisible, setPopupVisible] = useState(false); - const [libraries, setLibraries] = useState([]); + const [libraries, setLibraries] = useState([]); const [searchQuery, setSearchQuery] = useState(""); const [currentPage, setCurrentPage] = useState(1); const [totalPages, setTotalPages] = useState(1); const [totalLibraries, setTotalLibraries] = useState(0); const [loading, setLoading] = useState(false); - // 获取已选内容库详细信息 - const selectedLibraryObjs = libraries.filter(item => - selectedLibraries.includes(item.id), - ); - // 删除已选内容库 - const handleRemoveLibrary = (id: string) => { + const handleRemoveLibrary = (id: number) => { if (readonly) return; - onSelect(selectedLibraries.filter(g => g !== id)); + onSelect(selectedContent.filter(c => c.id !== id)); }; // 受控弹窗逻辑 @@ -153,30 +118,24 @@ export default function ContentLibrarySelection({ }; // 处理内容库选择 - const handleLibraryToggle = (libraryId: string) => { + const handleLibraryToggle = (library: ContentItem) => { if (readonly) return; - const newSelected = selectedLibraries.includes(libraryId) - ? selectedLibraries.filter(id => id !== libraryId) - : [...selectedLibraries, libraryId]; + const newSelected = selectedContent.some(c => c.id === library.id) + ? selectedContent.filter(c => c.id !== library.id) + : [...selectedContent, library]; onSelect(newSelected); - if (onSelectDetail) { - const selectedObjs = libraries.filter(item => - newSelected.includes(item.id), - ); - onSelectDetail(selectedObjs); - } }; // 获取显示文本 const getDisplayText = () => { - if (selectedLibraries.length === 0) return ""; - return `已选择 ${selectedLibraries.length} 个内容库`; + if (selectedContent.length === 0) return ""; + return `已选择 ${selectedContent.length} 个内容库`; }; // 确认选择 const handleConfirm = () => { if (onConfirm) { - onConfirm(selectedLibraries, selectedLibraryObjs); + onConfirm(selectedContent); } setRealVisible(false); }; @@ -202,7 +161,7 @@ export default function ContentLibrarySelection({ )} {/* 已选内容库列表窗口 */} - {showSelectedList && selectedLibraryObjs.length > 0 && ( + {showSelectedList && selectedContent.length > 0 && (
- {selectedLibraryObjs.map(item => ( + {selectedContent.map(item => (
setRealVisible(false)} onConfirm={handleConfirm} @@ -301,8 +260,8 @@ export default function ContentLibrarySelection({ {libraries.map(item => (
diff --git a/nkebao/src/pages/mobile/workspace/group-push/form/components/ContentSelector.tsx b/nkebao/src/pages/mobile/workspace/group-push/form/components/ContentSelector.tsx index e96c6e14..1e3adff0 100644 --- a/nkebao/src/pages/mobile/workspace/group-push/form/components/ContentSelector.tsx +++ b/nkebao/src/pages/mobile/workspace/group-push/form/components/ContentSelector.tsx @@ -1,23 +1,15 @@ import React, { useImperativeHandle, forwardRef } from "react"; import { Form, Card } from "antd"; -import ContentLibrarySelection from "@/components/ContentLibrarySelection"; - -interface ContentLibrary { - id: string; - name: string; - targets: Array<{ - id: string; - avatar: string; - }>; -} +import ContentSelection from "@/components/ContentSelection"; +import { ContentItem } from "@/components/ContentSelection/data"; interface ContentSelectorProps { - selectedLibraries: ContentLibrary[]; - onLibrariesChange: (libraries: ContentLibrary[]) => void; + selectedContent: ContentItem[]; onPrevious: () => void; - onNext: () => void; - onSave: () => void; - loading?: boolean; + onNext: (data: { + contentGroups: string[]; + contentGroupsOptions: ContentItem[]; + }) => void; } export interface ContentSelectorRef { @@ -26,17 +18,7 @@ export interface ContentSelectorRef { } const ContentSelector = forwardRef( - ( - { - selectedLibraries, - onLibrariesChange, - onPrevious, - onNext, - onSave, - loading = false, - }, - ref, - ) => { + ({ selectedContent, onNext }, ref) => { const [form] = Form.useForm(); // 暴露方法给父组件 @@ -55,20 +37,17 @@ const ContentSelector = forwardRef( }, })); - // 将 ContentLibrary[] 转换为 string[] 用于 ContentLibrarySelection - const selectedLibraryIds = selectedLibraries.map(lib => lib.id); - // 处理选择变化 - const handleLibrariesChange = (libraryIds: string[]) => { - // 这里需要根据选中的ID重新构建ContentLibrary对象 - // 由于ContentLibrarySelection只返回ID,我们需要从原始数据中获取完整信息 - // 暂时使用简化的处理方式 - const newSelectedLibraries = libraryIds.map(id => ({ + const handleLibrariesChange = (contentGroups: string[]) => { + const newSelectedLibraries = contentGroups.map(id => ({ id, name: `内容库 ${id}`, // 这里应该从API获取完整信息 targets: [], // 这里应该从API获取完整信息 })); - onLibrariesChange(newSelectedLibraries); + onNext({ + contentGroups: libraryIds, + contentGroupsOptions: newSelectedLibraries, + }); form.setFieldValue("contentLibraries", libraryIds); }; @@ -80,7 +59,7 @@ const ContentSelector = forwardRef( name: lib.name, targets: [], // 这里需要根据实际情况获取targets数据 })); - onLibrariesChange(convertedLibraries); + onNext(convertedLibraries); form.setFieldValue( "contentLibraries", libraries.map(lib => lib.id), @@ -112,8 +91,8 @@ const ContentSelector = forwardRef( { type: "array", max: 20, message: "最多只能选择20个内容库" }, ]} > - { const [wechatGroupsOptions, setWechatGroupsOptions] = useState< GroupSelectionItem[] >([]); + const [contentGroupsOptions, setContentGroupsOptions] = useState< + ContentItem[] + >([]); + const [formData, setFormData] = useState({ name: "", pushTimeStart: "06:00", @@ -37,7 +42,7 @@ const NewGroupPush: React.FC = () => { isImmediatePush: false, isEnabled: false, wechatGroups: [], - contentLibraries: [], + contentGroups: [], }); const [isEditMode, setIsEditMode] = useState(false); @@ -66,9 +71,13 @@ const NewGroupPush: React.FC = () => { })); setWechatGroupsOptions(data.wechatGroupsOptions); }; - - const handleLibrariesChange = (contentLibraries: ContentLibrary[]) => { - setFormData(prev => ({ ...prev, contentLibraries })); + //内容库选择 + const handleLibrariesChange = (data: { + contentGroups: string[]; + contentGroupsOptions: ContentItem[]; + }) => { + setFormData(prev => ({ ...prev, contentGroups: data.contentGroups })); + setContentGroupsOptions(data.contentGroupsOptions); }; const handleSave = async () => { @@ -230,12 +239,9 @@ const NewGroupPush: React.FC = () => { {currentStep === 3 && ( setCurrentStep(2)} - onNext={() => setCurrentStep(4)} - onSave={handleSave} - loading={loading} + onNext={handleLibrariesChange} /> )} {currentStep === 4 && ( diff --git a/nkebao/src/pages/mobile/workspace/moments-sync/new/index.tsx b/nkebao/src/pages/mobile/workspace/moments-sync/new/index.tsx index 8c6dea8e..32ac8209 100644 --- a/nkebao/src/pages/mobile/workspace/moments-sync/new/index.tsx +++ b/nkebao/src/pages/mobile/workspace/moments-sync/new/index.tsx @@ -13,7 +13,7 @@ import { getMomentsSyncDetail, } from "./api"; import DeviceSelection from "@/components/DeviceSelection"; -import ContentLibrarySelection from "@/components/ContentLibrarySelection"; +import ContentLibrarySelection from "@/components/ContentSelection"; import NavCommon from "@/components/NavCommon"; const steps = [