fix-0330: 修复AI接口失效问题

This commit is contained in:
shuguang 2025-03-22 20:35:03 +08:00
parent f012c93254
commit 156ee49215

View File

@ -1,9 +1,9 @@
<!-- -->
<template>
<div style="width: 100%; height: 80vh;">
<div style="width: 100%; height: 80vh">
<iframe
src="http://222.186.56.232:8080/ui/chat/4e57f91dccd39b1c"
style="width: 100%; height: 100%;"
src="http://110.40.62.21:8088/ui/chat/557a7986d311731a"
style="width: 100%; height: 100%"
frameborder="0"
allow="microphone"
></iframe>
@ -11,16 +11,14 @@
</template>
<script>
import MarkdownIt from 'markdown-it';
import MarkdownIt from "markdown-it";
export default {
name: 'ChatGPTPage',
name: "ChatGPTPage",
data() {
return {
message: '',
chatHistory: [
{ message: '欢迎使用竞赛AI助手', sentByUser: false },
],
message: "",
chatHistory: [{ message: "欢迎使用竞赛AI助手", sentByUser: false }],
socket: null,
};
},
@ -29,59 +27,57 @@ export default {
},
beforeDestroy() {
if (this.socket) {
this.socket.close(); // WebSocket
this.socket.close(); // WebSocket
}
},
methods: {
initializeWebSocket() {
this.socket = new WebSocket(`ws://222.186.56.183:8888/websocketClient/3`);
this.socket.onopen = () => {
console.log('WebSocket 连接已建立');
console.log("WebSocket 连接已建立");
};
this.socket.onmessage = (event) => {
console.log('收到消息:', event.data);
this.updateChatHistory(event.data, false)
// var str=""
// str=str+event.data
// console.log(str);
// 3
};
// setInterval(() => {this.updateChatHistory(str, false);},3000)
this.socket.onmessage = (event) => {
console.log("收到消息:", event.data);
this.updateChatHistory(event.data, false);
// var str=""
// str=str+event.data
// console.log(str);
// 3
};
// setInterval(() => {this.updateChatHistory(str, false);},3000)
this.socket.onerror = (error) => {
console.error('WebSocket 错误:', error);
console.error("WebSocket 错误:", error);
};
this.socket.onclose = () => {
console.log('WebSocket 连接已关闭');
console.log("WebSocket 连接已关闭");
};
},
sendMessage() {
const data = { session: this.message };
console.log('发送消息:', JSON.stringify(data));
console.log("发送消息:", JSON.stringify(data));
this.updateChatHistory(this.message, true);
if (this.socket.readyState === WebSocket.OPEN) {
this.socket.send(JSON.stringify(data));
}
this.message = '';
this.message = "";
},
updateChatHistory(msg, sentByUser) {
if (msg) {
//
this.chatHistory.push({ message: msg, sentByUser });
} else {
//
//
let answer = '';
for (const entry of this.chatHistory) {
answer += entry.message;
}
this.chatHistory.push({ message: answer, sentByUser });
//
// this.chatHistory = [];
}
}
if (msg) {
//
this.chatHistory.push({ message: msg, sentByUser });
} else {
//
//
let answer = "";
for (const entry of this.chatHistory) {
answer += entry.message;
}
this.chatHistory.push({ message: answer, sentByUser });
//
// this.chatHistory = [];
}
},
},
};
</script>
@ -92,9 +88,9 @@ export default {
}
/* 可以在这里添加样式来自定义页面外观 */
.logo {
display: flex;
flex-direction: row;
justify-content: center;
display: flex;
flex-direction: row;
justify-content: center;
font-size: 24px;
color: #333;
padding: 16px;