|
|
|
@ -27,6 +27,7 @@ |
|
|
|
|
|
|
|
<script> |
|
|
|
import {updateUserLanguage} from '@/api/user.js' |
|
|
|
import { normalizeLocale } from '@/i18n/i18n' |
|
|
|
// import PubSub from 'pubsub-js' |
|
|
|
import { |
|
|
|
searchSysLanguage |
|
|
|
@ -39,7 +40,7 @@ |
|
|
|
dataForm: { |
|
|
|
languageDefault: '' |
|
|
|
}, |
|
|
|
language: localStorage.getItem('locale'), |
|
|
|
language: normalizeLocale(localStorage.getItem('locale')), |
|
|
|
languageList: [] |
|
|
|
} |
|
|
|
}, |
|
|
|
@ -58,7 +59,7 @@ |
|
|
|
} |
|
|
|
}, |
|
|
|
currentLanguageName() { |
|
|
|
const langCode = this.language === 'en' ? 'en' : 'cn' |
|
|
|
const langCode = normalizeLocale(this.language) |
|
|
|
return this.$t(`main.languageName.${langCode}`) |
|
|
|
} |
|
|
|
}, |
|
|
|
@ -66,7 +67,7 @@ |
|
|
|
methods: { |
|
|
|
// 获取多语言列表 |
|
|
|
getLanguageList() { |
|
|
|
searchSysLanguage({ languageCode: this.$i18n.locale}).then(({data}) => { |
|
|
|
searchSysLanguage({}).then(({data}) => { |
|
|
|
const allowSet = new Set(['cn', 'en', 'zh-CN', 'en-US']) |
|
|
|
this.languageList = (data.rows || []).filter(item => allowSet.has(item.languageCode)) |
|
|
|
}) |
|
|
|
@ -80,10 +81,13 @@ |
|
|
|
}, |
|
|
|
// 修改用户默认语言 |
|
|
|
dataFormSubmit() { |
|
|
|
updateUserLanguage(this.dataForm).then(({data}) => { |
|
|
|
const normalizedLanguage = normalizeLocale(this.dataForm.languageDefault || this.language) |
|
|
|
updateUserLanguage({ languageDefault: normalizedLanguage }).then(({data}) => { |
|
|
|
if (data.code == 0) { |
|
|
|
language: localStorage.setItem('locale',this.dataForm.languageDefault) |
|
|
|
this.$router.go(0); |
|
|
|
this.$i18n.locale = normalizedLanguage |
|
|
|
this.language = normalizedLanguage |
|
|
|
localStorage.setItem('locale', normalizedLanguage) |
|
|
|
this.$router.go(0) |
|
|
|
// PubSub.publish('search',this.dataForm.languageDefault ) |
|
|
|
// this.$router.replace({name: 'login'}) |
|
|
|
} |
|
|
|
|