feat(聊天): 增强聊天功能并添加热门问题处理
This commit is contained in:
parent
d78a71d09e
commit
b3f0ae2f7f
|
|
@ -62,7 +62,9 @@
|
|||
:class="{
|
||||
'chat-item-active': item.isActiveChat,
|
||||
}"
|
||||
@click.stop="selectChatItem(groupIndex, index, item.id)"
|
||||
@click.stop="
|
||||
selectChatItem(groupIndex, index, item.id, item.conversationId)
|
||||
"
|
||||
>
|
||||
<view class="chat-item-content">
|
||||
<text class="chat-text u-line-1">{{ item.title }}</text>
|
||||
|
|
@ -87,7 +89,14 @@
|
|||
>
|
||||
<view
|
||||
class="popover-item"
|
||||
@click.stop="selectChatItem(groupIndex, index, item.id)"
|
||||
@click.stop="
|
||||
selectChatItem(
|
||||
groupIndex,
|
||||
index,
|
||||
item.id,
|
||||
item.conversationId
|
||||
)
|
||||
"
|
||||
>
|
||||
<u-icon
|
||||
name="chat"
|
||||
|
|
@ -307,12 +316,14 @@ export default {
|
|||
}
|
||||
},
|
||||
|
||||
selectChatItem(groupIndex, index, conversationId) {
|
||||
selectChatItem(groupIndex, index, id, conversationId) {
|
||||
// this.currentActiveGroup = groupIndex;
|
||||
// this.currentActiveIndex = index;
|
||||
console.log("selectChatItem", groupIndex, index, id, conversationId);
|
||||
|
||||
// 向父组件发送选中的对话信息
|
||||
this.$emit("select-conversation", {
|
||||
id,
|
||||
conversationId,
|
||||
});
|
||||
},
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@
|
|||
class="qa-item"
|
||||
v-for="(item, index) in hotQuestions"
|
||||
:key="index"
|
||||
@click="handleQAClick(item)"
|
||||
>
|
||||
<text class="qa-question">{{ item.content }}</text>
|
||||
</view>
|
||||
|
|
@ -319,7 +320,8 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
isChat: false,
|
||||
currentConversationId: "",
|
||||
currentConversationId: "", // 当前对话的ID
|
||||
currentDMid: "", // 当前对话的DMId
|
||||
advicePhoneShow: false,
|
||||
perfectInfoShow: false,
|
||||
isLoading: false, // loadingMore
|
||||
|
|
@ -465,6 +467,28 @@ export default {
|
|||
this.handlePopupShow();
|
||||
},
|
||||
|
||||
// 重置对话状态
|
||||
resetChatState({
|
||||
conversationId = "",
|
||||
dmid = "",
|
||||
autoResetSwitching = true,
|
||||
} = {}) {
|
||||
this.isChat = true;
|
||||
this.isSwitchingConversation = true;
|
||||
this.currentConversationId = conversationId;
|
||||
this.currentDMid = dmid;
|
||||
this.messageGroups = [];
|
||||
this.pageQuery.PageIndex = 1;
|
||||
this.isLoadingMore = false;
|
||||
this.noMoreData = false;
|
||||
|
||||
if (autoResetSwitching) {
|
||||
setTimeout(() => {
|
||||
this.isSwitchingConversation = false;
|
||||
}, 500);
|
||||
}
|
||||
},
|
||||
|
||||
async getChatHistoryList() {
|
||||
this.$u.api.GetConversationPage().then((res) => {
|
||||
this.chatHistoryList3 = res.data;
|
||||
|
|
@ -585,16 +609,23 @@ export default {
|
|||
// 添加加载状态消息到列表
|
||||
this.messageGroups.push(loadingMessage);
|
||||
|
||||
const params = {
|
||||
query: sendMessage,
|
||||
conversationId: this.currentConversationId || "",
|
||||
};
|
||||
|
||||
if (this.currentDMid) {
|
||||
params.dmId = this.currentDMid;
|
||||
}
|
||||
|
||||
this.$u.api
|
||||
.SendMessageApi({
|
||||
query: sendMessage,
|
||||
conversationId: this.currentConversationId,
|
||||
})
|
||||
.SendMessageApi(params)
|
||||
.then((res) => {
|
||||
console.log("res.....", res);
|
||||
const data = res.data;
|
||||
|
||||
this.currentConversationId = data.conversationId;
|
||||
this.currentDMid = data.dmid;
|
||||
|
||||
// 从消息列表中移除加载状态消息
|
||||
this.messageGroups = this.messageGroups.filter(
|
||||
|
|
@ -644,6 +675,121 @@ export default {
|
|||
});
|
||||
},
|
||||
|
||||
// 点击热门问题
|
||||
handleQAClick(item) {
|
||||
// 如果不在对话模式,切换到对话模式并初始化
|
||||
if (!this.isChat) {
|
||||
this.resetChatState();
|
||||
}
|
||||
|
||||
const sendMessage = item.content;
|
||||
console.log("点击热门问题", sendMessage);
|
||||
|
||||
// 重置加载更多标志位
|
||||
this.isLoadingMore = false;
|
||||
|
||||
// 创建新的用户消息对象
|
||||
const userMessage = {
|
||||
id: Math.random().toString(36).substring(2, 15),
|
||||
message: sendMessage,
|
||||
sendDate: "",
|
||||
isSend: true,
|
||||
isRead: false,
|
||||
interactMode: 0, // 用户消息
|
||||
messageType: 0,
|
||||
timeLabel: 0,
|
||||
displayTime: "",
|
||||
};
|
||||
|
||||
// 添加到消息列表
|
||||
this.messageGroups.push(userMessage);
|
||||
|
||||
// 立即添加一个AI回复的加载状态消息
|
||||
const loadingMessage = {
|
||||
id: "loading_" + Math.random().toString(36).substring(2, 15),
|
||||
message: "",
|
||||
sendDate: "",
|
||||
isSend: true,
|
||||
isRead: false,
|
||||
interactMode: 1, // AI消息
|
||||
messageType: 0,
|
||||
timeLabel: 0,
|
||||
displayTime: "",
|
||||
isLoading: true, // 标记为加载状态
|
||||
};
|
||||
|
||||
// 添加加载状态消息到列表
|
||||
this.messageGroups.push(loadingMessage);
|
||||
|
||||
const params = {
|
||||
id: item.id,
|
||||
};
|
||||
if (this.currentDMid) {
|
||||
params.dmId = this.currentDMid;
|
||||
}
|
||||
|
||||
this.$u.api
|
||||
.GetHotQuestionsFromId(params)
|
||||
.then((res) => {
|
||||
if (res.succeed) {
|
||||
console.log("hotQuestionsDetail.....", res.data);
|
||||
this.currentDMid = res.data.dmId;
|
||||
const data = res.data.entityInfo;
|
||||
|
||||
// 从消息列表中移除加载状态消息
|
||||
this.messageGroups = this.messageGroups.filter(
|
||||
(msg) => !msg.isLoading
|
||||
);
|
||||
|
||||
// 创建AI回复消息对象
|
||||
const aiMessage = {
|
||||
id:
|
||||
data.conversationId ||
|
||||
Math.random().toString(36).substring(2, 15),
|
||||
message: data.detailedExplanation,
|
||||
sendDate: "",
|
||||
isSend: true,
|
||||
isRead: false,
|
||||
interactMode: 1, // AI消息
|
||||
messageType: 0,
|
||||
timeLabel: 0,
|
||||
displayTime: "",
|
||||
};
|
||||
|
||||
// 添加到消息列表
|
||||
this.messageGroups.push(aiMessage);
|
||||
} else {
|
||||
// 从消息列表中移除加载状态消息
|
||||
this.messageGroups = this.messageGroups.filter(
|
||||
(msg) => !msg.isLoading
|
||||
);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("API请求失败:", error);
|
||||
|
||||
// 从消息列表中移除加载状态消息
|
||||
this.messageGroups = this.messageGroups.filter(
|
||||
(msg) => !msg.isLoading
|
||||
);
|
||||
|
||||
// 添加错误消息
|
||||
const errorMessage = {
|
||||
id: "error_" + Math.random().toString(36).substring(2, 15),
|
||||
message: "请求失败,请稍后重试",
|
||||
sendDate: "",
|
||||
isSend: true,
|
||||
isRead: false,
|
||||
interactMode: 1, // AI消息
|
||||
messageType: 0,
|
||||
timeLabel: 0,
|
||||
displayTime: "",
|
||||
};
|
||||
|
||||
this.messageGroups.push(errorMessage);
|
||||
});
|
||||
},
|
||||
|
||||
// 格式化时间的辅助方法
|
||||
formatTime(date) {
|
||||
const hours = date.getHours().toString().padStart(2, "0");
|
||||
|
|
@ -656,9 +802,10 @@ export default {
|
|||
// 关闭弹窗
|
||||
this.popupShow = false;
|
||||
|
||||
console.log("选中的对话:", data);
|
||||
console.log("选中的对话111:", data);
|
||||
// 根据conversationId加载对应的对话内容
|
||||
this.currentConversationId = data.conversationId;
|
||||
this.currentDMid = data.id;
|
||||
|
||||
this.isChat = true;
|
||||
|
||||
|
|
@ -689,7 +836,7 @@ export default {
|
|||
handleGetConversationDetail() {
|
||||
this.$u.api
|
||||
.GetConversationDetail({
|
||||
"Item1.Id": this.currentConversationId,
|
||||
"Item1.Id": this.currentDMid,
|
||||
PageIndex: this.pageQuery.PageIndex,
|
||||
PageSize: this.pageQuery.PageSize,
|
||||
})
|
||||
|
|
@ -744,44 +891,12 @@ export default {
|
|||
handleCreateConversation() {
|
||||
// 关闭弹窗
|
||||
this.popupShow = false;
|
||||
this.isChat = true;
|
||||
|
||||
// 设置切换对话标志位,防止触发上拉刷新
|
||||
this.isSwitchingConversation = true;
|
||||
|
||||
this.currentConversationId = "";
|
||||
this.messageGroups = [];
|
||||
|
||||
// 重置分页和加载状态
|
||||
this.pageQuery.PageIndex = 1;
|
||||
this.isLoadingMore = false;
|
||||
this.noMoreData = false;
|
||||
|
||||
// 延迟重置切换对话标志位
|
||||
setTimeout(() => {
|
||||
this.isSwitchingConversation = false;
|
||||
}, 500);
|
||||
this.resetChatState();
|
||||
},
|
||||
|
||||
// 开始新对话
|
||||
handleStartChat() {
|
||||
this.isChat = true;
|
||||
|
||||
// 设置切换对话标志位,防止触发上拉刷新
|
||||
this.isSwitchingConversation = true;
|
||||
|
||||
this.currentConversationId = "";
|
||||
this.messageGroups = [];
|
||||
|
||||
// 重置分页和加载状态
|
||||
this.pageQuery.PageIndex = 1;
|
||||
this.isLoadingMore = false;
|
||||
this.noMoreData = false;
|
||||
|
||||
// 延迟重置切换对话标志位
|
||||
setTimeout(() => {
|
||||
this.isSwitchingConversation = false;
|
||||
}, 500);
|
||||
this.resetChatState();
|
||||
},
|
||||
|
||||
// 滚动到底部事件处理
|
||||
|
|
@ -874,15 +989,6 @@ export default {
|
|||
}
|
||||
});
|
||||
},
|
||||
|
||||
// 点击热门问题
|
||||
handleQAClick(item) {
|
||||
this.$u.api.GetHotQuestionsFromId({ id: item.id }).then((res) => {
|
||||
if (res.succeed) {
|
||||
console.log("hotQuestionsDetail.....", res.data);
|
||||
}
|
||||
});
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Reference in New Issue