This commit is contained in:
liuyalei 2024-03-15 10:10:46 +08:00
parent ae85cf6ba2
commit 0a1908616f
4 changed files with 35 additions and 14 deletions

9
package-lock.json generated
View File

@ -12,6 +12,7 @@
"@rangermauve/fetch-event-source": "^1.0.3", "@rangermauve/fetch-event-source": "^1.0.3",
"axios": "^1.6.3", "axios": "^1.6.3",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"uuid": "^9.0.1",
"vant": "^4.8.0", "vant": "^4.8.0",
"vue": "^3.3.4", "vue": "^3.3.4",
"vue-router": "^4.2.5" "vue-router": "^4.2.5"
@ -675,6 +676,14 @@
"node": ">=8.0" "node": ">=8.0"
} }
}, },
"node_modules/uuid": {
"version": "9.0.1",
"resolved": "https://registry.npmmirror.com/uuid/-/uuid-9.0.1.tgz",
"integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
"bin": {
"uuid": "dist/bin/uuid"
}
},
"node_modules/vant": { "node_modules/vant": {
"version": "4.8.0", "version": "4.8.0",
"resolved": "https://registry.npmmirror.com/vant/-/vant-4.8.0.tgz", "resolved": "https://registry.npmmirror.com/vant/-/vant-4.8.0.tgz",

View File

@ -12,6 +12,7 @@
"@rangermauve/fetch-event-source": "^1.0.3", "@rangermauve/fetch-event-source": "^1.0.3",
"axios": "^1.6.3", "axios": "^1.6.3",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"uuid": "^9.0.1",
"vant": "^4.8.0", "vant": "^4.8.0",
"vue": "^3.3.4", "vue": "^3.3.4",
"vue-router": "^4.2.5" "vue-router": "^4.2.5"

View File

@ -280,12 +280,8 @@
<script setup> <script setup>
import { ref, reactive, nextTick, onMounted, watch } from 'vue' import { ref, reactive, nextTick, onMounted, watch } from 'vue'
// import { fetchEventSource } from '@microsoft/fetch-event-source'
// import {fetchEventSource} from '@/rangermauve/fetch-event-source'
// import fetchEventSource from '@rangermauve/fetch-event-source';
import { fetchEventSource } from '@microsoft/fetch-event-source'; import { fetchEventSource } from '@microsoft/fetch-event-source';
import { v4 as uuidv4 } from 'uuid';
import http from '@/api/http.js' import http from '@/api/http.js'
// import http from '@/utils/request.js' // import http from '@/utils/request.js'
let recomanTags = ref(['公积金查询', '2024放假安排', '附近推荐的锻炼场所']) let recomanTags = ref(['公积金查询', '2024放假安排', '附近推荐的锻炼场所'])
@ -294,7 +290,7 @@ let inputText = ref('')
let messages = reactive([ let messages = reactive([
]); ]);
// let lastMessageId = ref(0); // ID
// let messages = ref([ // let messages = ref([
// ]); // ]);
@ -340,14 +336,15 @@ const sendMessage = () => {
console.log("信息发送成功", inputText.value); console.log("信息发送成功", inputText.value);
let messageValue = inputText.value.trim() let messageValue = inputText.value.trim()
if (inputText.value.trim()) { if (inputText.value.trim()) {
messages.push({ id: Date.now(), text: inputText.value, isMe: true, type: 'txt', }); // lastMessageId.value += 1;
console.log("模型", pathname.value); messages.push({ id: uuidv4(), text: inputText.value, isMe: true, type: 'txt', });
console.log("模型", pathname.value, messages);
if (pathname.value == '/generate') { if (pathname.value == '/generate') {
messages.push({ id: Date.now(), text: '思考中。。。', isMe: true, type: 'loading', }); messages.push({ id: uuidv4(), text: '思考中。。。', isMe: true, type: 'loading', });
http.post(pathname.value, { "text": messageValue }).then((res) => { http.post(pathname.value, { "text": messageValue }).then((res) => {
// var msg = JSON.parse(res.name) // var msg = JSON.parse(res.name)
var msg = res.response var msg = res.response
messages.push({ id: Date.now() + 1, text: msg, isMe: false, type: 'txt' }); messages.push({ id: uuidv4(), text: msg, isMe: false, type: 'txt' });
messages.map((vv, ii) => { messages.map((vv, ii) => {
if (vv.type == 'loading') { if (vv.type == 'loading') {
messages.splice(ii, 1) messages.splice(ii, 1)
@ -363,6 +360,8 @@ const sendMessage = () => {
console.log('error', error) console.log('error', error)
}) })
} else if (pathname.value == '/main_serve') { } else if (pathname.value == '/main_serve') {
var mgsid= uuidv4()
messages.push({ id: mgsid, text: '媒体流加载中', isMe: false, type: 'txt' });
fetchEventSource('/main_serve', { fetchEventSource('/main_serve', {
method: 'POST', method: 'POST',
headers: { headers: {
@ -372,8 +371,13 @@ const sendMessage = () => {
"text": messageValue "text": messageValue
}), }),
onmessage(ev) { onmessage(ev) {
console.log("媒体流", ev.data); console.log("媒体流", JSON.parse(ev.data).response);
// messages.push({ id: Date.now() + 1, text: msg, isMe: false, type: 'txt' }); messages.map((v,i)=>{
if(v.id==mgsid){
// console.log("JSON.parse(ev.data).response",JSON.parse(ev.data).response);
v.text+=JSON.parse(ev.data).response
}
})
} }
}); });
} }
@ -406,7 +410,8 @@ const sendMessage = () => {
const goke = () => { const goke = () => {
// console.log("goke"); // console.log("goke");
const insertWord = '您想看普通还是专家门诊?如有其他需求,也请告诉我' const insertWord = '您想看普通还是专家门诊?如有其他需求,也请告诉我'
messagesCopy[11].id = Date.now(); // messagesCopy[11].id = Date.now();
messagesCopy[11].id = uuidv4();
messagesCopy[11].text = insertWord messagesCopy[11].text = insertWord
messages.push(messagesCopy[11]); messages.push(messagesCopy[11]);
@ -444,7 +449,8 @@ onMounted(() => {
scollToButtom() scollToButtom()
// messages // messages
setTimeout(() => { setTimeout(() => {
messages.push({ id: Date.now(), type: 'fstxt', text: '您可以点击下方快捷方式选择问题,或直接编辑问题发送给我哟', isMe: false }); // messages.push({ id: Date.now(), type: 'fstxt', text: '', isMe: false });
messages.push({ id: uuidv4(), type: 'fstxt', text: '您可以点击下方快捷方式选择问题,或直接编辑问题发送给我哟', isMe: false });
}, 500); }, 500);
}) })

View File

@ -389,6 +389,11 @@ to-regex-range@^5.0.1:
dependencies: dependencies:
is-number "^7.0.0" is-number "^7.0.0"
uuid@^9.0.1:
version "9.0.1"
resolved "https://registry.npmmirror.com/uuid/-/uuid-9.0.1.tgz"
integrity sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==
vant@^4.8.0: vant@^4.8.0:
version "4.8.0" version "4.8.0"
resolved "https://registry.npmmirror.com/vant/-/vant-4.8.0.tgz" resolved "https://registry.npmmirror.com/vant/-/vant-4.8.0.tgz"