1. 后台首页统计看板,用户积分,福利积分,现金券,用户积分总产出/消耗 平台线上/线下总消费,每日线上/线下消费新增
This commit is contained in:
2026-05-30 13:23:09 +08:00
parent e76b71a852
commit 54b02d83e0
2 changed files with 243 additions and 7 deletions

110
src/option/staticData.js Normal file
View File

@@ -0,0 +1,110 @@
export const createDashboardCards = (context) => {
const cards = [
{
key: 'userPoints',
title: '用户积分',
icon: 'el-icon-user',
color: '#2a7cb2',
path: '/common/commonUserPoint'
},
{
key: 'benefitPoints',
title: '福利积分',
icon: 'el-icon-medal',
color: '#3bb59d',
path: '/market/marketBenefitPoint'
},
{
key: 'cashCoupons',
title: '现金券',
icon: 'el-icon-present',
color: '#f5a623',
path: '/market/marketCashCoupon'
},
{
key: 'commissions',
title: '佣金',
icon: 'el-icon-money',
color: '#d4af37',
path: '/market/marketUserCommission'
}
];
return {
span: 12,
data: cards.map(card => ({
...card,
count: '--', // 初始占位
// 动态绑定点击行为(根据 key 决定跳转)
click: () => {
context.$router?.push(card.path).catch(() => {
});
}
}))
};
};
export const createUserPointCards = () => {
const cards = [
{
key: 'added',
fontColor: "#000",
title: '总产出'
},
{
key: 'deducted',
color: "red",
fontColor: "#000",
title: '总消耗'
}
];
return {
span: 12,
data: cards.map(card => ({
...card,
count: '--', // 初始占位
}))
};
};
export const createUserOrderCards = (context) => {
const cards = [
{
key: 'onlineTotal',
title: '线上总消费',
icon: 'el-icon-sell',
},
{
key: 'offlineTotal',
title: '线下总消费',
icon: 'el-icon-sold-out',
},
{
key: 'otherTotal',
title: '其他总消费',
icon: 'el-icon-shopping-bag',
},
{
key: 'increaseOnline',
title: '新增线上',
icon: 'el-icon-upload',
},
{
key: 'increaseOffline',
title: '新增线下',
icon: 'el-icon-download',
},
{
key: 'increaseOther',
title: '新增其他',
icon: 'el-icon-more',
},
];
return {
span: 8,
data: cards.map(card => ({
...card,
count: '--', // 初始占位
}))
};
};

View File

