feat:存一波
This commit is contained in:
2
nkebao/package-lock.json
generated
2
nkebao/package-lock.json
generated
@@ -50,7 +50,7 @@
|
||||
"@types/react-dom": "^18.2.17",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"axios": "^1.6.0",
|
||||
"chart.js": "latest",
|
||||
"chart.js": "^4.5.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "1.0.4",
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
"@types/react-dom": "^18.2.17",
|
||||
"autoprefixer": "^10.4.20",
|
||||
"axios": "^1.6.0",
|
||||
"chart.js": "latest",
|
||||
"chart.js": "^4.5.0",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "1.0.4",
|
||||
|
||||
@@ -13,8 +13,8 @@ export default function BottomNav() {
|
||||
const location = useLocation();
|
||||
|
||||
return (
|
||||
<nav className="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 z-50">
|
||||
<div className="w-full mx-auto flex justify-around">
|
||||
<nav className="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-200 z-50 h-16">
|
||||
<div className="w-full h-full mx-auto flex justify-around items-center">
|
||||
{navItems.map((item) => {
|
||||
const IconComponent = item.icon;
|
||||
const isActive = location.pathname === item.href;
|
||||
@@ -23,7 +23,7 @@ export default function BottomNav() {
|
||||
<Link
|
||||
key={item.href}
|
||||
to={item.href}
|
||||
className={`flex flex-col items-center py-2 px-3 ${
|
||||
className={`flex flex-col items-center justify-center py-2 px-3 h-full ${
|
||||
isActive ? "text-blue-500" : "text-gray-500"
|
||||
}`}
|
||||
>
|
||||
|
||||
@@ -42,7 +42,7 @@ export default function LayoutWrapper({ children }: LayoutWrapperProps) {
|
||||
// 其他页面显示底部导航
|
||||
return (
|
||||
<div className="flex flex-col h-screen">
|
||||
<div className="flex-1 overflow-hidden">
|
||||
<div className="flex-1 overflow-y-auto">
|
||||
{children}
|
||||
</div>
|
||||
{shouldShowBottomNav && <BottomNav />}
|
||||
|
||||
@@ -43,6 +43,7 @@ const scenarioFeatures = [
|
||||
export default function Home() {
|
||||
const navigate = useNavigate();
|
||||
const chartRef = useRef<HTMLCanvasElement>(null);
|
||||
const chartInstance = useRef<any>(null);
|
||||
|
||||
const handleDevicesClick = () => {
|
||||
navigate('/devices');
|
||||
@@ -54,44 +55,83 @@ export default function Home() {
|
||||
|
||||
useEffect(() => {
|
||||
if (chartRef.current) {
|
||||
// 如果已经有图表实例,先销毁它
|
||||
if (chartInstance.current) {
|
||||
chartInstance.current.destroy();
|
||||
}
|
||||
|
||||
const ctx = chartRef.current.getContext('2d');
|
||||
if (ctx) {
|
||||
// 清除之前的图表
|
||||
ctx.clearRect(0, 0, chartRef.current.width, chartRef.current.height);
|
||||
|
||||
// 绘制简单的柱状图
|
||||
const data = [12, 19, 15, 25, 22, 30, 28];
|
||||
const labels = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
|
||||
const barWidth = 30;
|
||||
const barSpacing = 20;
|
||||
const startX = 50;
|
||||
const startY = 200;
|
||||
|
||||
ctx.fillStyle = '#3B82F6';
|
||||
data.forEach((value, index) => {
|
||||
const x = startX + index * (barWidth + barSpacing);
|
||||
const height = (value / 30) * 150;
|
||||
const y = startY - height;
|
||||
|
||||
ctx.fillRect(x, y, barWidth, height);
|
||||
|
||||
// 绘制数值
|
||||
ctx.fillStyle = '#374151';
|
||||
ctx.font = '12px Arial';
|
||||
ctx.textAlign = 'center';
|
||||
ctx.fillText(value.toString(), x + barWidth / 2, y - 5);
|
||||
|
||||
// 绘制标签
|
||||
ctx.fillText(labels[index], x + barWidth / 2, startY + 20);
|
||||
|
||||
ctx.fillStyle = '#3B82F6';
|
||||
// 动态导入Chart.js
|
||||
import('chart.js/auto').then(({ Chart }) => {
|
||||
// 创建新的图表实例
|
||||
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,
|
||||
},
|
||||
},
|
||||
y: {
|
||||
beginAtZero: true,
|
||||
grid: {
|
||||
color: 'rgba(0, 0, 0, 0.05)',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 组件卸载时清理图表实例
|
||||
return () => {
|
||||
if (chartInstance.current) {
|
||||
chartInstance.current.destroy();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex-1 overflow-y-auto pb-20 bg-gray-50">
|
||||
<div className="flex-1 overflow-y-auto pb-24 bg-gray-50">
|
||||
<header className="sticky top-0 z-10 bg-white border-b">
|
||||
<div className="flex justify-between items-center p-4">
|
||||
<h1 className="text-xl font-semibold text-blue-600">存客宝</h1>
|
||||
|
||||
Reference in New Issue
Block a user