fix-0330: 修复AI接口失效问题
This commit is contained in:
parent
f012c93254
commit
156ee49215
@ -1,9 +1,9 @@
|
|||||||
<!-- -->
|
<!-- -->
|
||||||
<template>
|
<template>
|
||||||
<div style="width: 100%; height: 80vh;">
|
<div style="width: 100%; height: 80vh">
|
||||||
<iframe
|
<iframe
|
||||||
src="http://222.186.56.232:8080/ui/chat/4e57f91dccd39b1c"
|
src="http://110.40.62.21:8088/ui/chat/557a7986d311731a"
|
||||||
style="width: 100%; height: 100%;"
|
style="width: 100%; height: 100%"
|
||||||
frameborder="0"
|
frameborder="0"
|
||||||
allow="microphone"
|
allow="microphone"
|
||||||
></iframe>
|
></iframe>
|
||||||
@ -11,16 +11,14 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import MarkdownIt from 'markdown-it';
|
import MarkdownIt from "markdown-it";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ChatGPTPage',
|
name: "ChatGPTPage",
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
message: '',
|
message: "",
|
||||||
chatHistory: [
|
chatHistory: [{ message: "欢迎使用竞赛AI助手!", sentByUser: false }],
|
||||||
{ message: '欢迎使用竞赛AI助手!', sentByUser: false },
|
|
||||||
],
|
|
||||||
socket: null,
|
socket: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
@ -29,59 +27,57 @@ export default {
|
|||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
if (this.socket) {
|
if (this.socket) {
|
||||||
this.socket.close(); // 关闭 WebSocket 连接
|
this.socket.close(); // 关闭 WebSocket 连接
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initializeWebSocket() {
|
initializeWebSocket() {
|
||||||
this.socket = new WebSocket(`ws://222.186.56.183:8888/websocketClient/3`);
|
this.socket = new WebSocket(`ws://222.186.56.183:8888/websocketClient/3`);
|
||||||
this.socket.onopen = () => {
|
this.socket.onopen = () => {
|
||||||
console.log('WebSocket 连接已建立');
|
console.log("WebSocket 连接已建立");
|
||||||
};
|
};
|
||||||
this.socket.onmessage = (event) => {
|
this.socket.onmessage = (event) => {
|
||||||
console.log('收到消息:', event.data);
|
console.log("收到消息:", event.data);
|
||||||
this.updateChatHistory(event.data, false)
|
this.updateChatHistory(event.data, false);
|
||||||
// var str=""
|
// var str=""
|
||||||
// str=str+event.data
|
// str=str+event.data
|
||||||
// console.log(str);
|
// console.log(str);
|
||||||
// 定时器3秒后统一发出
|
// 定时器3秒后统一发出
|
||||||
|
};
|
||||||
|
// setInterval(() => {this.updateChatHistory(str, false);},3000)
|
||||||
};
|
|
||||||
// setInterval(() => {this.updateChatHistory(str, false);},3000)
|
|
||||||
|
|
||||||
this.socket.onerror = (error) => {
|
this.socket.onerror = (error) => {
|
||||||
console.error('WebSocket 错误:', error);
|
console.error("WebSocket 错误:", error);
|
||||||
};
|
};
|
||||||
this.socket.onclose = () => {
|
this.socket.onclose = () => {
|
||||||
console.log('WebSocket 连接已关闭');
|
console.log("WebSocket 连接已关闭");
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
sendMessage() {
|
sendMessage() {
|
||||||
const data = { session: this.message };
|
const data = { session: this.message };
|
||||||
console.log('发送消息:', JSON.stringify(data));
|
console.log("发送消息:", JSON.stringify(data));
|
||||||
this.updateChatHistory(this.message, true);
|
this.updateChatHistory(this.message, true);
|
||||||
if (this.socket.readyState === WebSocket.OPEN) {
|
if (this.socket.readyState === WebSocket.OPEN) {
|
||||||
this.socket.send(JSON.stringify(data));
|
this.socket.send(JSON.stringify(data));
|
||||||
}
|
}
|
||||||
this.message = '';
|
this.message = "";
|
||||||
},
|
},
|
||||||
updateChatHistory(msg, sentByUser) {
|
updateChatHistory(msg, sentByUser) {
|
||||||
if (msg) {
|
if (msg) {
|
||||||
// 如果收到的消息不为空,则将其添加到聊天历史中
|
// 如果收到的消息不为空,则将其添加到聊天历史中
|
||||||
this.chatHistory.push({ message: msg, sentByUser });
|
this.chatHistory.push({ message: msg, sentByUser });
|
||||||
} else {
|
} else {
|
||||||
// 如果收到的消息为空,则表示回答完成
|
// 如果收到的消息为空,则表示回答完成
|
||||||
// 将回答的内容合并并添加到聊天历史中
|
// 将回答的内容合并并添加到聊天历史中
|
||||||
let answer = '';
|
let answer = "";
|
||||||
for (const entry of this.chatHistory) {
|
for (const entry of this.chatHistory) {
|
||||||
answer += entry.message;
|
answer += entry.message;
|
||||||
}
|
}
|
||||||
this.chatHistory.push({ message: answer, sentByUser });
|
this.chatHistory.push({ message: answer, sentByUser });
|
||||||
// 清空聊天历史
|
// 清空聊天历史
|
||||||
// this.chatHistory = [];
|
// this.chatHistory = [];
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@ -92,9 +88,9 @@ export default {
|
|||||||
}
|
}
|
||||||
/* 可以在这里添加样式来自定义页面外观 */
|
/* 可以在这里添加样式来自定义页面外观 */
|
||||||
.logo {
|
.logo {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
color: #333;
|
color: #333;
|
||||||
padding: 16px;
|
padding: 16px;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user