1156 lines
33 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 教师端课程相关API接口
import { ApiRequest } from '../request'
import type {
ApiResponse,
ApiResponseWithResult,
} from '../types'
// 课程基础类型定义
export interface TeachCourse {
id?: string
name?: string | null
cover?: string | null
video?: string | null
school?: string | null
description?: string | null
type?: number | null
target?: string | null
difficulty?: number | null
subject?: string | null
outline?: string | null
prerequisite?: string | null
reference?: string | null
arrangement?: string | null
start_time?: string | null
end_time?: string | null
enroll_count?: number | null
max_enroll?: number | null
status?: number | null
question?: string | null
categoryId?: string | number | null // 课程分类ID
}
// 新建课程请求参数
export interface CreateCourseRequest {
name?: string | null
cover?: string | null
video?: string | null
school?: string | null
description?: string | null
type?: number | null
target?: string | null
difficulty?: number | null
subject?: string | null
outline?: string | null
prerequisite?: string | null
reference?: string | null
arrangement?: string | null
start_time?: string | null
end_time?: string | null
enroll_count?: number | null
max_enroll?: number | null
status?: string | number | null
question?: string | null
pauseExit?: string
allowSpeed?: string
showSubtitle?: string
categoryId?: number | string | null // 支持单个ID(number)或多个ID的逗号分隔字符串
}
// 编辑课程请求参数
export interface EditCourseRequest extends CreateCourseRequest {
id: string,
}
// 查询教师课程列表参数
export interface TeacherCourseListParams {
keyword?: string // 课程名关键词
status?: string // 课程状态0 未开始1进行中2已结束
}
// 批量添加学生请求参数
export interface AddStudentsRequest {
ids: string // 用户id多个用英文逗号拼接例如1955366202649014274,3d464b4ea0d2491aab8a7bde74c57e95
}
// 文件上传响应类型
export interface UploadResponse {
url: string
filename: string
size: number
}
// 学生信息类型
export interface CourseStudent {
id: string
username: string
realname: string
phone?: string
email?: string
avatar?: string
enrollTime?: string
}
// 课程章节类型定义
export interface CourseSection {
id?: string
course_id?: string | null
name?: string | null
type?: number | null
sort_order?: number | null
parent_id?: string | null
level?: number | null
}
// 新建课程章节请求参数
export interface CreateCourseSectionRequest {
course_id?: string | null
name?: string | null
type?: number | null
sort_order?: number | null
parent_id?: string | null
level?: number | null
}
// 编辑课程章节请求参数
export interface EditCourseSectionRequest extends CreateCourseSectionRequest {
id: string
}
// 查询课程章节参数
export interface QueryCourseSectionParams {
keyword?: string // 关键词模糊查询
}
/**
* 教师端课程API模块
*/
export class TeachCourseApi {
/**
* 新建课程
*/
static async createCourse(data: CreateCourseRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送新建课程请求:', { url: '/aiol/aiolCourse/teacher_add', data })
const response = await ApiRequest.post<any>('/aiol/aiolCourse/teacher_add', data)
console.log('📝 新建课程响应:', response)
return response
} catch (error) {
console.error('❌ 新建课程失败:', error)
throw error
}
}
/**
* 查询当前教师课程列表
*/
static async getTeacherCourseList(params?: TeacherCourseListParams): Promise<ApiResponseWithResult<TeachCourse[]>> {
try {
const response = await ApiRequest.get<{ result: TeachCourse[] }>('/aiol/aiolCourse/teacher_list', params)
return response
} catch (error) {
console.error('❌ 查询教师课程列表失败:', error)
throw error
}
}
/**
* 查询教师列表
*/
static async getTeacherList(): Promise<ApiResponseWithResult<any>> {
try {
const response = await ApiRequest.get<{ result: any[] }>('/aiol/aiolUser/teachers')
return response
} catch (error) {
console.error('❌ 查询教师列表失败:', error)
throw error
}
}
/**
* 编辑课程信息
*/
static async editCourse(data: EditCourseRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送编辑课程请求:', { url: '/aiol/aiolCourse/edit', data })
const response = await ApiRequest.put<any>('/aiol/aiolCourse/edit', data)
console.log('✏️ 编辑课程响应:', response)
return response
} catch (error) {
console.error('❌ 编辑课程失败:', error)
throw error
}
}
/**
* 删除课程
*/
static async deleteCourse(id: string): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送删除课程请求:', { url: '/aiol/aiolCourse/delete', id })
const response = await ApiRequest.delete<any>(`/aiol/aiolCourse/delete?id=${id}`, )
console.log('🗑️ 删除课程响应:', response)
return response
} catch (error) {
console.error('❌ 删除课程失败:', error)
throw error
}
}
/**
* 查询课程下的教师
*/
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 getSchoolList(): Promise<ApiResponseWithResult<any>> {
try {
const response = await ApiRequest.get<{ result: any[] }>(`/aiol/aiolUser/schools`)
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
}
}
/**
* 课程视频上架
*/
// static async deleteCourse(id: string): Promise<ApiResponse<any>> {
// }
/**
* 课程视频上传
*/
static async uploadVideo(file: File): Promise<ApiResponse<UploadResponse>> {
try {
console.log('🚀 发送视频上传请求:', { url: '/aiol/aiolResource/upload', fileName: file.name })
const formData = new FormData()
formData.append('file', file)
const response = await ApiRequest.post<UploadResponse>('/aiol/aiolResource/upload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
console.log('📹 视频上传响应:', response)
return response
} catch (error) {
console.error('❌ 视频上传失败:', error)
throw error
}
}
/**
* 批量导入学生
*/
static async addStudentsToCourse(courseId: string, data: AddStudentsRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送批量导入学生请求:', {
url: `/aiol/aiolCourse/${courseId}/add_students`,
courseId,
data
})
const response = await ApiRequest.post<any>(`/aiol/aiolCourse/${courseId}/add_students`, data)
console.log('👥 批量导入学生响应:', response)
return response
} catch (error) {
console.error('❌ 批量导入学生失败:', error)
throw error
}
}
/**
* 查询课程已报名学生列表
*/
static async getCourseStudents(courseId: string): Promise<ApiResponse<CourseStudent[]>> {
try {
console.log('🚀 发送查询课程学生列表请求:', {
url: `/aiol/aiolCourse/${courseId}/get_students`,
courseId
})
const response = await ApiRequest.get<CourseStudent[]>(`/aiol/aiolCourse/${courseId}/get_students`)
console.log('👨‍🎓 课程学生列表响应:', response)
return response
} catch (error) {
console.error('❌ 查询课程学生列表失败:', error)
throw error
}
}
/**
* 新建课程章节
*/
static async createCourseSection(data: CreateCourseSectionRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送新建课程章节请求:', { url: '/aiol/aiolCourseSection/add', data })
const response = await ApiRequest.post<any>('/aiol/aiolCourseSection/add', data)
console.log('📚 新建课程章节响应:', response)
return response
} catch (error) {
console.error('❌ 新建课程章节失败:', error)
throw error
}
}
/**
* 编辑课程章节信息
*/
static async editCourseSection(data: EditCourseSectionRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送编辑课程章节请求:', { url: '/aiol/aiolCourseSection/edit', data })
const response = await ApiRequest.put<any>('/aiol/aiolCourseSection/edit', data)
console.log('✏️ 编辑课程章节响应:', response)
return response
} catch (error) {
console.error('❌ 编辑课程章节失败:', error)
throw error
}
}
/**
* 章节绑定考试-考试列表查询
*/
static async getExamsList(params: { type: '0' | '1'; examName?: string; }): Promise<ApiResponseWithResult<any>> {
try {
const response = await ApiRequest.get<any>(`/aiol/aiolExam/queryExamList`, params)
return response
} catch (error) {
console.error('❌ 章节绑定考试-考试列表查询失败:', error)
throw error
}
}
/**
* 删除课程章节
*/
static async deleteCourseSection(id: string): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送删除课程章节请求:', { url: '/aiol/aiolCourseSection/delete', id })
const response = await ApiRequest.delete<any>('/aiol/aiolCourseSection/delete', {id})
console.log('🗑️ 删除课程章节响应:', response)
return response
} catch (error) {
console.error('❌ 删除课程章节失败:', error)
throw error
}
}
/**
* 查询课程章节列表
*/
static async getCourseSections(courseId: string, params?: QueryCourseSectionParams): Promise<ApiResponseWithResult<CourseSection[]>> {
try {
console.log('🚀 发送查询课程章节请求:', {
url: `/aiol/aiolCourse/${courseId}/section`,
courseId,
params
})
const response = await ApiRequest.get<{ result: CourseSection[] }>(`/aiol/aiolCourse/${courseId}/section`, params)
console.log('📑 课程章节列表响应:', response)
return response
} catch (error) {
console.error('❌ 查询课程章节列表失败:', error)
throw error
}
}
/**
* 查询课程课件列表
*/
static async queryCourseMaterials(params: { courseId: string; resourceType: number|string; name?:string }): Promise<ApiResponseWithResult<any[]>> {
try {
const response = await ApiRequest.get<{ result: any[] }>(`/aiol/aiolResource/course_materials`, params)
console.log('📑 查询课程课件响应:', response)
return response
} catch (error) {
console.error('❌ 查询课程课件失败:', error)
throw error
}
}
/**
* 上传视频课件
*/
static async uploadCursorVideo(data: { courseId: string; file: File; name:string }): Promise<ApiResponseWithResult<any[]>> {
try {
const formData = new FormData()
formData.append('courseId', data.courseId)
formData.append('file', data.file)
formData.append('name', data.name)
const response = await ApiRequest.post<{ result: any[] }>(`/aiol/aiolResource/video_upload`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
console.log('📑 上传视频课件响应:', response)
return response
} catch (error) {
console.error('❌ 上传视频课件失败:', error)
throw error
}
}
/**
* 文档上传
*/
static async uploadCursorDocument(data: { courseId: string; file: File; name:string }): Promise<ApiResponseWithResult<any[]>> {
try {
const formData = new FormData()
formData.append('courseId', data.courseId)
formData.append('file', data.file)
formData.append('name', data.name)
const response = await ApiRequest.post<{ result: any[] }>(`/aiol/aiolResource/document_upload`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
console.log('📑 上传文档课件响应:', response)
return response
} catch (error) {
console.error('❌ 上传文档课件失败:', error)
throw error
}
}
/**
* 图片上传
*/
static async uploadCursorImage(data: { courseId: string; file: File; name:string }): Promise<ApiResponseWithResult<any[]>> {
try {
const formData = new FormData()
formData.append('courseId', data.courseId)
formData.append('file', data.file)
formData.append('name', data.name)
const response = await ApiRequest.post<{ result: any[] }>(`/aiol/aiolResource/image_upload`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
})
console.log('📑 上传图片课件响应:', response)
return response
} catch (error) {
console.error('❌ 上传图片课件失败:', error)
throw error
}
}
/**
* 查询视频章节
*/
static async getSectionVideo(courseId:string,sectionId: string): Promise<ApiResponseWithResult<any>> {
try {
const response = await ApiRequest.get<{ result: any }>(`/aiol/aiolCourse/${courseId}/section_video/${sectionId}`)
console.log('📑 查询小节绑定的视频响应:', response)
return response
} catch (error) {
console.error('❌ 查询小节绑定的视频失败:', error)
throw error
}
}
/**
* 查询文档章节
*/
static async getSectionDocument(courseId:string,sectionId: string): Promise<ApiResponseWithResult<any>> {
try {
const response = await ApiRequest.get<{ result: any }>(`/aiol/aiolCourse/${courseId}/section_document/${sectionId}`)
console.log('📑 查询小节绑定的文档响应:', response)
return response
} catch (error) {
console.error('❌ 查询小节绑定的文档失败:', error)
throw error
}
}
/**
* 查询考试章节
*/
static async getSectionExam(courseId:string,sectionId: string): Promise<ApiResponseWithResult<any>> {
try {
const response = await ApiRequest.get<{ result: any }>(`/aiol/aiolCourse/${courseId}/section_exam/${sectionId}`)
console.log('📑 查询小节绑定的考试响应:', response)
return response
} catch (error) {
console.error('❌ 查询小节绑定的考试失败:', error)
throw error
}
}
/**
* 查询作业章节
*/
static async getSectionHomeWork(courseId:string,sectionId: string): Promise<ApiResponseWithResult<any>> {
try {
const response = await ApiRequest.get<{ result: any }>(`/aiol/aiolCourse/${courseId}/section_homework/${sectionId}`)
console.log('📑 查询小节绑定的作业响应:', response)
return response
} catch (error) {
console.error('❌ 查询小节绑定的作业失败:', error)
throw error
}
}
}
// 作业相关类型定义
export interface Homework {
id?: string
title?: string | null
description?: string | null
attachment?: string | null
max_score?: number | null
pass_score?: number | null
start_time?: string | null
end_time?: string | null
status?: number | null
allow_makeup?: string // 是否允许补交 0不允许 1允许
makeup_time?: string // 补交截止时间
notify_time?: string // 作业通知时间
classId?: string // 班级id多个用逗号分割
sectionId?: string // 章节id
courseId?: string // 课程id必填
}
// 新建作业请求参数
export interface CreateHomeworkRequest {
title?: string | null
description?: string | null
attachment?: string | null
maxScore?: number | null
passScore?: number | null
startTime?: string | null
endTime?: string | null
allowMakeup: string // 是否允许补交 0不允许 1允许 (必填)
makeupTime: string // 补交截止时间 (必填)
notifyTime: number // 作业通知时间 (必填)
classId: string // 班级id多个用逗号分割 (必填)
sectionId?: string // 章节id
courseId: string // 课程id必填
}
// 编辑作业请求参数
export interface EditHomeworkRequest {
id: string // 必填
title?: string | null
description?: string | null
attachment?: string | null
max_score?: number | null
pass_score?: number | null
start_time?: string | null
end_time?: string | null
status?: number | null
}
// 作业提交信息类型
export interface HomeworkSubmit {
id?: string
homeworkId?: string
studentId?: string
studentName?: string
submitTime?: string
score?: number | null
comment?: string | null
status?: number // 提交状态
attachment?: string | null
}
// 作业批阅请求参数
export interface ReviewHomeworkRequest {
submitId: string // 提交记录ID (必填)
score: string // 得分 (必填)
comment: string // 评语 (必填)
}
/**
* 作业API模块
*/
export class HomeworkApi {
/**
* 新建作业
*/
static async createHomework(data: CreateHomeworkRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送新建作业请求:', { url: '/aiol/aiolHomework/teacher_add', data })
const response = await ApiRequest.post<any>('/aiol/aiolHomework/teacher_add', data)
console.log('📝 新建作业响应:', response)
return response
} catch (error) {
console.error('❌ 新建作业失败:', error)
throw error
}
}
/**
* 编辑作业
*/
static async editHomework(data: EditHomeworkRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送编辑作业请求:', { url: '/aiol/aiolHomework/teacher_edit', data })
const response = await ApiRequest.post<any>('/aiol/aiolHomework/teacher_edit', data)
console.log('✏️ 编辑作业响应:', response)
return response
} catch (error) {
console.error('❌ 编辑作业失败:', error)
throw error
}
}
/**
* 删除作业
*/
static async deleteHomework(id: string): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送删除作业请求:', { url: '/aiol/aiolHomework/teacher_delete', id })
const response = await ApiRequest.delete<any>(`/aiol/aiolHomework/teacher_delete?id=${id}`)
console.log('🗑️ 删除作业响应:', response)
return response
} catch (error) {
console.error('❌ 删除作业失败:', error)
throw error
}
}
/**
* 查询作业详情
*/
static async getHomeworkById(id: string): Promise<ApiResponseWithResult<Homework>> {
try {
console.log('🚀 发送查询作业详情请求:', { url: '/aiol/aiolHomework/queryById', id })
const response = await ApiRequest.get<{ result: Homework }>(`/aiol/aiolHomework/queryById?id=${id}`)
console.log('📋 作业详情响应:', response)
return response
} catch (error) {
console.error('❌ 查询作业详情失败:', error)
throw error
}
}
/**
* 查询课程作业列表
*/
static async getTeacherHomeworkList(courseId: string): Promise<ApiResponse<{ code: number, result: Homework[] }>> {
try {
console.log('🚀 发送查询作业列表请求:', { url: '/aiol/aiolHomework/teacher_list', courseId })
const response = await ApiRequest.get<{ code: number, result: Homework[] }>('/aiol/aiolHomework/teacher_list', { courseId })
console.log('📋 作业列表响应:', response)
return response
} catch (error) {
console.error('❌ 查询作业列表失败:', error)
throw error
}
}
/**
* 查询作业提交情况
*/
static async getHomeworkSubmits(homeworkId: string): Promise<ApiResponseWithResult<HomeworkSubmit[]>> {
try {
console.log('🚀 发送查询作业提交情况请求:', {
url: `/aiol/aiolHomeworkSubmit/homework/${homeworkId}/submits`,
homeworkId
})
const response = await ApiRequest.get<{ result: HomeworkSubmit[] }>(`/aiol/aiolHomeworkSubmit/homework/${homeworkId}/submits`)
console.log('📊 作业提交情况响应:', response)
return response
} catch (error) {
console.error('❌ 查询作业提交情况失败:', error)
throw error
}
}
/**
* 作业批阅
*/
static async reviewHomework(data: ReviewHomeworkRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送作业批阅请求:', { url: '/aiol/aiolHomework/review', data })
const response = await ApiRequest.post<any>('/aiol/aiolHomework/review', data)
console.log('✅ 作业批阅响应:', response)
return response
} catch (error) {
console.error('❌ 作业批阅失败:', error)
throw error
}
}
}
// 默认导出
export default TeachCourseApi
// 导出讨论API
export { DiscussionApi }
/**
* 班级相关API
*/
export interface ClassInfo {
id?: string;
name: string;
course_id?: string;
}
export interface EditClassRequest {
id: string;
name: string;
}
export interface ImportStudentsRequest {
ids: string; // 逗号分隔的学生id
}
export interface CreatedStudentsRequest {
realName: string;
studentNumber: string;
password: string;
school: string;
classId: string;
}
export class ClassApi {
/**
* 创建班级
*/
static async createClass(data: { name: string; course_id: string|null }): Promise<ApiResponse<any>> {
return ApiRequest.post('/aiol/aiolClass/add', data);
}
static async queryClassList(params: { course_id: string|null }): Promise<ApiResponse<any>> {
return ApiRequest.get('/aiol/aiolClass/query_list', params);
}
/**
* 编辑班级
*/
static async editClass(data: EditClassRequest): Promise<ApiResponse<any>> {
return ApiRequest.put('/aiol/aiolClass/edit', data);
}
/**
* 删除班级
*/
static async deleteClass(id: string): Promise<ApiResponse<any>> {
return ApiRequest.delete('/aiol/aiolClass/delete', { id });
}
/**
* 添加学生
*/
static async createdStudents(data: CreatedStudentsRequest): Promise<ApiResponse<any>> {
return ApiRequest.post(`/aiol/aiolClass/create_and_add_student`, data);
}
/**
* 班级通过搜索导入学生
*/
static async importStudents(classId: string, data: ImportStudentsRequest): Promise<ApiResponse<any>> {
return ApiRequest.post(`/aiol/aiolClass/${classId}/import_students`, data);
}
/**
* 查询班级内学生
*/
static async getClassStudents(classId: string): Promise<ApiResponse<any>> {
return ApiRequest.get(`/aiol/aiolClass/${classId}/student_list`);
}
/**
* 删除班级内学生
*/
static async removeStudent(classId: string, studentId: string): Promise<ApiResponse<any>> {
return ApiRequest.delete(`/aiol/aiolClass/${classId}/remove_student/${studentId}`, undefined);
}
/**
* 查询课程内班级
*/
static async getCourseClasses(courseId: string): Promise<ApiResponse<any>> {
return ApiRequest.get(`/aiol/aiolCourse/${courseId}/class_list`);
}
/**
* 通过excel导入学生TODO
*/
static async importStudentsExcel(classId: string, file: File): Promise<ApiResponse<any>> {
const formData = new FormData();
formData.append('file', file);
return ApiRequest.post(`/aiol/aiolClass/${classId}/import_students_excel`, formData, {
headers: { 'Content-Type': 'multipart/form-data' }
});
}
/**
* 获取文件下载链接
*/
static async getFileDownloadUrl(fileId: string | number): Promise<ApiResponseWithResult<{ downloadUrl: string }>> {
try {
const response = await ApiRequest.get<{ result: { downloadUrl: string } }>(`/aiol/aiolResource/${fileId}/download_url`)
console.log('📥 获取文件下载链接响应:', response)
return response
} catch (error) {
console.error('❌ 获取文件下载链接失败:', error)
throw error
}
}
/**
* 直接下载文件
*/
static async downloadFile(fileId: string | number): Promise<Response> {
try {
const response = await fetch(`/api/aiol/aiolResource/${fileId}/download`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${localStorage.getItem('token') || ''}`
}
})
if (!response.ok) {
throw new Error(`下载失败: ${response.statusText}`)
}
console.log('📥 文件下载响应:', response)
return response
} catch (error) {
console.error('❌ 文件下载失败:', error)
throw error
}
}
}
// 讨论相关类型定义
export interface Discussion {
id?: string
title?: string | null
description?: string | null
sectionId?: string | null
courseId?: string | null
authorId?: string | null
authorName?: string | null
createTime?: string | null
updateTime?: string | null
status?: number | null
replyCount?: number | null
}
// 新增评论请求参数
export interface CreateCommentRequest {
content?: string // 评论内容
imgs?: string // 图片
targetType: string // 目标类型: course、comment、course_section、discussion
targetId: string // 目标id
}
// 新建讨论请求参数
export interface CreateDiscussionRequest {
title: string // 讨论标题 (必填)
description: string // 讨论描述 (必填)
sectionId?: string // 章节id
courseId?: string // 课程id
}
// 编辑讨论请求参数
export interface EditDiscussionRequest {
id: string // 讨论id (必填)
title: string // 讨论标题 (必填)
description?: string // 讨论描述
sectionId?: string // 章节id
}
/**
* 讨论API模块
*/
class DiscussionApi {
/**
* 新建讨论
*/
static async createDiscussion(data: CreateDiscussionRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送新建讨论请求:', { url: '/aiol/aiolDiscussion/add', data })
const response = await ApiRequest.post<any>('/aiol/aiolDiscussion/add', data)
console.log('💬 新建讨论响应:', response)
return response
} catch (error) {
console.error('❌ 新建讨论失败:', error)
throw error
}
}
/**
* 编辑讨论
*/
static async editDiscussion(data: EditDiscussionRequest): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送编辑讨论请求:', { url: '/aiol/aiolDiscussion/edit', data })
const response = await ApiRequest.put<any>('/aiol/aiolDiscussion/edit', data)
console.log('✏️ 编辑讨论响应:', response)
return response
} catch (error) {
console.error('❌ 编辑讨论失败:', error)
throw error
}
}
/**
* 删除讨论
*/
static async deleteDiscussion(id: string): Promise<ApiResponse<any>> {
try {
console.log('🚀 发送删除讨论请求:', { url: '/aiol/aiolDiscussion/delete', id })
const response = await ApiRequest.delete<any>(`/aiol/aiolDiscussion/delete?id=${id}`)
console.log('🗑️ 删除讨论响应:', response)
return response
} catch (error) {
console.error('❌ 删除讨论失败:', error)
throw error
}
}
/**
* 查询课程讨论列表
*/
static async getDiscussionList(courseId: string): Promise<ApiResponseWithResult<Discussion[]>> {
try {
console.log('🚀 发送查询讨论列表请求:', { url: '/aiol/aiolDiscussion/teacher_list', courseId })
const response = await ApiRequest.get<{ result: Discussion[] }>('/aiol/aiolDiscussion/teacher_list', { courseId })
console.log('📋 讨论列表响应:', response)
return response
} catch (error) {
console.error('❌ 查询讨论列表失败:', error)
throw error
}
}
/**
* 查询讨论详情
*/
static async getDiscussionById(id: string): Promise<ApiResponseWithResult<Discussion>> {
try {
console.log('🚀 发送查询讨论详情请求:', { url: '/aiol/aiolDiscussion/queryById', id })
const response = await ApiRequest.get<{ result: Discussion }>(`/aiol/aiolDiscussion/queryById?id=${id}`)
console.log('📝 讨论详情响应:', response)
return response
} catch (error) {
console.error('❌ 查询讨论详情失败:', error)
throw error
}
}
// ========== 评论相关接口 ==========
/**
* 查询讨论下的评论列表
*/
static async getDiscussionComments(discussionId: string): Promise<ApiResponseWithResult<any[]>> {
try {
console.log('🚀 发送查询讨论评论请求:', { url: `/aiol/aiolComment/discussion/${discussionId}/list`, discussionId })
const response = await ApiRequest.get<{ result: any[] }>(`/aiol/aiolComment/discussion/${discussionId}/list`)
console.log('💬 讨论评论响应:', response)
return response
} catch (error) {
console.error('❌ 查询讨论评论失败:', error)
throw error
}
}
/**
* 查询课程下的评论列表
*/
static async getCourseComments(courseId: string): Promise<ApiResponseWithResult<any[]>> {
try {
console.log('🚀 发送查询课程评论请求:', { url: `/aiol/aiolComment/course/${courseId}/list`, courseId })
const response = await ApiRequest.get<{ result: any[] }>(`/aiol/aiolComment/course/${courseId}/list`)
console.log('💬 课程评论响应:', response)
return response
} catch (error) {
console.error('❌ 查询课程评论失败:', error)
throw error
}
}
/**
* 新增评论
*/
static async createComment(commentData: CreateCommentRequest): Promise<ApiResponse> {
try {
console.log('🚀 发送新增评论请求:', { url: '/aiol/aiolComment/add', data: commentData })
const response = await ApiRequest.post<ApiResponse>('/aiol/aiolComment/add', commentData)
console.log('✅ 新增评论响应:', response)
return response
} catch (error) {
console.error('❌ 新增评论失败:', error)
throw error
}
}
/**
* 查询评论详情
*/
static async getCommentById(id: string): Promise<ApiResponseWithResult<any>> {
try {
console.log('🚀 发送查询评论详情请求:', { url: '/aiol/aiolComment/queryById', id })
const response = await ApiRequest.get<{ result: any }>(`/aiol/aiolComment/queryById?id=${id}`)
console.log('📝 评论详情响应:', response)
return response
} catch (error) {
console.error('❌ 查询评论详情失败:', error)
throw error
}
}
/**
* 评论点赞
*/
static async likeComment(commentId: string): Promise<ApiResponse> {
try {
console.log('🚀 发送评论点赞请求:', { url: `/aiol/aiolComment/like/${commentId}`, commentId })
const response = await ApiRequest.get<ApiResponse>(`/aiol/aiolComment/like/${commentId}`)
console.log('👍 评论点赞响应:', response)
return response
} catch (error) {
console.error('❌ 评论点赞失败:', error)
throw error
}
}
/**
* 评论置顶
*/
static async topComment(commentId: string): Promise<ApiResponse> {
try {
console.log('🚀 发送评论置顶请求:', { url: `/aiol/aiolComment/top/${commentId}`, commentId })
const response = await ApiRequest.get<ApiResponse>(`/aiol/aiolComment/top/${commentId}`)
console.log('👍 评论置顶响应:', response)
return response
} catch (error) {
console.error('❌ 评论置顶失败:', error)
throw error
}
}
/**
* 评论取消置顶
*/
static async untopComment(commentId: string): Promise<ApiResponse> {
try {
console.log('🚀 发送评论取消置顶请求:', { url: `/aiol/aiolComment/untop/${commentId}`, commentId })
const response = await ApiRequest.get<ApiResponse>(`/aiol/aiolComment/untop/${commentId}`)
console.log('👍 评论取消置顶响应:', response)
return response
} catch (error) {
console.error('❌ 评论取消置顶失败:', error)
throw error
}
}
}