feat(聊天): 增强聊天功能并添加热门问题处理

This commit is contained in:
yangzhe 2025-12-01 15:12:11 +08:00
parent d78a71d09e
commit b3f0ae2f7f
2 changed files with 170 additions and 53 deletions

View File

@ -62,7 +62,9 @@
:class="{ :class="{
'chat-item-active': item.isActiveChat, '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"> <view class="chat-item-content">
<text class="chat-text u-line-1">{{ item.title }}</text> <text class="chat-text u-line-1">{{ item.title }}</text>
@ -87,7 +89,14 @@
> >
<view <view
class="popover-item" class="popover-item"
@click.stop="selectChatItem(groupIndex, index, item.id)" @click.stop="
selectChatItem(
groupIndex,
index,
item.id,
item.conversationId
)
"
> >
<u-icon <u-icon
name="chat" name="chat"
@ -307,12 +316,14 @@ export default {
} }
}, },
selectChatItem(groupIndex, index, conversationId) { selectChatItem(groupIndex, index, id, conversationId) {
// this.currentActiveGroup = groupIndex; // this.currentActiveGroup = groupIndex;
// this.currentActiveIndex = index; // this.currentActiveIndex = index;
console.log("selectChatItem", groupIndex, index, id, conversationId);
// //
this.$emit("select-conversation", { this.$emit("select-conversation", {
id,
conversationId, conversationId,
}); });
}, },

View File

@ -101,6 +101,7 @@
class="qa-item" class="qa-item"
v-for="(item, index) in hotQuestions" v-for="(item, index) in hotQuestions"
:key="index" :key="index"
@click="handleQAClick(item)"
> >
<text class="qa-question">{{ item.content }}</text> <text class="qa-question">{{ item.content }}</text>
</view> </view>
@ -319,7 +320,8 @@ export default {
data() { data() {
return { return {
isChat: false, isChat: false,
currentConversationId: "", currentConversationId: "", // ID
currentDMid: "", // DMId
advicePhoneShow: false, advicePhoneShow: false,
perfectInfoShow: false, perfectInfoShow: false,
isLoading: false, // loadingMore isLoading: false, // loadingMore
@ -465,6 +467,28 @@ export default {
this.handlePopupShow(); 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() { async getChatHistoryList() {
this.$u.api.GetConversationPage().then((res) => { this.$u.api.GetConversationPage().then((res) => {
this.chatHistoryList3 = res.data; this.chatHistoryList3 = res.data;
@ -585,16 +609,23 @@ export default {
// //
this.messageGroups.push(loadingMessage); this.messageGroups.push(loadingMessage);
this.$u.api const params = {
.SendMessageApi({
query: sendMessage, query: sendMessage,
conversationId: this.currentConversationId, conversationId: this.currentConversationId || "",
}) };
if (this.currentDMid) {
params.dmId = this.currentDMid;
}
this.$u.api
.SendMessageApi(params)
.then((res) => { .then((res) => {
console.log("res.....", res); console.log("res.....", res);
const data = res.data; const data = res.data;
this.currentConversationId = data.conversationId; this.currentConversationId = data.conversationId;
this.currentDMid = data.dmid;
// //
this.messageGroups = this.messageGroups.filter( 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) { formatTime(date) {
const hours = date.getHours().toString().padStart(2, "0"); const hours = date.getHours().toString().padStart(2, "0");
@ -656,9 +802,10 @@ export default {
// //
this.popupShow = false; this.popupShow = false;
console.log("选中的对话:", data); console.log("选中的对话111:", data);
// conversationId // conversationId
this.currentConversationId = data.conversationId; this.currentConversationId = data.conversationId;
this.currentDMid = data.id;
this.isChat = true; this.isChat = true;
@ -689,7 +836,7 @@ export default {
handleGetConversationDetail() { handleGetConversationDetail() {
this.$u.api this.$u.api
.GetConversationDetail({ .GetConversationDetail({
"Item1.Id": this.currentConversationId, "Item1.Id": this.currentDMid,
PageIndex: this.pageQuery.PageIndex, PageIndex: this.pageQuery.PageIndex,
PageSize: this.pageQuery.PageSize, PageSize: this.pageQuery.PageSize,
}) })
@ -744,44 +891,12 @@ export default {
handleCreateConversation() { handleCreateConversation() {
// //
this.popupShow = false; this.popupShow = false;
this.isChat = true; this.resetChatState();
//
this.isSwitchingConversation = true;
this.currentConversationId = "";
this.messageGroups = [];
//
this.pageQuery.PageIndex = 1;
this.isLoadingMore = false;
this.noMoreData = false;
//
setTimeout(() => {
this.isSwitchingConversation = false;
}, 500);
}, },
// //
handleStartChat() { handleStartChat() {
this.isChat = true; this.resetChatState();
//
this.isSwitchingConversation = true;
this.currentConversationId = "";
this.messageGroups = [];
//
this.pageQuery.PageIndex = 1;
this.isLoadingMore = false;
this.noMoreData = false;
//
setTimeout(() => {
this.isSwitchingConversation = false;
}, 500);
}, },
// //
@ -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> </script>