feat:对接课程下教师的接口;修改章节页面
This commit is contained in:
parent
2031fa4ba4
commit
d9d80c8337
@ -48,17 +48,17 @@ export interface CreateCourseRequest {
|
|||||||
end_time?: string | null
|
end_time?: string | null
|
||||||
enroll_count?: number | null
|
enroll_count?: number | null
|
||||||
max_enroll?: number | null
|
max_enroll?: number | null
|
||||||
status?: number | null
|
status?: string | number | null
|
||||||
question?: string | null
|
question?: string | null
|
||||||
pauseExit: string
|
pauseExit?: string
|
||||||
allowSpeed: string
|
allowSpeed?: string
|
||||||
showSubtitle: string
|
showSubtitle?: string
|
||||||
categoryId?: number | string | null // 支持单个ID(number)或多个ID的逗号分隔字符串
|
categoryId?: number | string | null // 支持单个ID(number)或多个ID的逗号分隔字符串
|
||||||
}
|
}
|
||||||
|
|
||||||
// 编辑课程请求参数
|
// 编辑课程请求参数
|
||||||
export interface EditCourseRequest extends CreateCourseRequest {
|
export interface EditCourseRequest extends CreateCourseRequest {
|
||||||
id: string
|
id: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 查询教师课程列表参数
|
// 查询教师课程列表参数
|
||||||
@ -131,9 +131,9 @@ export class TeachCourseApi {
|
|||||||
*/
|
*/
|
||||||
static async createCourse(data: CreateCourseRequest): Promise<ApiResponse<any>> {
|
static async createCourse(data: CreateCourseRequest): Promise<ApiResponse<any>> {
|
||||||
try {
|
try {
|
||||||
console.log('🚀 发送新建课程请求:', { url: '/aiol/aiolCourse/add', data })
|
console.log('🚀 发送新建课程请求:', { url: '/aiol/aiolCourse/teacher_add', data })
|
||||||
|
|
||||||
const response = await ApiRequest.post<any>('/aiol/aiolCourse/add', data)
|
const response = await ApiRequest.post<any>('/aiol/aiolCourse/teacher_add', data)
|
||||||
|
|
||||||
console.log('📝 新建课程响应:', response)
|
console.log('📝 新建课程响应:', response)
|
||||||
return response
|
return response
|
||||||
@ -205,6 +205,49 @@ export class TeachCourseApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询课程下的教师
|
||||||
|
*/
|
||||||
|
static async getTeacherListInCourse(courseId:string): Promise<ApiResponseWithResult<any>> {
|
||||||
|
try {
|
||||||
|
const response = await ApiRequest.get<{ result: any[] }>(`/aiol/aiolCourse/${courseId}/teachers`)
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 查询教师失败:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 课程添加老师
|
||||||
|
*/
|
||||||
|
static async addTeacher(data: { courseId: string, userId: string }): Promise<ApiResponse<any>> {
|
||||||
|
try {
|
||||||
|
const response = await ApiRequest.post<any>(`/aiol/aiolCourse/${data.courseId}/bind_teacher?userId=${data.userId}`)
|
||||||
|
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 课程添加老师失败:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 课程移除老师
|
||||||
|
*/
|
||||||
|
static async unbindTeacher(data: { courseId: string, userId: string }): Promise<ApiResponse<any>> {
|
||||||
|
try {
|
||||||
|
const response = await ApiRequest.delete<any>(`/aiol/aiolCourse/${data.courseId}/unbind_teacher?userId=${data.userId}`)
|
||||||
|
|
||||||
|
return response
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 课程移除老师失败:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 课程视频上架
|
* 课程视频上架
|
||||||
*/
|
*/
|
||||||
|
@ -301,7 +301,7 @@ const getOptionsForCourse = (course: CourseDisplayItem) => {
|
|||||||
];
|
];
|
||||||
} else if (course.status === 2) { // 已结束
|
} else if (course.status === 2) { // 已结束
|
||||||
return [
|
return [
|
||||||
{ label: '查看', value: 'view', icon: '/images/teacher/查看.png' },
|
// { label: '查看', value: 'view', icon: '/images/teacher/小编辑.png' },
|
||||||
{ label: '删除', value: 'delete', icon: '/images/teacher/删除.png' }
|
{ label: '删除', value: 'delete', icon: '/images/teacher/删除.png' }
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -430,29 +430,12 @@ const handleOfflineCourse = (course: CourseDisplayItem) => {
|
|||||||
// 通过API下架课程 - 设置状态为已结束
|
// 通过API下架课程 - 设置状态为已结束
|
||||||
const updatedData = {
|
const updatedData = {
|
||||||
id: course.id!,
|
id: course.id!,
|
||||||
name: course.name,
|
status: '0',
|
||||||
description: course.description,
|
|
||||||
status: 2, // 2=已结束状态
|
|
||||||
// 添加必需的字段
|
|
||||||
pauseExit: '1',
|
|
||||||
allowSpeed: '1',
|
|
||||||
showSubtitle: '1'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
await TeachCourseApi.editCourse(updatedData);
|
await TeachCourseApi.editCourse(updatedData);
|
||||||
|
|
||||||
// 更新本地数据
|
getCourseList();
|
||||||
const targetCourse = courseList.value.find(c => c.id === course.id);
|
|
||||||
if (targetCourse) {
|
|
||||||
targetCourse.status = 2;
|
|
||||||
targetCourse.statusText = '已结束';
|
|
||||||
}
|
|
||||||
|
|
||||||
const originalCourse = originalCourseList.value.find(c => c.id === course.id);
|
|
||||||
if (originalCourse) {
|
|
||||||
originalCourse.status = 2;
|
|
||||||
originalCourse.statusText = '已结束';
|
|
||||||
}
|
|
||||||
|
|
||||||
message.success(`课程"${course.name}"已下架,现在可以删除了`);
|
message.success(`课程"${course.name}"已下架,现在可以删除了`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -465,12 +448,35 @@ const handleOfflineCourse = (course: CourseDisplayItem) => {
|
|||||||
|
|
||||||
// 发布课程
|
// 发布课程
|
||||||
const handlePublishCourse = (course: CourseDisplayItem) => {
|
const handlePublishCourse = (course: CourseDisplayItem) => {
|
||||||
const targetCourse = courseList.value.find(c => c.id === course.id);
|
if (!course.id) {
|
||||||
if (targetCourse) {
|
message.error('课程ID不存在,无法下架');
|
||||||
targetCourse.status = 1; // 设置为进行中状态
|
return;
|
||||||
targetCourse.statusText = '进行中';
|
|
||||||
message.success(`课程"${course.name}"已发布`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dialog.info({
|
||||||
|
title: '确认发布',
|
||||||
|
content: `确定要发布课程"${course.name}"吗?发布后课程不能删除。`,
|
||||||
|
positiveText: '确定发布',
|
||||||
|
negativeText: '取消',
|
||||||
|
onPositiveClick: async () => {
|
||||||
|
try {
|
||||||
|
// 通过API发布课程 - 设置状态为进行中
|
||||||
|
const updatedData = {
|
||||||
|
id: course.id!,
|
||||||
|
status: '1',
|
||||||
|
};
|
||||||
|
|
||||||
|
await TeachCourseApi.editCourse(updatedData);
|
||||||
|
|
||||||
|
getCourseList();
|
||||||
|
|
||||||
|
message.success(`课程"${course.name}"已下架,现在可以删除了`);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('下架课程失败:', error);
|
||||||
|
message.error('下架课程失败,请稍后重试');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// 移动课程
|
// 移动课程
|
||||||
|
@ -32,8 +32,8 @@
|
|||||||
|
|
||||||
<!-- 主讲老师 -->
|
<!-- 主讲老师 -->
|
||||||
<div class="form-item">
|
<div class="form-item">
|
||||||
<label class="form-label required">主讲老师:</label>
|
<label class="form-label required">授课老师:</label>
|
||||||
<n-select v-model:value="formData.instructors" multiple :options="instructorOptions" placeholder="请选择主讲老师"
|
<n-select v-model:value="formData.instructors" multiple :options="instructorOptions" placeholder="请选择授课老师"
|
||||||
class="form-input" />
|
class="form-input" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ import {
|
|||||||
import '@wangeditor/editor/dist/css/style.css'
|
import '@wangeditor/editor/dist/css/style.css'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
|
import { Editor, Toolbar } from '@wangeditor/editor-for-vue'
|
||||||
import TeachCourseApi from '@/api/modules/teachCourse'
|
import TeachCourseApi, { ClassApi } from '@/api/modules/teachCourse'
|
||||||
import UploadApi from '@/api/modules/upload'
|
import UploadApi from '@/api/modules/upload'
|
||||||
import CourseApi from '@/api/modules/course';
|
import CourseApi from '@/api/modules/course';
|
||||||
import { useCourseStore } from '@/stores/course'
|
import { useCourseStore } from '@/stores/course'
|
||||||
@ -258,6 +258,42 @@ const formData = reactive({
|
|||||||
requiredPoints: 60
|
requiredPoints: 60
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 保存原始的老师列表,用于编辑模式下比较变更
|
||||||
|
const originalInstructors = ref<string[]>([])
|
||||||
|
|
||||||
|
// 加载当前课程的老师列表
|
||||||
|
const loadCourseTeachers = async (courseId: string) => {
|
||||||
|
try {
|
||||||
|
console.log('🔄 开始获取课程老师列表,课程ID:', courseId)
|
||||||
|
|
||||||
|
const response = await TeachCourseApi.getTeacherListInCourse(courseId)
|
||||||
|
|
||||||
|
console.log('🔍 课程老师API响应:', response)
|
||||||
|
|
||||||
|
if (response.data && response.data.result) {
|
||||||
|
const teachers = response.data.result
|
||||||
|
console.log('✅ 获取到课程老师列表:', teachers)
|
||||||
|
|
||||||
|
// 提取老师ID列表
|
||||||
|
const teacherIds = teachers.map((teacher: any) => teacher.id || teacher.userId)
|
||||||
|
|
||||||
|
formData.instructors = teacherIds
|
||||||
|
originalInstructors.value = [...teacherIds]
|
||||||
|
|
||||||
|
console.log('📝 已设置课程老师ID列表:', teacherIds)
|
||||||
|
} else {
|
||||||
|
console.log('⚠️ 课程暂无绑定老师')
|
||||||
|
formData.instructors = []
|
||||||
|
originalInstructors.value = []
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 获取课程老师列表失败:', error)
|
||||||
|
// 发生错误时设置为空数组
|
||||||
|
formData.instructors = []
|
||||||
|
originalInstructors.value = []
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// 加载课程数据
|
// 加载课程数据
|
||||||
@ -278,7 +314,15 @@ const loadCourseData = async () => {
|
|||||||
} else {
|
} else {
|
||||||
formData.courseCategory = [];
|
formData.courseCategory = [];
|
||||||
}
|
}
|
||||||
formData.instructors = storeCourseData.instructors || [];
|
|
||||||
|
// 如果是编辑模式且有课程ID,调用API获取当前课程的老师
|
||||||
|
if (isEditMode.value && courseId.value) {
|
||||||
|
await loadCourseTeachers(courseId.value);
|
||||||
|
} else {
|
||||||
|
// 如果不是编辑模式,使用store中的数据
|
||||||
|
formData.instructors = storeCourseData.instructors || [];
|
||||||
|
originalInstructors.value = [...(storeCourseData.instructors || [])];
|
||||||
|
}
|
||||||
formData.startTime = storeCourseData.start_time || storeCourseData.startTime || null;
|
formData.startTime = storeCourseData.start_time || storeCourseData.startTime || null;
|
||||||
formData.endTime = storeCourseData.end_time || storeCourseData.endTime || null;
|
formData.endTime = storeCourseData.end_time || storeCourseData.endTime || null;
|
||||||
formData.studentType = (storeCourseData.type === 1 || storeCourseData.studentType === 'partial') ? 'partial' : 'all';
|
formData.studentType = (storeCourseData.type === 1 || storeCourseData.studentType === 'partial') ? 'partial' : 'all';
|
||||||
@ -333,7 +377,15 @@ const loadCourseData = async () => {
|
|||||||
} else {
|
} else {
|
||||||
formData.courseCategory = [];
|
formData.courseCategory = [];
|
||||||
}
|
}
|
||||||
formData.instructors = courseData.instructors || [];
|
|
||||||
|
// 如果是编辑模式且有课程ID,调用API获取当前课程的老师
|
||||||
|
if (isEditMode.value && courseId.value) {
|
||||||
|
await loadCourseTeachers(courseId.value);
|
||||||
|
} else {
|
||||||
|
// 如果不是编辑模式,使用路由数据中的老师信息
|
||||||
|
formData.instructors = courseData.instructors || [];
|
||||||
|
originalInstructors.value = [...(courseData.instructors || [])];
|
||||||
|
}
|
||||||
formData.startTime = courseData.start_time || courseData.startTime || null;
|
formData.startTime = courseData.start_time || courseData.startTime || null;
|
||||||
formData.endTime = courseData.end_time || courseData.endTime || null;
|
formData.endTime = courseData.end_time || courseData.endTime || null;
|
||||||
formData.studentType = (courseData.type === 1 || courseData.studentType === 'partial') ? 'partial' : 'all';
|
formData.studentType = (courseData.type === 1 || courseData.studentType === 'partial') ? 'partial' : 'all';
|
||||||
@ -384,17 +436,6 @@ const loadCourseData = async () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 组件挂载时处理
|
|
||||||
onMounted(() => {
|
|
||||||
// 如果是编辑模式(有courseId)、有通过路由传递的课程数据,或者store中有数据
|
|
||||||
if (isEditMode.value && courseId.value) {
|
|
||||||
loadCourseData()
|
|
||||||
} else if (route.query.courseData || courseStore.courseEditData) {
|
|
||||||
// 即使没有ID,也尝试从路由数据或store加载(用于从列表页面直接编辑的情况)
|
|
||||||
loadCourseData()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// 课程分类选项
|
// 课程分类选项
|
||||||
const categoryOptions: Ref<{ label: string; value: number }[]> = ref([])
|
const categoryOptions: Ref<{ label: string; value: number }[]> = ref([])
|
||||||
|
|
||||||
@ -402,12 +443,7 @@ const categoryOptions: Ref<{ label: string; value: number }[]> = ref([])
|
|||||||
const instructorOptions = ref([] as { label: string; value: string }[])
|
const instructorOptions = ref([] as { label: string; value: string }[])
|
||||||
|
|
||||||
// 班级选项
|
// 班级选项
|
||||||
const classOptions = [
|
const classOptions = ref([] as { label: string; value: string }[])
|
||||||
{ label: '前端开发班', value: 'frontend-class' },
|
|
||||||
{ label: '后端开发班', value: 'backend-class' },
|
|
||||||
{ label: 'AI算法班', value: 'ai-class' },
|
|
||||||
{ label: '全栈开发班', value: 'fullstack-class' }
|
|
||||||
]
|
|
||||||
|
|
||||||
// 文件上传相关方法
|
// 文件上传相关方法
|
||||||
const triggerFileUpload = () => {
|
const triggerFileUpload = () => {
|
||||||
@ -475,6 +511,78 @@ const formatDateTime = (timestamp: number): string => {
|
|||||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理老师变更(绑定和解绑)
|
||||||
|
const handleTeacherChanges = async (courseId: string, isCreateMode: boolean = false) => {
|
||||||
|
try {
|
||||||
|
console.log('🔄 开始处理老师变更...')
|
||||||
|
console.log('课程ID:', courseId)
|
||||||
|
console.log('当前老师列表:', formData.instructors)
|
||||||
|
console.log('原始老师列表:', originalInstructors.value)
|
||||||
|
|
||||||
|
if (isCreateMode) {
|
||||||
|
// 创建模式:绑定所有选中的老师
|
||||||
|
console.log('📝 创建模式:绑定所有老师')
|
||||||
|
for (const instructorId of formData.instructors) {
|
||||||
|
try {
|
||||||
|
console.log('➕ 正在绑定老师:', instructorId)
|
||||||
|
await TeachCourseApi.addTeacher({
|
||||||
|
courseId: courseId,
|
||||||
|
userId: instructorId
|
||||||
|
})
|
||||||
|
console.log('✅ 老师绑定成功:', instructorId)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 老师绑定失败:', instructorId, error)
|
||||||
|
// 不阻止其他老师的绑定,继续执行
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 编辑模式:比较变更并处理
|
||||||
|
console.log('✏️ 编辑模式:比较老师变更')
|
||||||
|
|
||||||
|
// 需要添加的老师(在新列表中但不在原列表中)
|
||||||
|
const teachersToAdd = formData.instructors.filter(id => !originalInstructors.value.includes(id))
|
||||||
|
console.log('需要添加的老师:', teachersToAdd)
|
||||||
|
|
||||||
|
// 需要移除的老师(在原列表中但不在新列表中)
|
||||||
|
const teachersToRemove = originalInstructors.value.filter(id => !formData.instructors.includes(id))
|
||||||
|
console.log('需要移除的老师:', teachersToRemove)
|
||||||
|
|
||||||
|
// 添加新老师
|
||||||
|
for (const instructorId of teachersToAdd) {
|
||||||
|
try {
|
||||||
|
console.log('➕ 正在添加老师:', instructorId)
|
||||||
|
await TeachCourseApi.addTeacher({
|
||||||
|
courseId: courseId,
|
||||||
|
userId: instructorId
|
||||||
|
})
|
||||||
|
console.log('✅ 老师添加成功:', instructorId)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 老师添加失败:', instructorId, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 移除老师
|
||||||
|
for (const instructorId of teachersToRemove) {
|
||||||
|
try {
|
||||||
|
console.log('➖ 正在移除老师:', instructorId)
|
||||||
|
await TeachCourseApi.unbindTeacher({
|
||||||
|
courseId: courseId,
|
||||||
|
userId: instructorId
|
||||||
|
})
|
||||||
|
console.log('✅ 老师移除成功:', instructorId)
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 老师移除失败:', instructorId, error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('✅ 老师变更处理完成')
|
||||||
|
} catch (error) {
|
||||||
|
console.error('❌ 处理老师变更失败:', error)
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 保存
|
// 保存
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
try {
|
try {
|
||||||
@ -546,9 +654,10 @@ const handleSubmit = async () => {
|
|||||||
description: formData.courseDescription,
|
description: formData.courseDescription,
|
||||||
type: formData.studentType === 'all' ? 0 : 1,
|
type: formData.studentType === 'all' ? 0 : 1,
|
||||||
categoryId: Array.isArray(formData.courseCategory) ? formData.courseCategory.join(',') : formData.courseCategory,
|
categoryId: Array.isArray(formData.courseCategory) ? formData.courseCategory.join(',') : formData.courseCategory,
|
||||||
target: formData.studentType === 'all' ? '' : formData.selectedClasses.join(','), // target 字段处理
|
target: '', // target 字段处理
|
||||||
start_time: formData.startTime ? formatDateTime(formData.startTime) : null,
|
classId: formData.studentType === 'all' ? '' : formData.selectedClasses.join(','), // classId
|
||||||
end_time: formData.endTime ? formatDateTime(formData.endTime) : null,
|
startTime: formData.startTime ? formatDateTime(formData.startTime) : null,
|
||||||
|
endTime: formData.endTime ? formatDateTime(formData.endTime) : null,
|
||||||
pauseExit: formData.stopOnLeave ? '1' : '0', // 离开页面停止播放
|
pauseExit: formData.stopOnLeave ? '1' : '0', // 离开页面停止播放
|
||||||
allowSpeed: formData.videoSpeedControl ? '1' : '0', // 视频倍数播放
|
allowSpeed: formData.videoSpeedControl ? '1' : '0', // 视频倍数播放
|
||||||
showSubtitle: formData.showVideoText ? '1' : '0', // 显示视频文本
|
showSubtitle: formData.showVideoText ? '1' : '0', // 显示视频文本
|
||||||
@ -576,6 +685,9 @@ const handleSubmit = async () => {
|
|||||||
const response = await TeachCourseApi.editCourse(editData)
|
const response = await TeachCourseApi.editCourse(editData)
|
||||||
|
|
||||||
if (response.data.code === 200) {
|
if (response.data.code === 200) {
|
||||||
|
// 课程更新成功后,处理老师的绑定和解绑
|
||||||
|
await handleTeacherChanges(courseId.value);
|
||||||
|
|
||||||
message.success('课程更新成功!')
|
message.success('课程更新成功!')
|
||||||
// 清除缓存数据
|
// 清除缓存数据
|
||||||
courseStore.clearCourseEditData();
|
courseStore.clearCourseEditData();
|
||||||
@ -589,6 +701,12 @@ const handleSubmit = async () => {
|
|||||||
const response = await TeachCourseApi.createCourse(createCourseData)
|
const response = await TeachCourseApi.createCourse(createCourseData)
|
||||||
|
|
||||||
if (response.data.code === 200) {
|
if (response.data.code === 200) {
|
||||||
|
// 课程创建成功后,获取新创建的课程ID并绑定老师
|
||||||
|
const newCourseId = response.data.data?.id || response.data.id;
|
||||||
|
if (newCourseId && formData.instructors.length > 0) {
|
||||||
|
await handleTeacherChanges(newCourseId.toString(), true);
|
||||||
|
}
|
||||||
|
|
||||||
message.success('课程创建成功!')
|
message.success('课程创建成功!')
|
||||||
// 清除缓存数据
|
// 清除缓存数据
|
||||||
courseStore.clearCourseEditData();
|
courseStore.clearCourseEditData();
|
||||||
@ -639,9 +757,33 @@ const getTeacherList = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取班级
|
||||||
|
const getClassList = () => {
|
||||||
|
ClassApi.queryClassList({course_id:null}).then(response => {
|
||||||
|
console.log('班级列表:', response.data.result);
|
||||||
|
|
||||||
|
response.data.result.forEach((cls: any) => {
|
||||||
|
classOptions.value.push({
|
||||||
|
label: cls.name,
|
||||||
|
value: cls.id
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('获取班级列表失败:', error)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
// 如果是编辑模式(有courseId)、有通过路由传递的课程数据,或者store中有数据
|
||||||
|
if (isEditMode.value && courseId.value) {
|
||||||
|
loadCourseData()
|
||||||
|
} else if (route.query.courseData || courseStore.courseEditData) {
|
||||||
|
// 即使没有ID,也尝试从路由数据或store加载(用于从列表页面直接编辑的情况)
|
||||||
|
loadCourseData()
|
||||||
|
}
|
||||||
getCourseList()
|
getCourseList()
|
||||||
getTeacherList()
|
getTeacherList()
|
||||||
|
getClassList()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -236,8 +236,8 @@ const toggleChapter = (chapter: Chapter) => {
|
|||||||
|
|
||||||
// 章节操作方法
|
// 章节操作方法
|
||||||
const addChapter = () => {
|
const addChapter = () => {
|
||||||
// 跳转到当前课程下的章节编辑器
|
// 跳转到当前课程下的章节编辑器,传递mode=add参数表示新增模式
|
||||||
router.push(`/teacher/chapter-editor-teacher/${courseId.value}`)
|
router.push(`/teacher/chapter-editor-teacher/${courseId.value}?mode=add`)
|
||||||
}
|
}
|
||||||
|
|
||||||
const importChapters = () => {
|
const importChapters = () => {
|
||||||
@ -261,10 +261,10 @@ const searchChapters = async () => {
|
|||||||
|
|
||||||
const editChapter = (chapter: Chapter) => {
|
const editChapter = (chapter: Chapter) => {
|
||||||
console.log('编辑章节:', chapter)
|
console.log('编辑章节:', chapter)
|
||||||
// 跳转到章节编辑器页面
|
// 跳转到章节编辑器页面,传递章节ID参数表示编辑模式
|
||||||
const courseId = route.params.id
|
const courseId = route.params.id
|
||||||
if (courseId) {
|
if (courseId) {
|
||||||
router.push(`/teacher/chapter-editor-teacher/${courseId}`)
|
router.push(`/teacher/chapter-editor-teacher/${courseId}?chapterId=${chapter.id}`)
|
||||||
} else {
|
} else {
|
||||||
message.error('课程ID不存在')
|
message.error('课程ID不存在')
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user