liuyu
22 小时以前 8534025c45b4736975730678b9ccf23570a75f95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import type { CourseItem, CoursePageQuery, PaperOption } from '#/views/x/tms/course/types';
 
import { defHttp } from '#/api/request';
 
/** 正式路径:/api/tms/course/** */
const prefix = '/api/tms/course';
 
async function unwrapData<T>(promise: Promise<any>): Promise<T> {
  const res = await promise;
  if (res && typeof res === 'object' && 'data' in res && ('code' in res || 'msg' in res)) {
    return res.data as T;
  }
  return res as T;
}
 
export function getCourseList(params: CoursePageQuery) {
  return unwrapData<{ list: CourseItem[]; pagination: Record<string, any> }>(
    defHttp.get({ url: `${prefix}/list`, params }),
  );
}
 
export function getCourseInfo(id: string) {
  return unwrapData<CourseItem>(defHttp.get({ url: `${prefix}/${id}` }));
}
 
export function getCoursePaperOptions() {
  return unwrapData<PaperOption[]>(defHttp.get({ url: `${prefix}/paper-options` }));
}
 
export function createCourse(data: Partial<CourseItem>) {
  return unwrapData<string>(defHttp.post({ url: prefix, data }));
}
 
export function updateCourse(data: Partial<CourseItem> & { id: string }) {
  return unwrapData(defHttp.put({ url: `${prefix}/${data.id}`, data }));
}
 
export function setCourseEnabled(id: string, enabled: '0' | '1') {
  return unwrapData(defHttp.put({ url: `${prefix}/${id}/enabled`, data: { enabled } }));
}
 
export function deleteCourse(id: string) {
  return unwrapData(defHttp.delete({ url: `${prefix}/${id}` }));
}