Jelajahi Sumber

中英文切换

Shan9312 9 bulan lalu
induk
melakukan
c06d556601

+ 3 - 3
src/i18n.js

@@ -11,7 +11,7 @@ import locale from 'element-ui/lib/locale'
 Vue.use(VueI18n)
 
 
-const lang = navigator.language || 'zh'
+const lang = localStorage.getItem('lang') || navigator.language
 console.log('初始语言类型', lang);
 
 const messages= {
@@ -20,9 +20,9 @@ const messages= {
 }
 
 const i18n = new VueI18n({
-  locale:'en' || lang, // set locale
+  locale: lang, // set locale
   messages:messages,
-  fallbackLocale: 'en', // 默认语言设置,当其他语言没有的情况下,使用en作为默认语言
+  // fallbackLocale: 'en', // 默认语言设置,当其他语言没有的情况下,使用en作为默认语言
 
 
 })

+ 1 - 0
src/icons/svg/lang.svg

@@ -0,0 +1 @@
+<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1718379151830" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3473" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M249.7536 378.5728c10.6496 31.6416 28.3648 59.0848 53.0432 83.2512 20.992-22.7328 36.7616-50.7904 47.0016-83.2512h-100.0448zM902.2464 191.488H511.2832L488.96 71.8848H125.952c-40.0384 0-72.6016 32.5632-72.6016 72.6016v617.1648c0 40.0384 32.5632 72.6016 72.6016 72.6016h330.9568l-26.5216 119.6032h471.9616c40.0384 0 72.6016-32.5632 72.6016-72.6016V264.192c-0.1024-40.1408-32.768-72.704-72.704-72.704zM409.3952 558.1824c-42.8032-15.7696-78.1312-35.84-106.5984-59.0848-29.7984 26.5216-67.072 46.08-110.2848 58.1632l-14.9504-24.6784c42.3936-11.1616 77.7216-27.9552 105.5744-51.712-28.7744-29.3888-48.8448-63.2832-60.1088-101.888h-40.448v-27.9552h105.5744c-6.5536-12.0832-14.9504-23.7568-24.6784-34.9184l27.9552-10.24c9.728 12.5952 18.6368 27.4432 26.5216 44.7488h100.9664v27.9552h-40.448c-13.0048 40.0384-31.6416 73.5232-56.32 100.5568 27.4432 21.9136 61.8496 40.0384 102.4 54.8864 0.1024 0.2048-15.1552 24.1664-15.1552 24.1664z m529.1008 322.56a36.352 36.352 0 0 1-36.352 36.352H475.9552l18.1248-83.2512h136.2944l-77.7216-433.2544-0.4096 2.3552-3.2768-17.3056 0.9216 0.4096-28.3648-158.3104h381.1328a36.352 36.352 0 0 1 36.352 36.352v616.6528h-0.512zM643.4816 538.2144h100.1472v-26.5216h-100.1472v-53.0432h106.5984V432.128H612.2496v190.7712h141.9264v-26.5216H643.4816v-58.1632z m208.9984-57.2416c-8.3968 0-15.7696 1.3312-22.7328 5.12-6.5536 3.2768-13.0048 8.3968-18.1248 14.9504v-16.2816H781.312v138.24h30.3104v-83.2512c0.9216-11.1616 4.7104-19.5584 11.1616-25.6 5.632-5.12 12.0832-7.9872 19.5584-7.9872 20.992 0 31.1296 11.1616 31.1296 33.9968v82.432h30.3104v-85.2992c0.8192-37.6832-16.896-56.32-51.3024-56.32z" fill="#01996a" p-id="3474"></path></svg>

+ 3 - 3
src/lang/zn/langModule/auth.js

@@ -20,7 +20,7 @@ export default{
    logpMsg:'您已注销。您可以取消或重新登录',
    relogo:'重新登陆',//重新登陆
    conLogo:'确认注销', //   确认注销
-   company:" Beijing Jingpeng Huanyu Animal Husbandry TechnologyCo., Ltd",
-   companyTit:"All Rights Reserved"
+   company:"北京京鹏环宇畜牧科技股份有限公司",
+   companyTit:"版权所有"
 
-}
+}

