说到后台管理系统,就免不了涉及到权限的管理。在项目中,主要遇到的有两种,一种是页面的限制,一种操作按钮的限制。
首先我们聊一下页面的权限限制:
一、路由的配置 (router—> index.js)
1、不对权限做限制的页面(路由的初始配置)
export const constantRouterMap = [
{
path: '/',
name: 'Login',
component: Login
},
{ path: '/404', component: () => import('@/views/errorPage/404'), hidden: true },
{ path: '/401', component: () => import('@/views/errorPage/401'), hidden: true },
]
export default new Router({
// mode: 'history', // 路由开启history模式时,需要进行服务器配置,vue官网有介绍
scrollBehavior: () => ({ y: 0 }),
routes: constantRouterMap
})
2、需要根据不同权限生成不同的路由列表
export const asyncRouterMap = [
{
path: '/home',
name: 'home',
component: Home,
redirect: {
name: "index"
},
meta: {
roles: [0, 1, 2],
isLogin: true
},
children: [
{
path: 'index',
name: 'index',
component: Index,
meta: {
roles: [0, 1, 2]
}
},
{
path: 'client',
name: 'client',
component: Client,
meta: {
roles: [0, 1, 2]
}
},
{
path: 'resource',
name: 'resource',
component: Resoure,