刘光辉
4 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
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
import type {
  TrainRecordCatalogDetail,
  TrainRecordCatalogQuery,
  TrainRecordPageQuery,
} from '#/views/x/tms/trainRecord/types';
 
import { defHttp } from '#/api/request';
 
const prefix = '/api/tms/train-record';
 
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 getTrainRecordList(params: TrainRecordPageQuery) {
  return unwrapData<{ list: any[]; pagination: Record<string, any> }>(
    defHttp.get({ url: `${prefix}/list`, params }),
  );
}
 
export function getTrainRecordCatalog(params: TrainRecordCatalogQuery) {
  const { recordId, startDate, endDate } = params;
  return unwrapData<TrainRecordCatalogDetail>(
    defHttp.get({
      url: `${prefix}/${recordId}/catalog`,
      params: { startDate, endDate },
    }),
  );
}
 
/** 后端导出培训目录 Excel */
export function exportTrainRecordCatalog(params: TrainRecordCatalogQuery) {
  const { recordId, startDate, endDate } = params;
  return defHttp.get(
    {
      url: `${prefix}/${recordId}/catalog/export`,
      params: { startDate, endDate },
      responseType: 'blob',
    },
    {
      isReturnNativeResponse: true,
      isTransformResponse: false,
    },
  );
}