diff --git a/src/layout/components/NavHeader/index.vue b/src/layout/components/NavHeader/index.vue
index bad83dfc9..aff63a9dc 100644
--- a/src/layout/components/NavHeader/index.vue
+++ b/src/layout/components/NavHeader/index.vue
@@ -18,11 +18,10 @@
@@ -46,13 +45,34 @@ export default {
},
data() {
return {
- LANG_COOKIE_NAME: 'django_language'
+ LANG_COOKIE_NAME: 'django_language',
+ supportLanguages: [
+ {
+ title: '中文(简体)',
+ code: 'cn',
+ cookieCode: 'zh-hans'
+ },
+ {
+ title: 'English',
+ code: 'en',
+ cookieCode: 'en'
+ }
+ ]
}
},
computed: {
...mapGetters([
'sidebar'
- ])
+ ]),
+ currentLang() {
+ const cookieCode = this.$cookie.get(this.LANG_COOKIE_NAME)
+ let lang = this.supportLanguages.find((v) => v.cookieCode === cookieCode)
+ if (!lang) {
+ lang = this.supportLanguages[0]
+ this.changeLangTo(lang)
+ }
+ return lang
+ }
},
methods: {
toggleSideBar() {
@@ -62,15 +82,11 @@ export default {
await this.$store.dispatch('users/logout')
this.$router.push(`/login?redirect=${this.$route.fullPath}`)
},
- changeLangToZH() {
- this.$i18n.locale = 'cn'
- localStorage.setItem('lang', 'cn')
- this.$cookie.set(this.LANG_COOKIE_NAME, 'zh-hans')
- },
- changeLangToEnglish() {
- this.$i18n.locale = 'en'
- localStorage.setItem('lang', 'en')
- this.$cookie.set(this.LANG_COOKIE_NAME, 'en')
+ changeLangTo(item) {
+ this.$i18n.locale = item.code
+ localStorage.setItem('lang', item.code)
+ this.$cookie.set(this.LANG_COOKIE_NAME, item.cookieCode)
+ window.location.reload()
}
}
}