This commit is contained in:
lorenx 2024-12-27 17:07:39 +08:00
parent 083deef2d2
commit 616429bcb7
1 changed files with 122 additions and 34 deletions

View File

@ -29,7 +29,7 @@
<!-- <img :src="item.url" alt="头像" class="head_portrait2" v-if="item.position == 'left'&&loading"/> --> <!-- <img :src="item.url" alt="头像" class="head_portrait2" v-if="item.position == 'left'&&loading"/> -->
<img :src="item.url" alt="头像" class="head_portrait2" /> <img :src="item.url" alt="头像" class="head_portrait2" />
<div :class="item.position == 'left' ? 'chatLeft' : 'chatRight'"> <div :class="item.position == 'left' ? 'chatLeft' : 'chatRight'">
<div class="text" v-html="item.info" v-if="item.info!==''"></div> <div class="text" id="text-container" v-html="item.info" v-if="item.info!==''"></div>
<div class="bounce" v-if="item.info===''&&item.position == 'left'&&loading"> <div class="bounce" v-if="item.info===''&&item.position == 'left'&&loading">
<div></div> <div></div>
<div></div> <div></div>
@ -43,6 +43,7 @@
<div class="infoIcon"></div> <div class="infoIcon"></div>
<textarea <textarea
type="textarea" type="textarea"
:disabled="disabled"
class="infoInput" class="infoInput"
v-model="textarea" v-model="textarea"
@keydown.enter.exact="handlePushKeyword($event)" @keydown.enter.exact="handlePushKeyword($event)"
@ -65,6 +66,7 @@ export default {
// //
act: Number, act: Number,
loading: false, loading: false,
disabled: false,
// //
userInfoList2: [ userInfoList2: [
{ {
@ -84,6 +86,7 @@ export default {
// position: "right" // position: "right"
// } // }
], ],
TestData: "",
// //
userInfoList: [], userInfoList: [],
// //
@ -101,6 +104,7 @@ export default {
methods: { methods: {
// //
setUp() { setUp() {
this.disabled = true;
console.log("发送内容:", this.textarea); console.log("发送内容:", this.textarea);
if (this.textarea.length < 1) { if (this.textarea.length < 1) {
// this.warn = true; // this.warn = true;
@ -131,34 +135,116 @@ export default {
timer: "2022/8/9", timer: "2022/8/9",
position: "left" position: "left"
}); });
setTimeout(() => { //
this.loading = false; let textarea = this.textarea;
this.userInfoList2.pop();
//
axios({
method: "POST",
url:
"http://dual.carbon.ap.5m.work/admin-api/energy/monitor/getTopology",
// "http://localhost/admin-api/energy/monitor/getTopology",
data: {
year: 2024
}
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
this.userInfoList2.push({
url: require("@/assets/img/gpt.png"),
username: "花间一壶酒",
info: "我来告诉你",
timer: "2022/8/9",
position: "left"
});
}, 2000);
this.textarea = ""; this.textarea = "";
fetch("http://192.168.40.45:5002/visit_record_summary_talk", {
method: "POST",
body: JSON.stringify({ message: textarea }),
headers: {
Accept: "text/event-stream",
"Content-Type": "application/json"
}
})
// this.TestData = "";
// fetch("http://192.168.40.45:5005/stream_json_data", {
// method: "POST",
// body: JSON.stringify({ message: textarea }),
// headers: {
// Accept: "text/event-stream",
// "Content-Type": "application/json"
// }
// })
.then(response => {
console.log(response, "respons");
if (!response.ok) {
throw new Error("Network response was not ok");
}
console.log(response.body, "response.text()response.text()");
return response.body;
// return response.json();
})
.then(stream => {
const reader = stream.getReader();
const encode = new TextDecoder("utf-8");
this.loading = false;
const that = this;
that.TestData = "";
function readChunk() {
reader.read().then(({ value, done }) => {
const decodeText = encode.decode(value);
if (decodeText) {
that.userInfoList2[
that.userInfoList2.length - 1
].info += JSON.parse(decodeText).text;
}
// const text = JSON.parse(decodeText).text; //
// const container = document.getElementById("text-container"); //
// container.textContent += text
// that.TestData += JSON.parse(decodeText).text;
// let index = 0; //
// function showText() {
// if (index < text.length) {
// container.textContent += text[index]; //
// index++;
// setTimeout(showText, 100); //
// }
// }
// showText(); //
if (done) {
that.disabled = false;
console.log(that.TestData, "that.TestData");
//
console.log("Done reading the stream");
return;
}
setTimeout(readChunk, 1000); // 1
});
}
readChunk(); //
})
.catch(error => {
console.error("Error:", error);
})
.finally(() => {
console.log("KKKKKKKKKKKKKKKKKKKKKKKKK");
// this.userInfoList = this.userInfoList2;
});
// axios({
// method: "POST",
// url: "http://192.168.40.45:5111/stream",
// // "http://localhost/admin-api/energy/monitor/getTopology",
// data: {
// message: textarea
// }
// })
// .then(response => {
// this.loading = false;
// this.userInfoList2.pop();
// this.textarea = "";
// console.log(response, "hhhhhhhhhhhhhhh");
// this.userInfoList2.push({
// url: require("@/assets/img/gpt.png"),
// username: "",
// info: response.data,
// timer: "2022/8/9",
// position: "left"
// });
// })
// .catch(error => {
// console.log(error);
// });
// }, 2000);
// //
this.$nextTick(() => { this.$nextTick(() => {
// nextTick // nextTick
@ -259,7 +345,8 @@ export default {
.titleBox { .titleBox {
height: 10%; height: 10%;
width: 100%; width: 100%;
background-image: linear-gradient(to right, #1e76bc, #69a3d5); /* background-image: linear-gradient(to right, #1e76bc, #69a3d5); */
background-color: #313541;
display: flex; display: flex;
align-items: center; align-items: center;
border-top-right-radius: 10px; border-top-right-radius: 10px;
@ -290,17 +377,18 @@ export default {
width: 100%; width: 100%;
border: none; border: none;
outline: none; outline: none;
font-family: "Micrsofot Yahei"; /* font-family: "Micrsofot Yahei"; */
font-size: 16px;
resize: none; resize: none;
} }
.fasong { .fasong {
height: 30px; height: 30px;
width: 80px; width: 80px;
background-color: #e8e8e8; background-color: #0fa47f;
text-align: center; text-align: center;
line-height: 30px; line-height: 30px;
border-radius: 4px; border-radius: 4px;
color: #58df4d; color: #f0f4f0;
margin-top: 1%; margin-top: 1%;
align-self: flex-end; align-self: flex-end;
margin-right: 20px; margin-right: 20px;
@ -434,9 +522,9 @@ export default {
align-items: flex-end; align-items: flex-end;
} }
.chatRight .text { .chatRight .text {
color: #434343; color: #f9f7f7;
/* margin-top: 8px; */ /* margin-top: 8px; */
background-color: #95ec69; background-color: #0fa47f;
display: inline-block; display: inline-block;
padding: 12px 16px; padding: 12px 16px;
line-height: 24px; line-height: 24px;