修改语言切换重新登录之后出现的问题

This commit is contained in:
qq787203167
2022-04-06 15:23:24 +08:00
parent da2ca66631
commit 1cc4f5803d
5 changed files with 55 additions and 42 deletions
+6 -3
View File
@@ -16,8 +16,9 @@ let setWatermark = (str) => {
document.getElementsByClassName('ant-layout-content')[0].style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat' document.getElementsByClassName('ant-layout-content')[0].style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat'
} else { } else {
document.getElementsByClassName('detail-content')[0].style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat' if (document.getElementsByClassName('detail-content') && document.getElementsByClassName('detail-content').length > 0) {
document.getElementsByClassName('detail-content')[0].style.background = 'url(' + can.toDataURL('image/png') + ') left top repeat'
}
} }
return id return id
} }
@@ -28,7 +29,9 @@ watermark.set = (str) => {
setInterval(() => { setInterval(() => {
let value = JSON.parse(localStorage.getItem('pro__Login_Userinfo')) let value = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
if (document.getElementById(id) === null) { if (document.getElementById(id) === null) {
id = setWatermark(value.value.username + ' ' + value.value.realname) if (value) {
id = setWatermark(value.value.username + ' ' + value.value.realname)
}
} }
}, 2000) }, 2000)
window.onresize = () => { window.onresize = () => {
@@ -21,12 +21,12 @@
Navigation: '文档管理', Navigation: '文档管理',
subNavigation: null, subNavigation: null,
selectedKeys: [], selectedKeys: [],
openKeys:[], openKeys: []
} }
}, },
watch: { watch: {
'$route': function(val) { '$route': function(val) {
if (val.meta.title == '首页') { if (val.meta.title == '首页' || val.meta.title === ' home page') {
this.Navigation = val.meta.title this.Navigation = val.meta.title
this.subNavigation = null this.subNavigation = null
} else { } else {
@@ -35,7 +35,8 @@
} }
}, },
mounted() { mounted() {
if (this.$route.meta.title == '首页') { console.log(this.$route.meta)
if (this.$route.meta.title === '首页' || this.$route.meta.title === ' home page') {
this.Navigation = this.$route.meta.title this.Navigation = this.$route.meta.title
this.subNavigation = null this.subNavigation = null
} else { } else {
@@ -56,7 +57,7 @@
routes.forEach(item => { routes.forEach(item => {
this.openKeys.push(item) this.openKeys.push(item)
}) })
this.Navigation =this.openKeys[1].meta.title this.Navigation = this.openKeys[1].meta.title
this.subNavigation = this.$route.meta.title this.subNavigation = this.$route.meta.title
} }
} }
+13 -5
View File
@@ -121,7 +121,7 @@
import 'moment/locale/zh-cn' import 'moment/locale/zh-cn'
import { generateIndexRouter } from '@/utils/util' import { generateIndexRouter } from '@/utils/util'
import store from '../../store' import store from '../../store'
import router,{resetRouter} from '../../router' import router, { resetRouter } from '../../router'
moment.locale('zh-cn') moment.locale('zh-cn')
const EN = 'en-us' const EN = 'en-us'
@@ -170,6 +170,15 @@
} }
} }
this.localeval = localStorage.getItem('language') this.localeval = localStorage.getItem('language')
if (this.localeval == 'zh-cn') {
this.$i18n.locale = ZH
this.locale = zhCN
moment.locale('zh-cn')
} else if (this.localeval == 'en-us') {
this.locale = enUS
moment.locale('en-us')
this.$i18n.locale = EN
}
}, },
computed: { computed: {
...mapState({ ...mapState({
@@ -292,7 +301,6 @@
/*update_end author:liushaoqian date:20200507 for: 刷新缓存*/ /*update_end author:liushaoqian date:20200507 for: 刷新缓存*/
moment, moment,
changeLocale(localeval) { changeLocale(localeval) {
console.log(localeval)
this.isLoading = true this.isLoading = true
switch (localeval) { switch (localeval) {
case 'zh-cn': case 'zh-cn':
@@ -303,10 +311,10 @@
break break
} }
store.dispatch('GetPermissionList').then(res => { store.dispatch('GetPermissionList').then(res => {
const menuData = res.result.menu; const menuData = res.result.menu
resetRouter() resetRouter()
let constRoutes = []; let constRoutes = []
constRoutes = generateIndexRouter(menuData); constRoutes = generateIndexRouter(menuData)
router.addRoutes(constRoutes) router.addRoutes(constRoutes)
this.$root.Bus.$emit('switchLanguage', localeval) this.$root.Bus.$emit('switchLanguage', localeval)
this.isLoading = false this.isLoading = false
+30 -29
View File
@@ -1,15 +1,15 @@
import Vue from 'vue' import Vue from 'vue'
import router from './router' import router, { resetRouter } from './router'
import store from './store' import store from './store'
import NProgress from 'nprogress' // progress bar import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style import 'nprogress/nprogress.css' // progress bar style
import notification from 'ant-design-vue/es/notification' import notification from 'ant-design-vue/es/notification'
import { ACCESS_TOKEN,INDEX_MAIN_PAGE_PATH } from '@/store/mutation-types' import { ACCESS_TOKEN, INDEX_MAIN_PAGE_PATH } from '@/store/mutation-types'
import { generateIndexRouter } from "@/utils/util" import { generateIndexRouter } from '@/utils/util'
NProgress.configure({ showSpinner: false }) // NProgress Configuration NProgress.configure({ showSpinner: false }) // NProgress Configuration
const whiteList = ['/user/login', '/user/register', '/user/register-result','/user/alteration'] // no redirect whitelist const whiteList = ['/user/login', '/user/register', '/user/register-result', '/user/alteration'] // no redirect whitelist
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
NProgress.start() // start progress bar NProgress.start() // start progress bar
@@ -22,32 +22,33 @@ router.beforeEach((to, from, next) => {
} else { } else {
if (store.getters.permissionList.length === 0) { if (store.getters.permissionList.length === 0) {
store.dispatch('GetPermissionList').then(res => { store.dispatch('GetPermissionList').then(res => {
const menuData = res.result.menu; const menuData = res.result.menu
if (menuData === null || menuData === "" || menuData === undefined) { if (menuData === null || menuData === '' || menuData === undefined) {
return; return
} }
let constRoutes = []; resetRouter()
constRoutes = generateIndexRouter(menuData); let constRoutes = []
// 添加主界面路由 constRoutes = generateIndexRouter(menuData)
store.dispatch('UpdateAppRouter', { constRoutes }).then(() => { // 添加主界面路由
// 根据roles权限生成可访问的路由表 store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
// 动态添加可访问路由表 // 根据roles权限生成可访问的路由表
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
const redirect = decodeURIComponent(from.query.redirect || to.path) router.addRoutes(store.getters.addRouters)
if (to.path === redirect) { const redirect = decodeURIComponent(from.query.redirect || to.path)
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record if (to.path === redirect) {
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
} else { next({ ...to, replace: true })
// 跳转到目的路由 } else {
next({ path: redirect }) // 跳转到目的路由
} next({ path: redirect })
}) }
}) })
})
.catch(() => { .catch(() => {
/* notification.error({ /* notification.error({
message: '系统提示', message: '系统提示',
description: '请求用户信息失败,请重试!' description: '请求用户信息失败,请重试!'
})*/ })*/
store.dispatch('Logout').then(() => { store.dispatch('Logout').then(() => {
next({ path: '/user/login', query: { redirect: to.fullPath } }) next({ path: '/user/login', query: { redirect: to.fullPath } })
}) })
+1 -1
View File
@@ -66,7 +66,7 @@ export function filterNodePermission(el, binding, vnode) {
* 全局权限控制 * 全局权限控制
*/ */
export function filterGlobalPermission(el, binding, vnode) { export function filterGlobalPermission(el, binding, vnode) {
console.log("全局页面权限--Global--"); // console.log("全局页面权限--Global--");
let permissionList = []; let permissionList = [];
let allPermissionList = []; let allPermissionList = [];