|
@@ -30,13 +30,13 @@ export const moduleRoutes = {
|
|
|
path: '/',
|
|
|
component: () => import('@/views/main/main'),
|
|
|
name: 'main',
|
|
|
- redirect: {name: 'home'},
|
|
|
+ redirect: {name: 'login'},
|
|
|
meta: {title: '主入口布局'},
|
|
|
children: [
|
|
|
- // {path: '/home', component: () => import('@/views/modules/home'), name: 'home', meta: {title: '首页'}},
|
|
|
- {path: 'home', component: () => import('@/views/business/home/home'), name: 'home', meta: {title: '首页'}},
|
|
|
- {path: 'demo/list-demo', component: () => import('@/views/modules/demo/listDemo/list-demo'), name: 'list-demo', meta: {title: '列表页'}},
|
|
|
- {path: 'demo/all-form-type', component: () => import('@/views/modules/demo/all-form-type'), name: 'all-form-type', meta: {title: '表单页'}}
|
|
|
+ // {path: '/home', component: () => import('@/views/modules/home'), name: 'home', meta: {title: '首页', parentUUID: 0, uuid: 'index1'}}
|
|
|
+ // {path: 'home', component: () => import('@/views/business/home/home'), name: 'home', meta: {title: '首页'}}
|
|
|
+ // {path: 'demo/list-demo', component: () => import('@/views/modules/demo/listDemo/list-demo'), name: 'list-demo', meta: {title: '列表页'}},
|
|
|
+ // {path: 'demo/all-form-type', component: () => import('@/views/modules/demo/all-form-type'), name: 'all-form-type', meta: {title: '表单页'}}
|
|
|
]
|
|
|
}
|
|
|
|
|
@@ -49,6 +49,7 @@ const router = new Router({
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
// 截取路由中token进行处理
|
|
|
filterToken(to, from, next)
|
|
|
+ // console.log(to)
|
|
|
// console.log(from)
|
|
|
// 添加动态(菜单)路由
|
|
|
// 已添加或者当前路由为页面路由, 可直接访问
|
|
@@ -62,14 +63,21 @@ router.beforeEach((to, from, next) => {
|
|
|
return next()
|
|
|
}
|
|
|
// 获取菜单列表, 添加并全局变量保存
|
|
|
- http.get('/sys/menu/nav').then(({data: res}) => {
|
|
|
+ http.get('/sys/menu/list').then(({data: res}) => {
|
|
|
if (res.code !== 0) {
|
|
|
Vue.prototype.$message.error(res.msg)
|
|
|
return next({name: 'login'})
|
|
|
}
|
|
|
-
|
|
|
- window.SITE_CONFIG['menuList'] = res.data
|
|
|
-
|
|
|
+ let homePage = {
|
|
|
+ 'uuid': 'index1',
|
|
|
+ 'parentUUID': 0,
|
|
|
+ 'name': '首页',
|
|
|
+ 'ename': 'home',
|
|
|
+ 'path': 'home',
|
|
|
+ 'componentPath': 'modules/home'
|
|
|
+ }
|
|
|
+ res.list.unshift(homePage)
|
|
|
+ window.SITE_CONFIG['menuList'] = res.list
|
|
|
fnAddDynamicMenuRoutes(window.SITE_CONFIG['menuList'])
|
|
|
next({...to, replace: true})
|
|
|
}).catch(() => {
|
|
@@ -107,27 +115,53 @@ function fnAddDynamicMenuRoutes (menuList = [], routes = []) {
|
|
|
temp = temp.concat(menuList[i].children)
|
|
|
continue
|
|
|
}
|
|
|
+ let path = menuList[i].path
|
|
|
+ let componentPath = menuList[i].componentPath
|
|
|
+ if (!path) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
// 组装路由
|
|
|
var route = {
|
|
|
- path: '',
|
|
|
- component: null,
|
|
|
- name: '',
|
|
|
+ path: path,
|
|
|
+ component: '',
|
|
|
+ name: menuList[i].ename,
|
|
|
meta: {
|
|
|
- ...window.SITE_CONFIG['contentTabDefault'],
|
|
|
- menuId: menuList[i].id,
|
|
|
+ uuid: menuList[i].uuid,
|
|
|
+ parentUUID: menuList[i].parentUUID,
|
|
|
title: menuList[i].name
|
|
|
}
|
|
|
}
|
|
|
- // eslint-disable-next-line
|
|
|
- let URL = (menuList[i].url || '').replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)) // URL支持{{ window.xxx }}占位符变量
|
|
|
- if (isURL(URL)) {
|
|
|
- route['path'] = route['name'] = `i-${menuList[i].id}`
|
|
|
- route['meta']['iframeURL'] = URL
|
|
|
+ menuList[i].url = 'https://juejin.im/' // 测试用
|
|
|
+ if (isURL(menuList[i].url)) {
|
|
|
+ route.meta.iframeURL = menuList[i].url
|
|
|
+ route.component = () => import(`@/views/modules/home`)
|
|
|
} else {
|
|
|
- URL = URL.replace(/^\//, '').replace(/_/g, '-')
|
|
|
- route['path'] = route['name'] = URL.replace(/\//g, '-')
|
|
|
- route['component'] = () => import(`@/views/modules/${URL}`)
|
|
|
+ route.component = () => import(`@/views/${componentPath}`)
|
|
|
}
|
|
|
+ // console.log(route)
|
|
|
+ // console.log(route)
|
|
|
+ // 组装路由
|
|
|
+ // var route = {
|
|
|
+ // path: '',
|
|
|
+ // component: null,
|
|
|
+ // name: '',
|
|
|
+ // meta: {
|
|
|
+ // ...window.SITE_CONFIG['contentTabDefault'],
|
|
|
+ // menuId: menuList[i].id,
|
|
|
+ // title: menuList[i].name
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // // eslint-disable-next-line
|
|
|
+ // let URL = (menuList[i].url || '').replace(/{{([^}}]+)?}}/g, (s1, s2) => eval(s2)) // URL支持{{ window.xxx }}占位符变量
|
|
|
+ // if (isURL(URL)) {
|
|
|
+ // route['path'] = route['name'] = `i-${menuList[i].id}`
|
|
|
+ // route['meta']['iframeURL'] = URL
|
|
|
+ // } else {
|
|
|
+ // URL = URL.replace(/^\//, '').replace(/_/g, '-')
|
|
|
+ // route['path'] = route['name'] = URL.replace(/\//g, '-')
|
|
|
+ // route['component'] = () => import(`@/views/modules/${URL}`)
|
|
|
+ // }
|
|
|
routes.push(route)
|
|
|
}
|
|
|
if (temp.length >= 1) {
|