Add category filter to monthly stats query and UI

This commit is contained in:
2026-05-06 22:49:19 +08:00
parent 08fbde8a39
commit bf0c6ce9b1
3 changed files with 44 additions and 41 deletions
+2 -2
View File
@@ -119,8 +119,8 @@ export async function getOverview(params = {}) {
return res.data;
}
export async function getMonthly(months = 12) {
const res = await api.get("/stats/monthly", { params: { months } });
export async function getMonthly(months = 12, categories) {
const params = { months }; if (categories && categories.length > 0) params.categories = categories.join(","); const res = await api.get("/stats/monthly", { params });
return res.data;
}
+7
View File
@@ -94,6 +94,13 @@ export default function Dashboard() {
loadData();
}, []);
// 勾选变化 → 重新拉月度数据
useEffect(() => {
if (!raw) return;
const cats = [...checked];
getMonthly(12, cats).then(setMonthly).catch(console.error);
}, [checked, raw]);
async function loadData() {
setLoading(true);
try {