import React, { useEffect, useRef } from 'react'; import { useNavigate } from 'react-router-dom'; import { Bell, Smartphone, Users, Activity } from 'lucide-react'; import Chart from 'chart.js/auto'; import Layout from '@/components/Layout'; import BottomNav from '@/components/BottomNav'; import '@/components/Layout.css'; // 模拟数据 const stats = { totalDevices: 12, totalWechatAccounts: 8, onlineWechatAccounts: 6, }; const scenarioFeatures = [ { id: "3", name: "抖音获客", value: 156, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-QR8ManuDplYTySUJsY4mymiZkDYnQ9.png", color: "bg-red-100", }, { id: "4", name: "小红书获客", value: 89, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-yvnMxpoBUzcvEkr8DfvHgPHEo1kmQ3.png", color: "bg-pink-100", }, { id: "6", name: "公众号获客", value: 234, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-Gsg0CMf5tsZb41mioszdjqU1WmsRxW.png", color: "bg-green-100", }, { id: "1", name: "海报获客", value: 167, icon: "https://hebbkx1anhila5yf.public.blob.vercel-storage.com/image-x92XJgXy4MI7moNYlA1EAes2FqDxMH.png", color: "bg-blue-100", }, ]; export default function Home() { const navigate = useNavigate(); const chartRef = useRef(null); const chartInstance = useRef(null); const handleDevicesClick = () => { navigate('/devices'); }; const handleWechatClick = () => { navigate('/wechat-accounts'); }; useEffect(() => { if (!chartRef.current) return; // 销毁旧实例 if (chartInstance.current) { chartInstance.current.destroy(); chartInstance.current = null; } const ctx = chartRef.current.getContext('2d'); if (ctx) { chartInstance.current = new Chart(ctx, { type: 'line', data: { labels: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], datasets: [ { label: '获客数量', data: [12, 19, 15, 25, 22, 30, 28], 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: any) => `获客数量: ${context.parsed.y}`, }, }, }, scales: { x: { grid: { display: false, }, ticks: { font: { size: 12, // 0.75rem }, }, }, y: { beginAtZero: true, grid: { color: 'rgba(0, 0, 0, 0.05)', }, ticks: { font: { size: 12, // 0.75rem }, }, }, }, }, }); } // 卸载时销毁 return () => { if (chartInstance.current) { chartInstance.current.destroy(); chartInstance.current = null; } }; }, []); return (

存客宝

} footer={} >
{/* 统计卡片 */}
设备数量
{stats.totalDevices}
微信号数量
{stats.totalWechatAccounts}
在线微信号
{stats.onlineWechatAccounts}
{/* 场景获客统计 */}

场景获客统计

{scenarioFeatures .sort((a, b) => b.value - a.value) .map((scenario) => (
navigate(`/scenarios/${scenario.id}?name=${encodeURIComponent(scenario.name)}`)} >
{scenario.name}
{scenario.value}
{scenario.name}
))}
{/* 每日获客趋势 */}

每日获客趋势

); }