From 4122bcd24006c3220b6413631d4a80b103ed2902 Mon Sep 17 00:00:00 2001 From: zhonghua Date: Mon, 23 Mar 2026 10:48:09 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AF=BE=E7=A8=8B=E5=8C=85=E5=B9=B4?= =?UTF-8?q?=E7=BA=A7=E7=AD=9B=E9=80=89=E4=B8=8E=E9=80=82=E7=94=A8=E5=B9=B4?= =?UTF-8?q?=E7=BA=A7=E5=AF=B9=E9=BD=90=EF=BC=8C=E4=BF=AE=E5=A4=8DJSON=5FCO?= =?UTF-8?q?NTAINS=E5=8D=A0=E4=BD=8D=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made-with: Cursor --- reading-platform-frontend/src/api/course.ts | 91 ++++++++++++++----- .../views/admin/courses/CourseListView.vue | 9 +- .../impl/CoursePackageServiceImpl.java | 4 +- 3 files changed, 70 insertions(+), 34 deletions(-) diff --git a/reading-platform-frontend/src/api/course.ts b/reading-platform-frontend/src/api/course.ts index b80e386..bd9cb6d 100644 --- a/reading-platform-frontend/src/api/course.ts +++ b/reading-platform-frontend/src/api/course.ts @@ -1,15 +1,19 @@ -import { getReadingPlatformAPI } from './generated'; -import { axios, customMutator } from './generated/mutator'; +import { getReadingPlatformAPI } from "./generated"; +import { axios, customMutator } from "./generated/mutator"; // 创建 API 实例 const api = getReadingPlatformAPI(); // 封装 http 方法(兼容原有代码) export const http = { - get: (url: string, config?: any) => customMutator({ url, method: 'get', ...config }), - post: (url: string, data?: any, config?: any) => customMutator({ url, method: 'post', data, ...config }), - put: (url: string, data?: any, config?: any) => customMutator({ url, method: 'put', data, ...config }), - delete: (url: string, config?: any) => customMutator({ url, method: 'delete', ...config }), + get: (url: string, config?: any) => + customMutator({ url, method: "get", ...config }), + post: (url: string, data?: any, config?: any) => + customMutator({ url, method: "post", data, ...config }), + put: (url: string, data?: any, config?: any) => + customMutator({ url, method: "put", data, ...config }), + delete: (url: string, config?: any) => + customMutator({ url, method: "delete", ...config }), }; // ============= 类型定义(保持向后兼容) ============= @@ -18,7 +22,7 @@ export interface CourseQueryParams { pageNum?: number; pageSize?: number; grade?: string; - gradeTags?: string; // 年级筛选(逗号分隔,如 "小班,中班,大班") + gradeTags?: string; // 年级筛选(逗号分隔,如 "小班,中班,大班") status?: string; keyword?: string; /** 审核管理页专用:仅返回待审核和已驳回,排除已通过 */ @@ -126,7 +130,7 @@ const toFindAllParams = (params: CourseQueryParams): any => ({ pageSize: params.pageSize ?? 10, keyword: params.keyword, category: params.grade, - gradeTags: params.gradeTags, // 年级筛选(逗号分隔) + gradeTags: params.gradeTags, // 年级筛选(逗号分隔) status: params.status || undefined, reviewOnly: params.reviewOnly, }); @@ -149,13 +153,20 @@ function normalizePageResult(raw: any): { // 获取课程包列表(7 步流程创建的教学资源) // 注意:这里的 Course 实际对应后端的 CoursePackage(课程包) +// 使用扁平 query 参数,确保 gradeTags(适用年级)正确传给后端 export function getCourses(params: CourseQueryParams): Promise<{ items: Course[]; total: number; page: number; pageSize: number; }> { - return api.getCoursePage1(toFindAllParams(params)).then(normalizePageResult) as any; + const flatParams = toFindAllParams(params); + return http + .get<{ list?: Course[]; items?: Course[]; total?: number; pageNum?: number; pageSize?: number }>( + "/v1/admin/packages", + { params: flatParams } + ) + .then(normalizePageResult) as any; } // 获取审核列表(仅返回待审核和已驳回,不含已通过) @@ -165,7 +176,13 @@ export function getReviewList(params: CourseQueryParams): Promise<{ page: number; pageSize: number; }> { - return api.getCoursePage1(toFindAllParams({ ...params, reviewOnly: true })).then(normalizePageResult) as any; + const flatParams = toFindAllParams({ ...params, reviewOnly: true }); + return http + .get<{ list?: Course[]; items?: Course[]; total?: number; pageNum?: number; pageSize?: number }>( + "/v1/admin/packages", + { params: flatParams } + ) + .then(normalizePageResult) as any; } // 获取课程包详情(id 支持 number | string,避免大整数精度丢失) @@ -197,8 +214,14 @@ export function validateCourse(_id: number): Promise { export function submitCourse(id: number | string): Promise { return http.post(`/v1/admin/packages/${id}/submit`).then((res: any) => { const body = res; - if (body && typeof body === 'object' && 'code' in body && body.code !== 200 && body.code !== 0) { - throw new Error(body.message || '提交失败'); + if ( + body && + typeof body === "object" && + "code" in body && + body.code !== 200 && + body.code !== 0 + ) { + throw new Error(body.message || "提交失败"); } return body?.data; }); @@ -206,27 +229,42 @@ export function submitCourse(id: number | string): Promise { // 撤销审核 (暂时使用更新接口,需要确认后端是否有此功能) export function withdrawCourse(id: number): Promise { - return api.updateCourse(id, { status: 'DRAFT' }) as any; + return api.updateCourse(id, { status: "DRAFT" }) as any; } // 审核通过 -export function approveCourse(id: number, _data: { checklist?: any; comment?: string }): Promise { +export function approveCourse( + id: number, + _data: { checklist?: any; comment?: string }, +): Promise { return api.publishCourse(id) as any; } // 审核驳回(课程专用,调用 POST /v1/admin/packages/{id}/reject) -export function rejectCourse(id: number | string, data: { comment: string }): Promise { +export function rejectCourse( + id: number | string, + data: { comment: string }, +): Promise { return http.post(`/v1/admin/packages/${id}/reject`, data).then((res: any) => { const body = res; - if (body && typeof body === 'object' && 'code' in body && body.code !== 200 && body.code !== 0) { - throw new Error(body.message || '驳回失败'); + if ( + body && + typeof body === "object" && + "code" in body && + body.code !== 200 && + body.code !== 0 + ) { + throw new Error(body.message || "驳回失败"); } return body?.data; }); } // 直接发布(超级管理员) -export function directPublishCourse(id: number, _skipValidation?: boolean): Promise { +export function directPublishCourse( + id: number, + _skipValidation?: boolean, +): Promise { return api.publishCourse(id) as any; } @@ -258,15 +296,18 @@ export function getCourseVersions(_id: number): Promise { // ============= 常量 ============= // 课程状态映射 -export const COURSE_STATUS_MAP: Record = { - DRAFT: { label: '草稿', color: 'default' }, - PENDING: { label: '审核中', color: 'processing' }, - REJECTED: { label: '已驳回', color: 'error' }, - PUBLISHED: { label: '已发布', color: 'success' }, - ARCHIVED: { label: '已下架', color: 'warning' }, +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' }; + return COURSE_STATUS_MAP[status] || { label: status, color: "default" }; } diff --git a/reading-platform-frontend/src/views/admin/courses/CourseListView.vue b/reading-platform-frontend/src/views/admin/courses/CourseListView.vue index aef57f8..003d581 100644 --- a/reading-platform-frontend/src/views/admin/courses/CourseListView.vue +++ b/reading-platform-frontend/src/views/admin/courses/CourseListView.vue @@ -4,7 +4,7 @@ - 小班 中班 @@ -59,12 +59,7 @@