<template>
  <el-dropdown class="lang" trigger="click" @command="handleSetLanguage">
    <div>{{ language }}</div>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item :disabled="language === '中文'" command="zh">
        中文
      </el-dropdown-item>
      <el-dropdown-item :disabled="language === 'English'" command="en">
        English
      </el-dropdown-item>
    </el-dropdown-menu>
  </el-dropdown>
</template>

<script lang="ts">
import { Component, Vue, Watch } from "vue-property-decorator";
import { setLocale } from "@/lang";
import { setPageTitle } from "@/utils";
@Component
export default class extends Vue {
  get language() {
    switch (this.$i18n.locale) {
      case "zh":
        return "中文";
      default:
        return "English";
    }
  }

  private handleSetLanguage(lang: string) {
    setLocale(lang);
    setPageTitle(this.$route.meta.title);
    if (process.env.NODE_ENV !== "development") {
      location.reload(); //因为接口得重新请求
    }

    // this.$message({
    //   message: `${this.$i18n.t("SLS")}`,
    //   type: "success"
    // });
  }
}
</script>
<style lang="scss" scoped>
.lang {
  font-size: 1.2rem;
  color: #333;
}
</style>
