import Vue from 'vue' // 引入vue
import Router from 'vue-router' // 引入vue-router
import Layout from '@/layout' // 页面布局 Layout

Vue.use(Router)

/**
 * 注意: 子菜单仅在route的children.length> = 1时出现
 * hidden: true                 如果为true，将不会显示侧边栏sidebar（默认值 false）
 * redirect: noRedirect         如果设置为noRedirect，则不会重定向
 * name:'router-name'           name被<keep-alive>使用 （必须设置!!!）
 * meta : {
    title: 'title'              侧边栏sidebar中显示的名称（推荐设置）
    icon: 'svg-name'            侧边栏sidebar中显示的icon图标
  }
 */

/**
 * constantRoutes
 * 没有权限要求的页面，所有角色roles都可以访问
 */
export const constantRoutes = [{
        path: '/',
        component: () =>
            import ('@/views/index/indexLayout')
    },
    {
        path: '/',
        component: Layout,
        redirect: 'noRedirect',
        children: [{
                path: 'indexLayout',
                name: 'IndexLayout',
                component: () =>
                    import ('@/views/index/indexLayout'),
                meta: {
                    title: '首页',
                    icon: ''
                },
                children: [{
                        path: 'home',
                        name: 'Home',
                        component: () =>
                            import ('@/views/index/workbench'),
                        meta: {
                            title: '首页',
                            icon: ''
                        }
                    }, {
                        path: 'data',
                        name: 'Data',
                        component: () =>
                            import ('@/views/index/data'),
                        meta: {
                            title: '数据中心',
                            icon: ''
                        }
                    },
                    {
                        path: 'guanyuwe',
                        name: 'Guanyuwe',
                        component: () =>
                            import ('@/views/index/guanyuwe'),
                        meta: {
                            title: '数据中心',
                            icon: ''
                        }
                    },
                    {
                        path: 'cae',
                        name: 'Cae',
                        component: () =>
                            import ('@/views/index/cae'),
                        meta: {
                            title: '前沿动力',
                            icon: ''
                        }
                    },
                    {
                        path: 'workbench',
                        name: 'Workbench',
                        component: () =>
                            import ('@/views/index/workbench'),
                        meta: {
                            title: '首页',
                            icon: ''
                        }
                    },
                    {
                        path: 'my-workbench',
                        name: 'MyWorkbench',
                        component: () =>
                            import ('@/views/index/my-workbench'),
                        meta: {
                            title: '我的工作台',
                            icon: ''
                        }
                    },
                    {
                        path: 'design',
                        name: 'Design',
                        component: () =>
                            import ('@/views/index/design'),
                        meta: {
                            title: '设计中心',
                            icon: ''
                        }
                    },
                    
                ]
            },
          
            
            {
                path: 'userLayout',
                name: 'UserLayout',
                component: () =>
                    import ('@/views/user/userLayout'),
                meta: {
                    title: '个人中心',
                    icon: ''
                },
                children: [
                    {
                        path: 'modify',
                        name: 'Modify',
                        component: () =>
                            import ('@/views/user/modify'),
                        meta: {
                            title: '修改密码',
                            icon: ''
                        }
                    },
                    {
                        path: 'real',
                        name: 'Real',
                        component: () =>
                            import ('@/views/user/real'),
                        meta: {
                            title: '实名认证',
                            icon: ''
                        }
                    },
                    {
                        path: 'project',
                        name: 'Project',
                        component: () =>
                            import ('@/views/user/project'),
                        meta: {
                            title: '我的项目',
                            icon: ''
                        }
                    },
                    {
                        path: 'megagame',
                        name: 'Megagame',
                        component: () =>
                            import ('@/views/user/megagame'),
                        meta: {
                            title: '大赛',
                            icon: ''
                        }
                    },
                    {
                        path: 'menu',
                        name: 'menu',
                        component: () =>
                            import ('@/views/user/menu'),
                        meta: {
                            title: '菜单',
                            icon: ''
                        }
                    },
                    {
                        path: 'details',
                        name: 'Details',
                        component: () =>
                            import ('@/views/user/project/details'),
                        meta: {
                            title: '项目详情',
                            icon: ''
                        }
                    },

                    {
                        path: 'resource',
                        name: 'Resource',
                        component: () =>
                            import ('@/views/user/resource'),
                        meta: {
                            title: '我的资源',
                            icon: ''
                        }
                    }, {
                        path: 'invoice',
                        name: 'Invoice',
                        component: () =>
                            import ('@/views/user/invoice'),
                        meta: {
                            title: '发票管理',
                            icon: ''
                        }
                    }, {
                        path: 'integral',
                        name: 'Integral',
                        component: () =>
                            import ('@/views/user/integral'),
                        meta: {
                            title: '我的积分',
                            icon: ''
                        }
                    },
                    {
                        path: 'account',
                        name: 'Account',
                        component: () =>
                            import ('@/views/user/account'),
                        meta: {
                            title: '账户管理',
                            icon: ''
                        }
                    },
                    {
                        path: 'customize',
                        name: 'Customize',
                        component: () =>
                            import ('@/views/user/customize'),
                        meta: {
                            title: '定制工作台',
                            icon: ''
                        }
                    },
                    {
                        path: 'user-info',
                        name: 'userInfo',
                        component: () =>
                            import ('@/views/user/user-info'),
                        meta: {
                            title: '用户信息',
                            icon: ''
                        }
                    },
                    //大赛页面
            {
                path: 'palan',
                name: 'palan',
                component: () =>
                    import ('@/views/user/match/palan'),
                meta: {
                    title: '大赛进度',
                    icon: ''
                }
            },
            {
                path: 'owerdas',
                name: 'owerdas',
                component: () =>
                    import ('@/views/user/match/owerdas'),
                meta: {
                    title: '我的大赛',
                    icon: ''
                }
            },
            {
                path: 'dsproject',
                name: 'dsproject',
                component: () =>
                    import ('@/views/user/match/owerdas/dsproject'),
                meta: {
                    title: '查看项目',
                    icon: ''
                }
            },
                ]
            },
            {
                path: 'matchLayout',
                name: 'MatchLayout',
                component: () =>
                    import ('@/views/megagame/matchLayout'),
                meta: {
                    title: '大赛',
                    icon: ''
                },
                children: [{
                    path: 'notice',
                    name: 'Notice',
                    component: () =>
                        import ('@/views/megagame/notice'),
                    meta: {
                        title: '大赛',
                        icon: ''
                    }
                }, {
                    path: 'timeline',
                    name: 'Timeline',
                    component: () =>
                        import ('@/views/megagame/timeline'),
                    meta: {
                        title: '报名成功',
                        icon: ''
                    }
                }, ]
            },
            {
                path: 'topic',
                name: 'Topic',
                component: () =>
                    import ('@/views/megagame/topic/index'),
                meta: {
                    title: '题目领取',
                    icon: ''
                }
            },
            {
                path: 'topic/detailsxq',
                name: 'Detailsxq',
                component: () =>
                    import ('@/views/megagame/topic/details/detailsxq'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'topic/detailafa',
                name: 'Detailafa',
                component: () =>
                    import ('@/views/megagame/topic/details/detailafa'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'topic/detailaw',
                name: 'detailaw',
                component: () =>
                    import ('@/views/megagame/topic/details/detailaw'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'topic/detailmw',
                name: 'detailmw',
                component: () =>
                    import ('@/views/megagame/topic/details/detailmw'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'topic/detailbyy',
                name: 'detailbyy',
                component: () =>
                    import ('@/views/megagame/topic/details/detailbyy'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'detailbzs1',
                name: 'detailbzs1',
                component: () =>
                    import ('@/views/megagame/topic/details/detailbzs1'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'detailbzs2',
                name: 'detailbzs2',
                component: () =>
                    import ('@/views/megagame/topic/details/detailbzs2'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'detailbzs3',
                name: 'detailbzs3',
                component: () =>
                    import ('@/views/megagame/topic/details/detailbzs3'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'detailbzs4',
                name: 'detailbzs4',
                component: () =>
                    import ('@/views/megagame/topic/details/detailbzs4'),
                meta: {
                    title: '领题的详情页面',
                    icon: ''
                }
            },
            {
                path: 'result',
                name: 'Result',
                component: () =>
                    import ('@/views/megagame/result'),
                meta: {
                    title: '比赛结果',
                    icon: ''
                }
            },
           
            {
                path: 'login',
                name: 'Login',
                component: () =>
                    import ('@/views/login'),
                meta: {
                    title: '登录',
                    icon: ''
                }
            },
            {

                path: 'forget',
                name: 'Forget',
                component: () =>
                    import ('@/views/forget'),
                meta: {
                    title: '忘记密码',
                    icon: ''
                }
            },
            {
                path: 'register',
                name: 'Register',
                component: () =>
                    import ('@/views/register'),
                meta: {
                    title: '免费注册',
                    icon: ''
                }
            },
            {
                path: 'protocol',
                name: 'Protocol',
                component: () =>
                    import ('@/views/protocol'),
                meta: {
                    title: '注册协议',
                    icon: ''
                }
            }
        ]
    },
    /*
        {
          path: '/example',
          name: 'Example',
          component: Layout,
          redirect: '/example/table',
          meta: { title: '云产品', icon: '' },
          children: [
            {
              path: 'table',
              name: 'Table',
              component: () => import('@/views/example/table'),
              meta: { title: '云产品1', icon: '' }
            },
            {
              path: 'tree',
              name: 'Tree',
              component: () => import('@/views/example/tree'),
              meta: { title: '云产品2', icon: '' }
            }
          ]
        },
        */
    {
        path: '/fail404',
        component: () =>
            import ('@/views/fail404'),
        hidden: true
    },

    // 404页必须放在末尾 !!!
    {
        path: '*',
        redirect: '/fail404',
        component: () =>
            import ('@/views/fail404'),
        hidden: true
    }
]

// 创建路由（hashHistory是以#后面的路径进行处理，通过HTML5 History进行前端路由管理，而 browserHistory 则是类似我们通常的页面访问路径，并没有#，但要通过服务端的配置，能够访问指定的url 都定向到当前页面，从而能够进行前端的路由管理。）
const createRouter = () => new Router({
    // mode: 'history', // history模式（browserHistory需要后端支持，本项目默认hashHistory ）
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRoutes
})

const router = createRouter()

// 重置路由（通过将路由的matcher对象替换为新创建的路由实例中的matcher对象来实现）
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher
}

export default router // 导出routernp