From 19099aed6f6ad841261e6262b0a7e1420f149fd5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=B8=85=E6=9F=AF?=
<10691891+qing_ke@user.noreply.gitee.com>
Date: Thu, 8 May 2025 09:28:53 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=87=8D=E6=96=B0=E5=9B=9E?=
=?UTF-8?q?=E7=AD=94=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=92=A4=E5=9B=9E=E5=8D=83?=
=?UTF-8?q?=E9=9D=A2=E7=9A=84=E9=97=AE=E7=AD=94=E5=86=85=E5=AE=B9=E4=B8=BA?=
=?UTF-8?q?=E5=8F=AF=E7=BC=96=E8=BE=91=E5=86=85=E5=AE=B9=EF=BC=8C=E6=92=A4?=
=?UTF-8?q?=E5=9B=9E=E7=9A=84=E5=86=85=E5=AE=B9=E4=B8=8D=E4=BC=9A=E5=A2=9E?=
=?UTF-8?q?=E5=8A=A0=E9=A2=9D=E5=A4=96=E7=9A=84=E4=B8=8A=E4=B8=8B=E6=96=87?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
web/src/components/ChatPrompt.vue | 48 ++++++++++-
web/src/components/ChatReply.vue | 9 +--
web/src/views/ChatPlus.vue | 128 ++++++++++++++++++++++++------
3 files changed, 152 insertions(+), 33 deletions(-)
diff --git a/web/src/components/ChatPrompt.vue b/web/src/components/ChatPrompt.vue
index a974dd84..a7aec543 100644
--- a/web/src/components/ChatPrompt.vue
+++ b/web/src/components/ChatPrompt.vue
@@ -29,7 +29,9 @@
-
+
{{ dateFormat(data.created_at) }}
{
processFiles()
})
@@ -475,4 +482,39 @@ const isExternalImg = (link, files) => {
}
}
+
+.operations
+ display none
+ position absolute
+ right 5px
+ top 5px
+
+.text-box
+ &:hover
+ .operations
+ display flex
+ gap 5px
+
+.op-edit
+ cursor pointer
+ color #409eff
+ font-size 16px
+
+ &:hover
+ color darken(#409eff, 10%)
+
+.position-relative {
+ position: relative;
+}
+
+.action-buttons {
+ position: absolute;
+ top: 10px;
+ right: 10px;
+ display: none;
+}
+
+.content:hover .action-buttons {
+ display: block;
+}
diff --git a/web/src/components/ChatReply.vue b/web/src/components/ChatReply.vue
index efe2ee5f..4ed50237 100644
--- a/web/src/components/ChatReply.vue
+++ b/web/src/components/ChatReply.vue
@@ -26,7 +26,7 @@
-
+
@@ -92,7 +92,7 @@
-
+
@@ -233,9 +233,8 @@ const stopSynthesis = () => {
}
// 重新生成
-const reGenerate = (prompt) => {
- console.log(prompt)
- emits('regen', prompt)
+const reGenerate = () => {
+ emits('regen')
}
diff --git a/web/src/views/ChatPlus.vue b/web/src/views/ChatPlus.vue
index aaa907e6..39910071 100644
--- a/web/src/views/ChatPlus.vue
+++ b/web/src/views/ChatPlus.vue
@@ -264,7 +264,7 @@
-
+
= 2) {
+ // 从后往前找,如果最后一条是AI回复,再往前一条是用户消息
+ if (chatData.value[chatData.value.length - 1].type === 'reply') {
+ // 删除AI回复
+ chatData.value.pop();
+
+ // 如果此时最后一条是用户消息,也删除它
+ if (chatData.value.length > 0 && chatData.value[chatData.value.length - 1].type === 'prompt') {
+ // 保存用户消息内容,填入输入框
+ const userPrompt = chatData.value[chatData.value.length - 1].content;
+ // 删除用户消息
+ chatData.value.pop();
+ // 填入输入框
+ prompt.value = userPrompt;
+ }
+ }
+ }
+
+ // 将光标定位到输入框并聚焦
+ nextTick(() => {
+ if (inputRef.value) {
+ inputRef.value.focus();
+ // 触发输入事件以更新文本高度
+ onInput({ keyCode: null });
+ }
+ });
+}
+
+// 编辑用户消息
+const editUserPrompt = function (messageId) {
+ // 找到要编辑的消息及其索引
+ let messageIndex = -1;
+ let messageContent = '';
+
+ for (let i = 0; i < chatData.value.length; i++) {
+ if (chatData.value[i].id === messageId) {
+ messageIndex = i;
+ messageContent = chatData.value[i].content;
+ break;
+ }
+ }
+
+ if (messageIndex === -1) return;
+
+ // 弹出编辑对话框
+ ElMessageBox.prompt('', '编辑消息', {
+ confirmButtonText: '确定',
+ cancelButtonText: '取消',
+ inputValue: messageContent,
+ inputType: 'textarea',
+ customClass: 'edit-prompt-dialog',
+ roundButton: true
+ }).then(({ value }) => {
+ if (value.trim() === '') {
+ ElMessage.warning('消息内容不能为空');
+ return;
+ }
+
+ // 更新用户消息
+ chatData.value[messageIndex].content = value;
+
+ // 移除该消息之后的所有消息
+ chatData.value = chatData.value.slice(0, messageIndex + 1);
+
+ // 添加空回复消息
+ const _role = getRoleById(roleId.value);
+ chatData.value.push({
+ chat_id: chatId,
+ role_id: roleId.value,
+ type: 'reply',
+ id: randString(32),
+ icon: _role['icon'],
+ content: '',
+ });
+
+ disableInput(false);
+
+ // 发送编辑后的消息
+ store.socket.conn.send(
+ JSON.stringify({
+ channel: 'chat',
+ type: 'text',
+ body: {
+ role_id: roleId.value,
+ model_id: modelID.value,
+ chat_id: chatId.value,
+ content: value,
+ tools: toolSelected.value,
+ stream: stream.value,
+ edit_message: true
+ },
+ })
+ );
+ }).catch(() => {
+ // 取消编辑
+ });
}
const chatName = ref('')