| | |
| | | } from '#/views/x/tms/trainRecord/types'; |
| | | |
| | | import { defHttp } from '#/api/request'; |
| | | import { mockGetTrainRecordCatalog, mockQueryTrainRecords } from '#/views/x/tms/trainRecord/mock'; |
| | | |
| | | /** 后端未就绪前走 mock;联调后改为 false */ |
| | | const USE_MOCK = true; |
| | | 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) { |
| | | if (USE_MOCK) return mockQueryTrainRecords(params); |
| | | return defHttp.get({ url: `${prefix}/list`, params }); |
| | | return unwrapData<{ list: any[]; pagination: Record<string, any> }>( |
| | | defHttp.get({ url: `${prefix}/list`, params }), |
| | | ); |
| | | } |
| | | |
| | | export function getTrainRecordCatalog(params: TrainRecordCatalogQuery) { |
| | | if (USE_MOCK) return mockGetTrainRecordCatalog(params); |
| | | return defHttp.get<TrainRecordCatalogDetail>({ url: `${prefix}/${params.recordId}/catalog`, params }); |
| | | const { recordId, startDate, endDate } = params; |
| | | return unwrapData<TrainRecordCatalogDetail>( |
| | | defHttp.get({ |
| | | url: `${prefix}/${recordId}/catalog`, |
| | | params: { startDate, endDate }, |
| | | }), |
| | | ); |
| | | } |