perf: 性能优化与代码质量改进
- 简化ToastProvider组件,移除未使用导入 - 简化Stats页面代码 - 添加React ESLint配置 - 添加数据库索引和API参数验证 - 清理重复文件server.js.backup - 移除前端未使用的UI代码和复杂样式 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
3975bbed73
commit
63c97ab31a
+14
-7
@@ -44,13 +44,9 @@ export default function Stats() {
|
||||
router.push('/login');
|
||||
return;
|
||||
}
|
||||
loadTrendData();
|
||||
}, [router, period, currentMonth]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!isLoggedIn()) return;
|
||||
loadCategoryData();
|
||||
}, [router, currentMonth, categoryType]);
|
||||
// 并行加载两个数据集
|
||||
Promise.all([loadTrendData(), loadCategoryData()]);
|
||||
}, [router, period, currentMonth, categoryType]);
|
||||
|
||||
const loadTrendData = async () => {
|
||||
setTrendLoading(true);
|
||||
@@ -75,9 +71,20 @@ export default function Stats() {
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
// 组件卸载时清理 Chart.js 实例
|
||||
if (trendChartInstance.current) {
|
||||
trendChartInstance.current.destroy();
|
||||
trendChartInstance.current = null;
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (trendChartInstance.current) {
|
||||
trendChartInstance.current.destroy();
|
||||
trendChartInstance.current = null;
|
||||
}
|
||||
if (trendChartRef.current && trendData.length > 0) {
|
||||
const ctx = trendChartRef.current.getContext('2d');
|
||||
|
||||
Reference in New Issue
Block a user