### 登录后跳转到配置的第一个菜单:
修改 src/permission.js,跳转到权限第一个菜单
router.beforeEach((to, from, next) => {
NProgress.start()
if (getToken()) {
to.meta.title && store.dispatch('settings/setTitle', to.meta.title)
/* has token*/
if (to.path === '/login') {
next({ path: '/' })
NProgress.done()
} else {
if (store.getters.roles.length === 0) {
isRelogin.show = true
// 判断当前用户是否已拉取完user_info信息
store.dispatch('GetInfo').then(() => {
isRelogin.show = false
store.dispatch('GenerateRoutes').then(accessRoutes => {
// 根据roles权限生成可访问的路由表
router.addRoutes(accessRoutes) // 动态添加可访问路由表
/****** 修改开始-qjs ******/
if(from.path == '/login'){
let path = ""
let flag = true
let child = accessRoutes;
while(flag){
if(!child[0].children){
path = child[0]
flag = false
}else{
child = child[0].children
}
}
next({ ...path, replace: true })
}else{
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
}
/****** 修改结束-qjs ******/
})
}).catch(err => {
store.dispatch('LogOut').then(() => {
Message.error(err)
next({ path: '/' })
})
})
} else {
next()
}
}
} else {
// 没有token
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next()
} else {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
NProgress.done()
}
}
})
隐藏侧边菜单栏的首页菜单:
修改 src/router/index.js ,增加 hidden:true 或者直接注释掉 path:'' 为空的路由及子类
export const constantRoutes = [
{
path: '',
component: Layout,
hidden: true,//qjs-去首页 去掉侧边菜单栏
redirect: 'index',
children: [
{
path: 'index',
component: () => import('@/views/index'),
name: 'Index',
meta: { title: '首页', icon: 'dashboard', affix: true }
}
]
},
]
去除面包屑的首页:
修改:/src/components/Breadcrumb/index.vue,注释 getBreadcrumb 方法中的代码
methods: {
getBreadcrumb() {
// only show routes with meta.title
let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
const first = matched[0]
//注释下面代码
//if (!this.isDashboard(first)) {
// matched = [{ path: '/index', meta: { title: '首页' }}].concat(matched)
//}
this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
},
}
去除顶部导航栏的首页:
修改 src/layout/components/TagsView/index.vue,不装载首页
filterAffixTags(routes, basePath = '/') {
let tags = []
routes.forEach(route => {
if (route.meta && route.meta.affix) {
const tagPath = path.resolve(basePath, route.path)
tags.push({
fullPath: tagPath,
path: tagPath,
name: route.name,
meta: { ...route.meta }
})
}
if (route.children) {
/**qjs-去首页 begin **/
if(route.redirect == 'index'){
return
}
/**qjs-去首页 end **/
const tempTags = this.filterAffixTags(route.children, route.path)
if (tempTags.length >= 1) {
tags = [...tags, ...tempTags]
}
}
})
return tags
},
去除错误页面跳转到首页
修改:src/views/error/401.vue 和 src/views/error/404.vue, 注释掉返回首页的
<!--
<router-link to="/">
回首页
</router-link>
-->
去除响应异常跳转到首页
修改 src/settings.js, 添加一个空白页
module.exports = {
/**
* 空白页
*/
indexPage: '',
修改 src/store/modules/settings.js, 增加首页
import defaultSettings from '@/settings'
const { indexPage,//增加首页-qjs
sideTheme, showSettings, topNav, tagsView, fixedHeader, sidebarLogo, dynamicTitle } = defaultSettings
const storageSetting = JSON.parse(localStorage.getItem('layout-setting')) || ''
const state = {
title: '',
indexPage: indexPage, //增加首页-qjs
theme: storageSetting.theme || '#409EFF',
sideTheme: storageSetting.sideTheme || sideTheme,
showSettings: showSettings,
topNav: storageSetting.topNav === undefined ? topNav : storageSetting.topNav,
tagsView: storageSetting.tagsView === undefined ? tagsView : storageSetting.tagsView,
fixedHeader: storageSetting.fixedHeader === undefined ? fixedHeader : storageSetting.fixedHeader,
sidebarLogo: storageSetting.sidebarLogo === undefined ? sidebarLogo : storageSetting.sidebarLogo,
dynamicTitle: storageSetting.dynamicTitle === undefined ? dynamicTitle : storageSetting.dynamicTitle
}
修改 src/utils/request.js, 跳转到设置的空白页
// 响应拦截器
service.interceptors.response.use(res => {
// 未设置状态码则默认成功状态
const code = res.data.code || 200;
// 获取错误信息
const msg = errorCode[code] || res.data.msg || errorCode['default']
// 二进制数据则直接返回
if(res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer'){
return res.data
}
if (code === 401) {
if (!isRelogin.show) {
isRelogin.show = true;
MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}
).then(() => {
isRelogin.show = false;
store.dispatch('LogOut').then(() => {
/****** qjs-去首页 注释下面代码,添加如下行 begin ****/
// location.href = '/index';
location.href = this.$store.state.settings.indexPage;
/****** qjs-去首页 注释下面代码,添加如下行 end ****/
})
}).catch(() => {
isRelogin.show = false;
});
}
欢迎来到这里!
我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。
注册 关于