mirror of
https://gitee.com/wot-design-uni/wot-design-uni.git
synced 2025-12-07 01:28:30 +08:00
91 lines
2.1 KiB
JavaScript
91 lines
2.1 KiB
JavaScript
/*
|
|
* @Author: weisheng
|
|
* @Date: 2023-07-20 00:34:54
|
|
* @LastEditTime: 2023-07-22 18:02:12
|
|
* @LastEditors: weisheng
|
|
* @Description:
|
|
* @FilePath: \wot-design-uni\docs\route.js
|
|
* 记得注释
|
|
*/
|
|
import Vue from 'vue'
|
|
import Router from 'vue-router'
|
|
import MainLayout from './layout/main'
|
|
import routesConfig from './routes.yml'
|
|
|
|
Vue.use(Router)
|
|
|
|
function getSideTabs(menu, parentName, sideTabs = []) {
|
|
menu.children.forEach((item) => {
|
|
if (item.type === 'module' || item.type === 'group') {
|
|
sideTabs = sideTabs.concat(getSideTabs(item, parentName))
|
|
} else if (item.type === 'page') {
|
|
sideTabs.push({
|
|
path: `/${parentName}/${item.name}`,
|
|
name: `${parentName}-${item.name}`,
|
|
component: () => import(`./pages/${item.name}`),
|
|
meta: {
|
|
demo: typeof item.demo !== 'boolean' && (item.demo || `/pages/${item.name}/Index`),
|
|
title: item.title,
|
|
parentName
|
|
}
|
|
})
|
|
} else {
|
|
sideTabs.push({
|
|
path: `/${parentName}/${item.name}`,
|
|
name: `${parentName}-${item.name}`,
|
|
component: () => import(`./docs/${item.name}`),
|
|
meta: {
|
|
demo: typeof item.demo !== 'boolean' && (item.demo || `/pages/${item.name}/Index`),
|
|
title: item.title,
|
|
parentName
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|
|
return sideTabs
|
|
}
|
|
|
|
let pages = []
|
|
routesConfig.forEach((menu) => {
|
|
if (menu.type === 'link') return
|
|
|
|
if (menu.type === 'page') {
|
|
pages.push({
|
|
path: `/${menu.name}`,
|
|
name: menu.name,
|
|
component: () => import(`./pages/${menu.name}`),
|
|
meta: {
|
|
title: menu.title
|
|
}
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
if (menu.children) {
|
|
let sideTabs = getSideTabs(menu, menu.name)
|
|
|
|
pages.push({
|
|
path: `/${menu.name}`,
|
|
name: menu.name,
|
|
component: () => import('./layout/sideTabs'),
|
|
redirect: sideTabs[0].path,
|
|
children: sideTabs
|
|
})
|
|
}
|
|
})
|
|
|
|
const router = new Router({
|
|
routes: [
|
|
{
|
|
path: '/',
|
|
component: MainLayout,
|
|
redirect: pages[0].children[0].path,
|
|
children: pages
|
|
}
|
|
]
|
|
})
|
|
|
|
export default router
|