Browse Source

修复多语言bug

xiaohaizhao 10 months ago
parent
commit
19b6224a27
3 changed files with 28 additions and 13 deletions
  1. 16 6
      src/components/newLayout/modules/header.vue
  2. 1 1
      src/utils/i18n.js
  3. 11 6
      src/views/login/login.vue

+ 16 - 6
src/components/newLayout/modules/header.vue

@@ -39,7 +39,18 @@
       </el-dropdown-menu>
     </el-dropdown>-->
       <!--    <el-divider direction="vertical"></el-divider>-->
-      <el-button size="mint" type="primary"  style="background-color:rgb(52 106 145);margin-right: 20px;color: #FFFFFF" v-if="(usertype == 1 || usertype == 0) && siteid == 'HY'" @click="$router.push('/serviceDataScreen')">{{$t(`业务数据大屏`)}}</el-button>
+      <el-button
+        size="mint"
+        type="primary"
+        style="
+          background-color: rgb(52 106 145);
+          margin-right: 20px;
+          color: #ffffff;
+        "
+        v-if="(usertype == 1 || usertype == 0) && siteid == 'HY'"
+        @click="$router.push('/serviceDataScreen')"
+        >{{ $t(`业务数据大屏`) }}</el-button
+      >
       <svg
         t="1725853431060"
         class="icon"
@@ -144,7 +155,7 @@ export default {
       nowType: "ZH",
       languagename: "",
       usertype: JSON.parse(sessionStorage.getItem("active_account")).usertype,
-      siteid: JSON.parse(sessionStorage.getItem('active_account')).siteid
+      siteid: JSON.parse(sessionStorage.getItem("active_account")).siteid,
     };
   },
   props: ["onRender"],
@@ -193,7 +204,6 @@ export default {
       sessionStorage.setItem("active_account", JSON.stringify(item));
       await this.basicData.query_userauth(() => {
         setTimeout(() => {
-          console.log("33333");
           this.$router.go(0);
         }, 1000);
       });
@@ -217,7 +227,6 @@ export default {
       });
     },
     loginOut() {
-      let lang = localStorage.getItem("lang");
       this.$confirm(this.$t("是否要退出当前账号") + "?", this.$t("提示"), {
         confirmButtonText: this.$t("确定"),
         cancelButtonText: this.$t("取消"),
@@ -225,7 +234,6 @@ export default {
       })
         .then(() => {
           sessionStorage.clear();
-          localStorage.setItem("lang", lang);
           this.$router.push("/");
           location.reload();
         })
@@ -293,6 +301,7 @@ export default {
         this.langusge.find((v) => v.languagecode == this.nowType)
           .languagename || "简体中文";
       localStorage.setItem("lang", type);
+      localStorage.setItem("languagename", this.languagename);
       this.$nextTick(() => {
         this.$i18n.locale = type;
         this.editorChangeLanguage();
@@ -343,10 +352,11 @@ export default {
       });
     },
   },
-
   mounted() {
     this.siteInfos();
     this.languagelist();
+    
+    this.languagename = localStorage.getItem("languagename") ||"简体中文";
 
     this.accountInfo = JSON.parse(sessionStorage.getItem("active_account"));
     this.accountList = JSON.parse(

+ 1 - 1
src/utils/i18n.js

@@ -37,7 +37,7 @@ api.requested({
 })
 // 准备翻译的语言环境信息
 const i18n = new VueI18n({
-    locale: localStorage.getItem('lang') || "EN", //将语言标识存入localStorage或sessionStorage中,页面刷新不会默认中文显示
+    locale: localStorage.getItem('lang') || "ZH", //将语言标识存入localStorage或sessionStorage中,页面刷新不会默认中文显示
     messages,
     silentTranslationWarn: true, //解决vue-i18n黄色警告"value of key 'xxx' is not a string"和"cannot translate the value of keypath 'xxx'.use the value of keypath as default",可忽略
     globalInjection: true, // 全局注入

+ 11 - 6
src/views/login/login.vue

@@ -315,11 +315,15 @@ export default {
           sessionStorage.setItem("active_password", res.remindchangepassword);
           this.basicData.query_userauth().then(() => {
             this.basicData.querySite_Parameter();
-            let usertype = JSON.parse(sessionStorage.getItem('active_account')).usertype
-            let siteid = JSON.parse(sessionStorage.getItem('active_account')).siteid
-            if ((usertype == 1 || usertype == 0) && siteid == 'HY' ){
-              this.$router.push('/serviceDataScreen')
-            }else {
+            let usertype = JSON.parse(
+              sessionStorage.getItem("active_account")
+            ).usertype;
+            let siteid = JSON.parse(
+              sessionStorage.getItem("active_account")
+            ).siteid;
+            if ((usertype == 1 || usertype == 0) && siteid == "HY") {
+              this.$router.push("/serviceDataScreen");
+            } else {
               this.$router.push({ path: "/main" });
             }
             this.getAccountInfo();
@@ -344,7 +348,6 @@ export default {
         id: 10026401,
       });
       this.langusge = res.data;
-      console.log("langusge", this.langusge);
       this.nowType =
         localStorage.getItem("lang") && localStorage.getItem("lang") !== null
           ? localStorage.getItem("lang")
@@ -352,6 +355,7 @@ export default {
       this.languagename =
         this.langusge.find((v) => v.languagecode == this.nowType)
           .languagename || "简体中文";
+      localStorage.setItem("languagename", this.languagename);
     },
     async i18nChangeLanguage(type) {
       this.nowType = type;
@@ -363,6 +367,7 @@ export default {
       this.languagename =
         this.langusge.find((v) => v.languagecode == this.nowType)
           .languagename || "简体中文";
+      localStorage.setItem("languagename", this.languagename);
     },
   },
 };