78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
|
|
import http from '@/api'
|
|||
|
|
import type { TestDevice } from './interface'
|
|||
|
|
|
|||
|
|
const TEST_DEVICE_BASE_URL = '/api/test-device'
|
|||
|
|
|
|||
|
|
const buildTestDeviceFormData = (request: TestDevice.TestDeviceSaveRequest, reportFile?: File | null) => {
|
|||
|
|
const formData = new FormData()
|
|||
|
|
|
|||
|
|
// 关键业务节点:检测设备新增/编辑接口按 request JSON 分段读取业务字段,报告文件单独传 reportFile。
|
|||
|
|
formData.append('request', new Blob([JSON.stringify(request)], { type: 'application/json' }))
|
|||
|
|
|
|||
|
|
if (reportFile) {
|
|||
|
|
formData.append('reportFile', reportFile)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return formData
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
const buildTestDeviceImportFormData = (file: File, reportZip: File) => {
|
|||
|
|
const formData = new FormData()
|
|||
|
|
|
|||
|
|
formData.append('file', file)
|
|||
|
|
formData.append('reportZip', reportZip)
|
|||
|
|
|
|||
|
|
return formData
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const listTestDevicesApi = (params: TestDevice.TestDeviceListParams) => {
|
|||
|
|
return http.post(`${TEST_DEVICE_BASE_URL}/list`, params)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const createTestDeviceApi = (request: TestDevice.TestDeviceSaveRequest, reportFile: File) => {
|
|||
|
|
return http.post<boolean>(`${TEST_DEVICE_BASE_URL}/add`, buildTestDeviceFormData(request, reportFile), {
|
|||
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const updateTestDeviceApi = (request: TestDevice.TestDeviceSaveRequest, reportFile?: File | null) => {
|
|||
|
|
return http.post<boolean>(`${TEST_DEVICE_BASE_URL}/update`, buildTestDeviceFormData(request, reportFile), {
|
|||
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|||
|
|
})
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const deleteTestDevicesApi = (ids: string[]) => {
|
|||
|
|
return http.post<boolean>(`${TEST_DEVICE_BASE_URL}/delete`, ids)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const getTestDeviceDetailApi = (id: string) => {
|
|||
|
|
return http.get<TestDevice.TestDeviceRecord>(`${TEST_DEVICE_BASE_URL}/${id}`)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const downloadTestDeviceImportTemplateApi = () => {
|
|||
|
|
return http.get(`${TEST_DEVICE_BASE_URL}/template`, undefined, { responseType: 'blob' })
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const importTestDevicesApi = (file: File, reportZip: File) => {
|
|||
|
|
return http.post<TestDevice.TestDeviceImportResult>(
|
|||
|
|
`${TEST_DEVICE_BASE_URL}/import`,
|
|||
|
|
buildTestDeviceImportFormData(file, reportZip),
|
|||
|
|
{
|
|||
|
|
headers: { 'Content-Type': 'multipart/form-data' }
|
|||
|
|
}
|
|||
|
|
)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const exportTestDevicesApi = (params: TestDevice.TestDeviceListParams) => {
|
|||
|
|
return http.get(`${TEST_DEVICE_BASE_URL}/export`, params, { responseType: 'blob' })
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const previewTestDeviceReportApi = (id: string) => {
|
|||
|
|
// 关键业务节点:test-device 当前仅提供 /{id}/report,预览与下载统一复用同一报告流,避免前端误调不存在的 preview 接口。
|
|||
|
|
return http.get(`${TEST_DEVICE_BASE_URL}/${id}/report`, undefined, { responseType: 'blob' })
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
export const downloadTestDeviceReportApi = (id: string) => {
|
|||
|
|
return http.get(`${TEST_DEVICE_BASE_URL}/${id}/report`, undefined, { responseType: 'blob' })
|
|||
|
|
}
|