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

51 lines
1.8 KiB
TypeScript

import { ndmClient, userClient, type IcmpEntity, type Station } from '@/apis';
import { unwrapResponse } from '@/utils';
export const exportIcmpApi = async (status?: 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/ndmIcmpExport/exportByTemplate`;
const body = new URLSearchParams();
body.append('status', status ?? '');
const resp = await client.post<Blob>(endpoint, body, {
responseType: 'blob',
retRaw: true,
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
signal,
});
const data = unwrapResponse(resp);
return data;
};
export const exportIcmpByStationApi = async (stationCodes: Station['code'][], status: string, options?: { signal?: AbortSignal }) => {
const { signal } = options ?? {};
const client = ndmClient;
const prefix = '';
const endpoint = `${prefix}/api/ndm/ndmIcmpExport/exportByTemplateByStation`;
const resp = await client.post<Blob>(
endpoint,
{
stationCode: stationCodes,
status,
},
{
responseType: 'blob',
retRaw: true,
signal,
},
);
const data = unwrapResponse(resp);
return data;
};
export const icmpEntityByDeviceId = async (deviceId: 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/ndmIcmpExport/icmpEntityByDeviceId`;
const resp = await client.get<IcmpEntity[]>(endpoint, { params: { deviceId }, signal, retRaw: true });
const data = unwrapResponse(resp);
return data;
};