import Vue from 'vue'; import VueRouter from 'vue-router'; import store from '@/store/index'; Vue.use(VueRouter); const routes = [ { path: '/', name: 'frame', component: () => import('@/views/index.vue'), children: [ { path: '/list', name: 'test_list', component: () => import('@/views/test/list.vue'), }, { path: '/detail', name: 'test_detail', component: () => import('@/views/test/detail.vue'), }, { path: '/itembank/detail', name: 'itembank_detail', meta: { title: '题库', sub: '详情' }, component: () => import('@/views/Itembank/detail.vue'), }, { path: '/itembank/index', name: 'itembank_index', meta: { title: '题库', sub: '管理' }, component: () => import('@/views/Itembank/index.vue'), }, // { // path: '/questionstate/detail', // name: 'questionstate_detail', // meta: { title: '问卷状态', sub: '详情' }, // component: () => import('@/views/questionstate/detail.vue'), // }, { path: '/questionstate/index', name: 'questionstate_index', meta: { title: '问卷状态', sub: '管理' }, component: () => import('@/views/questionstate/index.vue'), }, { path: '/certificaate/index', name: 'certificaate_index', meta: { title: '证书', sub: '管理' }, component: () => import('@/views/certificaate/index.vue'), }, { path: '/certificaate/detail', name: 'certificaate_detail', meta: { title: '证书', sub: '详情' }, component: () => import('@/views/certificaate/detail.vue'), }, { path: '/certificaate/look', name: 'certificaate_look', meta: { title: '证书', sub: '打印' }, component: () => import('@/views/certificaate/look.vue'), }, { path: '/questionnaire/index', name: 'questionnaire_index', meta: { title: '问卷', sub: '管理' }, component: () => import('@/views/questionnaire/index.vue'), }, { path: '/questionnaire/detail', name: 'questionnaire_detail', meta: { title: '问卷', sub: '详情' }, component: () => import('@/views/questionnaire/detail.vue'), }, { path: '/teacher/detail', name: 'teacher_detail', meta: { title: '教师', sub: '详情' }, component: () => import('@/views/teacher/detail.vue'), }, { path: '/teacher/index', name: 'teacher_index', meta: { title: '教师', sub: '管理' }, component: () => import('@/views/teacher/index.vue'), }, { path: '/teacher/means', name: 'teacher_means', component: () => import('@/views/teacher/means.vue'), }, { path: '/teacher/verify', name: 'teacher_verify', meta: { title: '教师', sub: '审核页' }, component: () => import('@/views/teacher/verify.vue'), }, { path: '/work/detail', name: 'work_detail', meta: { title: '作业', sub: '详情' }, component: () => import('@/views/work/detail.vue'), }, { path: '/work/index', name: 'work_index', meta: { title: '作业', sub: '管理' }, component: () => import('@/views/work/index.vue'), }, { path: '/work/look', name: 'work_look', meta: { title: '作业题', sub: '管理' }, component: () => import('@/views/work/look.vue'), }, { path: '/subject/index', name: 'subject_index', meta: { title: '科目', sub: '管理' }, component: () => import('@/views/subject/index.vue'), }, { path: '/subject/detail', name: 'subject_detail', meta: { title: '科目', sub: '详情' }, component: () => import('@/views/subject/detail.vue'), }, { path: '/director/index', name: 'director_index', meta: { title: '班主任', sub: '管理' }, component: () => import('@/views/director/index.vue'), }, { path: '/director/detail', name: 'director_detail', meta: { title: '班主任', sub: '详情' }, component: () => import('@/views/director/detail.vue'), }, { path: '/dept/index', name: 'dept_index', meta: { title: '部门', sub: '管理' }, component: () => import('@/views/dept/index.vue'), }, { path: '/dept/detail', name: 'dept_detail', meta: { title: '部门', sub: '详情' }, component: () => import('@/views/dept/detail.vue'), }, { path: '/duty/index', name: 'duty_index', meta: { title: '职责', sub: '说明' }, component: () => import('@/views/duty/index.vue'), }, { path: '/location/index', name: 'location_index', meta: { title: '地点', sub: '管理' }, component: () => import('@/views/location/index.vue'), }, { path: '/location/detail', name: 'location_detail', meta: { title: '地点', sub: '详情' }, component: () => import('@/views/location/detail.vue'), }, { path: '/bedroom/index', name: 'bedroom_index', meta: { title: '寝室', sub: '管理' }, component: () => import('@/views/bedroom/index.vue'), }, { path: '/bedroom/detail', name: 'bedroom_detail', meta: { title: '寝室', sub: '详情' }, component: () => import('@/views/bedroom/detail.vue'), }, { path: '/classes/index', name: 'classes_index', meta: { title: '班级', sub: '管理' }, component: () => import('@/views/classes/index.vue'), }, { path: '/classes/detail', name: 'classes_detail', meta: { title: '班级', sub: '详情' }, component: () => import('@/views/classes/detail.vue'), }, { path: '/student/index', name: 'student_index', meta: { title: '学生', sub: '管理' }, component: () => import('@/views/student/index.vue'), }, { path: '/student/detail', name: 'student_detail', meta: { title: '学生', sub: '详情' }, component: () => import('@/views/student/detail.vue'), }, { path: '/plan/index', name: 'plan_index', meta: { title: '计划', sub: '管理' }, component: () => import('@/views/plan/index.vue'), }, { path: '/plan/detail', name: 'plan_detail', meta: { title: '计划', sub: '详情' }, component: () => import('@/views/plan/detail.vue'), }, { path: '/plan/classes', name: 'plan_classes', meta: { title: '安排', sub: '班级' }, component: () => import('@/views/plan/classes.vue'), }, { path: '/plan/lesson', name: 'plan_lesson', meta: { title: '安排', sub: '课程' }, component: () => import('@/views/plan/lesson.vue'), }, { path: '/plan/msg', name: 'plan_msg', meta: { title: '发送', sub: '通知' }, component: () => import('@/views/plan/msg.vue'), }, { path: '/plan/question', name: 'plan_question', meta: { title: '问卷', sub: '管理' }, component: () => import('@/views/plan/question.vue'), }, ], }, { path: '/yearPlan/index', name: 'yearPlan_index', meta: { title: '全年计划', sub: '管理' }, component: () => import('@/views/yearPlan/index.vue'), }, ]; const router = new VueRouter({ mode: 'history', base: process.env.NODE_ENV === 'development' ? '' : process.env.VUE_APP_ROOT_URL + 'center', routes, }); router.beforeEach((to, form, next) => { store.commit('setUser'); let user = store.state.user; if (user) { if (user.type == process.env.VUE_APP_USER_TYPE) { console.log('缓存登陆'); next(); } else { console.error('非当前端用户,需要重新登陆'); // next('/login'); //TODO 跳转至登陆页 } } //下面是没登录的情况,需要跳转页面到用户未登录页 else next(); }); export default router;