feat(statistics): 优化统计数据响应式与新增今日统计数据
- 将核心统计数据和待处理事项改为computed,确保响应式更新 - 使用ref管理待发货订单数、退款申请数和优惠券使用数 - 异步请求接口获取待处理事项的实际数据并更新状态 - 在统计模块中新增今日销售额、订单数和新增用户的安全获取逻辑 - 将今日统计数据纳入本地状态合并,提高数据完整性 - 修正今日统计显示逻辑,替换模拟数据为真实数据来源
This commit is contained in:
@@ -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
|
||||
};
|
||||
|
||||
// 异步保存到数据库
|
||||
|
||||
Reference in New Issue
Block a user