liuyu
21 小时以前 93c133349a5ccd7a328371fa113dce69d5611f21
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
45
46
47
48
49
50
51
import type {
  MyPaperListItem,
  MyPaperPageQuery,
  OnlineExamDetail,
  OnlineExamPaper,
  OnlineExamSubmitResult,
} from '#/views/x/tms/onlineExam/types';
 
import { defHttp } from '#/api/request';
 
const prefix = '/api/tms/online-exam';
 
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 getMyPaperList(params: MyPaperPageQuery) {
  return unwrapData<{ list: MyPaperListItem[]; pagination: Record<string, any> }>(
    defHttp.get({ url: `${prefix}/my-papers`, params }),
  );
}
 
export function getMyPaperDetail(id: string) {
  return unwrapData<OnlineExamDetail>(defHttp.get({ url: `${prefix}/my-papers/${id}` }));
}
 
export function getExamReview(examId: string) {
  return unwrapData<OnlineExamDetail>(defHttp.get({ url: `${prefix}/exams/${examId}` }));
}
 
export function startOnlineExam(myPaperId: string) {
  return unwrapData<OnlineExamPaper>(
    defHttp.post({ url: `${prefix}/start`, data: { myPaperId } }, { errorMessageMode: 'none' }),
  );
}
 
export function saveOnlineExam(examId: string, answers: Record<string, string | string[]>) {
  return unwrapData(
    defHttp.post({ url: `${prefix}/${examId}/save`, data: { answers } }, { errorMessageMode: 'none' }),
  );
}
 
export function submitOnlineExam(examId: string, answers: Record<string, string | string[]>) {
  return unwrapData<OnlineExamSubmitResult>(
    defHttp.post({ url: `${prefix}/${examId}/submit`, data: { answers } }, { errorMessageMode: 'none' }),
  );
}