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()
|
}
|
|
function normalizeNumber(value) {
|
if (value === '' || value === null || value === undefined) {
|
return void 0
|
}
|
const numberValue = Number(value)
|
return Number.isNaN(numberValue) ? void 0 : numberValue
|
}
|
|
function filterParams(params = {}, ignoredKeys = []) {
|
return Object.fromEntries(
|
Object.entries(params)
|
.filter(([key, value]) => {
|
if (ignoredKeys.includes(key)) return false
|
if (value === undefined || value === null) return false
|
if (typeof value === 'string' && value.trim() === '') return false
|
return true
|
})
|
.map(([key, value]) => [key, normalizeText(value)])
|
)
|
}
|
|
export function buildDeviceBindPageParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...filterParams(params, ['current', 'pageSize', 'size'])
|
}
|
}
|
|
export function buildDeviceBindSearchParams(params = {}) {
|
const searchParams = {
|
condition: normalizeText(params.condition),
|
currentRow: normalizeNumber(params.currentRow),
|
startRow: normalizeNumber(params.startRow),
|
endRow: normalizeNumber(params.endRow),
|
deviceQty: normalizeNumber(params.deviceQty),
|
startDeviceNo: normalizeNumber(params.startDeviceNo),
|
endDeviceNo: normalizeNumber(params.endDeviceNo),
|
typeId: normalizeNumber(params.typeId),
|
staList: normalizeText(params.staList),
|
beSimilar: normalizeText(params.beSimilar),
|
emptySimilar: normalizeText(params.emptySimilar),
|
memo: normalizeText(params.memo),
|
timeStart: normalizeText(params.timeStart),
|
timeEnd: normalizeText(params.timeEnd)
|
}
|
|
return Object.fromEntries(
|
Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
|
)
|
}
|
|
export function buildDeviceBindSavePayload(formData = {}) {
|
return {
|
...(formData.id !== undefined && formData.id !== null && formData.id !== ''
|
? { id: Number(formData.id) }
|
: {}),
|
...(formData.currentRow !== undefined && formData.currentRow !== null && formData.currentRow !== ''
|
? { currentRow: Number(formData.currentRow) }
|
: {}),
|
...(formData.startRow !== undefined && formData.startRow !== null && formData.startRow !== ''
|
? { startRow: Number(formData.startRow) }
|
: {}),
|
...(formData.endRow !== undefined && formData.endRow !== null && formData.endRow !== ''
|
? { endRow: Number(formData.endRow) }
|
: {}),
|
...(formData.deviceQty !== undefined && formData.deviceQty !== null && formData.deviceQty !== ''
|
? { deviceQty: Number(formData.deviceQty) }
|
: {}),
|
...(formData.startDeviceNo !== undefined && formData.startDeviceNo !== null && formData.startDeviceNo !== ''
|
? { startDeviceNo: Number(formData.startDeviceNo) }
|
: {}),
|
...(formData.endDeviceNo !== undefined && formData.endDeviceNo !== null && formData.endDeviceNo !== ''
|
? { endDeviceNo: Number(formData.endDeviceNo) }
|
: {}),
|
staList: normalizeText(formData.staList) || '',
|
...(formData.typeId !== undefined && formData.typeId !== null && formData.typeId !== ''
|
? { typeId: Number(formData.typeId) }
|
: {}),
|
beSimilar: normalizeText(formData.beSimilar) || '',
|
emptySimilar: normalizeText(formData.emptySimilar) || '',
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function fetchDeviceBindPage(params = {}) {
|
return request.post({
|
url: '/deviceBind/page',
|
params: buildDeviceBindPageParams(params)
|
})
|
}
|
|
export function fetchDeviceBindList() {
|
return request.post({
|
url: '/deviceBind/list',
|
data: {}
|
})
|
}
|
|
export function fetchGetDeviceBindDetail(id) {
|
return request.get({
|
url: `/deviceBind/${id}`
|
})
|
}
|
|
export function fetchGetDeviceBindMany(ids) {
|
return request.post({
|
url: `/deviceBind/many/${normalizeIds(ids)}`
|
})
|
}
|
|
export function fetchSaveDeviceBind(params = {}) {
|
return request.post({
|
url: '/deviceBind/save',
|
params: buildDeviceBindSavePayload(params)
|
})
|
}
|
|
export function fetchUpdateDeviceBind(params = {}) {
|
return request.post({
|
url: '/deviceBind/update',
|
params: buildDeviceBindSavePayload(params)
|
})
|
}
|
|
export function fetchDeleteDeviceBind(ids) {
|
return request.post({
|
url: `/deviceBind/remove/${normalizeIds(ids)}`
|
})
|
}
|
|
export function fetchDeviceBindQuery(condition = '') {
|
return request.post({
|
url: '/deviceBind/query',
|
params: { condition: normalizeText(condition) }
|
})
|
}
|
|
export async function fetchExportDeviceBindReport(payload = {}, options = {}) {
|
return fetch(`${import.meta.env.VITE_API_URL}/deviceBind/export`, {
|
method: 'POST',
|
headers: {
|
'Content-Type': 'application/json',
|
...(options.headers || {})
|
},
|
body: JSON.stringify(payload)
|
})
|
}
|