feat: 增加消息停止功能,修改重发bug
This commit is contained in:
parent
6296bc5e19
commit
7c90333fcf
14
.vscode/launch.json
vendored
Normal file
14
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Debug h5",
|
||||
"type": "chrome",
|
||||
"runtimeArgs": ["--remote-debugging-port=9222"],
|
||||
"request": "launch",
|
||||
"url": "http://localhost:5173",
|
||||
"webRoot": "${workspaceFolder}",
|
||||
"preLaunchTask": "uni:h5"
|
||||
}
|
||||
]
|
||||
}
|
16
.vscode/tasks.json
vendored
Normal file
16
.vscode/tasks.json
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "uni:h5",
|
||||
"type": "npm",
|
||||
"script": "dev --devtools",
|
||||
"isBackground": true,
|
||||
"problemMatcher": "$vite",
|
||||
"group": {
|
||||
"kind": "build",
|
||||
"isDefault": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2
env/.env.production
vendored
2
env/.env.production
vendored
@ -5,6 +5,6 @@ VITE_DELETE_CONSOLE = true
|
||||
# 是否开启sourcemap
|
||||
VITE_SHOW_SOURCEMAP = false
|
||||
|
||||
VITE_SERVER_BASEURL = 'http://114.218.158.24:9020'
|
||||
VITE_SERVER_BASEURL = 'https://erpapi.fontree.cn' # 体制外 OA
|
||||
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
<div
|
||||
ref="scrollEl"
|
||||
class="flex-1 overflow-y-auto bg-#ffffff"
|
||||
:class="showActions ? 'pb-44' : 'pb-100'"
|
||||
:class="showActions ? 'pb-44' : 'pb-16'"
|
||||
>
|
||||
<div :class="['relative z-10 px-4 py-6', showActions ? 'mb--11 h-105' : 'mb--21']">
|
||||
<template v-for="(msg, idx) in messages" :key="idx">
|
||||
@ -181,11 +181,6 @@
|
||||
<!-- 文本消息 -->
|
||||
<view v-else class="pr-2">
|
||||
{{ msg.content }}
|
||||
<text
|
||||
v-if="msg.role === 'assistant' && msg.type === 'text' && !sendTextLoading"
|
||||
>
|
||||
...
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<view
|
||||
@ -351,12 +346,28 @@
|
||||
}"
|
||||
/>
|
||||
<image
|
||||
v-if="sendTextLoading && inputText.length <= 0"
|
||||
src="/static/aichat/enter-no.png"
|
||||
class="w-7 h-7"
|
||||
@click="sendText()"
|
||||
:disabled="loading"
|
||||
:class="[knowledgeOpen ? 'ml-2' : 'ml-0']"
|
||||
/>
|
||||
<image
|
||||
v-else-if="sendTextLoading"
|
||||
src="/static/aichat/enter.png"
|
||||
class="w-7 h-7"
|
||||
@click="sendText()"
|
||||
:disabled="loading"
|
||||
:class="[knowledgeOpen ? 'ml-2' : 'ml-0']"
|
||||
/>
|
||||
<image
|
||||
v-else
|
||||
src="/static/aichat/stop.png"
|
||||
class="w-7 h-7"
|
||||
@click="stopMsg()"
|
||||
:class="[knowledgeOpen ? 'ml-2' : 'ml-0']"
|
||||
/>
|
||||
</view>
|
||||
|
||||
<!-- 操作面板 -->
|
||||
@ -482,7 +493,7 @@ import {
|
||||
import 'dayjs/locale/zh-cn'
|
||||
import { showToastErr, showToastOk, time_format3 } from '@/utils/tools'
|
||||
import { uploadFileChunk } from './utils/api.js'
|
||||
// import { TOKEN, AVATAR } from './utils/test'
|
||||
import { TOKEN, AVATAR } from './utils/test'
|
||||
import { deepClone } from 'wot-design-uni/components/common/util'
|
||||
import { log } from 'console'
|
||||
|
||||
@ -1545,6 +1556,10 @@ interface EventTargetSendText {
|
||||
type EventTypeTarget = string | EventTargetSendText
|
||||
const sendTextLoading = ref(true) // false可以发送消息,true不可以发送,因为上一次发送未结束
|
||||
const refreshSend = ref(false)
|
||||
let stopStreamMsg = false
|
||||
const stopMsg = () => {
|
||||
stopStreamMsg = true
|
||||
}
|
||||
async function sendText() {
|
||||
console.log('uploadList: ', uploadList)
|
||||
if (uploadList.length > 0) {
|
||||
@ -1782,10 +1797,13 @@ async function sendText() {
|
||||
// aiMsg.content = ''
|
||||
// 发送问题到后端
|
||||
inputText.value = ''
|
||||
const controller = new AbortController()
|
||||
const signal = controller.signal
|
||||
const resp = await fetch(baseUrl + '/chat/app/completion', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', Authorization: token.value },
|
||||
body: JSON.stringify(body),
|
||||
signal: signal,
|
||||
})
|
||||
|
||||
const reader = resp.body!.getReader()
|
||||
@ -1794,6 +1812,12 @@ async function sendText() {
|
||||
let done = false
|
||||
|
||||
while (!done) {
|
||||
if (stopStreamMsg) {
|
||||
// 立刻停下
|
||||
// reader.cancel();
|
||||
controller.abort()
|
||||
stopStreamMsg = false
|
||||
}
|
||||
const { value, done: streamDone } = await reader.read()
|
||||
done = streamDone
|
||||
if (value) {
|
||||
@ -1857,6 +1881,7 @@ async function sendText() {
|
||||
sendTextLoading.value = true
|
||||
showActions.value = false
|
||||
refreshSend.value = false // 重发已经结束 关闭重发
|
||||
msgLoading.value = false
|
||||
}
|
||||
}
|
||||
function copyText(msg: IMessage) {
|
||||
@ -1892,11 +1917,17 @@ function refreshText() {
|
||||
// 2. 提取文本内容和文件列表
|
||||
let refreshText = null
|
||||
const refreshFiles: UploadFile[] = []
|
||||
if (msg1.type === 'text' && msg2.type !== 'text') {
|
||||
if (msg1 && msg1.type === 'text' && msg2 && msg2.type !== 'text') {
|
||||
msg1.mask = 'new'
|
||||
msg2.mask = 'new'
|
||||
refreshFiles.push(msg1)
|
||||
refreshFiles.push(msg2)
|
||||
} else if (msg1.type === 'text' && msg1.role === 'user' && !msg2) {
|
||||
msg1.mask = 'new'
|
||||
refreshFiles.push(msg1)
|
||||
} else if (msg2.type === 'text' && msg2.role === 'user' && !msg1) {
|
||||
msg2.mask = 'new'
|
||||
refreshFiles.push(msg2)
|
||||
} else {
|
||||
msg2.mask = 'new'
|
||||
refreshFiles.push(msg2)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 478 B |
BIN
src/static/aichat/enter-no.png
Normal file
BIN
src/static/aichat/enter-no.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
BIN
src/static/aichat/stop.png
Normal file
BIN
src/static/aichat/stop.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
Loading…
Reference in New Issue
Block a user