const STATUS_META = { 0: { text: '待执行', type: 'info' }, 1: { text: '处理中', type: 'warning' }, 2: { text: '已完成', type: 'success' }, 3: { text: '失败', type: 'danger' } } const RESOURCE_LABEL_MAP = { loc: '库位', warehouseAreasItem: '收货库存' } function normalizeText(value) { return String(value ?? '').trim() } function normalizeNumber(value) { if (value === '' || value === null || value === undefined) { return undefined } const numericValue = Number(value) return Number.isFinite(numericValue) ? numericValue : undefined } function normalizeDateTime(value) { return normalizeText(value) || '--' } export function createExportTaskSearchState() { return { condition: '', resourceKey: '', status: '', timeStart: '', timeEnd: '', orderBy: 'createTime desc' } } export function getExportTaskPaginationKey() { return { current: 'current', size: 'pageSize' } } export function getExportTaskStatusOptions() { return Object.entries(STATUS_META).map(([value, meta]) => ({ label: meta.text, value: Number(value) })) } export function getExportTaskResourceOptions() { return Object.entries(RESOURCE_LABEL_MAP).map(([value, label]) => ({ label, value })) } export function buildExportTaskSearchParams(params = {}) { return { ...(normalizeText(params.condition) ? { condition: normalizeText(params.condition) } : {}), ...(normalizeText(params.resourceKey) ? { resourceKey: normalizeText(params.resourceKey) } : {}), ...(normalizeNumber(params.status) !== undefined ? { status: normalizeNumber(params.status) } : {}), ...(params.timeStart ? { timeStart: params.timeStart } : {}), ...(params.timeEnd ? { timeEnd: params.timeEnd } : {}), orderBy: 'createTime desc' } } export function buildExportTaskPageQueryParams(params = {}) { return { current: params.current || 1, pageSize: params.pageSize || params.size || 20, ...buildExportTaskSearchParams(params) } } export function resolveExportTaskResourceLabel(resourceKey) { return RESOURCE_LABEL_MAP[normalizeText(resourceKey)] || normalizeText(resourceKey) || '--' } export function normalizeExportTaskRow(record = {}) { const statusValue = Number(record.status) const statusMeta = STATUS_META[statusValue] || STATUS_META[0] return { ...record, id: record.id ?? '--', taskCode: normalizeText(record.taskCode) || '--', resourceKey: normalizeText(record.resourceKey), resourceKeyText: resolveExportTaskResourceLabel(record.resourceKey), reportTitle: normalizeText(record.reportTitle) || '--', fileName: normalizeText(record.fileName) || '--', rowCount: record.rowCount ?? '--', statusText: record['status$'] || statusMeta.text, statusType: statusMeta.type, errorMsg: normalizeText(record.errorMsg) || '--', createTimeText: normalizeDateTime(record['createTime$'] || record.createTime), updateTimeText: normalizeDateTime(record['updateTime$'] || record.updateTime), expireTimeText: normalizeDateTime(record['expireTime$'] || record.expireTime), canDownload: statusValue === 2 } }