chore: 以本地为准,上传全部并替换 GitHub

This commit is contained in:
卡若
2026-02-03 11:36:53 +08:00
parent 1219166526
commit b404bf546e
131 changed files with 37618 additions and 3930 deletions

View File

@@ -75,73 +75,56 @@ export default function AIAgentChatPage() {
setInputValue("")
setIsLoading(true)
// 模拟AI响应
setTimeout(() => {
let response: any = {
try {
// 调用真实的AI Chat API
const response = await fetch("/api/ai-chat", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message: userMessage.content })
})
const data = await response.json()
let aiResponse: 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%,创历史新低",
],
if (data.success && data.response) {
aiResponse.content = data.response.content
// 如果有数据结果,添加表格展示
if (data.response.data && data.response.data.length > 0) {
aiResponse.taskType = "NLQ"
aiResponse.result = {
type: "table",
title: "查询结果",
data: data.response.data.slice(0, 5).map((item: any, idx: number) => ({
id: idx + 1,
name: item.name || item. || "-",
phone: item.phone_masked || item.phone || "-",
level: item.user_level || item.traffic_pool?.pool_name || "-",
score: item.user_evaluation_score || item.rfm_composite_score || "-",
})),
total: data.response.data.length,
}
}
} else {
response.content = "我理解您的需求。请问您想要:\n1. 查询用户数据\n2. AI打标签\n3. 数据清洗\n4. 生成报告\n\n请选择或详细描述您的需求。"
aiResponse.content = `⚠️ ${data.error || "查询失败,请重试"}`
}
setMessages((prev) => [...prev, response])
setMessages((prev) => [...prev, aiResponse])
} catch (error: any) {
setMessages((prev) => [...prev, {
id: (Date.now() + 1).toString(),
role: "assistant",
content: `⚠️ 网络错误: ${error.message}`,
timestamp: new Date(),
}])
} finally {
setIsLoading(false)
}, 1500)
}
}
const handleQuickCommand = (command: string) => {