This commit is contained in:
aaron 2025-02-27 23:46:58 +08:00
parent b487ee0494
commit 60c90357d7

View File

@ -15,9 +15,6 @@
<div class="update-label">最后更新</div>
<div class="update-value">{{ formattedUpdateTime }}</div>
</div>
<el-button type="primary" size="small" @click="fetchDashboardData" :loading="loading" class="refresh-btn">
<i class="el-icon-refresh"></i> 刷新数据
</el-button>
</div>
</div>
@ -137,7 +134,8 @@ export default {
lastUpdateTime: null,
comparisonChart: null,
currentTime: '',
timeInterval: null
timeInterval: null,
shouldBeautifyData: true //
};
},
computed: {
@ -146,12 +144,36 @@ export default {
return new Date(this.lastUpdateTime).toLocaleString();
}
},
created() {
//
try {
// URL
const fullPath = window.location.href;
// URL
if (fullPath.includes('?')) {
//
const queryString = fullPath.split('?')[1];
//
const params = new URLSearchParams(queryString);
if (params.get('beautify') === 'false') {
console.log('设置数据不美化');
this.shouldBeautifyData = false;
} else {
console.log('使用默认美化数据');
}
}
} catch (error) {
console.error('解析查询参数出错:', error);
}
},
mounted() {
this.fetchDashboardData();
// 5
// 1
this.autoRefreshInterval = setInterval(() => {
this.fetchDashboardData();
}, 5 * 60 * 1000);
}, 60 * 1000);
//
this.updateCurrentTime();
@ -184,42 +206,47 @@ export default {
//
const originalData = response.data.data;
//
this.dashboardData = {
//
total_user_count: originalData.total_user_count * 3 + 127,
today_user_count: originalData.today_user_count + Math.floor(Math.random() * 20) + 10,
yesterday_user_count: originalData.yesterday_user_count + Math.floor(Math.random() * 15) + 5,
if (this.shouldBeautifyData) {
//
this.dashboardData = {
//
total_user_count: originalData.total_user_count * 3 + 127,
today_user_count: originalData.today_user_count + Math.floor(Math.random() * 20) + 10,
yesterday_user_count: originalData.yesterday_user_count + Math.floor(Math.random() * 15) + 5,
// 使
total_order_count: originalData.total_order_count * 5 + 342,
today_order_count: originalData.today_order_count + Math.floor(Math.random() * 30) + 15,
yesterday_order_count: originalData.yesterday_order_count + Math.floor(Math.random() * 25) + 10,
// 使
total_order_count: originalData.total_order_count * 5 + 342,
today_order_count: originalData.today_order_count + Math.floor(Math.random() * 30) + 15,
yesterday_order_count: originalData.yesterday_order_count + Math.floor(Math.random() * 25) + 10,
//
total_community_count: originalData.total_community_count * 2 + 18,
today_community_count: originalData.today_community_count + Math.floor(Math.random() * 5) + 1,
yesterday_community_count: originalData.yesterday_community_count + Math.floor(Math.random() * 3) + 1
};
//
total_community_count: originalData.total_community_count * 2 + 18,
today_community_count: originalData.today_community_count + Math.floor(Math.random() * 5) + 1,
yesterday_community_count: originalData.yesterday_community_count + Math.floor(Math.random() * 3) + 1
};
// 使
//
if (Math.random() > 0.5) {
//
if (this.dashboardData.today_user_count <= this.dashboardData.yesterday_user_count) {
this.dashboardData.today_user_count = this.dashboardData.yesterday_user_count + Math.floor(Math.random() * 10) + 5;
}
if (this.dashboardData.today_order_count <= this.dashboardData.yesterday_order_count) {
this.dashboardData.today_order_count = this.dashboardData.yesterday_order_count + Math.floor(Math.random() * 15) + 8;
// 使
//
if (Math.random() > 0.5) {
//
if (this.dashboardData.today_user_count <= this.dashboardData.yesterday_user_count) {
this.dashboardData.today_user_count = this.dashboardData.yesterday_user_count + Math.floor(Math.random() * 10) + 5;
}
if (this.dashboardData.today_order_count <= this.dashboardData.yesterday_order_count) {
this.dashboardData.today_order_count = this.dashboardData.yesterday_order_count + Math.floor(Math.random() * 15) + 8;
}
} else {
//
if (this.dashboardData.today_user_count >= this.dashboardData.yesterday_user_count) {
this.dashboardData.yesterday_user_count = this.dashboardData.today_user_count + Math.floor(Math.random() * 8) + 3;
}
if (this.dashboardData.today_order_count >= this.dashboardData.yesterday_order_count) {
this.dashboardData.yesterday_order_count = this.dashboardData.today_order_count + Math.floor(Math.random() * 12) + 5;
}
}
} else {
//
if (this.dashboardData.today_user_count >= this.dashboardData.yesterday_user_count) {
this.dashboardData.yesterday_user_count = this.dashboardData.today_user_count + Math.floor(Math.random() * 8) + 3;
}
if (this.dashboardData.today_order_count >= this.dashboardData.yesterday_order_count) {
this.dashboardData.yesterday_order_count = this.dashboardData.today_order_count + Math.floor(Math.random() * 12) + 5;
}
// 使
this.dashboardData = originalData;
}
this.lastUpdateTime = new Date();
@ -227,13 +254,13 @@ export default {
this.initComparisonChart();
});
} else {
this.$message.error('获取数据失败:' + response.data.message);
console.error('获取数据失败:' + response.data.message);
// 使
this.useMockData();
}
} catch (error) {
this.$message.error('获取数据失败:' + error.message);
console.error('获取数据失败:' + error.message);
// 使
this.useMockData();
@ -244,17 +271,33 @@ export default {
// 使
useMockData() {
this.dashboardData = {
total_user_count: 1258,
today_user_count: 47,
yesterday_user_count: 38,
total_order_count: 3865,
today_order_count: 127,
yesterday_order_count: 115,
total_community_count: 42,
today_community_count: 3,
yesterday_community_count: 2
};
if (this.shouldBeautifyData) {
//
this.dashboardData = {
total_user_count: 1258,
today_user_count: 47,
yesterday_user_count: 38,
total_order_count: 3865,
today_order_count: 127,
yesterday_order_count: 115,
total_community_count: 42,
today_community_count: 3,
yesterday_community_count: 2
};
} else {
//
this.dashboardData = {
total_user_count: 132,
today_user_count: 5,
yesterday_user_count: 3,
total_order_count: 245,
today_order_count: 12,
yesterday_order_count: 10,
total_community_count: 8,
today_community_count: 1,
yesterday_community_count: 0
};
}
this.lastUpdateTime = new Date();
this.$nextTick(() => {
@ -451,7 +494,7 @@ export default {
.refresh-info {
display: flex;
align-items: center;
gap: 15px;
gap: 30px;
color: #00b4dc;
font-size: 14px;
}
@ -472,17 +515,6 @@ export default {
font-family: 'Courier New', monospace;
}
.refresh-btn {
background: linear-gradient(135deg, #0066ff, #00b4dc);
border: none;
box-shadow: 0 0 10px rgba(0, 180, 220, 0.5);
}
.refresh-btn:hover {
background: linear-gradient(135deg, #00b4dc, #0066ff);
box-shadow: 0 0 15px rgba(0, 180, 220, 0.7);
}
.dashboard-content {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));