LangeSelect.vue 3.3 KB
<template>
  <el-dropdown trigger="click" class="international" @command="handleSetLanguage">
    <div>
      <span class="el-dropdown-link">
        {{language}}
        <i class="el-icon-arrow-down el-icon--right"></i>
      </span>
    </div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item command="zh_CN">简体</el-dropdown-item>
      <el-dropdown-item command="zh_TW">繁體</el-dropdown-item>
      <el-dropdown-item command="en_US">English</el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>
<script>
export default {
  inject: ["reload"],
  data() {
    return {
      language: ""
    };
  },
  mounted() {
    let _lang = "";
    if (this.$Project === "store") {
      _lang = localStorage.getItem("lang");
      this.getLanguage(_lang);
      this.$i18n.locale = _lang;
      // this.langAddClass()
    } else {
      _lang = localStorage.getItem("lang");
      this.getLanguage(_lang);
      this.$i18n.locale = _lang;
    }
  },
  methods: {
    handleSetLanguage(lang) {
      this.$i18n.locale = lang;
      localStorage.setItem("lang", lang);
      this.reload();
      this.getLanguage(lang);
      // this.langAddClass()
    },
    getLanguage(val) {
      document.title = this.$t('login.platformName')
      if (val === "zh_CN" || val === "mall_CN") {
        this.language = "简体";
        // val == "mall_CN"
        //   ? (document.querySelector("title").innerText = "智慧商业客流分析平台")
        //   : (document.querySelector("title").innerText =
        //       "智慧连锁客流分析平台");
      }
      if (val === "en_US") {
        this.language = "English";
        // document.querySelector("title").innerText =
        //   "Wisdom Chain Traffic Analysis Platform";
      }
      if (val === "zh_TW") {
        this.language = "繁體";
        // document.querySelector("title").innerText = "智慧連鎖客流分析平台";
      }
    },
    langAddClass() {
      var elementDict = {
        "el-dialog": "enDialog",
        "el-form-item__label": "enLabel",
        "el-form-item__content": "enContent",
        "chart-title-icon": "en-icon"
      };
      if (this.language == "English") {
        setTimeout(() => {
          $(".el-dialog").addClass("en-dialog");
          $(".el-form-item__label").addClass("en-label");
          $(".el-form-item__content").addClass("en-content");
          $(".chart-title-icon").addClass("en-icon");
          $(".home .menu-item-box").addClass("home-title");
        }, 0);
      } else if (this.language == "简体") {
        setTimeout(() => {
          $(".el-dialog").removeClass("en-dialog");
          $(".el-form-item__label").removeClass("en-label");
          $(".el-form-item__content ").removeClass("en-content ");
          $(".home .menu-item-box").removeClass("home-title");
        }, 0);
      }
    }
  }
};
</script>
<style>
.international .el-dropdown-link {
  cursor: pointer;
  color: #fff;
  font-size: 14px;
  margin-left: 40px;
}
.el-icon-arrow-down {
  font-size: 14px;
}
.en-class {
  padding-left: 0.6rem !important;
}
.en-icon {
  left: 250px;
}
</style>
<style scoped>
.international-icon {
  font-size: 20px;
  cursor: pointer;
  vertical-align: -5px !important;
}
@media only screen and (max-width: 1280px) {
  .international .el-dropdown-link {
    font-size: 13px;
    margin-left: 10px;
  }
}
</style>