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
45
46
47
48
49
50
51
52
53
54
55
56
import type { QuestionBankOption } from '#/views/x/tms/question/types';
import type {
  SelfTestPaper,
  SelfTestStartPayload,
  SelfTestSubmitPayload,
  SelfTestSubmitResult,
  SelfTestRecordItem,
} from '#/views/x/tms/selfTest/types';
 
import { defHttp } from '#/api/request';
import { getQuestionBanks } from '#/api/x/tms/question';
 
/** 正式路径:/api/tms/self-test/** */
const prefix = '/api/tms/self-test';
 
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 getSelfTestBanks() {
  return getQuestionBanks() as Promise<QuestionBankOption[]>;
}
 
export function startSelfTest(data: SelfTestStartPayload) {
  return unwrapData<SelfTestPaper>(defHttp.post({ url: `${prefix}/start`, data }));
}
 
/** 暂存作答(不交卷,便于继续考试) */
export function saveSelfTest(paperId: string, data: SelfTestSubmitPayload) {
  return unwrapData<string>(defHttp.post({ url: `${prefix}/${paperId}/save`, data }));
}
 
export function submitSelfTest(paperId: string, data: SelfTestSubmitPayload) {
  return unwrapData<SelfTestSubmitResult>(defHttp.post({ url: `${prefix}/${paperId}/submit`, data }));
}
 
export function getSelfTestList(params?: {
  currentPage?: number;
  pageSize?: number;
  bankId?: string;
  testStatus?: string;
  startTimeBegin?: string;
  startTimeEnd?: string;
}) {
  return unwrapData<{ list: SelfTestRecordItem[]; pagination: Record<string, any> }>(
    defHttp.get({ url: `${prefix}/list`, params }),
  );
}
 
export function getSelfTestInfo(id: string) {
  return unwrapData<SelfTestPaper>(defHttp.get({ url: `${prefix}/${id}` }));
}