@@ -522,25 +522,40 @@
this.trendLoading = false;
} else {
this.$message.error('加载消息趋势失败');
+ // 设置默认值
+ this.trendData = { dates: [], counts: [] };
this.trendLoading = false;
}
})
.catch(error => {
console.error('加载消息趋势失败:', error);
this.$message.error('加载消息趋势失败: ' + error.message);
+ // 设置默认值
+ this.trendData = { dates: [], counts: [] };
this.trendLoading = false;
});
},
// 计算百分比的方法
getPercentage(index) {
- if (!this.trendData || !this.trendData.counts) return 0;
+ if (!this.trendData || !this.trendData.counts || !Array.isArray(this.trendData.counts)) return 0;
+ if (index < 0 || index >= this.trendData.counts.length) return 0;
+
const count = parseInt(this.trendData.counts[index] || 0);
return this.totalMessages > 0 ?
((count / this.totalMessages) * 100).toFixed(2) : 0;
+ },
+
+ // 确保在打开对话框时重置 trendData
+ viewMessageTrend(group) {
+ this.currentGroupId = group.group_id;
+ this.currentGroupName = group.group_name || group.group_id;
+ // 重置 trendData 为默认值
+ this.trendData = { dates: [], counts: [] };
+ this.trendDialogVisible = true;
}
- // ... 保留其他方法 ...
+ // ... 其他方法保持不变 ...
}
});