@@ -48,18 +48,21 @@
</el-col>
<el-col :span="15">
<basic-container>
<div class="section-title">余额概览</div>
<avue-data-rotate :option="option"></avue-data-rotate>
</basic-container>
</el-col>
<el-col :span="9">
<el-col :span="24">
<basic-container>
<div class="section-title">用户积分</div>
<avue-data-display :option="optionUserPoint"></avue-data-display>
</basic-container>
</el-col>
<el-col :span="24">
<basic-container>
<div class="section-title">消费与增长</div>
<avue-data-icons :option="optionUserOrder"></avue-data-icons>
</basic-container>
</el-col>
</el-col>
@@ -69,6 +72,7 @@
<script>
import {mapGetters} from 'vuex';
import {createDashboardCards, createUserPointCards, createUserOrderCards} from '@/option/staticData';
const QWEATHER_KEY = '977c0d0cdeaf497196d834579a8eddee';
@@ -84,6 +88,11 @@ export default {
currentDate: '',
weatherUpdateTimer: null,
cachedPosition: null,
option: createDashboardCards(this),
optionUserPoint: createUserPointCards(this),
optionUserOrder: createUserOrderCards(this),
statsRefreshTimer: null, // 定时器引用
isFetchingStats: false,
};
},
computed: {
@@ -104,18 +113,113 @@ export default {
this.weatherUpdateTimer = setInterval(() => {
this.autoGetWeatherByCurrentLocation();
}, 120 * 60 * 1000); // 120分钟
await this.fetchStats();
await this.fetchUserPointStats();
await this.fetchUserOrderStats();
this.statsRefreshTimer = setInterval(() => {
this.refreshAllStats();
}, 2 * 60 * 60 * 1000);
},
beforeUnmount() {
if (this.weatherUpdateTimer) {
clearInterval(this.weatherUpdateTimer);
this.weatherUpdateTimer = null;
}
if (this.statsRefreshTimer) {
clearInterval(this.statsRefreshTimer);
this.statsRefreshTimer = null;
}
},
methods: {
handleIconError() {
console.warn('SVG 图标加载失败,可考虑切换 PNG');
// 可选:动态替换为 PNG
// this.$el.querySelector('.weather-icon').src = ...png...
async refreshAllStats() {
if (this.isFetchingStats) return; // 防重入
this.isFetchingStats = true;
try {
await Promise.all([
this.fetchStats(),
this.fetchUserPointStats(),
this.fetchUserOrderStats()
]);
} catch (error) {
console.error('刷新统计数据失败:', error);
} finally {
this.isFetchingStats = false;
}
},
async fetchStats() {
try {
const stats = await this.$axios.get('/market-info/data-summary')
.then(r => r.data.data);
const newData = this.option.data.map(item => {
// 安全取值:支持 null/undefined,转为 0
const rawValue = stats[item.key];
const value = rawValue != null ? Number(rawValue) : 0;
// 格式化数字(可选)
const formatted = value.toLocaleString('zh-CN', {
minimumFractionDigits: 0,
maximumFractionDigits: 2
});
return {...item, count: formatted};
});
this.option = {...this.option, data: newData};
} catch (error) {
console.error('Failed to fetch stats:', error);
// 可选:显示错误提示
}
},
async fetchUserPointStats() {
try {
const stats = await this.$axios.get('/market-info/user-point-summary')
.then(r => r.data.data);
const newData = this.optionUserPoint.data.map(item => {
// 安全取值:支持 null/undefined,转为 0
const rawValue = stats[item.key];
const value = rawValue != null ? Number(rawValue) : 0;
// 格式化数字(可选)
const formatted = value.toLocaleString('zh-CN', {
minimumFractionDigits: 0,
maximumFractionDigits: 2
});
return {...item, count: formatted};
});
this.optionUserPoint = {...this.optionUserPoint, data: newData};
} catch (error) {
console.error('Failed to fetch stats:', error);
// 可选:显示错误提示
}
},
async fetchUserOrderStats() {
try {
const stats = await this.$axios.get('/market-info/user-order-summary')
.then(r => r.data.data);
const newData = this.optionUserOrder.data.map(item => {
// 安全取值:支持 null/undefined,转为 0
const rawValue = stats[item.key];
const value = rawValue != null ? Number(rawValue) : 0;
// 格式化数字(可选)
const formatted = value.toLocaleString('zh-CN', {
minimumFractionDigits: 0,
maximumFractionDigits: 2
});
return {...item, count: formatted};
});
this.optionUserOrder = {...this.optionUserOrder, data: newData};
} catch (error) {
console.error('Failed to fetch stats:', error);
// 可选:显示错误提示
}
},
refreshWeather() {
this.autoGetWeatherByCurrentLocation();
@@ -338,6 +442,28 @@ export default {
color: #909399;
}
.section-title {
display: flex;
align-items: center;
font-size: 16px;
font-weight: 600;
color: #303133;
margin-bottom: 12px;
padding: 4px 0 4px 12px;
background: #f8f9fa;
border-radius: 4px;
}
.section-title::before {
content: "";
display: inline-block;
width: 6px;
height: 16px;
background: #409EFF;
margin-right: 8px;
border-radius: 2px;
}
@media (max-width: 768px) {
.dashboard-header {
flex-direction: column;