feat: 增加消息停止功能,修改重发bug

This commit is contained in:
常东方 2025-06-06 13:50:06 +08:00
parent 6296bc5e19
commit 7c90333fcf
7 changed files with 70 additions and 9 deletions

14
.vscode/launch.json vendored Normal file
View 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
View 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
View File

@ -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

View File

@ -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) // falsetrue
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

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

BIN
src/static/aichat/stop.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB