diff --git a/nezha-fronted/src/components/common/i18n.js b/nezha-fronted/src/components/common/i18n.js
index a9a8076e8..55d153552 100644
--- a/nezha-fronted/src/components/common/i18n.js
+++ b/nezha-fronted/src/components/common/i18n.js
@@ -1,6 +1,7 @@
import Vue from 'vue'
import locale from 'element-ui/lib/locale'
import VueI18n from 'vue-i18n'
+import { get } from '@/http'
// import messages from './language'
Vue.use(VueI18n)
// 从localStorage获取语言选择。
@@ -15,14 +16,6 @@ export function loadI18n (i18nData) {
Object.keys(i18nData).forEach(lang => {
i18n.setLocaleMessage(lang, i18nData[lang])
})
- } else {
- i18nData = localStorage.getItem('nz-i18n-data')
- if (i18nData) {
- i18nData = JSON.parse(i18nData)
- Object.keys(i18nData).forEach(lang => {
- i18n.setLocaleMessage(lang, i18nData[lang])
- })
- }
}
}
export default i18n
diff --git a/nezha-fronted/src/components/common/login.vue b/nezha-fronted/src/components/common/login.vue
index 22fa1c8e3..495deb71d 100644
--- a/nezha-fronted/src/components/common/login.vue
+++ b/nezha-fronted/src/components/common/login.vue
@@ -112,6 +112,8 @@
import { mapActions } from 'vuex'
import QRCode from 'qrcodejs2'
import bus from '@/libs/bus.js'
+import { get } from '@/http'
+import { loadI18n } from '@/components/common/i18n'
export default {
name: 'login',
data () {
@@ -149,7 +151,6 @@ export default {
if (this.loading || !this.license.valid) {
return
}
- // if (this.license.valid && this.validateLogin() && (this.$route.path == '/' || this.$route.path == '/login')) {
if (this.validateLogin() && (this.$route.path == '/' || this.$route.path == '/login')) {
this.loading = true
this.$post('/sys/login', this.loginData).then(res => {
@@ -158,6 +159,14 @@ export default {
this.authToken = res.data.authToken
this.lang = res.data.user.lang
this.$i18n.locale = this.lang
+ // 获取可选语言
+ get('/sys/dict/all?type=lang').then(response => {
+ if (response.code === 200) {
+ const langList = response.data.map(lang => ({ name: lang.name, value: lang.value }))
+ this.$store.commit('setLangList', langList)
+ localStorage.setItem('nz-language-list', JSON.stringify(langList))
+ }
+ })
sessionStorage.setItem('nz-token', res.data.authToken)
if (res.data.authFlag === 1) {
if (res.data.authBind === 0) {
diff --git a/nezha-fronted/src/components/common/rightBox/profileBox.vue b/nezha-fronted/src/components/common/rightBox/profileBox.vue
index 52c6adbed..16af1b492 100644
--- a/nezha-fronted/src/components/common/rightBox/profileBox.vue
+++ b/nezha-fronted/src/components/common/rightBox/profileBox.vue
@@ -122,7 +122,13 @@ export default {
if (res.code === 200) {
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
this.esc(true)
- this.$emit('clickProfile')
+ if (this.editProfile.lang !== localStorage.getItem('nz-language')) {
+ localStorage.setItem('nz-language', this.editProfile.lang)
+ this.$i18n.locale = this.editProfile.lang
+ this.$emit('clickProfile', true)
+ } else {
+ this.$emit('clickProfile', false)
+ }
} else {
this.$message.error(res.msg)
}
diff --git a/nezha-fronted/src/components/layout/header.vue b/nezha-fronted/src/components/layout/header.vue
index cbffd7976..1a04af0b5 100644
--- a/nezha-fronted/src/components/layout/header.vue
+++ b/nezha-fronted/src/components/layout/header.vue
@@ -41,12 +41,6 @@
{{lang.name}}
-
@@ -65,7 +59,6 @@
-
@@ -73,12 +66,10 @@
diff --git a/nezha-fronted/src/permission.js b/nezha-fronted/src/permission.js
index f58a30f30..24e4866e7 100644
--- a/nezha-fronted/src/permission.js
+++ b/nezha-fronted/src/permission.js
@@ -12,8 +12,8 @@ const loginWhiteList = ['/setup', '/sys/license/upload', '/sys/license/state'] /
const permissionWhiteList = ['/profile', '/menu', ...loginWhiteList] // 权限白名单
router.beforeEach((to, from, next) => {
+ const configUrl = 'static/config.json?Timestamp=' + new Date().getTime()
if (to.path === '/login') { // 拦截登录页面,系统初始化检查
- const configUrl = 'static/config.json?Timestamp=' + new Date().getTime()
Vue.http.get(configUrl).then(config => {
get(config.body.baseUrl + 'setup/inited').then(res => {
if (res.code === 200) {
@@ -24,20 +24,33 @@ router.beforeEach((to, from, next) => {
}
}
})
+ if (!store.getters.i18nIsReady) {
+ get(config.body.baseUrl + 'sys/i18n/lang').then(res => {
+ if (res.code === 200) {
+ loadI18n(res.data)
+ store.commit('i18nReady', true)
+ }
+ })
+ }
})
} else if (sessionStorage.getItem('nz-token')) {
// 从localStorage加载i18n
if (!store.getters.i18nIsReady) {
- loadI18n()
+ Vue.http.get(configUrl).then(config => {
+ get(config.body.baseUrl + 'sys/i18n/lang').then(response => {
+ if (response.code === 200) {
+ loadI18n(response.data)
+ store.commit('i18nReady', true)
+ }
+ })
+ })
const langList = localStorage.getItem('nz-language-list')
if (langList) {
store.commit('setLangList', JSON.parse(langList))
}
- store.commit('i18nReady', true)
}
new Promise(resolve => {
if (store.getters.menuList.length === 0) {
- const configUrl = 'static/config.json?Timestamp=' + new Date().getTime()
Vue.http.get(configUrl).then(config => {
post(config.body.baseUrl + 'sys/user/permissions', { token: sessionStorage.getItem('nz-token') }).then(res => {
store.commit('setMenuList', sortByOrderNum(res.data.menus))
diff --git a/nezha-fronted/src/store/user.js b/nezha-fronted/src/store/user.js
index 4298e0368..0ab28199a 100644
--- a/nezha-fronted/src/store/user.js
+++ b/nezha-fronted/src/store/user.js
@@ -3,7 +3,6 @@ import router from '../router'
import bus from '../libs/bus'
import { sortByOrderNum } from '@/permission'
import moment from 'moment-timezone'
-import i18n, { loadI18n } from '@/components/common/i18n'
const user = {
state: {
@@ -75,32 +74,6 @@ const user = {
localStorage.setItem('nz-user-name', userList.name)
}
})
- // 获取用户语言,存进localStorage
- localStorage.setItem('nz-language', res.data.user.lang || 'en')
- // 获取国际化内容
- const getI18nData = new Promise(resolve => get('/sys/i18n/lang').then(response => {
- if (response.code === 200) {
- const i18nData = response.data
- localStorage.setItem('nz-i18n-data', JSON.stringify(i18nData))
- resolve(i18nData)
- } else {
- resolve()
- }
- }))
- // 获取可选语言
- const getLangList = new Promise(resolve => get('/sys/dict/all?type=lang').then(response => {
- if (response.code === 200) {
- const langList = response.data.map(lang => ({ name: lang.name, value: lang.value }))
- store.commit('setLangList', langList)
- localStorage.setItem('nz-language-list', JSON.stringify(langList))
- }
- resolve()
- }))
- Promise.all([getI18nData, getLangList]).then(response => {
- console.info(response)
- response[0] && loadI18n(response[0])
- store.commit('i18nReady', true)
- })
},
logoutSuccess (store, res) {
sessionStorage.removeItem('nz-username')