From 2cca9b2518e8d65b434596ad570e409201f4ff1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Tue, 14 Jul 2026 02:51:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(statistics):=20=E4=BC=98=E5=8C=96=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=95=B0=E6=8D=AE=E5=93=8D=E5=BA=94=E5=BC=8F=E4=B8=8E?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=8A=E6=97=A5=E7=BB=9F=E8=AE=A1=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将核心统计数据和待处理事项改为computed,确保响应式更新 - 使用ref管理待发货订单数、退款申请数和优惠券使用数 - 异步请求接口获取待处理事项的实际数据并更新状态 - 在统计模块中新增今日销售额、订单数和新增用户的安全获取逻辑 - 将今日统计数据纳入本地状态合并,提高数据完整性 - 修正今日统计显示逻辑,替换模拟数据为真实数据来源 --- src/store/modules/statistics.ts | 51 +++++++++++++-- src/views/shop/dashboard/index.vue | 101 ++++++++++++++++++++--------- 2 files changed, 116 insertions(+), 36 deletions(-) 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 @@