feat: 对话的调试调整
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
<ChatAvatar v-if="msg.messageRole === MessageRole.AI" :src="aiAvatar" />
|
||||
|
||||
<!-- 自己 发的消息 -->
|
||||
<ChatRoleMe v-if="msg.messageRole === MessageRole.ME" :msg="msg" >
|
||||
<ChatRoleMe v-if="msg.messageRole === MessageRole.ME" :msg="msg">
|
||||
<template #header>
|
||||
<!-- 名字和时间 -->
|
||||
<ChatNameTime :showReverse="true" />
|
||||
@@ -46,8 +46,8 @@
|
||||
</template>
|
||||
</ChatRoleAI>
|
||||
|
||||
<!-- User avatar -->
|
||||
<ChatAvatar v-if="msg.messageRole === MessageRole.ME" :src="userAvatar" />
|
||||
<!-- User avatar -->
|
||||
<ChatAvatar v-if="msg.messageRole === MessageRole.ME" :src="userAvatar" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -88,6 +88,8 @@ import { Session } from '../../utils/storage';
|
||||
|
||||
import userAvatar from '@assets/images/login/user_icon.png';
|
||||
import aiAvatar from '@assets/images/login/blue_logo.png';
|
||||
import { createConversation } from '../../api/ConversationApi';
|
||||
import { ElMessage, ElLoading } from 'element-plus'
|
||||
|
||||
// 支持外部通过 prop 控制是否为引导页
|
||||
const props = defineProps({
|
||||
@@ -108,6 +110,7 @@ watch(isGuidePage, (v) => {
|
||||
if (v) {
|
||||
// 当切换到引导页时,重置/清理会话状态
|
||||
resetConversation();
|
||||
createConversationRequest();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -122,7 +125,7 @@ const inputMessage = ref("");
|
||||
const isSendingMessage = ref(false);
|
||||
|
||||
/// agentId 首页接口中获取 1953462165250859010
|
||||
const agentId = ref("1");
|
||||
const agentId = ref("1953462165250859010");
|
||||
/// 会话ID 历史数据接口中获取
|
||||
const conversationId = ref("");
|
||||
// 会话进行中标志
|
||||
@@ -261,11 +264,12 @@ onMounted(() => {
|
||||
});
|
||||
|
||||
// token存在,初始化数据
|
||||
const initHandler = () => {
|
||||
const initHandler = async () => {
|
||||
console.log("initHandler");
|
||||
const token = getAccessToken();
|
||||
if (!token) return;
|
||||
initWebSocket();
|
||||
await createConversationRequest();
|
||||
await initWebSocket();
|
||||
};
|
||||
|
||||
const getAccessToken = () => {
|
||||
@@ -280,6 +284,12 @@ const checkToken = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 调用接口创建新会话
|
||||
const createConversationRequest = async () => {
|
||||
const res = await createConversation();
|
||||
conversationId.value = res.conversationId;
|
||||
};
|
||||
|
||||
/// =============对话↓================
|
||||
// 初始化WebSocket
|
||||
const initWebSocket = async () => {
|
||||
@@ -475,10 +485,7 @@ const sendMessage = async (message: string, isInstruct: boolean = false) => {
|
||||
if (!isWsConnected()) {
|
||||
console.log("WebSocket未连接,尝试重新连接...");
|
||||
// 显示加载提示
|
||||
// uni.showLoading({
|
||||
// title: "正在连接服务器...",
|
||||
// });
|
||||
|
||||
const loadingInstance = ElLoading.service({ fullscreen: true, text: '正在连接服务器...' });
|
||||
// 尝试重新初始化WebSocket连接
|
||||
try {
|
||||
await initWebSocket();
|
||||
@@ -487,31 +494,22 @@ const sendMessage = async (message: string, isInstruct: boolean = false) => {
|
||||
|
||||
// 检查连接是否成功建立
|
||||
if (!isWsConnected()) {
|
||||
// uni.hideLoading();
|
||||
// uni.showToast({
|
||||
// title: "连接服务器失败,请稍后重试",
|
||||
// icon: "none",
|
||||
// });
|
||||
loadingInstance.close();
|
||||
ElMessage({ message: '连接服务器失败,请稍后重试', type: 'error' })
|
||||
console.error("重新连接WebSocket后仍未连接成功");
|
||||
return;
|
||||
}
|
||||
// uni.hideLoading();
|
||||
loadingInstance.close();
|
||||
} catch (error) {
|
||||
loadingInstance.close();
|
||||
console.error("重新连接WebSocket失败:", error);
|
||||
// uni.hideLoading();
|
||||
// uni.showToast({
|
||||
// title: "连接服务器失败,请稍后重试",
|
||||
// icon: "none",
|
||||
// });
|
||||
ElMessage({ message: '连接服务器失败,请稍后重试', type: 'error' })
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (isSessionActive.value) {
|
||||
// uni.showToast({
|
||||
// title: "请等待当前回复完成",
|
||||
// icon: "none",
|
||||
// });
|
||||
ElMessage({ message: '当前会话正在进行中,请等待回复完成', type: 'warning' })
|
||||
console.warn("当前会话正在进行中,请等待回复完成");
|
||||
return;
|
||||
}
|
||||
@@ -801,5 +799,4 @@ const resetConversation = () => {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user