import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 主要框架
import Layout from '@/layout'

// 登录框架
import LoginLayout from '@/views/login/components/LoginLayout'

export const constantRoutes = [{
		path: '/redirect',
		component: Layout,
		hidden: true,
		children: [{
			path: '/redirect/:path*',
			component: () => import('@/views/redirect/index')
		}]
	},

	{
		path: '/login',
		component: LoginLayout,
		hidden: true,
		children: [{
				path: '/login',
				name: 'Login',
				component: () => import('@/views/login/index'),
				hidden: true
			},
			{
				path: '/register',
				name: 'Register',
				component: () => import('@/views/login/register'),
				hidden: true
			}
		]
	},

	{
		path: '/404',
		component: () => import('@/views/error-page/404'),
		hidden: true
	},
	{
		path: '/401',
		component: () => import('@/views/error-page/401'),
		hidden: true
	},
	{
		path: '/',
		component: Layout,
		redirect: '/dashboard',
		children: [{
			path: 'dashboard',
			component: () => import('@/views/dashboard/index'),
			name: 'Dashboard',
			meta: {
				title: '控制台',
				icon: 'dashboard',
				affix: true
			}
		}, ]
	},

	{
		path: '/profile',
		component: Layout,
		redirect: '/profile/index',
		hidden: true,
		children: [{
			path: 'index',
			component: () => import('@/views/profile/index'),
			name: 'Profile',
			meta: {
				title: '个人资料',
				icon: 'user',
				noCache: true
			}
		}]
	}
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

	 /*{
	  path: '/apply',
	  component: Layout,
	  redirect: '/apply/input',
	  name: 'Apply',
	  meta: {
	    title: '报销申请',
	    icon: 'example',
	    roles: ['root']
	  },
	  children: [
	    {
	      path: 'input',
	      component: () => import('@/views/apply/input'),
	      name: 'input',
	      meta: { title: '报销申请', noCache: true, icon: 'repo' }
	    }
	  ]
	},*/

	{
		path: '/sys',
		component: Layout,
		redirect: '/sys/config',
		name: 'Sys',
		meta: {
			title: '系统设置',
			icon: 'configure',
			roles: ['root']
		},
		children: [{
				path: 'config',
				component: () => import('@/views/sys/config'),
				name: 'SysConfig',
				meta: {
					title: '系统配置',
					icon: 'theme'
				}
			},
			{
				path: 'dict',
				component: () => import('@/views/sys/dict'),
				name: 'SysDict',
				meta: {
					title: '码值管理',
					icon: 'theme'
				}
			},
			/*{
				path: 'depart',
				component: () => import('@/views/sys/depart'),
				name: 'SysDepart',
				meta: {
					title: '部门管理',
					icon: 'tree'
				}
			},*/

			{
				path: 'role',
				component: () => import('@/views/sys/role'),
				name: 'SysRole',
				meta: {
					title: '角色管理',
					icon: 'role'
				}
			},

			{
				path: 'user',
				component: () => import('@/views/sys/user'),
				name: 'SysUser',
				meta: {
					title: '用户管理',
					icon: 'admin'
				}
			},

      {
        path: 'bookgl',
        component: () => import('@/views/sys/bookgl'),
        name: 'SysBookgl',
        meta: {
          title: '书籍信息管理',
          icon: 'admin'
        }
      },
      {
        path: 'jieshu',
        component: () => import('@/views/sys/jieshu'),
        name: 'SysJieshu',
        meta: {
          title: '图书搜索',
          icon: 'admin'
        }
      },

      {
        path: 'huanshu',
        component: () => import('@/views/sys/huanshu'),
        name: 'Syshuanshu',
        meta: {
          title: '我的借还',
          icon: 'admin'
        }
      },
      {
        path: 'jiehuanjilu',
        component: () => import('@/views/sys/jiehuanjilu'),
        name: 'SysJiehuanjilu',
        meta: {
          title: '借还记录',
          icon: 'admin'
        }
      },{
        path: 'gggl',
        component: () => import('@/views/sys/gggl'),
        name: 'SysGggl',
        meta: {
          title: '公告管理',
          icon: 'admin'
        }
      },
      {
        path: 'lygl',
        component: () => import('@/views/sys/liuyangl'),
        name: 'SysLygl',
        meta: {
          title: '留言管理',
          icon: 'admin'
        }
      },

		]



	},
  {
    path: '/sys',
    component: Layout,
    redirect: '/sys/config',
    name: 'student',
    meta: {
      title: '用户系统',
      icon: 'configure',
      roles: ['student']
    },// 学生路由页面
    children: [
      /*{
        path: 'grxxgl',
        component: () => import('@/views/sys/grxxgl'),
        name: 'SysGrxxgl',
        meta: {
          title: '个人信息管理',
          icon: 'admin'
        }
      },*/
      {
        path: 'jieshu',
        component: () => import('@/views/sys/jieshu'),
        name: 'SysJieshu',
        meta: {
          title: '图书搜索',
          icon: 'admin'
        }
      },

      {
        path: 'huanshu',
        component: () => import('@/views/sys/huanshu'),
        name: 'Syshuanshu',
        meta: {
          title: '我的借还',
          icon: 'admin'
        }
      },
      {
        path: 'jiehuanjilu',
        component: () => import('@/views/sys/jiehuanjilu'),
        name: 'SysJiehuanjilu',
        meta: {
          title: '借还记录',
          icon: 'admin'
        }
      }
      ,
      {
        path: 'liuyan',
        component: () => import('@/views/sys/stuliuyan'),
        name: 'SysStuliuyan',
        meta: {
          title: '留言板块',
          icon: 'admin'
        }
      }
      ,
      {
        path: 'gonggao',
        component: () => import('@/views/sys/stugggl'),
        name: 'SysStugggl',
        meta: {
          title: '公告板块',
          icon: 'admin'
        }
      }

    ]
  },

	// 404 page must be placed at the end !!!
	{
		path: '*',
		redirect: '/dashboard',
		hidden: true
	}
]

const createRouter = () => new Router({
	// mode: 'history', // require service support
	scrollBehavior: () => ({
		y: 0
	}),
	routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
	const newRouter = createRouter()
	router.matcher = newRouter.matcher // reset router
}

export default router
