NEZ-1164 fix: 登录页支持国际化
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import Vue from 'vue'
|
import Vue from 'vue'
|
||||||
import locale from 'element-ui/lib/locale'
|
import locale from 'element-ui/lib/locale'
|
||||||
import VueI18n from 'vue-i18n'
|
import VueI18n from 'vue-i18n'
|
||||||
|
import { get } from '@/http'
|
||||||
// import messages from './language'
|
// import messages from './language'
|
||||||
Vue.use(VueI18n)
|
Vue.use(VueI18n)
|
||||||
// 从localStorage获取语言选择。
|
// 从localStorage获取语言选择。
|
||||||
@@ -15,14 +16,6 @@ export function loadI18n (i18nData) {
|
|||||||
Object.keys(i18nData).forEach(lang => {
|
Object.keys(i18nData).forEach(lang => {
|
||||||
i18n.setLocaleMessage(lang, i18nData[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
|
export default i18n
|
||||||
|
|||||||
@@ -112,6 +112,8 @@
|
|||||||
import { mapActions } from 'vuex'
|
import { mapActions } from 'vuex'
|
||||||
import QRCode from 'qrcodejs2'
|
import QRCode from 'qrcodejs2'
|
||||||
import bus from '@/libs/bus.js'
|
import bus from '@/libs/bus.js'
|
||||||
|
import { get } from '@/http'
|
||||||
|
import { loadI18n } from '@/components/common/i18n'
|
||||||
export default {
|
export default {
|
||||||
name: 'login',
|
name: 'login',
|
||||||
data () {
|
data () {
|
||||||
@@ -149,7 +151,6 @@ export default {
|
|||||||
if (this.loading || !this.license.valid) {
|
if (this.loading || !this.license.valid) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// if (this.license.valid && this.validateLogin() && (this.$route.path == '/' || this.$route.path == '/login')) {
|
|
||||||
if (this.validateLogin() && (this.$route.path == '/' || this.$route.path == '/login')) {
|
if (this.validateLogin() && (this.$route.path == '/' || this.$route.path == '/login')) {
|
||||||
this.loading = true
|
this.loading = true
|
||||||
this.$post('/sys/login', this.loginData).then(res => {
|
this.$post('/sys/login', this.loginData).then(res => {
|
||||||
@@ -158,6 +159,14 @@ export default {
|
|||||||
this.authToken = res.data.authToken
|
this.authToken = res.data.authToken
|
||||||
this.lang = res.data.user.lang
|
this.lang = res.data.user.lang
|
||||||
this.$i18n.locale = this.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)
|
sessionStorage.setItem('nz-token', res.data.authToken)
|
||||||
if (res.data.authFlag === 1) {
|
if (res.data.authFlag === 1) {
|
||||||
if (res.data.authBind === 0) {
|
if (res.data.authBind === 0) {
|
||||||
|
|||||||
@@ -122,7 +122,13 @@ export default {
|
|||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
this.$message({ duration: 2000, type: 'success', message: this.$t('tip.saveSuccess') })
|
||||||
this.esc(true)
|
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 {
|
} else {
|
||||||
this.$message.error(res.msg)
|
this.$message.error(res.msg)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,6 @@
|
|||||||
<el-dropdown-item v-for="lang in langList" :key="lang.value">
|
<el-dropdown-item v-for="lang in langList" :key="lang.value">
|
||||||
<div :style="language === lang.value ? 'color:#f90' : ''" @click="changeLocal(lang.value)"><i :class="`nz-icon-lang-${lang.value}`" class="nz-icon"></i>{{lang.name}}</div>
|
<div :style="language === lang.value ? 'color:#f90' : ''" @click="changeLocal(lang.value)"><i :class="`nz-icon-lang-${lang.value}`" class="nz-icon"></i>{{lang.name}}</div>
|
||||||
</el-dropdown-item>
|
</el-dropdown-item>
|
||||||
<!-- <el-dropdown-item>
|
|
||||||
<div id="header-to-english" :style="language === 'en'?'color:#f90':''" @click="changeLocal('en')"><i class="nz-icon nz-icon-lang-en"></i>English</div>
|
|
||||||
</el-dropdown-item>
|
|
||||||
<el-dropdown-item>
|
|
||||||
<div id="header-to-chinese" :style="language === 'cn'?'color:#f90':''" @click="changeLocal('cn')"><i class="nz-icon nz-icon-lang-zh"></i>简体中文</div>
|
|
||||||
</el-dropdown-item>-->
|
|
||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
<el-dropdown trigger="click">
|
<el-dropdown trigger="click">
|
||||||
@@ -65,7 +59,6 @@
|
|||||||
</el-dropdown-menu>
|
</el-dropdown-menu>
|
||||||
</el-dropdown>
|
</el-dropdown>
|
||||||
</div>
|
</div>
|
||||||
<!-- <change-password :cur-user="username" :show-dialog="showChangePin" @click="showPinDialog" @dialogClosed="dialogClosed"></change-password>-->
|
|
||||||
<guide :show-dialog="showGuide" @dialogClosed="dialogClosed" @close="showGuide = false"></guide>
|
<guide :show-dialog="showGuide" @dialogClosed="dialogClosed" @close="showGuide = false"></guide>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -73,12 +66,10 @@
|
|||||||
<script>
|
<script>
|
||||||
import bus from '../../libs/bus'
|
import bus from '../../libs/bus'
|
||||||
import { mapActions } from 'vuex'
|
import { mapActions } from 'vuex'
|
||||||
// import changePin from '../page/config/changePin'
|
|
||||||
import guide from '@/components/common/popBox/guide'
|
import guide from '@/components/common/popBox/guide'
|
||||||
export default {
|
export default {
|
||||||
name: 'Header',
|
name: 'Header',
|
||||||
components: {
|
components: {
|
||||||
// 'change-password': changePin,
|
|
||||||
guide
|
guide
|
||||||
},
|
},
|
||||||
data () {
|
data () {
|
||||||
@@ -143,7 +134,6 @@ export default {
|
|||||||
getLinkData () {
|
getLinkData () {
|
||||||
this.$get('link').then(response => {
|
this.$get('link').then(response => {
|
||||||
this.$store.commit('setLinkData', response.data.list)
|
this.$store.commit('setLinkData', response.data.list)
|
||||||
// this.linkData = response.data.list
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
changeLocal (lang) {
|
changeLocal (lang) {
|
||||||
@@ -159,13 +149,6 @@ export default {
|
|||||||
document.location.href = '/'
|
document.location.href = '/'
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
// refreshLang () {
|
|
||||||
// this.language = localStorage.getItem('nz-language')
|
|
||||||
// this.$i18n.locale = this.language
|
|
||||||
// this.$nextTick(() => {
|
|
||||||
// // window.location.reload()
|
|
||||||
// })
|
|
||||||
// },
|
|
||||||
showPinDialog () {
|
showPinDialog () {
|
||||||
this.$router.push({
|
this.$router.push({
|
||||||
path: '/profile',
|
path: '/profile',
|
||||||
|
|||||||
@@ -226,6 +226,11 @@ export default {
|
|||||||
mounted () {
|
mounted () {
|
||||||
this.personalCenter()
|
this.personalCenter()
|
||||||
},
|
},
|
||||||
|
computed: {
|
||||||
|
langList () {
|
||||||
|
return this.$store.getters.getLangList
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 请求后端数据
|
// 请求后端数据
|
||||||
personalCenter () {
|
personalCenter () {
|
||||||
@@ -241,10 +246,9 @@ export default {
|
|||||||
}
|
}
|
||||||
this.tableProfile[1].prop = this.userList.email
|
this.tableProfile[1].prop = this.userList.email
|
||||||
this.tableProfile[2].prop = this.userList.mobile
|
this.tableProfile[2].prop = this.userList.mobile
|
||||||
if (this.userList.lang == 'cn') {
|
const findLang = this.langList.find(lang => this.userList.lang === lang.value)
|
||||||
this.tableProfile[3].prop = '简体中文'
|
if (findLang) {
|
||||||
} else {
|
this.tableProfile[3].prop = findLang.name
|
||||||
this.tableProfile[3].prop = 'English'
|
|
||||||
}
|
}
|
||||||
this.tableProfile[4].prop = this.userList.source
|
this.tableProfile[4].prop = this.userList.source
|
||||||
const name = this.userList.name.substr(0, 1)
|
const name = this.userList.name.substr(0, 1)
|
||||||
@@ -316,8 +320,13 @@ export default {
|
|||||||
closeRightBox () {
|
closeRightBox () {
|
||||||
this.rightBox.show = false
|
this.rightBox.show = false
|
||||||
},
|
},
|
||||||
clickProfile () {
|
clickProfile (refresh) {
|
||||||
this.personalCenter()
|
this.personalCenter()
|
||||||
|
if (refresh) {
|
||||||
|
setTimeout(() => {
|
||||||
|
window.location.reload()
|
||||||
|
}, 500)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
closeDialog () {
|
closeDialog () {
|
||||||
this.authBindShow = false
|
this.authBindShow = false
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
|
|
||||||
<script>
|
|
||||||
import en from '../../common/language/en'
|
|
||||||
import cn from '../../common/language/cn'
|
|
||||||
export default {
|
|
||||||
name: 'language',
|
|
||||||
data () {
|
|
||||||
return {
|
|
||||||
result: null,
|
|
||||||
languageList: []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
compareFile: function (obj, compareObj) {
|
|
||||||
if (!obj) {
|
|
||||||
obj = en
|
|
||||||
}
|
|
||||||
if (!compareObj) {
|
|
||||||
compareObj = cn
|
|
||||||
}
|
|
||||||
const keys = Object.keys(obj)
|
|
||||||
for (const key of keys) {
|
|
||||||
if (typeof obj[key] === 'object') {
|
|
||||||
if (!compareObj[key]) {
|
|
||||||
this.$set(compareObj, key, {})
|
|
||||||
}
|
|
||||||
this.compareFile(obj[key], compareObj[key])
|
|
||||||
} else {
|
|
||||||
if (!compareObj[key]) {
|
|
||||||
this.$set(compareObj, key, obj[key])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.result = cn
|
|
||||||
},
|
|
||||||
listLanguage: function (obj, compareObj) {
|
|
||||||
if (!obj) {
|
|
||||||
obj = en
|
|
||||||
}
|
|
||||||
if (!compareObj) {
|
|
||||||
compareObj = cn
|
|
||||||
}
|
|
||||||
const keys = Object.keys(obj)
|
|
||||||
for (const key of keys) {
|
|
||||||
if (typeof obj[key] === 'object') {
|
|
||||||
if (!compareObj[key]) {
|
|
||||||
this.$set(compareObj, key, {})
|
|
||||||
}
|
|
||||||
this.listLanguage(obj[key], compareObj[key])
|
|
||||||
} else {
|
|
||||||
if (!compareObj[key]) {
|
|
||||||
this.$set(compareObj, key, obj[key])
|
|
||||||
}
|
|
||||||
this.languageList.push({ en: obj[key], cn: compareObj[key] })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -12,8 +12,8 @@ const loginWhiteList = ['/setup', '/sys/license/upload', '/sys/license/state'] /
|
|||||||
const permissionWhiteList = ['/profile', '/menu', ...loginWhiteList] // 权限白名单
|
const permissionWhiteList = ['/profile', '/menu', ...loginWhiteList] // 权限白名单
|
||||||
|
|
||||||
router.beforeEach((to, from, next) => {
|
router.beforeEach((to, from, next) => {
|
||||||
|
const configUrl = 'static/config.json?Timestamp=' + new Date().getTime()
|
||||||
if (to.path === '/login') { // 拦截登录页面,系统初始化检查
|
if (to.path === '/login') { // 拦截登录页面,系统初始化检查
|
||||||
const configUrl = 'static/config.json?Timestamp=' + new Date().getTime()
|
|
||||||
Vue.http.get(configUrl).then(config => {
|
Vue.http.get(configUrl).then(config => {
|
||||||
get(config.body.baseUrl + 'setup/inited').then(res => {
|
get(config.body.baseUrl + 'setup/inited').then(res => {
|
||||||
if (res.code === 200) {
|
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')) {
|
} else if (sessionStorage.getItem('nz-token')) {
|
||||||
// 从localStorage加载i18n
|
// 从localStorage加载i18n
|
||||||
if (!store.getters.i18nIsReady) {
|
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')
|
const langList = localStorage.getItem('nz-language-list')
|
||||||
if (langList) {
|
if (langList) {
|
||||||
store.commit('setLangList', JSON.parse(langList))
|
store.commit('setLangList', JSON.parse(langList))
|
||||||
}
|
}
|
||||||
store.commit('i18nReady', true)
|
|
||||||
}
|
}
|
||||||
new Promise(resolve => {
|
new Promise(resolve => {
|
||||||
if (store.getters.menuList.length === 0) {
|
if (store.getters.menuList.length === 0) {
|
||||||
const configUrl = 'static/config.json?Timestamp=' + new Date().getTime()
|
|
||||||
Vue.http.get(configUrl).then(config => {
|
Vue.http.get(configUrl).then(config => {
|
||||||
post(config.body.baseUrl + 'sys/user/permissions', { token: sessionStorage.getItem('nz-token') }).then(res => {
|
post(config.body.baseUrl + 'sys/user/permissions', { token: sessionStorage.getItem('nz-token') }).then(res => {
|
||||||
store.commit('setMenuList', sortByOrderNum(res.data.menus))
|
store.commit('setMenuList', sortByOrderNum(res.data.menus))
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import router from '../router'
|
|||||||
import bus from '../libs/bus'
|
import bus from '../libs/bus'
|
||||||
import { sortByOrderNum } from '@/permission'
|
import { sortByOrderNum } from '@/permission'
|
||||||
import moment from 'moment-timezone'
|
import moment from 'moment-timezone'
|
||||||
import i18n, { loadI18n } from '@/components/common/i18n'
|
|
||||||
|
|
||||||
const user = {
|
const user = {
|
||||||
state: {
|
state: {
|
||||||
@@ -75,32 +74,6 @@ const user = {
|
|||||||
localStorage.setItem('nz-user-name', userList.name)
|
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) {
|
logoutSuccess (store, res) {
|
||||||
sessionStorage.removeItem('nz-username')
|
sessionStorage.removeItem('nz-username')
|
||||||
|
|||||||
Reference in New Issue
Block a user