From 9247edc215d8173debb41fcb677308c24630fea4 Mon Sep 17 00:00:00 2001
From: La123123 <617330105@qq.com>
Date: Tue, 21 Apr 2026 15:07:07 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E5=AE=A2=E6=9C=8D=E9=A1=B5=E9=9D=A2?=
=?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=8A=9F=E8=83=BD=E6=A0=B7=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../controller/LoginController.java | 15 ++++++--
im-web/src/components/chat/ChatBox.vue | 38 +++++++++++++++++++
2 files changed, 50 insertions(+), 3 deletions(-)
diff --git a/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java b/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java
index fba3da3..8375a18 100644
--- a/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java
+++ b/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java
@@ -75,13 +75,22 @@ public class LoginController {
}
@PostMapping("/getTranslate")
- @Operation(summary = "获取配置", description = "用户注册")
+ @Operation(summary = "翻译文本", description = "翻译文本")
public Result getTranslate(@RequestBody JSONObject jsonObject) {
- System.out.println("1111111111");
String str = jsonObject.getStr("str");
- String trans = BaiduTranslationUtils.translate(str,"zh");
+ if(str == null || str.isEmpty()){
+ return ResultUtils.success("","success");
+ }
+ //翻译目标国家
+ String country = jsonObject.getStr("country");
+ String trans = "";
+ if(country == null || country.isEmpty()) {
+ trans = BaiduTranslationUtils.translate(str, "zh");
+ }else{
+ trans = BaiduTranslationUtils.translate(str, country);
+ }
return ResultUtils.success(trans,"success");
}
diff --git a/im-web/src/components/chat/ChatBox.vue b/im-web/src/components/chat/ChatBox.vue
index f927c31..7b1212e 100644
--- a/im-web/src/components/chat/ChatBox.vue
+++ b/im-web/src/components/chat/ChatBox.vue
@@ -108,6 +108,23 @@
@submit="sendMessage"
/>
+
+
+
+ 翻译
Date: Tue, 21 Apr 2026 15:48:54 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=E5=AE=8C=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);
}
}
From 2ff61a8d162d0cdcdcce511d5aef4dc300dd29e4 Mon Sep 17 00:00:00 2001
From: La123123 <617330105@qq.com>
Date: Tue, 21 Apr 2026 15:56:33 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E7=BF=BB=E8=AF=91api=E5=8F=82=E6=95=B0?=
=?UTF-8?q?=E9=80=BB=E8=BE=91=E5=8F=98=E6=9B=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../java/com/bx/implatform/controller/LoginController.java | 3 +++
1 file changed, 3 insertions(+)
diff --git a/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java b/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java
index 8375a18..ef45259 100644
--- a/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java
+++ b/im-platform/src/main/java/com/bx/implatform/controller/LoginController.java
@@ -83,6 +83,9 @@ public class LoginController {
return ResultUtils.success("","success");
}
+ //如果有换行符,替换为空
+ str = str.replace("\n", "");
+
//翻译目标国家
String country = jsonObject.getStr("country");
String trans = "";