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="{
'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,
});
},

View File

@ -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>