2026-03-13 13:48:28 +08:00
|
|
|
|
import { getReadingPlatformAPI } from './generated';
|
2026-03-16 11:08:27 +08:00
|
|
|
|
import { axios } from './generated/mutator';
|
2026-03-13 13:48:28 +08:00
|
|
|
|
|
|
|
|
|
|
// 创建 API 实例
|
|
|
|
|
|
const api = getReadingPlatformAPI();
|
2026-03-12 13:05:20 +08:00
|
|
|
|
|
|
|
|
|
|
// ============= 类型定义(保持向后兼容) =============
|
2026-02-26 15:22:26 +08:00
|
|
|
|
|
|
|
|
|
|
export interface CourseQueryParams {
|
2026-03-14 16:50:54 +08:00
|
|
|
|
pageNum?: number;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
pageSize?: number;
|
|
|
|
|
|
grade?: string;
|
|
|
|
|
|
status?: string;
|
|
|
|
|
|
keyword?: string;
|
2026-03-16 11:08:27 +08:00
|
|
|
|
/** 审核管理页专用:仅返回待审核和已驳回,排除已通过 */
|
|
|
|
|
|
reviewOnly?: boolean;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface Course {
|
|
|
|
|
|
id: number;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
description?: string;
|
|
|
|
|
|
pictureBookName?: string;
|
|
|
|
|
|
grades: string[];
|
|
|
|
|
|
status: string;
|
|
|
|
|
|
version: string;
|
|
|
|
|
|
usageCount: number;
|
|
|
|
|
|
teacherCount: number;
|
|
|
|
|
|
avgRating: number;
|
|
|
|
|
|
createdAt: Date;
|
2026-02-28 16:41:39 +08:00
|
|
|
|
updatedAt: Date;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
submittedAt?: Date;
|
|
|
|
|
|
reviewedAt?: Date;
|
|
|
|
|
|
reviewComment?: string;
|
2026-02-28 16:41:39 +08:00
|
|
|
|
// 新增字段
|
|
|
|
|
|
themeId?: number;
|
|
|
|
|
|
theme?: { id: number; name: string };
|
|
|
|
|
|
coreContent?: string;
|
|
|
|
|
|
coverImagePath?: string;
|
|
|
|
|
|
domainTags?: string[];
|
|
|
|
|
|
gradeTags?: string[];
|
|
|
|
|
|
duration?: number;
|
|
|
|
|
|
// 课程介绍字段
|
|
|
|
|
|
introSummary?: string;
|
|
|
|
|
|
introHighlights?: string;
|
|
|
|
|
|
introGoals?: string;
|
|
|
|
|
|
introSchedule?: string;
|
|
|
|
|
|
introKeyPoints?: string;
|
|
|
|
|
|
introMethods?: string;
|
|
|
|
|
|
introEvaluation?: string;
|
|
|
|
|
|
introNotes?: string;
|
|
|
|
|
|
// 排课计划参考
|
|
|
|
|
|
scheduleRefData?: string;
|
|
|
|
|
|
// 环创建设
|
|
|
|
|
|
environmentConstruction?: string;
|
|
|
|
|
|
// 关联课程
|
|
|
|
|
|
courseLessons?: CourseLesson[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface CourseLesson {
|
|
|
|
|
|
id: number;
|
|
|
|
|
|
courseId: number;
|
|
|
|
|
|
lessonType: string;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
description?: string;
|
|
|
|
|
|
duration: number;
|
|
|
|
|
|
videoPath?: string;
|
|
|
|
|
|
videoName?: string;
|
|
|
|
|
|
pptPath?: string;
|
|
|
|
|
|
pptName?: string;
|
|
|
|
|
|
pdfPath?: string;
|
|
|
|
|
|
pdfName?: string;
|
|
|
|
|
|
objectives?: string;
|
|
|
|
|
|
preparation?: string;
|
|
|
|
|
|
extension?: string;
|
|
|
|
|
|
reflection?: string;
|
|
|
|
|
|
assessmentData?: string;
|
|
|
|
|
|
useTemplate: boolean;
|
|
|
|
|
|
sortOrder: number;
|
|
|
|
|
|
steps?: LessonStep[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface LessonStep {
|
|
|
|
|
|
id: number;
|
|
|
|
|
|
lessonId: number;
|
|
|
|
|
|
name: string;
|
|
|
|
|
|
content?: string;
|
|
|
|
|
|
duration: number;
|
|
|
|
|
|
objective?: string;
|
|
|
|
|
|
resourceIds?: string;
|
|
|
|
|
|
sortOrder: number;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ValidationResult {
|
|
|
|
|
|
valid: boolean;
|
|
|
|
|
|
errors: ValidationError[];
|
|
|
|
|
|
warnings: ValidationWarning[];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ValidationError {
|
|
|
|
|
|
field: string;
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
code: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface ValidationWarning {
|
|
|
|
|
|
field: string;
|
|
|
|
|
|
message: string;
|
|
|
|
|
|
code: string;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 13:05:20 +08:00
|
|
|
|
// ============= API 函数(使用生成的客户端) =============
|
|
|
|
|
|
|
|
|
|
|
|
// 转换查询参数类型
|
2026-03-13 13:48:28 +08:00
|
|
|
|
const toFindAllParams = (params: CourseQueryParams): any => ({
|
2026-03-16 11:08:27 +08:00
|
|
|
|
pageNum: params.pageNum ?? 1,
|
|
|
|
|
|
pageSize: params.pageSize ?? 10,
|
2026-03-12 13:05:20 +08:00
|
|
|
|
keyword: params.keyword,
|
2026-03-16 11:08:27 +08:00
|
|
|
|
category: params.grade,
|
|
|
|
|
|
status: params.status || undefined,
|
|
|
|
|
|
reviewOnly: params.reviewOnly,
|
2026-03-12 13:05:20 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-03-16 11:08:27 +08:00
|
|
|
|
// 后端 PageResult 返回 list,前端统一转为 items
|
|
|
|
|
|
function normalizePageResult(raw: any): {
|
|
|
|
|
|
items: Course[];
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
page: number;
|
|
|
|
|
|
pageSize: number;
|
|
|
|
|
|
} {
|
|
|
|
|
|
const list = raw?.list ?? raw?.items ?? [];
|
|
|
|
|
|
return {
|
|
|
|
|
|
items: Array.isArray(list) ? list : [],
|
|
|
|
|
|
total: raw?.total ?? 0,
|
|
|
|
|
|
page: raw?.pageNum ?? raw?.page ?? 1,
|
|
|
|
|
|
pageSize: raw?.pageSize ?? 10,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-26 15:22:26 +08:00
|
|
|
|
// 获取课程包列表
|
|
|
|
|
|
export function getCourses(params: CourseQueryParams): Promise<{
|
|
|
|
|
|
items: Course[];
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
page: number;
|
|
|
|
|
|
pageSize: number;
|
|
|
|
|
|
}> {
|
2026-03-16 11:08:27 +08:00
|
|
|
|
return api.getCoursePage1(toFindAllParams(params)).then(normalizePageResult) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-16 11:08:27 +08:00
|
|
|
|
// 获取审核列表(仅返回待审核和已驳回,不含已通过)
|
2026-02-26 15:22:26 +08:00
|
|
|
|
export function getReviewList(params: CourseQueryParams): Promise<{
|
|
|
|
|
|
items: Course[];
|
|
|
|
|
|
total: number;
|
|
|
|
|
|
page: number;
|
|
|
|
|
|
pageSize: number;
|
|
|
|
|
|
}> {
|
2026-03-16 11:08:27 +08:00
|
|
|
|
return api.getCoursePage1(toFindAllParams({ ...params, reviewOnly: true })).then(normalizePageResult) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-16 14:13:59 +08:00
|
|
|
|
// 获取课程包详情(id 支持 number | string,避免大整数精度丢失)
|
|
|
|
|
|
export function getCourse(id: number | string): Promise<any> {
|
|
|
|
|
|
return api.getCourse1(id as number) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 创建课程包
|
|
|
|
|
|
export function createCourse(data: any): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return api.createCourse(data) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 更新课程包
|
2026-03-16 14:13:59 +08:00
|
|
|
|
export function updateCourse(id: number | string, data: any): Promise<any> {
|
|
|
|
|
|
return api.updateCourse(id as number, data) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 删除课程包
|
2026-03-16 14:13:59 +08:00
|
|
|
|
export function deleteCourse(id: number | string): Promise<any> {
|
|
|
|
|
|
return api.deleteCourse(id as number) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 13:48:28 +08:00
|
|
|
|
// 验证课程完整性 (暂时返回 true,后端可能没有此接口)
|
2026-02-26 15:22:26 +08:00
|
|
|
|
export function validateCourse(id: number): Promise<ValidationResult> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return Promise.resolve({ valid: true, errors: [], warnings: [] });
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 提交审核
|
2026-03-13 13:48:28 +08:00
|
|
|
|
export function submitCourse(id: number, copyrightConfirmed?: boolean): Promise<any> {
|
|
|
|
|
|
return api.submit(id) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 13:48:28 +08:00
|
|
|
|
// 撤销审核 (暂时使用更新接口,需要确认后端是否有此功能)
|
2026-02-26 15:22:26 +08:00
|
|
|
|
export function withdrawCourse(id: number): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return api.updateCourse(id, { status: 'DRAFT' }) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 审核通过
|
|
|
|
|
|
export function approveCourse(id: number, data: { checklist?: any; comment?: string }): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return api.publishCourse(id) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-16 11:08:27 +08:00
|
|
|
|
// 审核驳回(课程专用,调用 POST /api/v1/admin/courses/{id}/reject)
|
2026-02-26 15:22:26 +08:00
|
|
|
|
export function rejectCourse(id: number, data: { checklist?: any; comment: string }): Promise<any> {
|
2026-03-16 11:08:27 +08:00
|
|
|
|
return axios.post(`/api/v1/admin/courses/${id}/reject`, { comment: data.comment }).then((res: any) => {
|
|
|
|
|
|
const body = res?.data;
|
|
|
|
|
|
if (body && typeof body === 'object' && 'code' in body && body.code !== 200 && body.code !== 0) {
|
|
|
|
|
|
throw new Error(body.message || '驳回失败');
|
|
|
|
|
|
}
|
|
|
|
|
|
return body?.data;
|
|
|
|
|
|
});
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 直接发布(超级管理员)
|
|
|
|
|
|
export function directPublishCourse(id: number, skipValidation?: boolean): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return api.publishCourse(id) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 13:05:20 +08:00
|
|
|
|
// 发布课程包
|
2026-02-26 15:22:26 +08:00
|
|
|
|
export function publishCourse(id: number): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return api.publishCourse(id) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 下架课程包
|
|
|
|
|
|
export function unpublishCourse(id: number): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return api.archiveCourse(id) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 13:48:28 +08:00
|
|
|
|
// 重新发布 (使用发布接口)
|
2026-02-26 15:22:26 +08:00
|
|
|
|
export function republishCourse(id: number): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return api.publishCourse(id) as any;
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 13:48:28 +08:00
|
|
|
|
// 获取课程包统计数据 (暂时返回空对象)
|
2026-03-16 14:13:59 +08:00
|
|
|
|
export function getCourseStats(id: number | string): Promise<any> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return Promise.resolve({});
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-13 13:48:28 +08:00
|
|
|
|
// 获取版本历史 (暂时返回空数组)
|
2026-02-26 15:22:26 +08:00
|
|
|
|
export function getCourseVersions(id: number): Promise<any[]> {
|
2026-03-13 13:48:28 +08:00
|
|
|
|
return Promise.resolve([]);
|
2026-02-26 15:22:26 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-12 13:05:20 +08:00
|
|
|
|
// ============= 常量 =============
|
|
|
|
|
|
|
2026-02-26 15:22:26 +08:00
|
|
|
|
// 课程状态映射
|
|
|
|
|
|
export const COURSE_STATUS_MAP: Record<string, { label: string; color: string }> = {
|
|
|
|
|
|
DRAFT: { label: '草稿', color: 'default' },
|
|
|
|
|
|
PENDING: { label: '审核中', color: 'processing' },
|
|
|
|
|
|
REJECTED: { label: '已驳回', color: 'error' },
|
|
|
|
|
|
PUBLISHED: { label: '已发布', color: 'success' },
|
|
|
|
|
|
ARCHIVED: { label: '已下架', color: 'warning' },
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// 获取状态显示信息
|
|
|
|
|
|
export function getCourseStatusInfo(status: string) {
|
|
|
|
|
|
return COURSE_STATUS_MAP[status] || { label: status, color: 'default' };
|
|
|
|
|
|
}
|