"use client" import { Card } from "@/components/ui/card" import { Button } from "@/components/ui/button" import { Bell, Smartphone, Users, Activity } from "lucide-react" import { Progress } from "@/components/ui/progress" import { useRouter } from "next/navigation" import Link from "next/link" import { useState, useEffect, useRef } from "react" // 导入Chart.js import { Chart, registerables } from "chart.js" Chart.register(...registerables) export default function Home() { const router = useRouter() const chartRef = useRef(null) const chartInstance = useRef(null) // 统一设备数据 const [stats, setStats] = useState({ totalDevices: 42, onlineDevices: 35, totalWechatAccounts: 42, onlineWechatAccounts: 35, }) useEffect(() => { // 模拟API调用 const fetchStats = async () => { // 这里应该是实际的API调用 const mockStats = { totalDevices: 42, onlineDevices: 35, totalWechatAccounts: 42, onlineWechatAccounts: 35, } setStats(mockStats) } fetchStats() }, []) // 使用Chart.js创建图表 useEffect(() => { if (chartRef.current) { // 如果已经有图表实例,先销毁它 if (chartInstance.current) { chartInstance.current.destroy() } const ctx = chartRef.current.getContext("2d") // 创建新的图表实例 chartInstance.current = new Chart(ctx, { type: "line", data: { labels: ["周一", "周二", "周三", "周四", "周五", "周六", "周日"], datasets: [ { label: "获客数量", data: [120, 150, 180, 200, 230, 210, 190], backgroundColor: "rgba(59, 130, 246, 0.2)", borderColor: "rgba(59, 130, 246, 1)", borderWidth: 2, tension: 0.3, pointRadius: 4, pointBackgroundColor: "rgba(59, 130, 246, 1)", pointHoverRadius: 6, }, ], }, options: { responsive: true, maintainAspectRatio: false, plugins: { legend: { display: false, }, tooltip: { backgroundColor: "rgba(255, 255, 255, 0.9)", titleColor: "#333", bodyColor: "#666", borderColor: "#ddd", borderWidth: 1, padding: 10, displayColors: false, callbacks: { label: (context) => `获客数量: ${context.parsed.y}`, }, }, }, scales: { x: { grid: { display: false, }, }, y: { beginAtZero: true, grid: { color: "rgba(0, 0, 0, 0.05)", }, }, }, }, }) } // 组件卸载时清理图表实例 return () => { if (chartInstance.current) { chartInstance.current.destroy() } } }, []) const handleDevicesClick = () => { router.push("/devices") } const handleWechatClick = () => { router.push("/wechat-accounts") } const scenarioFeatures = [ { id: "douyin", name: "抖音获客", icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-QR8ManuDplYTySUJsY4mymiZkDYnQ9.png", color: "bg-blue-100 text-blue-600", value: 156, growth: 12, }, { id: "xiaohongshu", name: "小红书获客", icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-yvnMxpoBUzcvEkr8DfvHgPHEo1kmQ3.png", color: "bg-red-100 text-red-600", value: 89, growth: 8, }, { id: "gongzhonghao", name: "公众号获客", icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-Gsg0CMf5tsZb41mioszdjqU1WmsRxW.png", color: "bg-green-100 text-green-600", value: 234, growth: 15, }, { id: "haibao", name: "海报获客", icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-x92XJgXy4MI7moNYlA1EAes2FqDxMH.png", color: "bg-orange-100 text-orange-600", value: 167, growth: 10, }, ] return (