diff --git a/cmdb-ui/src/components/tools/UserMenu.vue b/cmdb-ui/src/components/tools/UserMenu.vue index ffcb814..4e410ef 100644 --- a/cmdb-ui/src/components/tools/UserMenu.vue +++ b/cmdb-ui/src/components/tools/UserMenu.vue @@ -48,7 +48,7 @@ import NoticeIcon from '@/components/NoticeIcon' import { mapActions, mapGetters } from 'vuex' import LangSelect from '@/components/tools/LangSelect' -import { showLocale } from '@/locales' +import config from '@/config/defaultSettings' export default { name: 'UserMenu', @@ -57,7 +57,7 @@ export default { }, data () { return { - showLocale: showLocale + showLocale: config.showLocale } }, methods: { diff --git a/cmdb-ui/src/config/defaultSettings.js b/cmdb-ui/src/config/defaultSettings.js index a7136e2..3658d94 100644 --- a/cmdb-ui/src/config/defaultSettings.js +++ b/cmdb-ui/src/config/defaultSettings.js @@ -14,6 +14,8 @@ */ export default { + showLocale: true, + defaultLang: 'zh-CN', useSSO: false, primaryColor: '#1890ff', // primary color of ant design navTheme: 'dark', // theme for nav menu diff --git a/cmdb-ui/src/locales/index.js b/cmdb-ui/src/locales/index.js index db7a755..4616e50 100644 --- a/cmdb-ui/src/locales/index.js +++ b/cmdb-ui/src/locales/index.js @@ -6,12 +6,10 @@ import enUS from './lang/en-US' import zhCN from './lang/zh-CN' // change default accept-language import { axios } from '@/utils/request' +import config from '@/config/defaultSettings' Vue.use(VueI18n) -export const defaultLang = 'zh-CN' -export const showLocale = true - const messages = { 'en-US': { ...enUS @@ -22,14 +20,14 @@ const messages = { } const i18n = new VueI18n({ - locale: defaultLang, - fallbackLocale: defaultLang, + locale: config.defaultLang, + fallbackLocale: config.defaultLang, messages }) export default i18n -const loadedLanguages = [defaultLang] +const loadedLanguages = [config.defaultLang] function setI18nLanguage (lang) { i18n.locale = lang @@ -42,9 +40,9 @@ export function i18nRender (key) { return i18n.t(key) } -export function loadLanguageAsync (lang = defaultLang) { +export function loadLanguageAsync (lang = config.defaultLang) { return new Promise(resolve => { - Vue.ls.set('lang', lang) + localStorage.setItem('lang', lang) if (i18n.locale !== lang) { if (!loadedLanguages.includes(lang)) { return import(/* webpackChunkName: "lang-[request]" */ `./lang/${lang}`).then(msg => { @@ -59,6 +57,6 @@ export function loadLanguageAsync (lang = defaultLang) { }) } -// if (Vue.ls.get('lang') !== null && defaultLang !== Vue.ls.get('lang')) { -// loadLanguageAsync(localStorage.lang) -// } +if (localStorage.getItem('lang') !== null && config.defaultLang !== localStorage.getItem('lang')) { + loadLanguageAsync(localStorage.lang) +}