• vuerouter 无登录页根据权限动态添加菜单栏


    import Vue from 'vue'
    import VueRouter from 'vue-router'
    import Home from '../views/Home.vue'
    import { getCurrentInfo } from '../service/getData'
    Vue.use(VueRouter);
    const staticRouter = [
    	
    	
    	
    	{
    		path: '/RelieveAdd',
    		name: 'RelieveAdd',
    		component:() => import(/* webpackChunkName: "DocApprovalHistory" */ '../views/report/components/RelieveAdd.vue'),
    	},
    	{
    		path: 'objectDetail',
    		name: 'ObjectDetail',
    		component: () => import(/* webpackChunkName: "DocApprovalHistory" */ '../views/report/components/ObjectDetail.vue'),
    	},
    	{
    		path: 'docDetail',
    		name: 'DocDetail',
    		component: () => import(/* webpackChunkName: "DocApprovalHistory" */ '../views/report/components/DocDetail.vue'),
    	}
    ]
    const authRouters = [
    	{
    		key: 'CON_REPORT_DOC',
    		path: '/ControlReportList',
    		name: 'ControlReportList',
    		component: () => import(/* webpackChunkName: "ControlReportList" */ '../views/controlReport/ControlReportList.vue')
    	},
    	{
    		key: 'CON_REPORT_DOC',
    		path: '/docApproval',
    		name: 'DocApproval',
    		component: () => import(/* webpackChunkName: "DocApproval" */ '../views/controlReport/DocApproval.vue')
    	},
    	{
    		key: 'CON_REPORT_DOC',
    		path: '/DocApprovalHistory',
    		name: 'DocApprovalHistory',
    		component: () => import(/* webpackChunkName: "DocApprovalHistory" */ '../views/controlReport/DocApprovalHistory.vue')
    	},
    	{
    		key: 'BIZ_REPORT_DOC',
    		path: '/ReportList',
    		name: 'ReportList',
    		component: () => import(/* webpackChunkName: "ReportList" */ '../views/report/ReportList.vue')
    	},
    	{
    		key: 'BIZ_REPORT_DOC',
    		path: '/reportDocApproval',
    		name: 'reportDocApproval',
    		component: () => import(/* webpackChunkName: "DocApproval" */ '../views/report/DocApproval.vue')
    	},
    	{
    		key: 'BIZ_REPORT_DOC',
    		path: '/reportDocApprovalHistory',
    		name: 'reportDocApprovalHistory',
    		component: () => import(/* webpackChunkName: "DocApprovalHistory" */ '../views/report/DocApprovalHistory.vue')
    	},
    	{
    		key: 'REPORT_CENTRE_DICT',
    		path: '/DictList',
    		name: 'DictList',
    		component: () => import(/* webpackChunkName: "DocApprovalHistory" */ '../views/dict/DictList.vue'),
    	}
    ]
    const routes = [
    	{
    		path: '/',
    		// redirect: accessRouters.length && accessRouters[0].path ? accessRouters[0].path : '/noData',
    		redirect: '/ControlReportList',
    		component: Home,
    		children: staticRouter
    	},
    	{
    		path: '/about',
    		name: 'About',
    		// route level code-splitting
    		// this generates a separate chunk (about.[hash].js) for this route
    		// which is lazy-loaded when the route is visited.
    		component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
    	},
    	{
    		path: '/noData',
    		name: 'noData',
    		component: () => import(/* webpackChunkName: "about" */ '@/components/error/noData.vue')
    	},
    	{
    		path: '*', component: resolve => {
    		  	require(['@/components/error/404.vue'], resolve)
    		}
    	}
    ]
    
    const router = new VueRouter({
      	routes,
    	mode: 'history'
    })
    getCurrentInfo().then(res => {
    	if(res.statusCode == 200) {
    	  let auth = res.data.user.ocodeList;
    	   let accessRouters = authRouters.filter(item => { 
    		   return auth.includes(item.key);
    	   }) || []
    	   let routers = [
    		 {
    		   path: '/',
    		   component: Home,
    		   children: accessRouters
    		 }
    	   ];
                // 重点这段代码
    	   router.addRoutes(routers);
    	   if (window.location.hash === '#/' || window.location.hash === '') {
    		 if (accessRouters[0] && accessRouters.length) {
    		   router.push(accessRouters[0])
    		 } else {
    			router.push('/noData')
    		 }
    	   }
    	}
      })
    
    
    
    export default router
        
    

      

  • 相关阅读:
    CodeForces 522B 手速题
    mybatis多数据源报错
    as依赖解决报错
    As 400错
    maven直接饮用jar包的写法
    测试一下多线程同时往list中添加元素会不会出问题
    jmeter中判断数据库是否存在相应的记录
    jmeter打开图形化界面时指定代理
    wz
    初阳胜阴
  • 原文地址:https://www.cnblogs.com/whlBooK/p/16170388.html
Copyright © 2020-2023  润新知