"use client" import { useState, useEffect } from "react" import { useRouter } from "next/navigation" import { ChevronLeft, Info, Users, Target, Settings, ArrowRight, ArrowLeft } from "lucide-react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Label } from "@/components/ui/label" import { Textarea } from "@/components/ui/textarea" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group" import { Switch } from "@/components/ui/switch" import { Tabs, TabsList, TabsTrigger, TabsContent } from "@/components/ui/tabs" import { Slider } from "@/components/ui/slider" import { Badge } from "@/components/ui/badge" import { TrafficPoolSelector } from "@/app/components/traffic-pool-selector" // 模拟数据 const planDetails = { id: "1", name: "抖音直播引流计划", description: "从抖音直播间获取的潜在客户流量分发", status: "active", source: "douyin", sourceIcon: "🎬", distributionMethod: "even", targetGroups: ["新客户", "潜在客户"], devices: ["iPhone 13", "华为 P40", "小米 11"], totalUsers: 1250, dailyAverage: 85, weeklyData: [42, 56, 78, 64, 85, 92, 76], createdAt: "2024-03-10T08:30:00Z", lastUpdated: "2024-03-18T10:30:00Z", rules: { maxPerDay: 50, timeRestriction: "custom", customTimeStart: "09:00", customTimeEnd: "21:00", userFilters: [], excludeTags: [], }, selectedUsers: [], } export default function EditTrafficDistributionPage({ params }: { params: { id: string } }) { const router = useRouter() const [currentStep, setCurrentStep] = useState(1) const [formData, setFormData] = useState({ name: "", description: "", source: "", distributionMethod: "even", // even, priority, ratio targetGroups: [] as string[], targetDevices: [] as string[], autoTag: true, activeStatus: true, priorityOrder: [] as string[], ratioSettings: {} as Record, rules: { maxPerDay: 50, timeRestriction: "all", // all, custom customTimeStart: "09:00", customTimeEnd: "21:00", userFilters: [] as string[], excludeTags: [] as string[], }, selectedUsers: [], isPoolSelectorOpen: false, }) // 加载计划详情 useEffect(() => { // 模拟API请求 setFormData({ name: planDetails.name, description: planDetails.description || "", source: planDetails.source, distributionMethod: planDetails.distributionMethod, targetGroups: planDetails.targetGroups, targetDevices: planDetails.devices, autoTag: true, activeStatus: planDetails.status === "active", priorityOrder: planDetails.targetGroups, ratioSettings: planDetails.targetGroups.reduce( (acc, group, index, arr) => { acc[group] = Math.floor(100 / arr.length) return acc }, {} as Record, ), rules: planDetails.rules, selectedUsers: planDetails.selectedUsers || [], isPoolSelectorOpen: false, }) }, [params.id]) const updateFormData = (field: string, value: any) => { setFormData((prev) => { if (field.includes(".")) { const [parent, child] = field.split(".") return { ...prev, [parent]: { ...prev[parent as keyof typeof prev], [child]: value, }, } } return { ...prev, [field]: value } }) } const handleNext = () => { setCurrentStep((prev) => prev + 1) } const handleBack = () => { if (currentStep > 1) { setCurrentStep((prev) => prev - 1) } else { router.back() } } const handleSubmit = () => { // 这里处理表单提交逻辑 console.log("提交表单数据:", formData) router.push(`/workspace/traffic-distribution/${params.id}`) } const isStep1Valid = formData.name && formData.source const isStep2Valid = formData.targetGroups.length > 0 || formData.targetDevices.length > 0 const isStep3Valid = true // 规则设置可以有默认值 return (

编辑流量分发

{/* 步骤指示器 */}
{[ { step: 1, title: "基本信息", icon: }, { step: 2, title: "目标设置", icon: }, { step: 3, title: "规则配置", icon: }, ].map(({ step, title, icon }) => (
{step < currentStep ? "✓" : icon}
{title}
))}
{/* 步骤1:基本信息 */} {currentStep === 1 && ( 基本信息 设置流量分发计划的基本信息
updateFormData("name", e.target.value)} />