fix: 修复语言设置逻辑问题
This commit is contained in:
@@ -39,10 +39,10 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { mapActions } from 'vuex'
|
import { mapActions } from 'vuex'
|
||||||
import { post, get } from '@/utils/http'
|
import { get } from '@/utils/http'
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { storageKey } from '@/utils/constants'
|
import { storageKey, defaultLang } from '@/utils/constants'
|
||||||
import { api } from '@/utils/api'
|
import { api } from '@/utils/api'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
@@ -73,17 +73,18 @@ export default {
|
|||||||
axios.post(api.login, { username: this.username, pin: this.pin }).then(
|
axios.post(api.login, { username: this.username, pin: this.pin }).then(
|
||||||
res => {
|
res => {
|
||||||
if (res.data.code === 200) {
|
if (res.data.code === 200) {
|
||||||
if (!_.isEmpty(res.data.data.lang)) {
|
if (!_.isEmpty(res.data.data.user.lang)) {
|
||||||
localStorage.setItem(storageKey.language, res.data.data.lang)
|
localStorage.setItem(storageKey.language, res.data.data.user.lang)
|
||||||
}
|
}
|
||||||
if (!_.isEmpty(res.data.data.theme)) {
|
if (!_.isEmpty(res.data.data.user.theme)) {
|
||||||
localStorage.setItem(storageKey.theme, res.data.data.theme)
|
localStorage.setItem(storageKey.theme, res.data.data.user.theme)
|
||||||
}
|
}
|
||||||
res.loginSuccessPath = this.$route.query.redirect
|
res.loginSuccessPath = this.$route.query.redirect
|
||||||
this.loginSuccess(res)
|
this.loginSuccess(res)
|
||||||
localStorage.setItem(storageKey.username, this.username)
|
localStorage.setItem(storageKey.username, this.username)
|
||||||
localStorage.setItem(storageKey.userId, res.data.data.user ? res.data.data.user.userId : res.data.data.userId)
|
localStorage.setItem(storageKey.userId, res.data.data.user.userId)
|
||||||
localStorage.setItem(storageKey.token, res.data.data.token)
|
localStorage.setItem(storageKey.token, res.data.data.token)
|
||||||
|
this.$i18n.locale = localStorage.getItem(storageKey.language)
|
||||||
} else if (res.data.code === 518005) {
|
} else if (res.data.code === 518005) {
|
||||||
this.$message.error(this.$t('Incorrect username or password'))
|
this.$message.error(this.$t('Incorrect username or password'))
|
||||||
this.loading = false
|
this.loading = false
|
||||||
@@ -110,7 +111,7 @@ export default {
|
|||||||
},
|
},
|
||||||
appearanceOut (data) {
|
appearanceOut (data) {
|
||||||
if (_.isEmpty(localStorage.getItem(storageKey.language))) {
|
if (_.isEmpty(localStorage.getItem(storageKey.language))) {
|
||||||
localStorage.setItem(storageKey.language, data.lang || 'zh')
|
localStorage.setItem(storageKey.language, data.lang || defaultLang)
|
||||||
}
|
}
|
||||||
if (_.isEmpty(localStorage.getItem(storageKey.theme))) {
|
if (_.isEmpty(localStorage.getItem(storageKey.theme))) {
|
||||||
localStorage.setItem(storageKey.theme, data.theme || 'light')
|
localStorage.setItem(storageKey.theme, data.theme || 'light')
|
||||||
|
|||||||
@@ -2,15 +2,9 @@ import { createI18n } from 'vue-i18n/index'
|
|||||||
import { storageKey } from '@/utils/constants'
|
import { storageKey } from '@/utils/constants'
|
||||||
import { getI18n } from '@/utils/api'
|
import { getI18n } from '@/utils/api'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
// import cn from './cn'
|
|
||||||
// import en from './en'
|
|
||||||
|
|
||||||
const i18n = createI18n({
|
const i18n = createI18n({
|
||||||
locale: localStorage.getItem(storageKey.language) || 'en'
|
locale: localStorage.getItem(storageKey.language) || 'en'
|
||||||
/* messages: {
|
|
||||||
cn: cn,
|
|
||||||
en: en
|
|
||||||
} */
|
|
||||||
})
|
})
|
||||||
export async function loadI18n () {
|
export async function loadI18n () {
|
||||||
if (!store.state.i18n) {
|
if (!store.state.i18n) {
|
||||||
|
|||||||
@@ -22,9 +22,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
}
|
}
|
||||||
if (localStorage.getItem(storageKey.token)) {
|
if (localStorage.getItem(storageKey.token)) {
|
||||||
// 加载i18n
|
// 加载i18n
|
||||||
if (!localStorage.getItem(storageKey.i18n)) {
|
|
||||||
await loadI18n()
|
await loadI18n()
|
||||||
}
|
|
||||||
// 加载权限
|
// 加载权限
|
||||||
if (permissionWhiteList.indexOf(to.path) !== -1) {
|
if (permissionWhiteList.indexOf(to.path) !== -1) {
|
||||||
next()
|
next()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
export const defaultPageSize = 20
|
export const defaultPageSize = 20
|
||||||
|
export const defaultLang = 'en'
|
||||||
// indexedDB库名
|
// indexedDB库名
|
||||||
export const dbName = 'cn-db'
|
export const dbName = 'cn-db'
|
||||||
// indexedDB表名
|
// indexedDB表名
|
||||||
@@ -16,7 +16,6 @@ export const dbGalaxySettingTableColumnCustomizeConfig = 'cn-table-column-custom
|
|||||||
export const storageKey = {
|
export const storageKey = {
|
||||||
iso36112Capital: 'cn-iso3611-2-capital',
|
iso36112Capital: 'cn-iso3611-2-capital',
|
||||||
iso36112WorldLow: 'cn-iso3611-2-world-low',
|
iso36112WorldLow: 'cn-iso3611-2-world-low',
|
||||||
i18n: 'cn-i18n',
|
|
||||||
s3Enable: 'cn-s3-enable',
|
s3Enable: 'cn-s3-enable',
|
||||||
languages: 'cn-languages',
|
languages: 'cn-languages',
|
||||||
language: 'cn-language',
|
language: 'cn-language',
|
||||||
|
|||||||
Reference in New Issue
Block a user