LangeSelect.vue 2.68 KB
<template>
  <el-dropdown v-if="!login" 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>
  <div v-else class="login-change">
    <div class="item" v-for="(item, idx) in lans" :key="idx"
      :style="{
        color: language === item.label ? '#69C0FF' : '#fff',
        marginRight: idx === 2 ? 0 : '32px'
      }" @click="handleSetLanguage(item.key)">{{ item.name }}</div>
  </div>
</template>
<script>
export default {
  inject: ["reload"],
  props: {
    login: Boolean
  },
  data() {
    return {
      language: "",
      lans: [
        {
          name: '简体中文',
          label: '简体',
          key: 'zh_CN'
        },
        {
          name: '繁體中文',
          label: '繁體',
          key: 'zh_TW'
        },
        {
          name: 'English',
          label: 'English',
          key: 'en_US'
        }
      ]
    };
  },
  mounted() {
    this.$nextTick(()=>{
      setTimeout(()=>{
        let _lang = "";
        _lang = localStorage.getItem("lang");
        this.$i18n.locale = _lang;
        this.getLanguage(_lang);
        document.title = this.$t('login.platformName')
      },1000)
    })
  },
  methods: {
    handleSetLanguage(lang) {
      this.$i18n.locale = lang;
      localStorage.setItem("lang", lang);
      this.reload();
      this.getLanguage(lang);
    },
    getLanguage(val) {
      document.title = this.$t('login.platformName')
      if (val === "zh_CN" || val === "mall_CN") {
        this.language = "简体";
      }
      if (val === "en_US") {
        this.language = "English";
      }
      if (val === "zh_TW") {
        this.language = "繁體";
      }
    },
  }
};
</script>
<style>
.international .el-dropdown-link {
  cursor: pointer;
  color: #fff;
  font-size: 14px;
  margin-left: 20px;
  margin-right: 20px;
}
.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;
}
.login-change {
  display: flex;
}
.login-change .item {
  font-size: 15px;
  line-height: 18px;
  cursor: pointer;
}
@media only screen and (max-width: 1280px) {
  .international .el-dropdown-link {
    font-size: 13px;
    margin-left: 10px;
  }
}
</style>