Merge branch 'dev' of github.com:fit2cloudrd/metersphere-server into dev

This commit is contained in:
Captain.B 2020-02-25 11:49:00 +08:00
commit 7aca1d5163
2 changed files with 26 additions and 4 deletions

View File

@ -1,15 +1,14 @@
import Vue from 'vue'; import Vue from 'vue';
import VueI18n from "vue-i18n"; import VueI18n from "vue-i18n";
import axios from "axios";
import enLocale from "element-ui/lib/locale/lang/en"; import enLocale from "element-ui/lib/locale/lang/en";
import zh_CNLocale from "element-ui/lib/locale/lang/zh-CN"; import zh_CNLocale from "element-ui/lib/locale/lang/zh-CN";
import en_US from "./en_US";
import zh_CN from "./zh_CN"; import zh_CN from "./zh_CN";
Vue.use(VueI18n); Vue.use(VueI18n);
const messages = { const messages = {
'en_US': { 'en_US': {
...en_US,
...enLocale ...enLocale
}, },
'zh_CN': { 'zh_CN': {
@ -19,8 +18,31 @@ const messages = {
}; };
const i18n = new VueI18n({ const i18n = new VueI18n({
locale: 'en_US', locale: 'zh_CN',
messages, messages,
}); });
const loadedLanguages = ['zh_CN'];
function setI18nLanguage(lang) {
i18n.locale = lang;
axios.defaults.headers.common['Accept-Language'] = lang;
document.querySelector('html').setAttribute('lang', lang);
return lang;
}
Vue.prototype.$setLang = function (lang) {
if (i18n.locale !== lang) {
if (!loadedLanguages.includes(lang)) {
return import(`./${lang}`).then(response => {
i18n.mergeLocaleMessage(lang, response.default);
loadedLanguages.push(lang);
return setI18nLanguage(lang)
})
}
return Promise.resolve(setI18nLanguage(lang))
}
return Promise.resolve(lang)
};
export default i18n; export default i18n;

View File

@ -85,7 +85,7 @@
handleCommand(command) { handleCommand(command) {
switch (command) { switch (command) {
case "personal": case "personal":
this.$i18n.locale = "zh_CN"; this.$setLang("en_US");
break; break;
case "logout": case "logout":
this.$get("/signout", function () { this.$get("/signout", function () {