Files
shensheshou/app/ai-assistant/page.tsx
v0 22e725887a refactor: restructure project into 5 core modules
Organize project by 5 core modules based on requirement docs.

Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
2026-01-31 04:18:24 +00:00

237 lines
9.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"use client"
import Link from "next/link"
import { useState } from "react"
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
import { Badge } from "@/components/ui/badge"
import { Button } from "@/components/ui/button"
import { Textarea } from "@/components/ui/textarea"
import { Cpu, BarChart3, TrendingUp, Users, Target, Brain, ArrowRight, Send, Sparkles } from 'lucide-react'
export default function AIAssistant() {
const [message, setMessage] = useState("")
const [chatHistory, setChatHistory] = useState([
{
role: "assistant",
content: "你好我是神射手AI助手可以帮助你分析用户数据、生成报告、预测趋势。有什么我可以帮助你的吗",
timestamp: "10:30",
},
])
// AI功能卡片
const aiFeatures = [
{
icon: <BarChart3 className="w-8 h-8" />,
title: "数据分析",
description: "自动分析用户行为,生成洞察报告",
color: "from-blue-500 to-cyan-500",
href: "/platform/ai-assistant/data-analysis",
stats: { reports: 1258, insights: 856 }
},
{
icon: <TrendingUp className="w-8 h-8" />,
title: "趋势预测",
description: "预测用户行为和价值变化趋势",
color: "from-purple-500 to-pink-500",
href: "/platform/ai-assistant/trend-prediction",
stats: { accuracy: 94.2, predictions: 2450 }
},
{
icon: <Users className="w-8 h-8" />,
title: "用户画像",
description: "智能生成用户群体画像",
color: "from-green-500 to-emerald-500",
href: "/platform/ai-assistant/user-profiling",
stats: { profiles: 4285, segments: 128 }
},
{
icon: <Target className="w-8 h-8" />,
title: "精准推荐",
description: "推荐最佳营销策略和用户群",
color: "from-orange-500 to-red-500",
href: "/platform/ai-assistant/recommendation",
stats: { campaigns: 586, conversion: 18.5 }
},
]
// 快捷问题
const quickQuestions = [
"分析今日新增用户特征",
"预测本月用户增长趋势",
"高价值用户流失预警",
"生成本周运营报告",
]
const handleSend = () => {
if (!message.trim()) return
setChatHistory([
...chatHistory,
{
role: "user",
content: message,
timestamp: new Date().toLocaleTimeString("zh-CN", { hour: "2-digit", minute: "2-digit" }),
},
{
role: "assistant",
content: "正在分析您的问题,请稍候...",
timestamp: new Date().toLocaleTimeString("zh-CN", { hour: "2-digit", minute: "2-digit" }),
},
])
setMessage("")
}
return (
<div className="min-h-screen bg-gray-50 p-6">
{/* Header */}
<div className="mb-8">
<div className="flex items-center gap-3 mb-2">
<div className="w-12 h-12 rounded-xl bg-gradient-to-br from-blue-500 to-purple-500 flex items-center justify-center">
<Brain className="w-6 h-6 text-white" />
</div>
<div>
<h1 className="text-4xl font-bold text-gray-900">AI智能助手</h1>
<p className="text-gray-600"></p>
</div>
</div>
</div>
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
{/* AI状态 */}
<Card>
<CardHeader>
<CardTitle className="text-gray-900 flex items-center gap-2">
<Cpu className="w-5 h-5 text-green-600" />
AI运行状态
</CardTitle>
</CardHeader>
<CardContent>
<div className="space-y-3">
<div className="flex items-center justify-between">
<span className="text-gray-600"></span>
<Badge variant="outline" className="border-green-500 text-green-600 bg-green-50">
<div className="w-2 h-2 rounded-full bg-green-500 animate-pulse mr-2"></div>
</Badge>
</div>
<div className="flex items-center justify-between">
<span className="text-gray-600"></span>
<span className="text-gray-900 font-semibold">v3.5</span>
</div>
<div className="flex items-center justify-between">
<span className="text-gray-600"></span>
<span className="text-gray-900 font-semibold">0.8s</span>
</div>
<div className="flex items-center justify-between">
<span className="text-gray-600"></span>
<span className="text-green-600 font-semibold">94.2%</span>
</div>
</div>
</CardContent>
</Card>
{/* AI功能卡片 */}
<div className="lg:col-span-2 grid grid-cols-1 lg:grid-cols-2 gap-6">
{aiFeatures.map((feature, index) => (
<Link key={index} href={feature.href}>
<Card className="hover:shadow-lg transition-shadow cursor-pointer h-full">
<CardContent className="p-6">
<div className="flex items-start gap-4 mb-4">
<div className={`w-16 h-16 rounded-xl bg-gradient-to-br ${feature.color} flex items-center justify-center text-white`}>
{feature.icon}
</div>
<div className="flex-1">
<div className="flex items-center justify-between mb-2">
<h3 className="text-xl font-semibold text-gray-900">{feature.title}</h3>
<ArrowRight className="w-5 h-5 text-gray-400" />
</div>
<p className="text-gray-600 text-sm">{feature.description}</p>
</div>
</div>
<div className="grid grid-cols-2 gap-4 pt-4 border-t border-gray-200">
{Object.entries(feature.stats).map(([key, value], i) => (
<div key={i}>
<div className="text-xs text-gray-600 mb-1">{key === 'reports' ? '报告数' : key === 'insights' ? '洞察数' : key === 'accuracy' ? '准确率' : key === 'predictions' ? '预测数' : key === 'profiles' ? '画像数' : key === 'segments' ? '分组数' : key === 'campaigns' ? '活动数' : '转化率'}</div>
<div className="text-lg font-semibold text-gray-900">
{typeof value === 'number' && value % 1 !== 0 ? `${value}%` : value}
</div>
</div>
))}
</div>
</CardContent>
</Card>
</Link>
))}
</div>
{/* 对话区域 */}
<div className="lg:col-span-2">
<Card className="bg-white/5 border-white/10 h-[calc(100vh-200px)]">
<CardHeader className="border-b border-white/10">
<CardTitle className="text-white flex items-center gap-2">
<BarChart3 className="w-5 h-5" />
AI对话
</CardTitle>
</CardHeader>
<CardContent className="p-6 flex flex-col h-[calc(100%-80px)]">
{/* 聊天历史 */}
<div className="flex-1 overflow-y-auto space-y-4 mb-6">
{chatHistory.map((chat, index) => (
<div key={index} className={`flex ${chat.role === "user" ? "justify-end" : "justify-start"}`}>
<div
className={`max-w-[80%] rounded-2xl p-4 ${
chat.role === "user"
? "bg-gradient-to-br from-blue-500 to-purple-500 text-white"
: "bg-white/10 text-white"
}`}
>
<div className="mb-1">{chat.content}</div>
<div className="text-xs opacity-70">{chat.timestamp}</div>
</div>
</div>
))}
</div>
{/* 快捷问题 */}
<div className="mb-4 flex flex-wrap gap-2">
{quickQuestions.map((question, index) => (
<Button
key={index}
variant="outline"
size="sm"
onClick={() => setMessage(question)}
className="bg-white/5 border-white/10 hover:bg-white/10 text-xs"
>
<Sparkles className="w-3 h-3 mr-1" />
{question}
</Button>
))}
</div>
{/* 输入框 */}
<div className="flex items-end gap-3">
<Textarea
value={message}
onChange={(e) => setMessage(e.target.value)}
onKeyPress={(e) => {
if (e.key === "Enter" && !e.shiftKey) {
e.preventDefault()
handleSend()
}
}}
placeholder="输入您的问题按Enter发送..."
className="bg-white/5 border-white/10 text-white resize-none"
rows={3}
/>
<Button onClick={handleSend} className="bg-gradient-to-r from-blue-500 to-purple-500 h-[88px]">
<Send className="w-5 h-5" />
</Button>
</div>
</CardContent>
</Card>
</div>
</div>
</div>
)
}