fix
This commit is contained in:
@@ -153,7 +153,7 @@ const router = useRouter()
|
||||
const messageStore = useMessageStore()
|
||||
|
||||
// 主题
|
||||
const theme = computed(() => messageStore.isDarkMode ? 'dark' : 'light')
|
||||
const theme = computed(() => (messageStore.isDarkMode ? 'dark' : 'light'))
|
||||
|
||||
// 状态管理
|
||||
const loading = ref(false)
|
||||
@@ -196,8 +196,16 @@ const noneCategories = ref([])
|
||||
|
||||
// 颜色配置
|
||||
const categoryColors = [
|
||||
'#FF6B6B', '#4ECDC4', '#45B7D1', '#96CEB4', '#FFEAA7',
|
||||
'#DDA0DD', '#98D8C8', '#F7DC6F', '#BB8FCE', '#85C1E9'
|
||||
'#FF6B6B',
|
||||
'#4ECDC4',
|
||||
'#45B7D1',
|
||||
'#96CEB4',
|
||||
'#FFEAA7',
|
||||
'#DDA0DD',
|
||||
'#98D8C8',
|
||||
'#F7DC6F',
|
||||
'#BB8FCE',
|
||||
'#85C1E9'
|
||||
]
|
||||
|
||||
// 计算属性
|
||||
@@ -266,7 +274,6 @@ const loadStatistics = async () => {
|
||||
|
||||
// 加载分类统计
|
||||
await loadCategoryStatistics(year, month)
|
||||
|
||||
} catch (error) {
|
||||
console.error('加载统计数据失败:', error)
|
||||
hasError.value = true
|
||||
@@ -303,8 +310,8 @@ const loadMonthlyData = async (year, month) => {
|
||||
if (dailyResult?.success && dailyResult.data) {
|
||||
// 转换数据格式:添加完整的 date 字段
|
||||
trendStats.value = dailyResult.data
|
||||
.filter(item => item != null)
|
||||
.map(item => ({
|
||||
.filter((item) => item != null)
|
||||
.map((item) => ({
|
||||
date: `${year}-${month.toString().padStart(2, '0')}-${item.day.toString().padStart(2, '0')}`,
|
||||
expense: item.expense || 0,
|
||||
income: item.income || 0,
|
||||
@@ -323,15 +330,18 @@ const loadYearlyData = async (year) => {
|
||||
const trendResult = await getTrendStatistics({ startYear: year, startMonth: 1, monthCount: 12 })
|
||||
if (trendResult?.success && trendResult.data) {
|
||||
// 计算年度汇总
|
||||
const yearTotal = trendResult.data.reduce((acc, item) => {
|
||||
const expense = item.expense || 0
|
||||
const income = item.income || 0
|
||||
return {
|
||||
totalExpense: acc.totalExpense + expense,
|
||||
totalIncome: acc.totalIncome + income,
|
||||
balance: acc.balance + income - expense
|
||||
}
|
||||
}, { totalExpense: 0, totalIncome: 0, balance: 0 })
|
||||
const yearTotal = trendResult.data.reduce(
|
||||
(acc, item) => {
|
||||
const expense = item.expense || 0
|
||||
const income = item.income || 0
|
||||
return {
|
||||
totalExpense: acc.totalExpense + expense,
|
||||
totalIncome: acc.totalIncome + income,
|
||||
balance: acc.balance + income - expense
|
||||
}
|
||||
},
|
||||
{ totalExpense: 0, totalIncome: 0, balance: 0 }
|
||||
)
|
||||
|
||||
monthlyStats.value = {
|
||||
...yearTotal,
|
||||
@@ -339,7 +349,7 @@ const loadYearlyData = async (year) => {
|
||||
incomeCount: 0
|
||||
}
|
||||
|
||||
trendStats.value = trendResult.data.map(item => ({
|
||||
trendStats.value = trendResult.data.map((item) => ({
|
||||
date: `${item.year}-${item.month.toString().padStart(2, '0')}-01`,
|
||||
amount: (item.income || 0) - (item.expense || 0),
|
||||
count: 1
|
||||
@@ -371,7 +381,8 @@ const loadWeeklyData = async () => {
|
||||
monthlyStats.value = {
|
||||
totalExpense: weekSummaryResult.data.totalExpense || 0,
|
||||
totalIncome: weekSummaryResult.data.totalIncome || 0,
|
||||
balance: (weekSummaryResult.data.totalIncome || 0) - (weekSummaryResult.data.totalExpense || 0),
|
||||
balance:
|
||||
(weekSummaryResult.data.totalIncome || 0) - (weekSummaryResult.data.totalExpense || 0),
|
||||
expenseCount: weekSummaryResult.data.expenseCount || 0,
|
||||
incomeCount: weekSummaryResult.data.incomeCount || 0
|
||||
}
|
||||
@@ -450,7 +461,11 @@ const loadCategoryStatistics = async (year, month) => {
|
||||
const currentColors = getChartColors()
|
||||
|
||||
// 处理支出分类结果
|
||||
if (expenseResult.status === 'fulfilled' && expenseResult.value?.success && expenseResult.value.data) {
|
||||
if (
|
||||
expenseResult.status === 'fulfilled' &&
|
||||
expenseResult.value?.success &&
|
||||
expenseResult.value.data
|
||||
) {
|
||||
expenseCategories.value = expenseResult.value.data.map((item, index) => ({
|
||||
classify: item.classify,
|
||||
amount: item.amount || 0,
|
||||
@@ -461,7 +476,11 @@ const loadCategoryStatistics = async (year, month) => {
|
||||
}
|
||||
|
||||
// 处理收入分类结果
|
||||
if (incomeResult.status === 'fulfilled' && incomeResult.value?.success && incomeResult.value.data) {
|
||||
if (
|
||||
incomeResult.status === 'fulfilled' &&
|
||||
incomeResult.value?.success &&
|
||||
incomeResult.value.data
|
||||
) {
|
||||
incomeCategories.value = incomeResult.value.data.map((item) => ({
|
||||
classify: item.classify,
|
||||
amount: item.amount || 0,
|
||||
@@ -510,7 +529,11 @@ const loadCategoryStatistics = async (year, month) => {
|
||||
const currentColors = getChartColors()
|
||||
|
||||
// 处理支出分类结果
|
||||
if (expenseResult.status === 'fulfilled' && expenseResult.value?.success && expenseResult.value.data) {
|
||||
if (
|
||||
expenseResult.status === 'fulfilled' &&
|
||||
expenseResult.value?.success &&
|
||||
expenseResult.value.data
|
||||
) {
|
||||
expenseCategories.value = expenseResult.value.data.map((item, index) => ({
|
||||
classify: item.classify,
|
||||
amount: item.amount || 0,
|
||||
@@ -521,7 +544,11 @@ const loadCategoryStatistics = async (year, month) => {
|
||||
}
|
||||
|
||||
// 处理收入分类结果
|
||||
if (incomeResult.status === 'fulfilled' && incomeResult.value?.success && incomeResult.value.data) {
|
||||
if (
|
||||
incomeResult.status === 'fulfilled' &&
|
||||
incomeResult.value?.success &&
|
||||
incomeResult.value.data
|
||||
) {
|
||||
incomeCategories.value = incomeResult.value.data.map((item) => ({
|
||||
classify: item.classify,
|
||||
amount: item.amount || 0,
|
||||
@@ -618,8 +645,7 @@ const isLastPeriod = () => {
|
||||
}
|
||||
case 'month': {
|
||||
// 比较年月
|
||||
return current.getFullYear() === now.getFullYear() &&
|
||||
current.getMonth() === now.getMonth()
|
||||
return current.getFullYear() === now.getFullYear() && current.getMonth() === now.getMonth()
|
||||
}
|
||||
case 'year': {
|
||||
// 比较年份
|
||||
@@ -717,20 +743,14 @@ watch(currentPeriod, () => {
|
||||
if (currentPeriod.value === 'year') {
|
||||
selectedDate.value = [currentDate.value.getFullYear()]
|
||||
} else {
|
||||
selectedDate.value = [
|
||||
currentDate.value.getFullYear(),
|
||||
currentDate.value.getMonth() + 1
|
||||
]
|
||||
selectedDate.value = [currentDate.value.getFullYear(), currentDate.value.getMonth() + 1]
|
||||
}
|
||||
})
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
// 设置默认选中日期
|
||||
selectedDate.value = [
|
||||
currentDate.value.getFullYear(),
|
||||
currentDate.value.getMonth() + 1
|
||||
]
|
||||
selectedDate.value = [currentDate.value.getFullYear(), currentDate.value.getMonth() + 1]
|
||||
loadStatistics()
|
||||
})
|
||||
</script>
|
||||
@@ -792,4 +812,4 @@ onMounted(() => {
|
||||
padding-bottom: calc(95px + env(safe-area-inset-bottom, 0px));
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user