diff --git a/src/store/modules/statistics.ts b/src/store/modules/statistics.ts index c5fcab6..de1dff1 100644 --- a/src/store/modules/statistics.ts +++ b/src/store/modules/statistics.ts @@ -183,7 +183,38 @@ export const useStatisticsStore = defineStore('statistics', { return 0; })(); - // 安全获取总销售额,处理数组情况 + // 安全获取今日销售额 + const todaySales = (() => { + if (statisticsData && statisticsData.length > 0) { + const stats = statisticsData[0]; + if (stats.todaySales !== undefined && stats.todaySales !== null) { + return safeNumber(stats.todaySales); + } + } + return 0; + })(); + + // 安全获取今日订单数 + const todayOrders = (() => { + if (statisticsData && statisticsData.length > 0) { + const stats = statisticsData[0]; + if (stats.todayOrders !== undefined && stats.todayOrders !== null) { + return safeNumber(stats.todayOrders); + } + } + return 0; + })(); + + // 安全获取今日新增用户 + const todayUsers = (() => { + if (statisticsData && statisticsData.length > 0) { + const stats = statisticsData[0]; + if (stats.todayUsers !== undefined && stats.todayUsers !== null) { + return safeNumber(stats.todayUsers); + } + } + return 0; + })(); const totalSales = (() => { if (!total) { console.warn('⚠️ 订单总额API返回空数据'); @@ -224,13 +255,22 @@ export const useStatisticsStore = defineStore('statistics', { }, 1000); // 更新本地数据 - statistics = { ...existingStatistics, ...updateData }; + statistics = { + ...existingStatistics, + ...updateData, + todaySales, + todayOrders, + todayUsers + }; } else { // 如果现有数据无效,使用基础数据 statistics = { userCount: userCount, orderCount: orderCount, - totalSales: totalSales + totalSales: totalSales, + todaySales: todaySales, + todayOrders: todayOrders, + todayUsers: todayUsers }; } } else { @@ -238,7 +278,10 @@ export const useStatisticsStore = defineStore('statistics', { statistics = { userCount: userCount, orderCount: orderCount, - totalSales: totalSales + totalSales: totalSales, + todaySales: todaySales, + todayOrders: todayOrders, + todayUsers: todayUsers }; // 异步保存到数据库 diff --git a/src/views/shop/dashboard/index.vue b/src/views/shop/dashboard/index.vue index ff6c7d9..93c09bd 100644 --- a/src/views/shop/dashboard/index.vue +++ b/src/views/shop/dashboard/index.vue @@ -205,7 +205,7 @@