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

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'
} 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
}
@@ -28,7 +29,9 @@ watermark.set = (str) => {
setInterval(() => {
let value = JSON.parse(localStorage.getItem('pro__Login_Userinfo'))
if (document.getElementById(id) === null) {
id = setWatermark(value.value.username + ' ' + value.value.realname)
if (value) {
id = setWatermark(value.value.username + ' ' + value.value.realname)
}
}
}, 2000)
window.onresize = () => {
@@ -21,12 +21,12 @@
Navigation: '文档管理',
subNavigation: null,
selectedKeys: [],
openKeys:[],
openKeys: []
}
},
watch: {
'$route': function(val) {
if (val.meta.title == '首页') {
if (val.meta.title == '首页' || val.meta.title === ' home page') {
this.Navigation = val.meta.title
this.subNavigation = null
} else {
@@ -35,7 +35,8 @@
}
},
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.subNavigation = null
} else {
@@ -56,7 +57,7 @@
routes.forEach(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
}
}
+13 -5
View File
@@ -121,7 +121,7 @@
import 'moment/locale/zh-cn'
import { generateIndexRouter } from '@/utils/util'
import store from '../../store'
import router,{resetRouter} from '../../router'
import router, { resetRouter } from '../../router'
moment.locale('zh-cn')
const EN = 'en-us'
@@ -170,6 +170,15 @@
}
}
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: {
...mapState({
@@ -292,7 +301,6 @@
/*update_end author:liushaoqian date:20200507 for: 刷新缓存*/
moment,
changeLocale(localeval) {
console.log(localeval)
this.isLoading = true
switch (localeval) {
case 'zh-cn':
@@ -303,10 +311,10 @@
break
}
store.dispatch('GetPermissionList').then(res => {
const menuData = res.result.menu;
const menuData = res.result.menu
resetRouter()
let constRoutes = [];
constRoutes = generateIndexRouter(menuData);
let constRoutes = []
constRoutes = generateIndexRouter(menuData)
router.addRoutes(constRoutes)
this.$root.Bus.$emit('switchLanguage', localeval)
this.isLoading = false
+30 -29
View File
@@ -1,15 +1,15 @@
import Vue from 'vue'
import router from './router'
import router, { resetRouter } from './router'
import store from './store'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css' // progress bar style
import notification from 'ant-design-vue/es/notification'
import { ACCESS_TOKEN,INDEX_MAIN_PAGE_PATH } from '@/store/mutation-types'
import { generateIndexRouter } from "@/utils/util"
import { ACCESS_TOKEN, INDEX_MAIN_PAGE_PATH } from '@/store/mutation-types'
import { generateIndexRouter } from '@/utils/util'
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) => {
NProgress.start() // start progress bar
@@ -22,32 +22,33 @@ router.beforeEach((to, from, next) => {
} else {
if (store.getters.permissionList.length === 0) {
store.dispatch('GetPermissionList').then(res => {
const menuData = res.result.menu;
if (menuData === null || menuData === "" || menuData === undefined) {
return;
}
let constRoutes = [];
constRoutes = generateIndexRouter(menuData);
// 添加主界面路由
store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
// 根据roles权限生成可访问的路由表
// 动态添加可访问路由表
router.addRoutes(store.getters.addRouters)
const redirect = decodeURIComponent(from.query.redirect || to.path)
if (to.path === redirect) {
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
next({ ...to, replace: true })
} else {
// 跳转到目的路由
next({ path: redirect })
}
})
})
const menuData = res.result.menu
if (menuData === null || menuData === '' || menuData === undefined) {
return
}
resetRouter()
let constRoutes = []
constRoutes = generateIndexRouter(menuData)
// 添加主界面路由
store.dispatch('UpdateAppRouter', { constRoutes }).then(() => {
// 根据roles权限生成可访问路由表
// 动态添加可访问路由表
router.addRoutes(store.getters.addRouters)
const redirect = decodeURIComponent(from.query.redirect || to.path)
if (to.path === redirect) {
// hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
next({ ...to, replace: true })
} else {
// 跳转到目的路由
next({ path: redirect })
}
})
})
.catch(() => {
/* notification.error({
message: '系统提示',
description: '请求用户信息失败,请重试!'
})*/
/* notification.error({
message: '系统提示',
description: '请求用户信息失败,请重试!'
})*/
store.dispatch('Logout').then(() => {
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) {
console.log("全局页面权限--Global--");
// console.log("全局页面权限--Global--");
let permissionList = [];
let allPermissionList = [];