1.1需求完成
This commit is contained in:
@@ -1429,7 +1429,6 @@ export default {
|
||||
// 加载历史消息
|
||||
async loadHistoryMessages() {
|
||||
if (this.isLoadingHistory || !this.roomId) return;
|
||||
|
||||
this.isLoadingHistory = true;
|
||||
try {
|
||||
const response = await getHistory7({
|
||||
@@ -1437,41 +1436,18 @@ export default {
|
||||
userType: this.userType,
|
||||
email: this.userEmail,
|
||||
});
|
||||
|
||||
// console.log("📋 初始历史消息加载响应:", {
|
||||
// code: response?.code,
|
||||
// dataExists: !!response?.data,
|
||||
// dataLength: response?.data?.length || 0,
|
||||
// isArray: Array.isArray(response?.data),
|
||||
// });
|
||||
|
||||
if (response?.code === 200 && Array.isArray(response.data)) {
|
||||
// 使用统一的格式化方法
|
||||
const historyMessages = this.formatHistoryMessages(response.data);
|
||||
|
||||
if (historyMessages.length > 0) {
|
||||
// 有历史消息,按时间顺序排序
|
||||
this.messages = historyMessages.sort(
|
||||
(a, b) => new Date(a.time) - new Date(b.time)
|
||||
);
|
||||
// console.log(
|
||||
// "✅ 成功加载",
|
||||
// historyMessages.length,
|
||||
// "条初始历史消息"
|
||||
// );
|
||||
|
||||
// 保持对话框打开状态
|
||||
this.isChatOpen = true;
|
||||
this.isMinimized = false;
|
||||
|
||||
// 只有在初始加载历史消息时才滚动到底部(当消息列表为空时)
|
||||
// 不自动弹窗,只滚动
|
||||
await this.$nextTick();
|
||||
// 添加一个小延时确保所有内容都渲染完成
|
||||
setTimeout(() => {
|
||||
this.scrollToBottom(true); // 传入 true 表示强制滚动
|
||||
this.scrollToBottom(true);
|
||||
}, 100);
|
||||
} else {
|
||||
// 格式化后没有有效消息
|
||||
this.messages = [
|
||||
{
|
||||
type: "system",
|
||||
@@ -1480,10 +1456,8 @@ export default {
|
||||
time: new Date().toISOString(),
|
||||
},
|
||||
];
|
||||
// console.log("📋 初始历史消息为空(格式化后无有效消息)");
|
||||
}
|
||||
} else {
|
||||
// 响应无效或无数据
|
||||
this.messages = [
|
||||
{
|
||||
type: "system",
|
||||
@@ -1492,11 +1466,9 @@ export default {
|
||||
time: new Date().toISOString(),
|
||||
},
|
||||
];
|
||||
// console.log("📋 初始历史消息为空(响应无效)");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("加载历史消息失败:", error);
|
||||
// === 简化历史消息加载失败提示 ===
|
||||
this.$message.error(
|
||||
this.$t("chat.loadHistoryFailed") || "加载历史消息失败"
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user