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
|
# 是否开启sourcemap
|
||||||
VITE_SHOW_SOURCEMAP = false
|
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
|
<div
|
||||||
ref="scrollEl"
|
ref="scrollEl"
|
||||||
class="flex-1 overflow-y-auto bg-#ffffff"
|
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']">
|
<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">
|
<template v-for="(msg, idx) in messages" :key="idx">
|
||||||
@ -181,11 +181,6 @@
|
|||||||
<!-- 文本消息 -->
|
<!-- 文本消息 -->
|
||||||
<view v-else class="pr-2">
|
<view v-else class="pr-2">
|
||||||
{{ msg.content }}
|
{{ msg.content }}
|
||||||
<text
|
|
||||||
v-if="msg.role === 'assistant' && msg.type === 'text' && !sendTextLoading"
|
|
||||||
>
|
|
||||||
...
|
|
||||||
</text>
|
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view
|
<view
|
||||||
@ -351,12 +346,28 @@
|
|||||||
}"
|
}"
|
||||||
/>
|
/>
|
||||||
<image
|
<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"
|
src="/static/aichat/enter.png"
|
||||||
class="w-7 h-7"
|
class="w-7 h-7"
|
||||||
@click="sendText()"
|
@click="sendText()"
|
||||||
:disabled="loading"
|
:disabled="loading"
|
||||||
:class="[knowledgeOpen ? 'ml-2' : 'ml-0']"
|
: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>
|
</view>
|
||||||
|
|
||||||
<!-- 操作面板 -->
|
<!-- 操作面板 -->
|
||||||
@ -482,7 +493,7 @@ import {
|
|||||||
import 'dayjs/locale/zh-cn'
|
import 'dayjs/locale/zh-cn'
|
||||||
import { showToastErr, showToastOk, time_format3 } from '@/utils/tools'
|
import { showToastErr, showToastOk, time_format3 } from '@/utils/tools'
|
||||||
import { uploadFileChunk } from './utils/api.js'
|
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 { deepClone } from 'wot-design-uni/components/common/util'
|
||||||
import { log } from 'console'
|
import { log } from 'console'
|
||||||
|
|
||||||
@ -1545,6 +1556,10 @@ interface EventTargetSendText {
|
|||||||
type EventTypeTarget = string | EventTargetSendText
|
type EventTypeTarget = string | EventTargetSendText
|
||||||
const sendTextLoading = ref(true) // false可以发送消息,true不可以发送,因为上一次发送未结束
|
const sendTextLoading = ref(true) // false可以发送消息,true不可以发送,因为上一次发送未结束
|
||||||
const refreshSend = ref(false)
|
const refreshSend = ref(false)
|
||||||
|
let stopStreamMsg = false
|
||||||
|
const stopMsg = () => {
|
||||||
|
stopStreamMsg = true
|
||||||
|
}
|
||||||
async function sendText() {
|
async function sendText() {
|
||||||
console.log('uploadList: ', uploadList)
|
console.log('uploadList: ', uploadList)
|
||||||
if (uploadList.length > 0) {
|
if (uploadList.length > 0) {
|
||||||
@ -1782,10 +1797,13 @@ async function sendText() {
|
|||||||
// aiMsg.content = ''
|
// aiMsg.content = ''
|
||||||
// 发送问题到后端
|
// 发送问题到后端
|
||||||
inputText.value = ''
|
inputText.value = ''
|
||||||
|
const controller = new AbortController()
|
||||||
|
const signal = controller.signal
|
||||||
const resp = await fetch(baseUrl + '/chat/app/completion', {
|
const resp = await fetch(baseUrl + '/chat/app/completion', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json', Authorization: token.value },
|
headers: { 'Content-Type': 'application/json', Authorization: token.value },
|
||||||
body: JSON.stringify(body),
|
body: JSON.stringify(body),
|
||||||
|
signal: signal,
|
||||||
})
|
})
|
||||||
|
|
||||||
const reader = resp.body!.getReader()
|
const reader = resp.body!.getReader()
|
||||||
@ -1794,6 +1812,12 @@ async function sendText() {
|
|||||||
let done = false
|
let done = false
|
||||||
|
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
if (stopStreamMsg) {
|
||||||
|
// 立刻停下
|
||||||
|
// reader.cancel();
|
||||||
|
controller.abort()
|
||||||
|
stopStreamMsg = false
|
||||||
|
}
|
||||||
const { value, done: streamDone } = await reader.read()
|
const { value, done: streamDone } = await reader.read()
|
||||||
done = streamDone
|
done = streamDone
|
||||||
if (value) {
|
if (value) {
|
||||||
@ -1857,6 +1881,7 @@ async function sendText() {
|
|||||||
sendTextLoading.value = true
|
sendTextLoading.value = true
|
||||||
showActions.value = false
|
showActions.value = false
|
||||||
refreshSend.value = false // 重发已经结束 关闭重发
|
refreshSend.value = false // 重发已经结束 关闭重发
|
||||||
|
msgLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function copyText(msg: IMessage) {
|
function copyText(msg: IMessage) {
|
||||||
@ -1892,11 +1917,17 @@ function refreshText() {
|
|||||||
// 2. 提取文本内容和文件列表
|
// 2. 提取文本内容和文件列表
|
||||||
let refreshText = null
|
let refreshText = null
|
||||||
const refreshFiles: UploadFile[] = []
|
const refreshFiles: UploadFile[] = []
|
||||||
if (msg1.type === 'text' && msg2.type !== 'text') {
|
if (msg1 && msg1.type === 'text' && msg2 && msg2.type !== 'text') {
|
||||||
msg1.mask = 'new'
|
msg1.mask = 'new'
|
||||||
msg2.mask = 'new'
|
msg2.mask = 'new'
|
||||||
refreshFiles.push(msg1)
|
refreshFiles.push(msg1)
|
||||||
refreshFiles.push(msg2)
|
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 {
|
} else {
|
||||||
msg2.mask = 'new'
|
msg2.mask = 'new'
|
||||||
refreshFiles.push(msg2)
|
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