From a3f2ffefb246f4b3756ce4d34851671b7e2ca10d Mon Sep 17 00:00:00 2001 From: La123123 <617330105@qq.com> Date: Tue, 21 Apr 2026 15:48:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=8A=9F=E8=83=BD=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-web/src/components/chat/ChatBox.vue | 35 ++++++++- im-web/src/components/chat/ChatInput.vue | 91 ++++++++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) diff --git a/im-web/src/components/chat/ChatBox.vue b/im-web/src/components/chat/ChatBox.vue index 7b1212e..87d96e2 100644 --- a/im-web/src/components/chat/ChatBox.vue +++ b/im-web/src/components/chat/ChatBox.vue @@ -122,7 +122,7 @@ 翻译 { + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i]; + if (!node) { + continue; + } + // 文本节点 + if (node.nodeType === 3) { + continue; + } + let nodeName = node.nodeName.toLowerCase(); + // 忽略script标签 + if (nodeName === 'script') { + continue; + } + // 图片节点(包括emoji) + if (nodeName === 'img') { + hasNonTextContent = true; + return; + } + // 文件节点 + if (nodeName === 'div' && node.dataset.fileId) { + hasNonTextContent = true; + return; + } + // @用户节点 + if (nodeName === 'span' && node.dataset.id) { + hasNonTextContent = true; + return; + } + // 递归检查子节点 + if (node.childNodes && node.childNodes.length > 0) { + each(node.childNodes); + if (hasNonTextContent) { + return; + } + } + } + }; + each(nodes); + return !hasNonTextContent; + }, + // 获取纯文本内容 + getTextContent() { + let nodes = this.$refs.content.childNodes; + let textContent = ''; + let each = (nodes) => { + for (let i = 0; i < nodes.length; i++) { + let node = nodes[i]; + if (!node) { + continue; + } + // 文本节点 + if (node.nodeType === 3) { + textContent += node.textContent; + continue; + } + let nodeName = node.nodeName.toLowerCase(); + // 忽略script标签 + if (nodeName === 'script') { + continue; + } + // 忽略div节点(换行) + if (nodeName === 'div' && !node.dataset.fileId) { + textContent += '\n'; + each(node.childNodes); + continue; + } + // 递归检查子节点 + if (node.childNodes && node.childNodes.length > 0) { + each(node.childNodes); + } + } + }; + each(nodes); + return textContent.trim(); + }, + // 设置纯文本内容 + setTextContent(text) { + // 清空内容 + this.$refs.content.innerHTML = ""; + // 添加文本节点到content中 + let textNode = document.createTextNode(text); + this.$refs.content.appendChild(textNode); + // 将光标定位到文本末尾 + this.selectElement(textNode, text.length); } }