"use client" import { useState } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent } from "@/components/ui/card" import { Dialog, DialogContent, DialogHeader, DialogTitle } from "@/components/ui/dialog" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Input } from "@/components/ui/input" import { Search, Plus, Trash2 } from "lucide-react" import { ScrollArea } from "@/components/ui/scroll-area" export interface ContentTarget { id: string avatar: string name?: string } export interface ContentLibrary { id: string name: string type?: string count?: number targets?: ContentTarget[] } export interface ContentSelectorProps { /** 已选择的内容库 */ selectedLibraries: ContentLibrary[] /** 内容库变更回调 */ onLibrariesChange: (libraries: ContentLibrary[]) => void /** 上一步回调 */ onPrevious?: () => void /** 下一步回调 */ onNext?: () => void /** 保存回调 */ onSave?: () => void /** 取消回调 */ onCancel?: () => void /** 自定义内容库列表,不传则使用模拟数据 */ contentLibraries?: ContentLibrary[] /** 自定义类名 */ className?: string /** 是否使用卡片包装 */ withCard?: boolean } /** * 统一的内容选择器组件 */ export function ContentSelector({ selectedLibraries = [], onLibrariesChange, onPrevious, onNext, onSave, onCancel, contentLibraries: propContentLibraries, className, withCard = true, }: ContentSelectorProps) { const [isDialogOpen, setIsDialogOpen] = useState(false) const [searchTerm, setSearchTerm] = useState("") // 模拟内容库数据 const defaultContentLibraries: ContentLibrary[] = [ { id: "1", name: "卡若朋友圈", type: "朋友圈", count: 307, targets: [{ id: "t1", avatar: "/placeholder.svg?height=40&width=40&query=avatar1" }], }, { id: "2", name: "业务推广内容", type: "朋友圈", count: 156, targets: [ { id: "t2", avatar: "/placeholder.svg?height=40&width=40&query=avatar2" }, { id: "t3", avatar: "/placeholder.svg?height=40&width=40&query=avatar3" }, ], }, { id: "3", name: "产品介绍", type: "群发", count: 42, targets: [ { id: "t4", avatar: "/placeholder.svg?height=40&width=40&query=avatar4" }, { id: "t5", avatar: "/placeholder.svg?height=40&width=40&query=avatar5" }, ], }, ] const contentLibraries = propContentLibraries || defaultContentLibraries const handleAddLibrary = (library: ContentLibrary) => { if (!selectedLibraries.some((l) => l.id === library.id)) { onLibrariesChange([...selectedLibraries, library]) } setIsDialogOpen(false) } const handleRemoveLibrary = (libraryId: string) => { onLibrariesChange(selectedLibraries.filter((library) => library.id !== libraryId)) } const filteredLibraries = contentLibraries.filter((library) => library.name.toLowerCase().includes(searchTerm.toLowerCase()), ) const ContentSelectorContent = () => (
* 选择内容库:
{selectedLibraries.length > 0 ? ( 序号 内容库名称 {contentLibraries[0]?.type && 类型} {contentLibraries[0]?.count && 内容数量} 采集对象 操作 {selectedLibraries.map((library, index) => ( {index + 1} {library.name} {contentLibraries[0]?.type && {library.type}} {contentLibraries[0]?.count && {library.count}}
{library.targets?.map((target) => (
{target.name
))}
))}
) : (
请点击"选择内容库"按钮添加内容库
)}
{(onPrevious || onNext || onSave || onCancel) && (
{onPrevious && ( )} {onNext && ( )} {onSave && ( )} {onCancel && ( )}
)}
) return ( <> {withCard ? ( ) : (
)} 选择内容库
setSearchTerm(e.target.value)} />
序号 内容库名称 {contentLibraries[0]?.type && 类型} {contentLibraries[0]?.count && 内容数量} 采集对象 操作 {filteredLibraries.map((library, index) => ( {index + 1} {library.name} {contentLibraries[0]?.type && {library.type}} {contentLibraries[0]?.count && {library.count}}
{library.targets?.map((target) => (
{target.name
))}
))}
) }