Files
ndm-web-platform/src/apis/request/biz/video/ndm-keyboard.ts
yangsy 495dc001a1 refactor: 优化请求封装
- 优化Result接口定义
- 新增响应数据解析逻辑
- 优化错误解析逻辑
2025-12-17 15:38:08 +08:00

86 lines
3.8 KiB
TypeScript

import {
ndmClient,
userClient,
type ImportMsg,
type NdmKeyboardPageQuery,
type NdmKeyboardResultVO,
type NdmKeyboardSaveVO,
type NdmKeyboardUpdateVO,
type PageParams,
type PageResult,
type Station,
} from '@/apis';
import { unwrapResponse } from '@/utils';
export const pageKeyboardApi = async (pageQuery: PageParams<NdmKeyboardPageQuery>, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
const client = stationCode ? ndmClient : userClient;
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmKeyboard/page`;
const resp = await client.post<PageResult<NdmKeyboardResultVO>>(endpoint, pageQuery, { signal });
const data = unwrapResponse(resp);
return data;
};
export const detailKeyboardApi = async (id: string, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
const client = stationCode ? ndmClient : userClient;
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmKeyboard/detail`;
const resp = await client.get<NdmKeyboardResultVO>(endpoint, { params: { id }, signal });
const data = unwrapResponse(resp);
return data;
};
export const saveKeyboardApi = async (saveVO: NdmKeyboardSaveVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
const client = stationCode ? ndmClient : userClient;
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmKeyboard`;
const resp = await client.post<NdmKeyboardResultVO>(endpoint, saveVO, { signal });
const data = unwrapResponse(resp);
return data;
};
export const updateKeyboardApi = async (updateVO: NdmKeyboardUpdateVO, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
const client = stationCode ? ndmClient : userClient;
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmKeyboard`;
const resp = await client.put<NdmKeyboardResultVO>(endpoint, updateVO, { signal });
const data = unwrapResponse(resp);
return data;
};
export const deleteKeyboardApi = async (ids: string[], options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
const client = stationCode ? ndmClient : userClient;
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmKeyboard`;
const resp = await client.delete<boolean>(endpoint, ids, { signal });
const data = unwrapResponse(resp);
return data;
};
export const exportKeyboardApi = async (pageQuery: PageParams<NdmKeyboardPageQuery>, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
const client = stationCode ? ndmClient : userClient;
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmKeyboard/defaultExportByTemplate`;
const resp = await client.post<Blob>(endpoint, pageQuery, { responseType: 'blob', retRaw: true, signal });
const data = unwrapResponse(resp);
return data;
};
export const importKeyboardApi = async (file: File, options?: { stationCode?: Station['code']; signal?: AbortSignal }) => {
const { stationCode, signal } = options ?? {};
const client = stationCode ? ndmClient : userClient;
const prefix = stationCode ? `/${stationCode}` : '';
const endpoint = `${prefix}/api/ndm/ndmKeyboard/importReturnMsg`;
const formData = new FormData();
formData.append('file', file);
const resp = await client.post<ImportMsg>(endpoint, formData, { signal, upload: true });
const data = unwrapResponse(resp);
return data;
};