import Vue from "vue";
import VueRouter from "vue-router";

import Display from "../views/Display";
import Login from "../views/Login";
import Layout from "../views/Layout";
import BusRouter from "../views/Business/BusRouter";
import DocRouter from "../views/Docpan/DocRouter";

Vue.use(VueRouter);

const DisplayRouter = BusRouter.map(route => {
    const newRoute = Object.assign({}, route)
    newRoute.name = newRoute.name + 'Display'
    return newRoute;
})

/**
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 * 
 * name:'router-name'             name 必填 <keep-alive>使用这个
 * meta : {
 *   title: 'title'               title
 *   icon: 'svg-name'/'el-icon-x' 图标
 *   noCache: true                无需缓存起来的页面
 *   affix: true                  固定的页面视图
 *   activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 * }
 */
export const routes = [
    // 刷新时使用
    {
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [
            {
                path: '/redirect/:path(.*)',
                component: () => import('~/views/Redirect/index')
            }
        ]
    },
    {
        path: "/",
        component: Layout,
        redirect: "/home",
        children: [
            { path: 'home', component: () => import('~/views/Home'), name: 'Home', meta: { title: '首页', icon: 'el-icon-s-home', affix: true} },
            { path: 'taskList', component: () => import('~/views/TaskList'), name: 'TaskList', meta: { title: '任务列表', icon: 'el-icon-s-claim', affix: true} },
        ],
    },
    { path: "/display", component: Display, children: DisplayRouter },
    { path: "/business", component: Layout, children: BusRouter },
    { path: "/login", component: Login },
    { path: "/docpan", component: () => import("../views/Docpan"), children: DocRouter },
];

const rootRouter = new VueRouter({
    routes,
});


// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

export default rootRouter;
