fix: 修复统计图表不显示与对比上月Infinity问题

- ChartWrapper: 添加 type 属性修复 uCharts 不渲染
- ChartWrapper: 使用 pixelRatio=1 避免双重缩放导致字体线条过大
- ChartWrapper: 统一 fontSize/fontColor/padding 配置
- ChartWrapper: 挂载时保存实例引用避免异步回调中 getCurrentInstance 返回 undefined
- stats: Number() 强制类型转换避免字符串导致 Infinity
- stats: !prev 宽松判断覆盖 null/undefined/0 除零情况
- stores: fetchOverview/fetchCategoryStats/fetchTrend 确保数据字段为数字
This commit is contained in:
2026-06-03 11:30:41 +08:00
parent db81ad8eb2
commit 9162b2c87c
3 changed files with 117 additions and 41 deletions

View File

@@ -15,7 +15,14 @@ export const useStatsStore = defineStore('stats', () => {
async function fetchOverview(month?: string) {
try {
overview.value = await api.getOverview({ month: month || getCurrentMonth() })
const data = await api.getOverview({ month: month || getCurrentMonth() })
// 确保数据字段是数字类型
overview.value = {
expense: Number(data?.expense) || 0,
income: Number(data?.income) || 0,
count: Number(data?.count) || 0,
daily: Number(data?.daily) || 0
}
} catch {
overview.value = { expense: 0, income: 0, count: 0, daily: 0 }
}
@@ -23,7 +30,13 @@ export const useStatsStore = defineStore('stats', () => {
async function fetchCategoryStats(month?: string, type: string = 'expense') {
try {
categoryStats.value = await api.getCategoryStats(month || getCurrentMonth(), type)
const data = await api.getCategoryStats(month || getCurrentMonth(), type)
// 确保返回的是数组,且金额是数字
categoryStats.value = Array.isArray(data) ? data.map(item => ({
...item,
amount: Number(item.amount) || 0,
count: Number(item.count) || 0
})) : []
} catch {
categoryStats.value = []
}
@@ -31,7 +44,12 @@ export const useStatsStore = defineStore('stats', () => {
async function fetchTrend(month?: string, type: string = 'expense') {
try {
trendData.value = await api.getTrend(month || getCurrentMonth(), type)
const data = await api.getTrend(month || getCurrentMonth(), type)
// 确保返回的是数组,且金额是数字
trendData.value = Array.isArray(data) ? data.map(item => ({
...item,
amount: Number(item.amount) || 0
})) : []
} catch {
trendData.value = []
}