| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- import router, { adminRouter, normalRouter, agentRouter } from '@/router'
- import store from '@/store'
- import { checklogin } from '@/api/login'
- import { message } from 'ant-design-vue'
- const appType = import.meta.env.VITE_APP_TYPE
- console.log(appType)
- // adminRouter.forEach(r => { router.addRoute(r) }) // 添加静态路由
- // normalRouter.forEach(r => { router.addRoute(r) })
- // agentRouter.forEach(r => { router.addRoute(r) })
- store.commit('SET_ROUTES', normalRouter)
- router.beforeEach(async (to, from, next) => {
- // const isLogin = await checklogin()
- // console.log(isLogin)
- const isLogin = false
- if (to.path === '/login' || to.path === '/' || to.path === '/init') {
- if (isLogin) {
- const pathMap = {
- admin: '/audit/index',
- merchant: '/order/index',
- agent: '/scenicOrder/index'
- }
- next({ path: pathMap[appType], replace: true })
- } else {
- next()
- }
- } else {
- next()
- // if (isLogin) {
- // if (store.state.addRoutes) {
- // next()
- // } else {
- // const routerMap = {
- // admin: adminRouter,
- // merchant: normalRouter,
- // agent: agentRouter
- // }
- // const asyncRouter = routerMap[appType]
- // await store.dispatch('getUserPermission').then(permissions => {
- // if (permissions) {
- // asyncRouter.forEach(r => {
- // r.children = r.children.filter(item => {
- // return permissions.indexOf(item.meta.permission) > -1 || !item.meta.permission
- // })
- // })
- // }
- // store.commit('SET_ROUTES', asyncRouter) // 筛选权限列表
- // })
- // asyncRouter.forEach(r => {
- // router.addRoute(r) // 添加动态路由
- // })
- // let availableRouters = []
- // asyncRouter.forEach(v => {
- // v.children.length && (availableRouters = [...availableRouters, ...v.children]) // 将所有可进入的路由 降级为一维数组
- // })
- // if (availableRouters.length === 0) return message.error('对不起,您暂时没有权限访问该系统,请联系管理员修改权限')
- // const path = router.getRoutes().find(i => i.path.indexOf(to.path) > -1) ? to.path : availableRouters[0].path // 取所有可进入路由的第一个
- // next({ path, replace: true })
- // }
- // } else {
- // next({ path: '/login', replace: true })
- // }
- }
- })
|