import type { PaperEntity, PaperPageQuery } from '#/views/x/tms/paper/types';
|
|
import { defHttp } from '#/api/request';
|
|
/** 正式路径:/api/tms/paper/** */
|
const prefix = '/api/tms/paper';
|
|
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 getPaperList(params: PaperPageQuery) {
|
return unwrapData<{ list: PaperEntity[]; pagination: Record<string, any> }>(
|
defHttp.get({ url: `${prefix}/list`, params }),
|
);
|
}
|
|
export function getPaperInfo(id: string) {
|
return unwrapData<PaperEntity>(defHttp.get({ url: `${prefix}/${id}` }));
|
}
|
|
export function createPaper(data: PaperEntity) {
|
return unwrapData<string>(defHttp.post({ url: prefix, data }));
|
}
|
|
export function updatePaper(data: PaperEntity) {
|
return unwrapData(defHttp.put({ url: `${prefix}/${data.id}`, data }));
|
}
|
|
/** 废弃 = biz_status=invalid */
|
export function invalidatePaper(id: string) {
|
return unwrapData(defHttp.put({ url: `${prefix}/${id}/invalidate` }));
|
}
|
|
/** 启用/停用:open | closed */
|
export function setPaperStatus(id: string, bizStatus: 'open' | 'closed') {
|
return unwrapData(defHttp.put({ url: `${prefix}/${id}/status`, data: { bizStatus } }));
|
}
|
|
/** 导出试卷试题清单 */
|
export function exportPaperQuestions(ids: string[]) {
|
return defHttp.post(
|
{
|
url: `${prefix}/export`,
|
data: { ids },
|
responseType: 'blob',
|
},
|
{
|
isReturnNativeResponse: true,
|
isTransformResponse: false,
|
},
|
);
|
}
|