refactor: restructure navigation and module layout
Reorganize navigation and module structure based on new requirements. Co-authored-by: null <4804959+fnvtk@users.noreply.github.com>
This commit is contained in:
432
app/ai-agent/chat/page.tsx
Normal file
432
app/ai-agent/chat/page.tsx
Normal file
@@ -0,0 +1,432 @@
|
||||
"use client"
|
||||
|
||||
import { useState, useRef, useEffect } from "react"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { ScrollArea } from "@/components/ui/scroll-area"
|
||||
import {
|
||||
Bot,
|
||||
Send,
|
||||
User,
|
||||
Sparkles,
|
||||
Database,
|
||||
Tags,
|
||||
FileText,
|
||||
Download,
|
||||
Copy,
|
||||
ThumbsUp,
|
||||
ThumbsDown,
|
||||
Loader2,
|
||||
Zap,
|
||||
Search,
|
||||
BarChart3,
|
||||
Table,
|
||||
RefreshCw,
|
||||
} from "lucide-react"
|
||||
|
||||
// 第四部分:AI Agent智能系统 - 智能对话
|
||||
export default function AIAgentChatPage() {
|
||||
const [messages, setMessages] = useState<any[]>([
|
||||
{
|
||||
id: "1",
|
||||
role: "assistant",
|
||||
content: "您好!我是神射手AI Agent,可以帮您完成以下任务:\n\n- **自然语言查询**:用自然语言查询用户数据\n- **智能打标**:AI自动为用户打标签\n- **数据清洗**:AI识别并清洗异常数据\n- **智能报告**:自动生成数据分析报告\n\n请问有什么可以帮您?",
|
||||
timestamp: new Date(),
|
||||
},
|
||||
])
|
||||
const [inputValue, setInputValue] = useState("")
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const scrollRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
// 快捷指令
|
||||
const quickCommands = [
|
||||
{ icon: Search, label: "查询高价值用户", command: "帮我找出最近30天内消费超过1万元的高价值用户" },
|
||||
{ icon: Tags, label: "AI打标签", command: "为最近7天未登录的用户打上流失风险标签" },
|
||||
{ icon: Zap, label: "数据清洗", command: "检查用户表中的手机号格式,清洗异常数据" },
|
||||
{ icon: FileText, label: "生成报告", command: "生成本月用户增长分析报告" },
|
||||
]
|
||||
|
||||
// 支持的指令类型
|
||||
const supportedTasks = [
|
||||
{ type: "NLQ", label: "自然语言查询", desc: "用自然语言查询数据库", icon: Search },
|
||||
{ type: "TAG", label: "AI打标", desc: "智能为用户打标签", icon: Tags },
|
||||
{ type: "CLEAN", label: "数据清洗", desc: "AI识别清洗异常数据", icon: Zap },
|
||||
{ type: "REPORT", label: "智能报告", desc: "自动生成分析报告", icon: FileText },
|
||||
]
|
||||
|
||||
useEffect(() => {
|
||||
if (scrollRef.current) {
|
||||
scrollRef.current.scrollTop = scrollRef.current.scrollHeight
|
||||
}
|
||||
}, [messages])
|
||||
|
||||
const handleSend = async () => {
|
||||
if (!inputValue.trim() || isLoading) return
|
||||
|
||||
const userMessage = {
|
||||
id: Date.now().toString(),
|
||||
role: "user",
|
||||
content: inputValue,
|
||||
timestamp: new Date(),
|
||||
}
|
||||
setMessages((prev) => [...prev, userMessage])
|
||||
setInputValue("")
|
||||
setIsLoading(true)
|
||||
|
||||
// 模拟AI响应
|
||||
setTimeout(() => {
|
||||
let response: any = {
|
||||
id: (Date.now() + 1).toString(),
|
||||
role: "assistant",
|
||||
timestamp: new Date(),
|
||||
}
|
||||
|
||||
// 根据输入内容生成不同类型的响应
|
||||
if (inputValue.includes("高价值") || inputValue.includes("消费") || inputValue.includes("查询")) {
|
||||
response.content = "我已理解您的需求。正在为您查询符合条件的用户..."
|
||||
response.taskType = "NLQ"
|
||||
response.result = {
|
||||
type: "table",
|
||||
title: "高价值用户查询结果",
|
||||
sql: "SELECT * FROM users WHERE total_spending > 10000 AND last_active_date >= DATE_SUB(NOW(), INTERVAL 30 DAY)",
|
||||
data: [
|
||||
{ id: "U001", name: "张三", phone: "138****1234", spending: "¥15,680", lastActive: "2天前" },
|
||||
{ id: "U002", name: "李四", phone: "139****5678", spending: "¥12,340", lastActive: "1天前" },
|
||||
{ id: "U003", name: "王五", phone: "137****9012", spending: "¥11,890", lastActive: "3天前" },
|
||||
],
|
||||
total: 823,
|
||||
}
|
||||
} else if (inputValue.includes("打标") || inputValue.includes("标签")) {
|
||||
response.content = "我将为符合条件的用户打上「流失风险」标签。这是一个AI打标任务,需要您确认后执行。"
|
||||
response.taskType = "TAG"
|
||||
response.result = {
|
||||
type: "confirmation",
|
||||
title: "AI打标任务确认",
|
||||
description: "为最近7天未登录的用户打上「流失风险」标签",
|
||||
affectedCount: 12456,
|
||||
confidence: 0.87,
|
||||
needReview: true,
|
||||
}
|
||||
} else if (inputValue.includes("清洗") || inputValue.includes("异常")) {
|
||||
response.content = "我已扫描用户表,发现以下数据质量问题:"
|
||||
response.taskType = "CLEAN"
|
||||
response.result = {
|
||||
type: "cleaning",
|
||||
title: "数据清洗建议",
|
||||
issues: [
|
||||
{ field: "phone", issue: "格式不规范", count: 234, example: "1381234567 → 138****4567" },
|
||||
{ field: "email", issue: "缺失值", count: 1256, suggestion: "填充默认值或标记" },
|
||||
{ field: "birth_date", issue: "超出范围", count: 45, example: "2099-01-01" },
|
||||
],
|
||||
needReview: true,
|
||||
}
|
||||
} else if (inputValue.includes("报告") || inputValue.includes("分析")) {
|
||||
response.content = "正在为您生成用户增长分析报告..."
|
||||
response.taskType = "REPORT"
|
||||
response.result = {
|
||||
type: "report",
|
||||
title: "用户增长分析报告(2026年1月)",
|
||||
summary: "本月新增用户23,456人,同比增长15.2%;活跃用户856,234人,DAU/MAU比值0.32。",
|
||||
highlights: [
|
||||
"新用户转化率提升至18.5%,环比增长3.2%",
|
||||
"高价值用户占比8.7%,贡献65%的交易额",
|
||||
"用户流失率下降至2.1%,创历史新低",
|
||||
],
|
||||
}
|
||||
} else {
|
||||
response.content = "我理解您的需求。请问您想要:\n1. 查询用户数据\n2. AI打标签\n3. 数据清洗\n4. 生成报告\n\n请选择或详细描述您的需求。"
|
||||
}
|
||||
|
||||
setMessages((prev) => [...prev, response])
|
||||
setIsLoading(false)
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
const handleQuickCommand = (command: string) => {
|
||||
setInputValue(command)
|
||||
}
|
||||
|
||||
const renderMessageContent = (message: any) => {
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
<p className="whitespace-pre-wrap">{message.content}</p>
|
||||
|
||||
{message.result?.type === "table" && (
|
||||
<Card className="bg-gray-50 border-0">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between mb-3">
|
||||
<h4 className="font-medium text-gray-900">{message.result.title}</h4>
|
||||
<Badge variant="secondary">共 {message.result.total} 条</Badge>
|
||||
</div>
|
||||
<div className="bg-gray-100 rounded p-2 mb-3 font-mono text-xs text-gray-600 overflow-x-auto">
|
||||
{message.result.sql}
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b">
|
||||
<th className="text-left py-2 px-3">ID</th>
|
||||
<th className="text-left py-2 px-3">姓名</th>
|
||||
<th className="text-left py-2 px-3">手机</th>
|
||||
<th className="text-left py-2 px-3">消费金额</th>
|
||||
<th className="text-left py-2 px-3">最近活跃</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{message.result.data.map((row: any, index: number) => (
|
||||
<tr key={index} className="border-b border-gray-100">
|
||||
<td className="py-2 px-3">{row.id}</td>
|
||||
<td className="py-2 px-3">{row.name}</td>
|
||||
<td className="py-2 px-3">{row.phone}</td>
|
||||
<td className="py-2 px-3 text-green-600 font-medium">{row.spending}</td>
|
||||
<td className="py-2 px-3">{row.lastActive}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<Button size="sm" variant="outline">
|
||||
<Download className="h-4 w-4 mr-1" />
|
||||
导出Excel
|
||||
</Button>
|
||||
<Button size="sm" variant="outline">
|
||||
<Copy className="h-4 w-4 mr-1" />
|
||||
复制SQL
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{message.result?.type === "confirmation" && (
|
||||
<Card className="bg-blue-50 border-blue-200">
|
||||
<CardContent className="p-4">
|
||||
<h4 className="font-medium text-gray-900 mb-2">{message.result.title}</h4>
|
||||
<p className="text-sm text-gray-600 mb-3">{message.result.description}</p>
|
||||
<div className="flex items-center gap-4 text-sm mb-3">
|
||||
<span>影响用户数:<strong>{message.result.affectedCount.toLocaleString()}</strong></span>
|
||||
<span>置信度:<strong>{(message.result.confidence * 100).toFixed(0)}%</strong></span>
|
||||
</div>
|
||||
{message.result.needReview && (
|
||||
<div className="flex items-center gap-2">
|
||||
<Button size="sm">确认执行</Button>
|
||||
<Button size="sm" variant="outline">查看详情</Button>
|
||||
<Button size="sm" variant="ghost">取消</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{message.result?.type === "cleaning" && (
|
||||
<Card className="bg-yellow-50 border-yellow-200">
|
||||
<CardContent className="p-4">
|
||||
<h4 className="font-medium text-gray-900 mb-3">{message.result.title}</h4>
|
||||
<div className="space-y-3">
|
||||
{message.result.issues.map((issue: any, index: number) => (
|
||||
<div key={index} className="flex items-start justify-between p-3 bg-white rounded-lg">
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge variant="secondary">{issue.field}</Badge>
|
||||
<span className="text-sm font-medium">{issue.issue}</span>
|
||||
</div>
|
||||
{issue.example && (
|
||||
<p className="text-xs text-gray-500 mt-1">示例:{issue.example}</p>
|
||||
)}
|
||||
{issue.suggestion && (
|
||||
<p className="text-xs text-gray-500 mt-1">建议:{issue.suggestion}</p>
|
||||
)}
|
||||
</div>
|
||||
<Badge className="bg-red-100 text-red-700">{issue.count} 条</Badge>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<Button size="sm">一键清洗</Button>
|
||||
<Button size="sm" variant="outline">预览修改</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
|
||||
{message.result?.type === "report" && (
|
||||
<Card className="bg-green-50 border-green-200">
|
||||
<CardContent className="p-4">
|
||||
<h4 className="font-medium text-gray-900 mb-2">{message.result.title}</h4>
|
||||
<p className="text-sm text-gray-600 mb-3">{message.result.summary}</p>
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm font-medium text-gray-700">核心发现:</p>
|
||||
{message.result.highlights.map((highlight: string, index: number) => (
|
||||
<div key={index} className="flex items-start gap-2 text-sm text-gray-600">
|
||||
<span className="text-green-500">•</span>
|
||||
{highlight}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-3">
|
||||
<Button size="sm">
|
||||
<Download className="h-4 w-4 mr-1" />
|
||||
下载完整报告
|
||||
</Button>
|
||||
<Button size="sm" variant="outline">
|
||||
<BarChart3 className="h-4 w-4 mr-1" />
|
||||
查看图表
|
||||
</Button>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50/30 to-purple-50/20">
|
||||
<div className="flex h-[calc(100vh-64px)]">
|
||||
{/* 左侧:功能面板 */}
|
||||
<div className="w-64 border-r bg-white/80 backdrop-blur p-4 hidden lg:block">
|
||||
<h3 className="font-semibold text-gray-900 mb-4">AI能力</h3>
|
||||
<div className="space-y-2">
|
||||
{supportedTasks.map((task) => (
|
||||
<div
|
||||
key={task.type}
|
||||
className="flex items-start gap-3 p-3 rounded-lg hover:bg-gray-50 cursor-pointer transition-colors"
|
||||
>
|
||||
<div className="p-2 rounded-lg bg-blue-50">
|
||||
<task.icon className="h-4 w-4 text-blue-500" />
|
||||
</div>
|
||||
<div>
|
||||
<p className="text-sm font-medium text-gray-900">{task.label}</p>
|
||||
<p className="text-xs text-gray-500">{task.desc}</p>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="mt-6">
|
||||
<h3 className="font-semibold text-gray-900 mb-4">快捷指令</h3>
|
||||
<div className="space-y-2">
|
||||
{quickCommands.map((cmd, index) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => handleQuickCommand(cmd.command)}
|
||||
className="w-full flex items-center gap-2 p-2 rounded-lg text-left text-sm text-gray-600 hover:bg-gray-50 transition-colors"
|
||||
>
|
||||
<cmd.icon className="h-4 w-4 text-gray-400" />
|
||||
{cmd.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 中间:对话区域 */}
|
||||
<div className="flex-1 flex flex-col">
|
||||
{/* 消息列表 */}
|
||||
<ScrollArea className="flex-1 p-6" ref={scrollRef}>
|
||||
<div className="max-w-3xl mx-auto space-y-6">
|
||||
{messages.map((message) => (
|
||||
<div
|
||||
key={message.id}
|
||||
className={`flex gap-4 ${message.role === "user" ? "flex-row-reverse" : ""}`}
|
||||
>
|
||||
<div
|
||||
className={`w-10 h-10 rounded-full flex items-center justify-center shrink-0 ${
|
||||
message.role === "user"
|
||||
? "bg-blue-500"
|
||||
: "bg-gradient-to-br from-purple-500 to-blue-500"
|
||||
}`}
|
||||
>
|
||||
{message.role === "user" ? (
|
||||
<User className="h-5 w-5 text-white" />
|
||||
) : (
|
||||
<Bot className="h-5 w-5 text-white" />
|
||||
)}
|
||||
</div>
|
||||
<div
|
||||
className={`flex-1 ${message.role === "user" ? "text-right" : ""}`}
|
||||
>
|
||||
<div
|
||||
className={`inline-block max-w-full text-left rounded-2xl px-4 py-3 ${
|
||||
message.role === "user"
|
||||
? "bg-blue-500 text-white"
|
||||
: "bg-white shadow-sm"
|
||||
}`}
|
||||
>
|
||||
{message.role === "user" ? (
|
||||
<p>{message.content}</p>
|
||||
) : (
|
||||
renderMessageContent(message)
|
||||
)}
|
||||
</div>
|
||||
{message.role === "assistant" && (
|
||||
<div className="flex items-center gap-2 mt-2">
|
||||
<Button variant="ghost" size="sm" className="h-7 px-2">
|
||||
<ThumbsUp className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" className="h-7 px-2">
|
||||
<ThumbsDown className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" className="h-7 px-2">
|
||||
<Copy className="h-3 w-3" />
|
||||
</Button>
|
||||
<Button variant="ghost" size="sm" className="h-7 px-2">
|
||||
<RefreshCw className="h-3 w-3" />
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{isLoading && (
|
||||
<div className="flex gap-4">
|
||||
<div className="w-10 h-10 rounded-full bg-gradient-to-br from-purple-500 to-blue-500 flex items-center justify-center">
|
||||
<Bot className="h-5 w-5 text-white" />
|
||||
</div>
|
||||
<div className="bg-white rounded-2xl px-4 py-3 shadow-sm">
|
||||
<div className="flex items-center gap-2 text-gray-500">
|
||||
<Loader2 className="h-4 w-4 animate-spin" />
|
||||
<span>AI正在思考...</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
{/* 输入区域 */}
|
||||
<div className="border-t bg-white/80 backdrop-blur p-4">
|
||||
<div className="max-w-3xl mx-auto">
|
||||
<div className="flex items-center gap-3">
|
||||
<div className="flex-1 relative">
|
||||
<Input
|
||||
value={inputValue}
|
||||
onChange={(e) => setInputValue(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && !e.shiftKey && handleSend()}
|
||||
placeholder="输入您的问题,例如:帮我找出最近30天的高价值用户..."
|
||||
className="pr-12 py-6 bg-white"
|
||||
/>
|
||||
<Button
|
||||
size="icon"
|
||||
className="absolute right-2 top-1/2 -translate-y-1/2"
|
||||
onClick={handleSend}
|
||||
disabled={isLoading || !inputValue.trim()}
|
||||
>
|
||||
<Send className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 mt-2 text-center">
|
||||
AI生成的内容可能存在误差,重要操作请人工确认
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
336
app/ai-agent/nlq/page.tsx
Normal file
336
app/ai-agent/nlq/page.tsx
Normal file
@@ -0,0 +1,336 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import {
|
||||
Search,
|
||||
Play,
|
||||
Download,
|
||||
Copy,
|
||||
History,
|
||||
Star,
|
||||
StarOff,
|
||||
Clock,
|
||||
Database,
|
||||
Loader2,
|
||||
ChevronRight,
|
||||
Table,
|
||||
BarChart3,
|
||||
} from "lucide-react"
|
||||
|
||||
// 第四部分:AI Agent - 自然语言查询 (NLQ)
|
||||
export default function NLQPage() {
|
||||
const [query, setQuery] = useState("")
|
||||
const [isLoading, setIsLoading] = useState(false)
|
||||
const [activeTab, setActiveTab] = useState("query")
|
||||
const [showResult, setShowResult] = useState(false)
|
||||
const [queryResult, setQueryResult] = useState<any>(null)
|
||||
|
||||
// 示例查询
|
||||
const exampleQueries = [
|
||||
{ label: "高价值用户", query: "查找最近30天消费超过1万元的用户" },
|
||||
{ label: "流失用户分析", query: "统计最近7天未登录的活跃用户数量" },
|
||||
{ label: "地域分布", query: "按省份统计用户数量,按数量降序排列" },
|
||||
{ label: "消费趋势", query: "统计每天的交易金额,最近30天" },
|
||||
]
|
||||
|
||||
// 历史查询
|
||||
const historyQueries = [
|
||||
{ id: "1", query: "查找最近30天消费超过1万元的用户", time: "2分钟前", starred: true },
|
||||
{ id: "2", query: "统计各渠道用户转化率", time: "1小时前", starred: false },
|
||||
{ id: "3", query: "获取VIP用户的平均消费金额", time: "2小时前", starred: true },
|
||||
{ id: "4", query: "按年龄段统计用户数量", time: "昨天", starred: false },
|
||||
{ id: "5", query: "查询高活跃度但低消费的用户群体", time: "昨天", starred: false },
|
||||
]
|
||||
|
||||
const handleExecuteQuery = () => {
|
||||
if (!query.trim()) return
|
||||
setIsLoading(true)
|
||||
setShowResult(false)
|
||||
|
||||
// 模拟AI解析和查询
|
||||
setTimeout(() => {
|
||||
setQueryResult({
|
||||
sql: `SELECT u.id, u.name, u.phone, SUM(t.amount) as total_spending
|
||||
FROM users u
|
||||
JOIN transactions t ON u.id = t.user_id
|
||||
WHERE t.created_at >= DATE_SUB(NOW(), INTERVAL 30 DAY)
|
||||
GROUP BY u.id, u.name, u.phone
|
||||
HAVING total_spending > 10000
|
||||
ORDER BY total_spending DESC
|
||||
LIMIT 100`,
|
||||
data: [
|
||||
{ id: "U001", name: "张三", phone: "138****1234", total_spending: 25680 },
|
||||
{ id: "U002", name: "李四", phone: "139****5678", total_spending: 18920 },
|
||||
{ id: "U003", name: "王五", phone: "137****9012", total_spending: 15340 },
|
||||
{ id: "U004", name: "赵六", phone: "136****3456", total_spending: 13280 },
|
||||
{ id: "U005", name: "钱七", phone: "135****7890", total_spending: 12150 },
|
||||
],
|
||||
totalCount: 823,
|
||||
executionTime: "0.23s",
|
||||
explanation: "我将您的查询解析为:从用户表和交易表中联合查询,筛选最近30天内消费总额超过10000元的用户,按消费金额降序排列。",
|
||||
})
|
||||
setShowResult(true)
|
||||
setIsLoading(false)
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
const handleExampleClick = (exampleQuery: string) => {
|
||||
setQuery(exampleQuery)
|
||||
}
|
||||
|
||||
const handleHistoryClick = (historyQuery: string) => {
|
||||
setQuery(historyQuery)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50/30 to-purple-50/20">
|
||||
<div className="p-6 space-y-6">
|
||||
{/* 顶部标题 */}
|
||||
<div className="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">自然语言查询</h1>
|
||||
<p className="text-sm text-gray-500 mt-1">用自然语言描述您的数据需求,AI自动转换为SQL并执行查询</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 lg:grid-cols-4 gap-6">
|
||||
{/* 左侧:历史记录 */}
|
||||
<div className="lg:col-span-1">
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardHeader className="pb-2">
|
||||
<CardTitle className="text-base font-semibold flex items-center gap-2">
|
||||
<History className="h-4 w-4" />
|
||||
历史查询
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-2">
|
||||
{historyQueries.map((item) => (
|
||||
<button
|
||||
key={item.id}
|
||||
onClick={() => handleHistoryClick(item.query)}
|
||||
className="w-full text-left p-3 rounded-lg hover:bg-gray-50 transition-colors group"
|
||||
>
|
||||
<div className="flex items-start justify-between">
|
||||
<p className="text-sm text-gray-700 line-clamp-2 group-hover:text-blue-600">
|
||||
{item.query}
|
||||
</p>
|
||||
{item.starred ? (
|
||||
<Star className="h-4 w-4 text-yellow-500 shrink-0" />
|
||||
) : (
|
||||
<StarOff className="h-4 w-4 text-gray-300 shrink-0 opacity-0 group-hover:opacity-100" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-1 mt-1 text-xs text-gray-400">
|
||||
<Clock className="h-3 w-3" />
|
||||
{item.time}
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* 右侧:查询区域 */}
|
||||
<div className="lg:col-span-3 space-y-6">
|
||||
{/* 查询输入 */}
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-6">
|
||||
<div className="space-y-4">
|
||||
<div className="relative">
|
||||
<Search className="absolute left-4 top-1/2 -translate-y-1/2 h-5 w-5 text-gray-400" />
|
||||
<Input
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
onKeyDown={(e) => e.key === "Enter" && handleExecuteQuery()}
|
||||
placeholder="输入您的查询,例如:查找最近30天消费超过1万元的用户"
|
||||
className="pl-12 py-6 text-lg bg-white"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-sm text-gray-500">示例查询:</span>
|
||||
{exampleQueries.map((example, index) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => handleExampleClick(example.query)}
|
||||
className="text-sm text-blue-600 hover:text-blue-700 hover:underline"
|
||||
>
|
||||
{example.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<Button onClick={handleExecuteQuery} disabled={isLoading || !query.trim()}>
|
||||
{isLoading ? (
|
||||
<>
|
||||
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
|
||||
解析中...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Play className="h-4 w-4 mr-2" />
|
||||
执行查询
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 查询结果 */}
|
||||
{showResult && queryResult && (
|
||||
<div className="space-y-4">
|
||||
{/* AI解释 */}
|
||||
<Card className="bg-blue-50 border-blue-200">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="p-2 rounded-lg bg-blue-100">
|
||||
<Database className="h-4 w-4 text-blue-600" />
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
<p className="text-sm text-blue-800">{queryResult.explanation}</p>
|
||||
<div className="flex items-center gap-4 mt-2 text-xs text-blue-600">
|
||||
<span>执行时间:{queryResult.executionTime}</span>
|
||||
<span>结果数量:{queryResult.totalCount} 条</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* SQL和结果 */}
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardHeader className="pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
||||
<TabsList className="bg-gray-100">
|
||||
<TabsTrigger value="query">
|
||||
<Table className="h-4 w-4 mr-1" />
|
||||
查询结果
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="sql">
|
||||
<Database className="h-4 w-4 mr-1" />
|
||||
SQL语句
|
||||
</TabsTrigger>
|
||||
<TabsTrigger value="chart">
|
||||
<BarChart3 className="h-4 w-4 mr-1" />
|
||||
图表
|
||||
</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="outline" size="sm">
|
||||
<Copy className="h-4 w-4 mr-1" />
|
||||
复制
|
||||
</Button>
|
||||
<Button variant="outline" size="sm">
|
||||
<Download className="h-4 w-4 mr-1" />
|
||||
导出
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<TabsContent value="query" className="mt-0">
|
||||
<div className="overflow-x-auto">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b bg-gray-50">
|
||||
<th className="text-left py-3 px-4 font-medium">用户ID</th>
|
||||
<th className="text-left py-3 px-4 font-medium">姓名</th>
|
||||
<th className="text-left py-3 px-4 font-medium">手机号</th>
|
||||
<th className="text-right py-3 px-4 font-medium">消费总额</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{queryResult.data.map((row: any, index: number) => (
|
||||
<tr key={index} className="border-b border-gray-100 hover:bg-gray-50">
|
||||
<td className="py-3 px-4 font-mono text-gray-600">{row.id}</td>
|
||||
<td className="py-3 px-4">{row.name}</td>
|
||||
<td className="py-3 px-4 text-gray-500">{row.phone}</td>
|
||||
<td className="py-3 px-4 text-right text-green-600 font-semibold">
|
||||
¥{row.total_spending.toLocaleString()}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="flex items-center justify-between mt-4 pt-4 border-t">
|
||||
<span className="text-sm text-gray-500">
|
||||
显示 1-{queryResult.data.length} 条,共 {queryResult.totalCount} 条
|
||||
</span>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="outline" size="sm" disabled>
|
||||
上一页
|
||||
</Button>
|
||||
<Button variant="outline" size="sm">
|
||||
下一页
|
||||
<ChevronRight className="h-4 w-4 ml-1" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
<TabsContent value="sql" className="mt-0">
|
||||
<div className="bg-gray-900 rounded-lg p-4 font-mono text-sm text-gray-100 overflow-x-auto">
|
||||
<pre className="whitespace-pre-wrap">{queryResult.sql}</pre>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-4">
|
||||
<Button variant="outline" size="sm">
|
||||
<Copy className="h-4 w-4 mr-1" />
|
||||
复制SQL
|
||||
</Button>
|
||||
<Button variant="outline" size="sm">
|
||||
在SQL编辑器中打开
|
||||
</Button>
|
||||
</div>
|
||||
</TabsContent>
|
||||
<TabsContent value="chart" className="mt-0">
|
||||
<div className="h-64 flex items-center justify-center bg-gray-50 rounded-lg">
|
||||
<div className="text-center text-gray-500">
|
||||
<BarChart3 className="h-12 w-12 mx-auto mb-2 text-gray-300" />
|
||||
<p>图表视图即将支持</p>
|
||||
</div>
|
||||
</div>
|
||||
</TabsContent>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 无结果时的提示 */}
|
||||
{!showResult && !isLoading && (
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-12 text-center">
|
||||
<Search className="h-12 w-12 mx-auto mb-4 text-gray-300" />
|
||||
<h3 className="text-lg font-medium text-gray-900 mb-2">开始您的数据探索</h3>
|
||||
<p className="text-sm text-gray-500 mb-6">
|
||||
输入自然语言描述您想要查询的数据,AI将自动转换为SQL并执行
|
||||
</p>
|
||||
<div className="flex flex-wrap justify-center gap-2">
|
||||
{exampleQueries.map((example, index) => (
|
||||
<button
|
||||
key={index}
|
||||
onClick={() => handleExampleClick(example.query)}
|
||||
className="px-4 py-2 rounded-full bg-gray-100 text-sm text-gray-600 hover:bg-gray-200 transition-colors"
|
||||
>
|
||||
{example.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
550
app/ai-agent/smart-tag/page.tsx
Normal file
550
app/ai-agent/smart-tag/page.tsx
Normal file
@@ -0,0 +1,550 @@
|
||||
"use client"
|
||||
|
||||
import { useState } from "react"
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog"
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select"
|
||||
import {
|
||||
Tags,
|
||||
Plus,
|
||||
Search,
|
||||
Play,
|
||||
Pause,
|
||||
CheckCircle2,
|
||||
Clock,
|
||||
AlertCircle,
|
||||
Settings,
|
||||
FileText,
|
||||
RefreshCw,
|
||||
Sparkles,
|
||||
ThumbsUp,
|
||||
ThumbsDown,
|
||||
Eye,
|
||||
MoreVertical,
|
||||
Bot,
|
||||
Zap,
|
||||
} from "lucide-react"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
|
||||
// 第四部分:AI Agent - AI打标
|
||||
export default function AISmartTagPage() {
|
||||
const [activeTab, setActiveTab] = useState("tasks")
|
||||
const [searchQuery, setSearchQuery] = useState("")
|
||||
const [showCreateDialog, setShowCreateDialog] = useState(false)
|
||||
const [showReviewDialog, setShowReviewDialog] = useState(false)
|
||||
const [selectedTask, setSelectedTask] = useState<any>(null)
|
||||
const [selectedItems, setSelectedItems] = useState<string[]>([])
|
||||
|
||||
// AI打标任务列表
|
||||
const tagTasks = [
|
||||
{
|
||||
id: "1",
|
||||
name: "高价值用户识别",
|
||||
prompt: "根据用户的消费金额、频次、最近活跃时间,识别高价值用户",
|
||||
status: "completed",
|
||||
targetTag: "高价值用户",
|
||||
dataSource: "用户表+交易表",
|
||||
affectedCount: 45678,
|
||||
confidence: 0.92,
|
||||
createdAt: "2026-01-30 10:00",
|
||||
completedAt: "2026-01-30 10:15",
|
||||
needReview: false,
|
||||
},
|
||||
{
|
||||
id: "2",
|
||||
name: "流失风险预警",
|
||||
prompt: "识别最近30天未登录且之前活跃的用户,标记为流失风险",
|
||||
status: "pending_review",
|
||||
targetTag: "流失风险",
|
||||
dataSource: "用户行为表",
|
||||
affectedCount: 12456,
|
||||
confidence: 0.87,
|
||||
createdAt: "2026-01-31 09:00",
|
||||
completedAt: "2026-01-31 09:12",
|
||||
needReview: true,
|
||||
reviewStats: { approved: 0, rejected: 0, pending: 12456 },
|
||||
},
|
||||
{
|
||||
id: "3",
|
||||
name: "兴趣标签推断",
|
||||
prompt: "根据用户浏览和购买记录,推断用户兴趣偏好",
|
||||
status: "running",
|
||||
targetTag: "兴趣标签",
|
||||
dataSource: "行为日志表",
|
||||
affectedCount: 0,
|
||||
confidence: 0,
|
||||
createdAt: "2026-01-31 14:00",
|
||||
progress: 67,
|
||||
},
|
||||
{
|
||||
id: "4",
|
||||
name: "地域特征识别",
|
||||
prompt: "根据IP地址和收货地址,识别用户地域特征",
|
||||
status: "failed",
|
||||
targetTag: "地域标签",
|
||||
dataSource: "用户表+订单表",
|
||||
affectedCount: 0,
|
||||
confidence: 0,
|
||||
createdAt: "2026-01-29 15:00",
|
||||
error: "数据源连接超时",
|
||||
},
|
||||
]
|
||||
|
||||
// 待审核的标签结果
|
||||
const pendingReviews = [
|
||||
{ id: "r1", userId: "U10001", userName: "张三", currentTags: ["活跃用户"], newTag: "流失风险", confidence: 0.92, reason: "30天未登录" },
|
||||
{ id: "r2", userId: "U10002", userName: "李四", currentTags: ["普通用户"], newTag: "流失风险", confidence: 0.88, reason: "25天未登录" },
|
||||
{ id: "r3", userId: "U10003", userName: "王五", currentTags: ["新用户"], newTag: "流失风险", confidence: 0.75, reason: "注册后未活跃" },
|
||||
{ id: "r4", userId: "U10004", userName: "赵六", currentTags: ["VIP用户"], newTag: "流失风险", confidence: 0.65, reason: "消费频次下降" },
|
||||
{ id: "r5", userId: "U10005", userName: "钱七", currentTags: ["活跃用户"], newTag: "流失风险", confidence: 0.58, reason: "互动减少" },
|
||||
]
|
||||
|
||||
const getStatusBadge = (status: string) => {
|
||||
switch (status) {
|
||||
case "completed":
|
||||
return <Badge className="bg-green-100 text-green-700">已完成</Badge>
|
||||
case "running":
|
||||
return <Badge className="bg-blue-100 text-blue-700">执行中</Badge>
|
||||
case "pending_review":
|
||||
return <Badge className="bg-yellow-100 text-yellow-700">待审核</Badge>
|
||||
case "failed":
|
||||
return <Badge className="bg-red-100 text-red-700">失败</Badge>
|
||||
default:
|
||||
return <Badge variant="secondary">未知</Badge>
|
||||
}
|
||||
}
|
||||
|
||||
const getConfidenceColor = (confidence: number) => {
|
||||
if (confidence >= 0.8) return "text-green-600"
|
||||
if (confidence >= 0.6) return "text-yellow-600"
|
||||
return "text-red-600"
|
||||
}
|
||||
|
||||
const handleOpenReview = (task: any) => {
|
||||
setSelectedTask(task)
|
||||
setShowReviewDialog(true)
|
||||
}
|
||||
|
||||
const handleBatchApprove = () => {
|
||||
console.log("批量通过", selectedItems)
|
||||
setSelectedItems([])
|
||||
}
|
||||
|
||||
const handleBatchReject = () => {
|
||||
console.log("批量拒绝", selectedItems)
|
||||
setSelectedItems([])
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gradient-to-br from-slate-50 via-blue-50/30 to-purple-50/20">
|
||||
<div className="p-6 space-y-6">
|
||||
{/* 顶部标题 */}
|
||||
<div className="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold text-gray-900">AI智能打标</h1>
|
||||
<p className="text-sm text-gray-500 mt-1">使用AI自动识别用户特征并打标签,支持人工审核确认</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<Button onClick={() => setShowCreateDialog(true)}>
|
||||
<Plus className="h-4 w-4 mr-2" />
|
||||
创建打标任务
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 统计卡片 */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm text-gray-500">任务总数</p>
|
||||
<p className="text-2xl font-bold text-gray-900">{tagTasks.length}</p>
|
||||
</div>
|
||||
<Bot className="h-8 w-8 text-purple-500" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm text-gray-500">待审核</p>
|
||||
<p className="text-2xl font-bold text-yellow-600">
|
||||
{tagTasks.filter((t) => t.status === "pending_review").length}
|
||||
</p>
|
||||
</div>
|
||||
<Clock className="h-8 w-8 text-yellow-500" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm text-gray-500">已打标用户</p>
|
||||
<p className="text-2xl font-bold text-green-600">58,134</p>
|
||||
</div>
|
||||
<Tags className="h-8 w-8 text-green-500" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
<p className="text-sm text-gray-500">平均置信度</p>
|
||||
<p className="text-2xl font-bold text-blue-600">87.5%</p>
|
||||
</div>
|
||||
<Sparkles className="h-8 w-8 text-blue-500" />
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
{/* Tabs */}
|
||||
<Tabs value={activeTab} onValueChange={setActiveTab}>
|
||||
<div className="flex items-center justify-between">
|
||||
<TabsList className="bg-white">
|
||||
<TabsTrigger value="tasks">打标任务</TabsTrigger>
|
||||
<TabsTrigger value="review">审核中心</TabsTrigger>
|
||||
<TabsTrigger value="history">历史记录</TabsTrigger>
|
||||
</TabsList>
|
||||
<div className="relative">
|
||||
<Search className="absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400" />
|
||||
<Input
|
||||
placeholder="搜索任务..."
|
||||
value={searchQuery}
|
||||
onChange={(e) => setSearchQuery(e.target.value)}
|
||||
className="pl-9 w-64 bg-white"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<TabsContent value="tasks" className="mt-4">
|
||||
<div className="space-y-4">
|
||||
{tagTasks.map((task) => (
|
||||
<Card key={task.id} className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-5">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-3 mb-2">
|
||||
<h3 className="font-semibold text-gray-900">{task.name}</h3>
|
||||
{getStatusBadge(task.status)}
|
||||
<Badge variant="outline">{task.targetTag}</Badge>
|
||||
</div>
|
||||
<p className="text-sm text-gray-500 mb-3">{task.prompt}</p>
|
||||
<div className="flex items-center gap-6 text-sm text-gray-500">
|
||||
<span>数据源:{task.dataSource}</span>
|
||||
{task.affectedCount > 0 && (
|
||||
<span>影响用户:{task.affectedCount.toLocaleString()}</span>
|
||||
)}
|
||||
{task.confidence > 0 && (
|
||||
<span className={getConfidenceColor(task.confidence)}>
|
||||
置信度:{(task.confidence * 100).toFixed(0)}%
|
||||
</span>
|
||||
)}
|
||||
<span>创建时间:{task.createdAt}</span>
|
||||
</div>
|
||||
{task.status === "running" && (
|
||||
<div className="mt-3">
|
||||
<div className="flex items-center justify-between text-sm mb-1">
|
||||
<span className="text-gray-500">执行进度</span>
|
||||
<span className="text-blue-600">{task.progress}%</span>
|
||||
</div>
|
||||
<div className="w-full h-2 bg-gray-100 rounded-full overflow-hidden">
|
||||
<div
|
||||
className="h-full bg-blue-500 rounded-full transition-all"
|
||||
style={{ width: `${task.progress}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{task.status === "failed" && (
|
||||
<div className="mt-3 p-3 bg-red-50 rounded-lg text-sm text-red-600">
|
||||
错误信息:{task.error}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
{task.status === "pending_review" && (
|
||||
<Button size="sm" onClick={() => handleOpenReview(task)}>
|
||||
<Eye className="h-4 w-4 mr-1" />
|
||||
审核
|
||||
</Button>
|
||||
)}
|
||||
{task.status === "failed" && (
|
||||
<Button size="sm" variant="outline">
|
||||
<RefreshCw className="h-4 w-4 mr-1" />
|
||||
重试
|
||||
</Button>
|
||||
)}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem>
|
||||
<FileText className="h-4 w-4 mr-2" />
|
||||
查看日志
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem>
|
||||
<Settings className="h-4 w-4 mr-2" />
|
||||
编辑配置
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="review" className="mt-4">
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardHeader className="pb-2">
|
||||
<div className="flex items-center justify-between">
|
||||
<CardTitle className="text-base font-semibold">待审核标签(共 {pendingReviews.length} 条)</CardTitle>
|
||||
<div className="flex items-center gap-2">
|
||||
{selectedItems.length > 0 && (
|
||||
<>
|
||||
<span className="text-sm text-gray-500">已选 {selectedItems.length} 项</span>
|
||||
<Button size="sm" onClick={handleBatchApprove}>
|
||||
<ThumbsUp className="h-4 w-4 mr-1" />
|
||||
批量通过
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" onClick={handleBatchReject}>
|
||||
<ThumbsDown className="h-4 w-4 mr-1" />
|
||||
批量拒绝
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="space-y-3">
|
||||
{pendingReviews.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className={`flex items-center justify-between p-4 rounded-lg border transition-colors ${
|
||||
selectedItems.includes(item.id) ? "bg-blue-50 border-blue-200" : "bg-gray-50 border-transparent"
|
||||
}`}
|
||||
>
|
||||
<div className="flex items-center gap-4">
|
||||
<Checkbox
|
||||
checked={selectedItems.includes(item.id)}
|
||||
onCheckedChange={(checked) => {
|
||||
if (checked) {
|
||||
setSelectedItems([...selectedItems, item.id])
|
||||
} else {
|
||||
setSelectedItems(selectedItems.filter((id) => id !== item.id))
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<div>
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-medium text-gray-900">{item.userName}</span>
|
||||
<span className="text-sm text-gray-500">({item.userId})</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<span className="text-sm text-gray-500">现有标签:</span>
|
||||
{item.currentTags.map((tag, index) => (
|
||||
<Badge key={index} variant="secondary" className="text-xs">
|
||||
{tag}
|
||||
</Badge>
|
||||
))}
|
||||
<span className="text-gray-400">→</span>
|
||||
<Badge className="bg-yellow-100 text-yellow-700 text-xs">
|
||||
+ {item.newTag}
|
||||
</Badge>
|
||||
</div>
|
||||
<p className="text-xs text-gray-400 mt-1">原因:{item.reason}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
<div className="text-right">
|
||||
<p className="text-sm text-gray-500">置信度</p>
|
||||
<p className={`font-semibold ${getConfidenceColor(item.confidence)}`}>
|
||||
{(item.confidence * 100).toFixed(0)}%
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button size="sm" variant="outline" className="text-green-600 border-green-200 hover:bg-green-50 bg-transparent">
|
||||
<ThumbsUp className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" className="text-red-600 border-red-200 hover:bg-red-50 bg-transparent">
|
||||
<ThumbsDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
|
||||
<TabsContent value="history" className="mt-4">
|
||||
<Card className="bg-white/80 backdrop-blur border-0 shadow-sm">
|
||||
<CardContent className="p-6 text-center text-gray-500">
|
||||
历史记录将显示所有已完成的打标任务及其审核结果
|
||||
</CardContent>
|
||||
</Card>
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
{/* 创建任务弹窗 */}
|
||||
<Dialog open={showCreateDialog} onOpenChange={setShowCreateDialog}>
|
||||
<DialogContent className="max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>创建AI打标任务</DialogTitle>
|
||||
<DialogDescription>配置AI打标规则,AI将自动识别符合条件的用户并打标签</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="space-y-4 py-4">
|
||||
<div className="space-y-2">
|
||||
<Label>任务名称</Label>
|
||||
<Input placeholder="例如:高价值用户识别" />
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>AI提示词</Label>
|
||||
<Textarea
|
||||
placeholder="描述你希望AI如何识别用户,例如:根据用户的消费金额、频次、最近活跃时间,识别高价值用户"
|
||||
rows={4}
|
||||
/>
|
||||
<p className="text-xs text-gray-400">
|
||||
提示:清晰描述识别条件,AI将自动分析数据并打标签
|
||||
</p>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<div className="space-y-2">
|
||||
<Label>目标标签</Label>
|
||||
<Select>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="选择或创建标签" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="high-value">高价值用户</SelectItem>
|
||||
<SelectItem value="churn-risk">流失风险</SelectItem>
|
||||
<SelectItem value="new-user">新用户</SelectItem>
|
||||
<SelectItem value="vip">VIP用户</SelectItem>
|
||||
<SelectItem value="custom">创建新标签...</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>数据源</Label>
|
||||
<Select>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="选择数据源" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="users">用户表</SelectItem>
|
||||
<SelectItem value="transactions">交易表</SelectItem>
|
||||
<SelectItem value="behaviors">行为表</SelectItem>
|
||||
<SelectItem value="all">全部数据</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>置信度阈值</Label>
|
||||
<div className="flex items-center gap-4">
|
||||
<Input type="number" defaultValue="0.7" min="0" max="1" step="0.1" className="w-24" />
|
||||
<span className="text-sm text-gray-500">低于此阈值的结果需要人工审核</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox id="auto-approve" />
|
||||
<Label htmlFor="auto-approve" className="text-sm font-normal">
|
||||
高置信度结果自动通过(置信度 ≥ 90%)
|
||||
</Label>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setShowCreateDialog(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={() => setShowCreateDialog(false)}>
|
||||
<Zap className="h-4 w-4 mr-2" />
|
||||
开始执行
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* 审核弹窗 */}
|
||||
<Dialog open={showReviewDialog} onOpenChange={setShowReviewDialog}>
|
||||
<DialogContent className="max-w-4xl max-h-[80vh]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>审核 - {selectedTask?.name}</DialogTitle>
|
||||
<DialogDescription>
|
||||
共 {selectedTask?.affectedCount.toLocaleString()} 条待审核,请确认AI打标结果
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4 max-h-96 overflow-y-auto">
|
||||
<div className="space-y-3">
|
||||
{pendingReviews.map((item) => (
|
||||
<div key={item.id} className="flex items-center justify-between p-3 bg-gray-50 rounded-lg">
|
||||
<div>
|
||||
<span className="font-medium">{item.userName}</span>
|
||||
<span className="text-gray-500 ml-2">({item.userId})</span>
|
||||
<p className="text-sm text-gray-500 mt-1">{item.reason}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className={getConfidenceColor(item.confidence)}>
|
||||
{(item.confidence * 100).toFixed(0)}%
|
||||
</span>
|
||||
<Button size="sm" variant="outline" className="text-green-600 bg-transparent">
|
||||
<ThumbsUp className="h-4 w-4" />
|
||||
</Button>
|
||||
<Button size="sm" variant="outline" className="text-red-600 bg-transparent">
|
||||
<ThumbsDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setShowReviewDialog(false)}>
|
||||
关闭
|
||||
</Button>
|
||||
<Button variant="outline">全部拒绝</Button>
|
||||
<Button>全部通过</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user