+ 4 - 19
src/layout/components/Navbar.vue

@@ -34,13 +34,13 @@
       </el-dropdown> -->
 
       <!-- 切换中英文 -->
-      <el-switch
+      <!-- <el-switch
         class="swichs"
         v-model="langValue"
         inactive-text="英文"
         active-text="中文"
         @change="translate"
-      ></el-switch>
+      ></el-switch> -->
       <el-dropdown class="avatar-container" trigger="click">
         <div class="avatar-wrapper">
           <!-- <img src="@/assets/cow.jpg" class="user-avatar"> -->
@@ -105,7 +105,7 @@ export default {
     ])
   },
   created() {
-    this.setSwitch();
+    // this.setSwitch();
 
     // window.setInterval(() => {
     //   setTimeout(() => {
@@ -115,22 +115,7 @@ export default {
     // }, 100)
   },
   methods: {
-    // 获取浏览器当前中英文
-    setSwitch() {
-      console.log(navigator.language,'navigator.language1')
-      this.lang = navigator.language === 'zh-CN'? 'zh' :'en'
-      this.translate()
-    },
-    // 切换中英文的调用
-    translate() {
-      this.lang = this.lang === 'zh' ? 'en' : 'zh'
-      this.$i18n.locale = this.lang
-      if(this.$i18n.locale == 'zh'){
-        localStorage.setItem('lang','zh-CN')
-      }else{
-        localStorage.setItem('lang','en-US')
-      }
-    },
+
 
     toggleSideBar() {
       this.$store.dispatch('app/toggleSideBar')

+ 34 - 1
src/views/login/index.vue

@@ -1,5 +1,16 @@
 <template>
   <div class="login-container">
+    <div class="lang">
+      <el-dropdown trigger="click" @command="translate">
+        <span class="el-dropdown-link svgs">
+            <svg-icon icon-class="lang" />
+        </span>
+      <el-dropdown-menu slot="dropdown">
+        <el-dropdown-item command="zh-CN">简体中文</el-dropdown-item>
+        <el-dropdown-item command="en-US">English</el-dropdown-item>
+      </el-dropdown-menu>
+</el-dropdown>
+    </div>
     <div class="new-login">
       <div class="new-login-l">
         <div class="imgs">
@@ -76,6 +87,7 @@ export default {
       }
     }
     return {
+      lang:"",
       loginForm: {
         username: '',
         password: ''
@@ -113,6 +125,7 @@ export default {
     }
   },
   created() {
+
     var that = this
     document.onkeydown = function (e) {
       e = window.event || e
@@ -126,11 +139,22 @@ export default {
       }
     }
   },
-  mounted: function () {
+  mounted() {
     // 读取cookie中的账号信息,如果有accountInfo的话,则说明该用户之前勾选了记住密码的功能,则需要自动填上账号密码
+    this.setSwitch()
     this.loadAccountInfo()
   },
   methods: {
+     // 获取浏览器当前中英文
+     setSwitch() {
+      this.lang =localStorage.getItem('lang') ||  navigator.language
+
+    },
+    // 切换中英文的调用
+    translate(val) {
+      this.$i18n.locale = val
+      localStorage.setItem('lang',val)
+    },
     showPwd() {
       if (this.passwordType === 'password') {
         this.passwordType = ''
@@ -435,6 +459,15 @@ $light_gray: #000;
 $bg: #ccc;
 $light_gray: #ccc;
 $cursor: #000;
+.lang{
+  float:right;
+  padding-right: 50px;
+  margin-top: 30px;
+  cursor: pointer;
+  .svgs{
+    font-size:32px;
+  }
+}
 .login-container {
   position: relative;
   height: 100%;