import request from '@/utils/http'
|
|
function normalizeText(value) {
|
return typeof value === 'string' ? value.trim() : value
|
}
|
|
function normalizeIds(ids) {
|
if (Array.isArray(ids)) {
|
return ids.map((id) => String(id).trim()).filter(Boolean).join(',')
|
}
|
if (ids === null || ids === undefined) {
|
return ''
|
}
|
return String(ids).trim()
|
}
|
|
export function buildQlyInspectPageParams(params = {}) {
|
const entries = Object.entries(params).filter(([key, value]) => {
|
if (['current', 'pageSize', 'size'].includes(key)) {
|
return false
|
}
|
if (value === undefined || value === null) {
|
return false
|
}
|
if (typeof value === 'string' && value.trim() === '') {
|
return false
|
}
|
return true
|
})
|
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...Object.fromEntries(entries.map(([key, value]) => [key, normalizeText(value)]))
|
}
|
}
|
|
export function buildQlyInspectItemPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...(params.ispectId !== undefined ? { ispectId: params.ispectId } : {})
|
}
|
}
|
|
export function fetchQlyInspectPage(params = {}) {
|
return request.post({
|
url: '/qlyInspect/page',
|
params: buildQlyInspectPageParams(params)
|
})
|
}
|
|
export function fetchQlyInspectItemPage(params = {}) {
|
return request.post({
|
url: '/qlyIsptItem/page',
|
params: buildQlyInspectItemPageParams(params)
|
})
|
}
|
|
export function fetchGetQlyInspectMany(ids) {
|
const normalizedIds = normalizeIds(ids)
|
return request.post({
|
url: `/qlyInspect/many/${normalizedIds}`
|
})
|
}
|
|
export async function fetchExportQlyInspectReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/qlyInspect/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|