调整为表格~~~

This commit is contained in:
liuwei
2025-03-26 14:33:25 +08:00
parent afb1ae2899
commit 7dcd0c491f

View File

@@ -247,7 +247,8 @@
trendData: { trendData: {
dates: [], dates: [],
counts: [] counts: []
} },
charts: {} // 保留charts对象以防其他地方还在使用
} }
}, },
computed: { computed: {
@@ -261,25 +262,28 @@
}, },
// 计算属性用于趋势数据 // 计算属性用于趋势数据
totalMessages() { totalMessages() {
if (!this.trendData || !this.trendData.counts) return 0;
return this.trendData.counts.reduce((sum, count) => sum + parseInt(count || 0), 0); return this.trendData.counts.reduce((sum, count) => sum + parseInt(count || 0), 0);
}, },
avgMessages() { avgMessages() {
return this.trendData.dates.length > 0 ? if (!this.trendData || !this.trendData.dates || this.trendData.dates.length === 0) return 0;
(this.totalMessages / this.trendData.dates.length).toFixed(2) : 0; return (this.totalMessages / this.trendData.dates.length).toFixed(2);
}, },
maxMessages() { maxMessages() {
return this.trendData.counts.length > 0 ? if (!this.trendData || !this.trendData.counts || this.trendData.counts.length === 0) return 0;
Math.max(...this.trendData.counts.map(c => parseInt(c || 0))) : 0; return Math.max(...this.trendData.counts.map(c => parseInt(c || 0)));
}, },
minMessages() { minMessages() {
return this.trendData.counts.length > 0 ? if (!this.trendData || !this.trendData.counts || this.trendData.counts.length === 0) return 0;
Math.min(...this.trendData.counts.map(c => parseInt(c || 0))) : 0; return Math.min(...this.trendData.counts.map(c => parseInt(c || 0)));
}, },
maxDay() { maxDay() {
if (!this.trendData || !this.trendData.counts || !this.trendData.dates) return '';
const maxIndex = this.trendData.counts.indexOf(this.maxMessages.toString()); const maxIndex = this.trendData.counts.indexOf(this.maxMessages.toString());
return maxIndex >= 0 ? this.trendData.dates[maxIndex] : ''; return maxIndex >= 0 ? this.trendData.dates[maxIndex] : '';
}, },
minDay() { minDay() {
if (!this.trendData || !this.trendData.counts || !this.trendData.dates) return '';
const minIndex = this.trendData.counts.indexOf(this.minMessages.toString()); const minIndex = this.trendData.counts.indexOf(this.minMessages.toString());
return minIndex >= 0 ? this.trendData.dates[minIndex] : ''; return minIndex >= 0 ? this.trendData.dates[minIndex] : '';
} }
@@ -530,6 +534,7 @@
// 计算百分比的方法 // 计算百分比的方法
getPercentage(index) { getPercentage(index) {
if (!this.trendData || !this.trendData.counts) return 0;
const count = parseInt(this.trendData.counts[index] || 0); const count = parseInt(this.trendData.counts[index] || 0);
return this.totalMessages > 0 ? return this.totalMessages > 0 ?
((count / this.totalMessages) * 100).toFixed(2) : 0; ((count / this.totalMessages) * 100).toFixed(2) : 0;