const FLAG_META = {
|
1: { text: '是', type: 'success', bool: true },
|
0: { text: '否', type: 'danger', bool: false }
|
}
|
|
export const DEVICE_BIND_REPORT_TITLE = '设备绑定报表'
|
export const DEVICE_BIND_REPORT_STYLE = {
|
titleAlign: 'center',
|
titleLevel: 'strong',
|
orientation: 'portrait',
|
density: 'compact',
|
showSequence: true
|
}
|
|
function normalizeText(value) {
|
return String(value ?? '').trim()
|
}
|
|
function normalizeNumber(value, fallback = void 0) {
|
if (value === '' || value === null || value === undefined) {
|
return fallback
|
}
|
const numberValue = Number(value)
|
return Number.isNaN(numberValue) ? fallback : numberValue
|
}
|
|
function normalizeFlagValue(value, fallback = '0') {
|
if (value === 1 || value === '1' || value === true) {
|
return '1'
|
}
|
if (value === 0 || value === '0' || value === false) {
|
return '0'
|
}
|
const text = normalizeText(value)
|
return text || fallback
|
}
|
|
function normalizeFlagText(value) {
|
if (value === 1 || value === '1' || value === true) {
|
return FLAG_META[1].text
|
}
|
if (value === 0 || value === '0' || value === false) {
|
return FLAG_META[0].text
|
}
|
return '--'
|
}
|
|
function splitStaList(value) {
|
return normalizeText(value)
|
.split(/[;,,\n\r]+/g)
|
.map((item) => item.trim())
|
.filter(Boolean)
|
}
|
|
export function createDeviceBindSearchState() {
|
return {
|
condition: '',
|
currentRow: null,
|
startRow: null,
|
endRow: null,
|
deviceQty: null,
|
startDeviceNo: null,
|
endDeviceNo: null,
|
typeId: '',
|
staList: '',
|
beSimilar: '',
|
emptySimilar: '',
|
memo: '',
|
timeStart: '',
|
timeEnd: ''
|
}
|
}
|
|
export function createDeviceBindFormState() {
|
return {
|
id: void 0,
|
currentRow: void 0,
|
startRow: void 0,
|
endRow: void 0,
|
deviceQty: void 0,
|
startDeviceNo: void 0,
|
endDeviceNo: void 0,
|
staList: '',
|
typeId: void 0,
|
beSimilar: '0',
|
emptySimilar: '0',
|
memo: ''
|
}
|
}
|
|
export function getDeviceBindPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getDeviceBindFlagOptions() {
|
return [
|
{ label: '是', value: '1' },
|
{ label: '否', value: '0' }
|
]
|
}
|
|
export function getDeviceBindFlagMeta(value) {
|
if (value === true || Number(value) === 1) {
|
return FLAG_META[1]
|
}
|
if (value === false || Number(value) === 0) {
|
return FLAG_META[0]
|
}
|
return { text: '--', type: 'info', bool: void 0 }
|
}
|
|
export function resolveDeviceBindTypeOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.id ?? item.areaId ?? item.value
|
if (value === void 0 || value === null || value === '') {
|
return null
|
}
|
return {
|
value: Number(value),
|
label: normalizeText(item.name || item.areaName || item.code || item.areaCode || `库区 ${value}`)
|
}
|
})
|
.filter(Boolean)
|
}
|
|
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 buildDeviceBindPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildDeviceBindSearchParams(params)
|
}
|
}
|
|
export function buildDeviceBindSavePayload(formData = {}) {
|
return {
|
...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
|
? { id: Number(formData.id) }
|
: {}),
|
...(formData.currentRow !== void 0 && formData.currentRow !== null && formData.currentRow !== ''
|
? { currentRow: Number(formData.currentRow) }
|
: {}),
|
...(formData.startRow !== void 0 && formData.startRow !== null && formData.startRow !== ''
|
? { startRow: Number(formData.startRow) }
|
: {}),
|
...(formData.endRow !== void 0 && formData.endRow !== null && formData.endRow !== ''
|
? { endRow: Number(formData.endRow) }
|
: {}),
|
...(formData.deviceQty !== void 0 && formData.deviceQty !== null && formData.deviceQty !== ''
|
? { deviceQty: Number(formData.deviceQty) }
|
: {}),
|
...(formData.startDeviceNo !== void 0 && formData.startDeviceNo !== null && formData.startDeviceNo !== ''
|
? { startDeviceNo: Number(formData.startDeviceNo) }
|
: {}),
|
...(formData.endDeviceNo !== void 0 && formData.endDeviceNo !== null && formData.endDeviceNo !== ''
|
? { endDeviceNo: Number(formData.endDeviceNo) }
|
: {}),
|
staList: normalizeText(formData.staList) || '',
|
...(formData.typeId !== void 0 && formData.typeId !== null && formData.typeId !== ''
|
? { typeId: Number(formData.typeId) }
|
: {}),
|
beSimilar: normalizeFlagValue(formData.beSimilar),
|
emptySimilar: normalizeFlagValue(formData.emptySimilar),
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function buildDeviceBindDialogModel(record = {}) {
|
return {
|
...createDeviceBindFormState(),
|
...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
|
currentRow:
|
record.currentRow !== void 0 && record.currentRow !== null && record.currentRow !== ''
|
? Number(record.currentRow)
|
: void 0,
|
startRow:
|
record.startRow !== void 0 && record.startRow !== null && record.startRow !== ''
|
? Number(record.startRow)
|
: void 0,
|
endRow:
|
record.endRow !== void 0 && record.endRow !== null && record.endRow !== ''
|
? Number(record.endRow)
|
: void 0,
|
deviceQty:
|
record.deviceQty !== void 0 && record.deviceQty !== null && record.deviceQty !== ''
|
? Number(record.deviceQty)
|
: void 0,
|
startDeviceNo:
|
record.startDeviceNo !== void 0 && record.startDeviceNo !== null && record.startDeviceNo !== ''
|
? Number(record.startDeviceNo)
|
: void 0,
|
endDeviceNo:
|
record.endDeviceNo !== void 0 && record.endDeviceNo !== null && record.endDeviceNo !== ''
|
? Number(record.endDeviceNo)
|
: void 0,
|
staList: normalizeText(record.staList || ''),
|
typeId:
|
record.typeId !== void 0 && record.typeId !== null && record.typeId !== ''
|
? Number(record.typeId)
|
: void 0,
|
beSimilar: normalizeFlagValue(record.beSimilar, '0'),
|
emptySimilar: normalizeFlagValue(record.emptySimilar, '0'),
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export function normalizeDeviceBindDetailRecord(record = {}, resolveTypeLabel) {
|
const beSimilarMeta = getDeviceBindFlagMeta(record.beSimilar)
|
const emptySimilarMeta = getDeviceBindFlagMeta(record.emptySimilar)
|
|
return {
|
...record,
|
currentRow:
|
record.currentRow !== void 0 && record.currentRow !== null && record.currentRow !== ''
|
? Number(record.currentRow)
|
: void 0,
|
startRow:
|
record.startRow !== void 0 && record.startRow !== null && record.startRow !== ''
|
? Number(record.startRow)
|
: void 0,
|
endRow:
|
record.endRow !== void 0 && record.endRow !== null && record.endRow !== ''
|
? Number(record.endRow)
|
: void 0,
|
deviceQty:
|
record.deviceQty !== void 0 && record.deviceQty !== null && record.deviceQty !== ''
|
? Number(record.deviceQty)
|
: void 0,
|
startDeviceNo:
|
record.startDeviceNo !== void 0 && record.startDeviceNo !== null && record.startDeviceNo !== ''
|
? Number(record.startDeviceNo)
|
: void 0,
|
endDeviceNo:
|
record.endDeviceNo !== void 0 && record.endDeviceNo !== null && record.endDeviceNo !== ''
|
? Number(record.endDeviceNo)
|
: void 0,
|
staList: normalizeText(record.staList || ''),
|
staListItems: splitStaList(record.staList),
|
typeIdText:
|
normalizeText(record.typeId$ || record.typeIdText || '') ||
|
(typeof resolveTypeLabel === 'function' ? normalizeText(resolveTypeLabel(record.typeId)) : ''),
|
beSimilarText: beSimilarMeta.text,
|
beSimilarType: beSimilarMeta.type,
|
emptySimilarText: emptySimilarMeta.text,
|
emptySimilarType: emptySimilarMeta.type,
|
memo: normalizeText(record.memo || ''),
|
createByText: normalizeText(record.createBy$ || record.createByText || ''),
|
createTimeText: normalizeText(record.createTime$ || record.createTime || ''),
|
updateByText: normalizeText(record.updateBy$ || record.updateByText || ''),
|
updateTimeText: normalizeText(record.updateTime$ || record.updateTime || '')
|
}
|
}
|
|
export function normalizeDeviceBindListRow(record = {}, resolveTypeLabel) {
|
return normalizeDeviceBindDetailRecord(record, resolveTypeLabel)
|
}
|
|
export function buildDeviceBindPrintRows(records = [], resolveTypeLabel) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeDeviceBindListRow(record, resolveTypeLabel))
|
}
|
|
export function buildDeviceBindReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = DEVICE_BIND_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: DEVICE_BIND_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...DEVICE_BIND_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|