import React, { useState } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { Check, Settings } from 'lucide-react'; import PageHeader from '@/components/PageHeader'; import { useToast } from '@/components/ui/toast'; // 步骤定义 const steps = [ { id: 1, title: "步骤一", subtitle: "基础设置" }, { id: 2, title: "步骤二", subtitle: "好友申请设置" }, { id: 3, title: "步骤三", subtitle: "消息设置" }, ]; interface ScenarioOption { id: string; name: string; icon: string; description: string; image: string; } const scenarioOptions: ScenarioOption[] = [ { id: "douyin", name: "抖音获客", icon: "🎵", description: "通过抖音平台进行精准获客", image: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-QR8ManuDplYTySUJsY4mymiZkDYnQ9.png", }, { id: "xiaohongshu", name: "小红书获客", icon: "📖", description: "利用小红书平台进行内容营销获客", image: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-yvnMxpoBUzcvEkr8DfvHgPHEo1kmQ3.png", }, { id: "gongzhonghao", name: "公众号获客", icon: "📱", description: "通过微信公众号进行获客", image: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-Gsg0CMf5tsZb41mioszdjqU1WmsRxW.png", }, { id: "haibao", name: "海报获客", icon: "🖼️", description: "通过海报分享进行获客", image: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-x92XJgXy4MI7moNYlA1EAes2FqDxMH.png", }, ]; interface FormData { planName: string; posters: any[]; device: any[]; remarkType: string; greeting: string; addInterval: number; startTime: string; endTime: string; enabled: boolean; sceneId: string; scenario: string; planNameEdited: boolean; } export default function NewPlan() { const navigate = useNavigate(); const searchParams = useSearchParams(); const { toast } = useToast(); const [currentStep, setCurrentStep] = useState(1); const [loading, setLoading] = useState(false); const [formData, setFormData] = useState({ planName: "", posters: [], device: [], remarkType: "default", greeting: "", addInterval: 60, startTime: "09:00", endTime: "18:00", enabled: true, sceneId: searchParams[0].get("scenario") || "", scenario: searchParams[0].get("scenario") || "", planNameEdited: false }); // 更新表单数据 const onChange = (data: Partial) => { if ('planName' in data) { setFormData(prev => ({ ...prev, planNameEdited: true, ...data })); } else { setFormData(prev => ({ ...prev, ...data })); } }; // 处理保存 const handleSave = async () => { try { setLoading(true); // 模拟API调用 await new Promise(resolve => setTimeout(resolve, 1000)); toast({ title: "创建成功", description: "获客计划已创建", }); navigate("/scenarios"); } catch (error: any) { toast({ title: "创建失败", description: error?.message || "创建计划失败,请重试", variant: "destructive", }); } finally { setLoading(false); } }; // 下一步 const handleNext = () => { if (currentStep === steps.length) { handleSave(); } else { setCurrentStep((prev) => prev + 1); } }; // 上一步 const handlePrev = () => { setCurrentStep((prev) => Math.max(prev - 1, 1)); }; // 步骤指示器组件 const StepIndicator = ({ steps, currentStep }: { steps: any[], currentStep: number }) => (
{steps.map((step, index) => (
step.id ? 'bg-green-500 text-white' : currentStep === step.id ? 'bg-blue-500 text-white' : 'bg-gray-200 text-gray-500' }`}> {currentStep > step.id ? : step.id}
{step.title}
{step.subtitle}
{index < steps.length - 1 && (
step.id ? 'bg-green-500' : 'bg-gray-200' }`} /> )}
))}
); // 基础设置步骤 const BasicSettings = () => { return (

选择获客场景

{scenarioOptions.map((scenario) => (
onChange({ sceneId: scenario.id, scenario: scenario.id })} > {formData.sceneId === scenario.id && (
)}
{scenario.name}

{scenario.name}

{scenario.description}

))}

计划信息

onChange({ planName: e.target.value })} placeholder="请输入计划名称" className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required />
onChange({ startTime: e.target.value })} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />
onChange({ endTime: e.target.value })} className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />
); }; // 好友申请设置步骤 const FriendRequestSettings = () => (

好友申请设置

onChange({ addInterval: parseInt(e.target.value) || 60 })} min="30" max="3600" className="w-full px-3 py-2 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" />

建议设置60-300秒,避免被限制

{formData.remarkType === 'custom' && (
)}
); // 消息设置步骤 const MessageSettings = () => (

消息设置