Commit 4a8d1aff authored by 水玉婷's avatar 水玉婷
Browse files

feat:点击消息直接放在输入框里

parent 9266ba84
...@@ -50,14 +50,8 @@ ...@@ -50,14 +50,8 @@
/> />
</template> </template>
<!-- 普通内容块 --> <!-- 普通内容块 -->
<div v-else class="message-inner-box"> <div v-else class="message-inner-box" @click="msg.messageType === 'sent' ? handleMessageClick(msg, item) : null">
<div v-html="item.content"></div> <div v-html="item.content"></div>
<!-- 复制按钮 -->
<div v-if="msg.messageType === 'sent'" class="message-actions">
<a-button class="copy-button" @click="copyMessage(msg)" title="复制">
<copy-outlined />
</a-button>
</div>
</div> </div>
<!-- 思考过程框 --> <!-- 思考过程框 -->
<div v-if="item.hasThinkBox" class="think-box-wrapper"> <div v-if="item.hasThinkBox" class="think-box-wrapper">
...@@ -520,50 +514,55 @@ const retrySendMessage = async (messageIndex: number) => { ...@@ -520,50 +514,55 @@ const retrySendMessage = async (messageIndex: number) => {
}); });
}; };
// 复制消息
const copyMessage = async (message: Message) => {
// 处理消息点击 - 将消息内容放到输入框
const handleMessageClick = (message: Message, block: any) => {
// 只处理文字消息,不处理音频、图表等特殊消息
if (block.audioData || block.chartData) {
return;
}
try { try {
// 提取消息中的所有文本内容 // 提取消息中的文本内容
let textToCopy = ''; let textToInput = '';
if (message.contentBlocks && message.contentBlocks.length > 0) { if (message.contentBlocks && message.contentBlocks.length > 0) {
message.contentBlocks.forEach(block => { message.contentBlocks.forEach(block => {
// 跳过非文字内容块
if (block.audioData || block.chartData) {
return;
}
if (block.content) { if (block.content) {
// 移除HTML标签,只保留纯文本 // 移除HTML标签,只保留纯文本
const textContent = block.content.replace(/<[^>]*>/g, '').trim(); const textContent = block.content.replace(/<[^>]*>/g, '').trim();
if (textContent) { if (textContent) {
textToCopy += textContent + '\n'; textToInput += textContent + '\n';
} }
} }
}); });
} }
// 如果没有内容,使用原始内容 // 如果没有内容,使用原始内容
if (!textToCopy.trim() && message.originalContent) { if (!textToInput.trim() && message.originalContent) {
textToCopy = message.originalContent; textToInput = message.originalContent;
} }
if (textToCopy.trim()) { if (textToInput.trim()) {
await navigator.clipboard.writeText(textToCopy.trim()); // 将内容设置到输入框
// 复制成功提示 messageText.value = textToInput.trim();
antdMessage.success('消息已复制到剪贴板'); // 自动调整输入框高度
} else { adjustTextareaHeight();
antdMessage.warning('没有可复制的内容'); // 聚焦到输入框
if (textarea.value) {
textarea.value.focus();
}
// 提示用户
antdMessage.success('消息内容已放入输入框');
} }
} catch (error) { } catch (error) {
console.error('复制失败:', error); console.error('处理消息点击失败:', error);
// 备用方案:使用传统的execCommand方法
try {
const textArea = document.createElement('textarea');
textArea.value = message.originalContent || '';
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
antdMessage.success('消息已复制到剪贴板');
} catch (fallbackError) {
console.error('备用复制方法也失败:', fallbackError);
}
} }
}; };
......
...@@ -294,17 +294,6 @@ li { ...@@ -294,17 +294,6 @@ li {
.message.sent .message-content { .message.sent .message-content {
background: #5B8AFE; background: #5B8AFE;
color: @white; color: @white;
.message-inner-box {
display: flex;
.copy-button {
margin-left: 8px;
width: 24px;
height: 24px;
color: #fff;
background: none;
border: none;
}
}
} }
// 图表块样式 // 图表块样式
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment