"use client" import { useState, useEffect } from "react" import { Button } from "@/components/ui/button" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" import { ArrowLeft, Plus, FileText, BarChart2, Mail, Tag } from "lucide-react" import { useRouter } from "next/navigation" import { Badge } from "@/components/ui/badge" import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" import Link from "next/link" interface StrategyPlan { id: string name: string deviceIds: string[] deviceNames: string[] status: "running" | "completed" | "failed" createdAt: string completedAt?: string strategyType: "jd" | "yisi" | "database" | "custom" strategyName: string trafficPoolSize: number optimizedUsers: number } export default function AIStrategyPage() { const router = useRouter() const [plans, setPlans] = useState([]) const [isLoading, setIsLoading] = useState(true) useEffect(() => { // 模拟加载数据 const fetchPlans = async () => { await new Promise((resolve) => setTimeout(resolve, 1000)) const mockPlans: StrategyPlan[] = [ { id: "plan-1", name: "京东会员优化", deviceIds: ["device-1", "device-2"], deviceNames: ["设备1", "设备2"], status: "completed", createdAt: "2023-12-15T10:30:00Z", completedAt: "2023-12-15T11:45:00Z", strategyType: "jd", strategyName: "京东会员识别", trafficPoolSize: 287, optimizedUsers: 142, }, { id: "plan-2", name: "易思API用户分析", deviceIds: ["device-3"], deviceNames: ["设备3"], status: "running", createdAt: "2023-12-16T09:15:00Z", strategyType: "yisi", strategyName: "易思用户画像", trafficPoolSize: 156, optimizedUsers: 0, }, { id: "plan-3", name: "数据库客户匹配", deviceIds: ["device-1", "device-4"], deviceNames: ["设备1", "设备4"], status: "completed", createdAt: "2023-12-14T14:20:00Z", completedAt: "2023-12-14T16:10:00Z", strategyType: "database", strategyName: "CRM客户匹配", trafficPoolSize: 423, optimizedUsers: 215, }, ] setPlans(mockPlans) setIsLoading(false) } fetchPlans() }, []) const getStatusBadge = (status: StrategyPlan["status"]) => { switch (status) { case "running": return ( 执行中 ) case "completed": return ( 已完成 ) case "failed": return ( 失败 ) } } const getStrategyLabel = (type: StrategyPlan["strategyType"]) => { switch (type) { case "jd": return "京东会员" case "yisi": return "易思接口" case "database": return "数据库匹配" case "custom": return "自定义策略" } } return (
{/* 头部 */}

AI策略优化

{/* 主内容区域 */}
全部策略 执行中 已完成 {isLoading ? (
) : plans.length > 0 ? ( plans.map((plan) => (
{plan.name} 设备: {plan.deviceNames.join(", ")}
{getStatusBadge(plan.status)}
策略类型 {getStrategyLabel(plan.strategyType)}
策略名称 {plan.strategyName}
流量池大小 {plan.trafficPoolSize} 用户
{plan.status === "completed" && (
优化用户数 {plan.optimizedUsers} 用户
)}
创建时间 {new Date(plan.createdAt).toLocaleString()}
{plan.completedAt && (
完成时间 {new Date(plan.completedAt).toLocaleString()}
)}
{plan.status === "completed" && ( <> )} {plan.status === "running" && ( )}
)) ) : (

暂无优化策略

创建一个新的AI策略优化计划来开始

)}
{isLoading ? (
) : plans.filter((p) => p.status === "running").length > 0 ? ( plans .filter((p) => p.status === "running") .map((plan) => ( {/* 与上面相同的卡片内容 */}
{plan.name} 设备: {plan.deviceNames.join(", ")}
{getStatusBadge(plan.status)}
策略类型 {getStrategyLabel(plan.strategyType)}
策略名称 {plan.strategyName}
流量池大小 {plan.trafficPoolSize} 用户
创建时间 {new Date(plan.createdAt).toLocaleString()}
)) ) : (

暂无执行中的优化策略

)}
{isLoading ? (
) : plans.filter((p) => p.status === "completed").length > 0 ? ( plans .filter((p) => p.status === "completed") .map((plan) => ( {/* 与上面相同的卡片内容 */}
{plan.name} 设备: {plan.deviceNames.join(", ")}
{getStatusBadge(plan.status)}
策略类型 {getStrategyLabel(plan.strategyType)}
策略名称 {plan.strategyName}
流量池大小 {plan.trafficPoolSize} 用户
优化用户数 {plan.optimizedUsers} 用户
创建时间 {new Date(plan.createdAt).toLocaleString()}
完成时间 {new Date(plan.completedAt!).toLocaleString()}
)) ) : (

暂无已完成的优化策略

)}
) }