353 lines
7.6 KiB
TypeScript
353 lines
7.6 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
import type { RouteRecordRaw } from 'vue-router'
|
|
|
|
// 导入页面组件
|
|
import Home from '@/views/Home.vue'
|
|
import Courses from '@/views/Courses.vue'
|
|
import CourseDetail from '@/views/CourseDetail.vue'
|
|
import CourseDetailEnrolled from '@/views/CourseDetailEnrolled.vue'
|
|
import CourseStudy from '@/views/CourseStudy.vue'
|
|
import Learning from '@/views/Learning.vue'
|
|
import Profile from '@/views/Profile.vue'
|
|
|
|
import LearningPaths from '@/views/LearningPaths.vue'
|
|
import Faculty from '@/views/Faculty.vue'
|
|
import TeacherDetail from '@/views/TeacherDetail.vue'
|
|
import Resources from '@/views/Resources.vue'
|
|
import Activities from '@/views/Activities.vue'
|
|
import ActivityDetail from '@/views/ActivityDetail.vue'
|
|
import ActivityRegistration from '@/views/ActivityRegistration.vue'
|
|
import Exam from '@/views/Exam.vue'
|
|
import ExamNotice from '@/views/ExamNotice.vue'
|
|
import ExamSubmitted from '@/views/ExamSubmitted.vue'
|
|
import TestSections from '@/views/TestSections.vue'
|
|
import LocalVideoDemo from '@/views/LocalVideoDemo.vue'
|
|
import SpecialTraining from '@/views/SpecialTraining.vue'
|
|
import SpecialTrainingDetail from '@/views/SpecialTrainingDetail.vue'
|
|
import HelpCenter from '@/views/HelpCenter.vue'
|
|
|
|
// 管理员路由
|
|
import AdminDashboard from '@/views/teacher/AdminDashboard.vue'
|
|
import PersonalCenter from '@/components/admin/PersonalCenter.vue'
|
|
import CourseManagement from '@/components/admin/CourseManagement.vue'
|
|
import MyResources from '@/components/admin/MyResources.vue'
|
|
import StudentManagement from '@/components/admin/StudentManagement.vue'
|
|
// 课程管理子路由组件
|
|
import CourseCategory from '@/components/admin/CourseComponents/CourseCategory.vue'
|
|
import MaterialCategory from '@/components/admin/CourseComponents/MaterialCategory.vue'
|
|
import CourseAnalysis from '@/components/admin/CourseComponents/CourseAnalysis.vue'
|
|
|
|
|
|
const routes: RouteRecordRaw[] = [
|
|
{
|
|
path: '/teacher',
|
|
|
|
name: 'AdminDashboard',
|
|
component: AdminDashboard,
|
|
meta: {
|
|
title: '管理后台',
|
|
requiresAuth: true
|
|
},
|
|
children: [
|
|
{
|
|
path: 'personal-center',
|
|
name: 'PersonalCenter',
|
|
component: PersonalCenter,
|
|
meta: {
|
|
title: '个人中心'
|
|
}
|
|
},
|
|
{
|
|
path: 'course-management',
|
|
name: 'CourseManagement',
|
|
component: CourseManagement,
|
|
meta: {
|
|
title: '课程管理'
|
|
},
|
|
children: [
|
|
{
|
|
path: 'course-category',
|
|
name: 'CourseCategory',
|
|
component: CourseCategory,
|
|
meta: {
|
|
title: '课程分类'
|
|
}
|
|
},
|
|
{
|
|
path: 'material-category',
|
|
name: 'MaterialCategory',
|
|
component: MaterialCategory,
|
|
meta: {
|
|
title: '资料分类'
|
|
}
|
|
},
|
|
{
|
|
path: 'course-analysis',
|
|
name: 'CourseAnalysis',
|
|
component: CourseAnalysis,
|
|
meta: {
|
|
title: '课程分析'
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: 'my-resources',
|
|
name: 'MyResources',
|
|
component: MyResources,
|
|
meta: {
|
|
title: '我的资源'
|
|
}
|
|
},
|
|
{
|
|
path: 'student-management',
|
|
name: 'StudentManagement',
|
|
component: StudentManagement,
|
|
meta: {
|
|
title: '学员管理'
|
|
}
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: '/help-center',
|
|
name: 'HelpCenter',
|
|
component: HelpCenter,
|
|
meta: {
|
|
title: '帮助中心'
|
|
}
|
|
},
|
|
{
|
|
path: '/',
|
|
name: 'Home',
|
|
component: Home,
|
|
meta: {
|
|
title: '首页'
|
|
}
|
|
},
|
|
{
|
|
path: '/courses',
|
|
name: 'Courses',
|
|
component: Courses,
|
|
meta: {
|
|
title: '课程列表'
|
|
}
|
|
},
|
|
{
|
|
path: '/course/:id',
|
|
name: 'CourseDetail',
|
|
component: CourseDetail,
|
|
meta: {
|
|
title: '课程详情'
|
|
}
|
|
},
|
|
{
|
|
path: '/course/:id/enrolled',
|
|
name: 'CourseDetailEnrolled',
|
|
component: CourseDetailEnrolled,
|
|
meta: {
|
|
title: '课程详情 - 已报名'
|
|
}
|
|
},
|
|
{
|
|
path: '/course/study/:id',
|
|
name: 'CourseStudy',
|
|
component: CourseStudy,
|
|
meta: {
|
|
title: '课程学习',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: '/learning/:id',
|
|
name: 'Learning',
|
|
component: Learning,
|
|
meta: {
|
|
title: '学习中心',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
{
|
|
path: '/profile',
|
|
name: 'Profile',
|
|
component: Profile,
|
|
meta: {
|
|
title: '个人中心',
|
|
requiresAuth: true
|
|
}
|
|
},
|
|
|
|
{
|
|
path: '/learning-paths',
|
|
name: 'LearningPaths',
|
|
component: LearningPaths,
|
|
meta: {
|
|
title: '学习路径'
|
|
}
|
|
},
|
|
{
|
|
path: '/faculty',
|
|
name: 'Faculty',
|
|
component: Faculty,
|
|
meta: {
|
|
title: '师资力量'
|
|
}
|
|
},
|
|
{
|
|
path: '/teacher/:id',
|
|
name: 'TeacherDetail',
|
|
component: TeacherDetail,
|
|
meta: {
|
|
title: '讲师详情'
|
|
}
|
|
},
|
|
{
|
|
path: '/resources',
|
|
name: 'Resources',
|
|
component: Resources,
|
|
meta: {
|
|
title: '精选资源'
|
|
}
|
|
},
|
|
{
|
|
path: '/special-training',
|
|
name: 'SpecialTraining',
|
|
component: SpecialTraining,
|
|
meta: {
|
|
title: '专题训练'
|
|
}
|
|
},
|
|
{
|
|
path: '/special-training/:id',
|
|
name: 'SpecialTrainingDetail',
|
|
component: SpecialTrainingDetail,
|
|
meta: {
|
|
title: '专题训练详情'
|
|
}
|
|
},
|
|
{
|
|
path: '/activities',
|
|
name: 'Activities',
|
|
component: Activities,
|
|
meta: {
|
|
title: '全部活动'
|
|
}
|
|
},
|
|
{
|
|
path: '/activity/:id',
|
|
name: 'ActivityDetail',
|
|
component: ActivityDetail,
|
|
meta: {
|
|
title: '活动详情'
|
|
}
|
|
},
|
|
{
|
|
path: '/activity/:id/register',
|
|
name: 'ActivityRegistration',
|
|
component: ActivityRegistration,
|
|
meta: {
|
|
title: '活动报名'
|
|
}
|
|
},
|
|
{
|
|
path: '/course/:courseId/exam/:sectionId/notice',
|
|
name: 'ExamNotice',
|
|
component: ExamNotice,
|
|
meta: {
|
|
title: '考前须知'
|
|
}
|
|
},
|
|
{
|
|
path: '/course/:courseId/exam/:sectionId',
|
|
name: 'Exam',
|
|
component: Exam,
|
|
meta: {
|
|
title: '在线考试'
|
|
}
|
|
},
|
|
{
|
|
path: '/exam/submitted',
|
|
name: 'ExamSubmitted',
|
|
component: ExamSubmitted,
|
|
meta: {
|
|
title: '考试提交成功'
|
|
}
|
|
},
|
|
{
|
|
path: '/ai',
|
|
name: 'AI',
|
|
component: () => import('@/views/Ai.vue'),
|
|
meta: {
|
|
title: 'AI'
|
|
}
|
|
},
|
|
{
|
|
path: '/ai-demo',
|
|
name: 'AIDemo',
|
|
component: () => import('@/views/DetailView.vue'),
|
|
meta: {
|
|
title: 'AI演示'
|
|
}
|
|
},
|
|
{
|
|
path: '/test-sections',
|
|
name: 'TestSections',
|
|
component: TestSections,
|
|
meta: {
|
|
title: '测试章节API'
|
|
}
|
|
},
|
|
{
|
|
path: '/local-video-demo',
|
|
name: 'LocalVideoDemo',
|
|
component: LocalVideoDemo,
|
|
meta: {
|
|
title: '本地视频播放演示'
|
|
}
|
|
},
|
|
{
|
|
path: '/:pathMatch(.*)*',
|
|
name: 'NotFound',
|
|
component: () => import('@/views/NotFound.vue'),
|
|
meta: {
|
|
title: '页面未找到'
|
|
},
|
|
|
|
}
|
|
]
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes,
|
|
scrollBehavior(_to, _from, savedPosition) {
|
|
if (savedPosition) {
|
|
return savedPosition
|
|
} else {
|
|
return { top: 0 }
|
|
}
|
|
}
|
|
})
|
|
|
|
// 路由守卫
|
|
router.beforeEach((to, _from, next) => {
|
|
// 设置页面标题
|
|
if (to.meta.title) {
|
|
document.title = `${to.meta.title} - 在线学习平台`
|
|
}
|
|
|
|
// 检查是否需要登录
|
|
if (to.meta.requiresAuth) {
|
|
// 检查用户登录状态
|
|
const token = localStorage.getItem('token')
|
|
if (!token) {
|
|
// 未登录时跳转到首页,用户可以通过模态框登录
|
|
next('/')
|
|
return
|
|
}
|
|
}
|
|
|
|
next()
|
|
})
|
|
|
|
export default router
|