zhs 3 vuotta sitten
vanhempi
commit
2dfd4d36f1

+ 1 - 3
src/main/resources/static/js/indexHome/even.js

@@ -9,6 +9,4 @@ var countSum = 0;//消息数量
 var username = null;//用户编号
 var nickname = null;//用户名称
 var headImg = null;//头像
-// var token = null;
-
-var type = "zh";
+var type = "zh";//当前语言类型

+ 29 - 1
src/main/resources/static/js/indexHome/function.js

@@ -427,7 +427,35 @@ function messageLoadOld(item, img, time){
 }
 //翻译
 function translation(){
-
+    let value = clickEven.find("p").eq(0).text();
+    clickEven.find("p").eq(1).html(translationResults(value)).show();
+}
+//翻译结果
+function translationResults(translationVal){
+    let results = null;
+    $.ajax({
+        url: 'https://www.tuyatrip.com/api/translationInterface/translation',
+        async: false,
+        type: "get",
+        data: {
+            "translationVal": translationVal,
+            "from": "auto",
+            "to": type
+        },
+        headers: {"token": localStorage.getItem("token")},
+        dataType: "json",
+        success: (data) => {
+            if(data.hasOwnProperty("error_code")){
+                results = "翻译失败"
+            } else {
+                results = data.result.trans_result[0].dst;
+            }
+        },
+        error: () => {
+            results = "翻译失败"
+        }
+    });
+    return results;
 }
 //复制
 function copyVal(){