index.js 6.63 KB
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [
      {
        path: 'home',
        name: 'Home',
        component: () => import('@/views/home/index'),
        meta: { title: '首页', icon: 'el-icon-s-home', dec: '这是首页' }
      },
      {
        path: 'notice',
        name: 'Notice',
        component: () => import('@/views/home/notice/index'),
        meta: { title: '公告列表', activeMenu: '/home' },
        hidden: true
      }
    ]
  },

  {
    path: '/user',
    component: Layout,
    redirect: '/user/account',
    name: 'User',
    meta: { title: '用户管理', icon: 'el-icon-s-custom' },
    children: [
      {
        path: 'account',
        name: 'account',
        component: () => import('@/views/account/index'),
        meta: { title: '账号管理', dec: '这是表格页面' }
      },
      {
        path: 'role',
        name: 'role',
        component: () => import('@/views/role/index'),
        meta: { title: '角色管理', icon: '' }
      }
    ]
  },

  {
    path: '/classes',
    component: Layout,
    redirect: '/classes/classes',
    name: 'Classes',
    meta: { title: '班级管理', icon: 'classes1' },
    children: [
      {
        path: 'classes',
        name: 'Classes',
        component: () => import('@/views/classes/classes'),
        meta: { title: '班级管理' }
      },
      {
        path: 'classDetail',
        name: 'ClassDetail',
        component: () => import('@/views/classes/classes/page/detail'),
        meta: { title: '查看班级', activeMenu: '/classes/classes' },
        hidden: true
      },
      {
        path: 'add',
        name: 'Add',
        component: () => import('@/views/classes/classes/page/add'),
        meta: { title: '班级信息', activeMenu: '/classes/classes' },
        hidden: true
      },
      {
        path: 'blend',
        name: 'Blend',
        component: () => import('@/views/classes/blend'),
        meta: { title: '混班考试' }
      },
      {
        path: 'blendDetail',
        name: 'BlendDetail',
        component: () => import('@/views/classes/blend/detail'),
        meta: { title: '混班名册', activeMenu: '/classes/blend' },
        hidden: true
      }
    ]
  },

  {
    path: '/testpaper',
    component: Layout,
    redirect: '/testpaper/test',
    name: 'Testpaper',
    meta: {
      title: '试卷管理',
      icon: 'el-ump-shijuan'
    },
    children: [
      {
        path: 'test',
        component: () => import('@/views/testpaper/test/index'), // Parent router-view
        name: 'Menu1',
        meta: { title: '试卷管理' }
      }
    ]
  },

  {
    path: '/analysis',
    name: 'Analysis',
    component: Layout,
    redirect: '/analysis/test',
    meta: { title: '考试分析', icon: 'el-icon-data-line' },
    children: [
      {
        path: 'test',
        component: () => import('@/views/analysis/test/index'), // Parent router-view
        name: 'Test',
        meta: { title: '考试纪录' }
      },
      {
        path: 'testdetail',
        component: () => import('@/views/analysis/test/page/testdetail'), // Parent router-view
        name: 'Testdetail',
        hidden: true,
        meta: { title: '答题详情', activeMenu: '/analysis/test' }
      },
      {
        path: 'testinfo',
        component: () => import('@/views/analysis/page/testinfo'), // Parent router-view
        name: 'Testinfo',
        hidden: true,
        meta: { title: '考试分析', activeMenu: '/analysis/test' }
      },
      {
        path: 'classes1',
        component: () => import('@/views/analysis/classes/index'), // Parent router-view
        name: 'Classes1',
        meta: { title: '班级分析' }
      },
      {
        path: 'testpaper',
        component: () => import('@/views/analysis/testpaper/index'), // Parent router-view
        name: 'Testpaper',
        meta: { title: '试卷统计' }
      }
    ]
  },

  {
    path: '/system',
    component: Layout,
    redirect: '/system/setdata',
    name: 'System',
    meta: { title: '系统设置', icon: 'el-icon-s-tools' },
    children: [
      {
        path: 'setdata',
        name: 'Setdata',
        component: () => import('@/views/system/setdata'),
        meta: { title: '参数设置', icon: '' }
      }, {
        path: 'setobject',
        name: 'Setobject',
        component: () => import('@/views/system/setobject'),
        meta: { title: '科目设置', icon: '' }
      },
      {
        path: 'feedback',
        name: 'Feedback',
        component: () => import('@/views/system/feedback'),
        meta: { title: '意见反馈', icon: '' }
      }
    ]
  },

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

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

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router