456 lines
13 KiB
TypeScript
456 lines
13 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'
|
|
import CourseCreate from '@/components/admin/CourseComponents/CourseCreate.vue'
|
|
|
|
// 课程编辑子组件(新增)
|
|
import CourseEditor from '@/views/teacher/course/CourseEditor.vue'
|
|
import CoursewareManagement from '@/views/teacher/course/CoursewareManagement.vue'
|
|
import ChapterManagement from '@/views/teacher/course/ChapterManagement.vue'
|
|
import PracticeManagement from '@/views/teacher/course/PracticeManagement.vue'
|
|
import QuestionBankManagement from '@/views/teacher/course/QuestionBankManagement.vue'
|
|
import CertificateManagement from '@/views/teacher/course/CertificateManagement.vue'
|
|
import DiscussionManagement from '@/views/teacher/course/DiscussionManagement.vue'
|
|
import StatisticsManagement from '@/views/teacher/course/StatisticsManagement.vue'
|
|
import NotificationManagement from '@/views/teacher/course/NotificationManagement.vue'
|
|
import GeneralManagement from '@/views/teacher/course/GeneralManagement.vue'
|
|
|
|
// 作业子组件
|
|
import HomeworkLibrary from '@/views/teacher/course/HomeworkLibrary.vue'
|
|
import HomeworkReview from '@/views/teacher/course/HomeworkReview.vue'
|
|
|
|
// 考试管理组件
|
|
import ExamManagement from '@/views/teacher/ExamPages/ExamPage.vue'
|
|
import QuestionManagement from '@/views/teacher/ExamPages/QuestionManagement.vue'
|
|
import ExamLibrary from '@/views/teacher/ExamPages/ExamLibrary.vue'
|
|
import MarkingCenter from '@/views/teacher/ExamPages/MarkingCenter.vue'
|
|
import AddExam from '@/views/teacher/ExamPages/AddExam.vue'
|
|
|
|
import ChapterEditor from '@/views/teacher/course/ChapterEditor.vue'
|
|
|
|
// ========== 路由配置 ==========
|
|
const routes: RouteRecordRaw[] = [
|
|
// 管理后台路由
|
|
{
|
|
path: '/teacher',
|
|
name: 'AdminDashboard',
|
|
component: AdminDashboard,
|
|
meta: {
|
|
title: '管理后台',
|
|
requiresAuth: true
|
|
},
|
|
redirect: '/teacher/course-management',
|
|
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: 'course-create',
|
|
name: 'CourseCreate',
|
|
component: CourseCreate,
|
|
meta: { title: '创建课程' }
|
|
},
|
|
{
|
|
path: 'course-editor/:id',
|
|
name: 'CourseEditor',
|
|
component: CourseEditor,
|
|
meta: { title: '编辑课程' },
|
|
redirect: (to) => `/teacher/course-editor/${to.params.id}/courseware`,
|
|
children: [
|
|
{
|
|
path: 'courseware',
|
|
name: 'CoursewareManagement',
|
|
component: CoursewareManagement,
|
|
meta: { title: '课件管理' }
|
|
},
|
|
{
|
|
path: 'chapters',
|
|
name: 'ChapterManagement',
|
|
component: ChapterManagement,
|
|
meta: { title: '章节管理' }
|
|
},
|
|
|
|
{
|
|
path: 'homework',
|
|
name: 'HomeworkManagement',
|
|
redirect: (to) => `/teacher/course-editor/${to.params.id}/homework/library`,
|
|
children: [
|
|
{
|
|
path: 'library',
|
|
name: 'HomeworkLibrary',
|
|
component: HomeworkLibrary,
|
|
meta: { title: '作业库' }
|
|
},
|
|
{
|
|
path: 'review',
|
|
name: 'HomeworkReview',
|
|
component: HomeworkReview,
|
|
meta: { title: '批阅作业' }
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: 'practice',
|
|
name: 'PracticeManagement',
|
|
component: PracticeManagement,
|
|
meta: { title: '考试管理' },
|
|
},
|
|
{
|
|
path: 'question-bank',
|
|
name: 'QuestionBankManagement',
|
|
component: QuestionBankManagement,
|
|
meta: { title: '题库管理' }
|
|
},
|
|
{
|
|
path: 'certificate',
|
|
name: 'CertificateManagement',
|
|
component: CertificateManagement,
|
|
meta: { title: '证书管理' }
|
|
},
|
|
{
|
|
path: 'discussion',
|
|
name: 'DiscussionManagement',
|
|
component: DiscussionManagement,
|
|
meta: { title: '讨论管理' }
|
|
},
|
|
{
|
|
path: 'statistics',
|
|
name: 'StatisticsManagement',
|
|
component: StatisticsManagement,
|
|
meta: { title: '统计管理' }
|
|
},
|
|
{
|
|
path: 'notification',
|
|
name: 'NotificationManagement',
|
|
component: NotificationManagement,
|
|
meta: { title: '通知管理' }
|
|
},
|
|
{
|
|
path: 'management',
|
|
name: 'GeneralManagement',
|
|
component: GeneralManagement,
|
|
meta: { title: '综合管理' }
|
|
}
|
|
]
|
|
},
|
|
{
|
|
path: 'my-resources',
|
|
name: 'MyResources',
|
|
component: MyResources,
|
|
meta: { title: '我的资源' }
|
|
},
|
|
{
|
|
path: 'student-management',
|
|
name: 'StudentManagement',
|
|
component: StudentManagement,
|
|
meta: { title: '学员管理' }
|
|
},
|
|
{
|
|
path: 'chapter-editor-teacher/:courseId',
|
|
name: 'ChapterEditor',
|
|
component: ChapterEditor,
|
|
meta: { title: '章节编辑' }
|
|
},
|
|
{
|
|
path: 'exam-management',
|
|
name: 'ExamManagement',
|
|
component: ExamManagement,
|
|
meta: { title: '考试管理' },
|
|
redirect: '/teacher/exam-management/question-management',
|
|
children: [
|
|
{
|
|
path: 'question-management',
|
|
name: 'QuestionManagement',
|
|
component: QuestionManagement,
|
|
meta: { title: '试题管理' }
|
|
},
|
|
{
|
|
path: 'exam-library',
|
|
name: 'ExamLibrary',
|
|
component: ExamLibrary,
|
|
meta: { title: '试卷管理' }
|
|
},
|
|
{
|
|
path: 'marking-center',
|
|
name: 'MarkingCenter',
|
|
component: MarkingCenter,
|
|
meta: { title: '阅卷中心' }
|
|
},
|
|
{
|
|
path: 'add',
|
|
name: 'AddExam',
|
|
component: AddExam,
|
|
meta: { title: '添加试卷' }
|
|
}
|
|
]
|
|
},
|
|
]
|
|
},
|
|
|
|
|
|
// 帮助中心
|
|
{
|
|
path: '/help-center',
|
|
name: 'HelpCenter',
|
|
component: HelpCenter,
|
|
meta: { title: '帮助中心' }
|
|
},
|
|
|
|
// 首页与课程
|
|
{
|
|
path: '/service-agreement',
|
|
name: 'ServiceAgreement',
|
|
component: () => import('@/views/ServiceAgreement.vue'),
|
|
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: '本地视频播放演示' }
|
|
},
|
|
|
|
// 404 路由
|
|
{
|
|
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 |