const STATUS_META = {
|
1: { text: '正常', type: 'success', bool: true },
|
0: { text: '冻结', type: 'danger', bool: false }
|
}
|
|
const TYPE_META = {
|
0: { text: '智能站点', type: 'primary' },
|
1: { text: '普通站点', type: 'warning' }
|
}
|
|
const BOOLEAN_META = {
|
1: { text: '是', type: 'success' },
|
0: { text: '否', type: 'info' }
|
}
|
|
export const BAS_STATION_REPORT_TITLE = '站点管理报表'
|
export const BAS_STATION_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 parsed = Number(value)
|
return Number.isNaN(parsed) ? fallback : parsed
|
}
|
|
function normalizeIdArray(values = []) {
|
if (!Array.isArray(values)) {
|
return []
|
}
|
|
return values
|
.map((item, index) => {
|
if (item === null || item === undefined || item === '') {
|
return null
|
}
|
if (typeof item === 'object') {
|
const id = normalizeNumber(item.id ?? item.areaId ?? item.value, void 0)
|
if (id === void 0) {
|
return null
|
}
|
return {
|
id,
|
sort: normalizeNumber(item.sort, index + 1)
|
}
|
}
|
const id = normalizeNumber(item, void 0)
|
if (id === void 0) {
|
return null
|
}
|
return {
|
id,
|
sort: index + 1
|
}
|
})
|
.filter(Boolean)
|
.sort((left, right) => {
|
const leftSort = normalizeNumber(left.sort, Number.MAX_SAFE_INTEGER)
|
const rightSort = normalizeNumber(right.sort, Number.MAX_SAFE_INTEGER)
|
return leftSort - rightSort
|
})
|
.map((item, index) => ({
|
id: item.id,
|
sort: index + 1
|
}))
|
}
|
|
function normalizePlainIdArray(values = []) {
|
if (!Array.isArray(values)) {
|
return []
|
}
|
return values
|
.map((item) => normalizeNumber(item, void 0))
|
.filter((item) => item !== void 0 && item !== null)
|
}
|
|
export function createBasStationSearchState() {
|
return {
|
condition: '',
|
stationName: '',
|
stationId: '',
|
type: '',
|
useStatus: '',
|
area: '',
|
isCrossZone: '',
|
isWcs: '',
|
barcode: '',
|
autoTransfer: '',
|
status: '',
|
memo: '',
|
timeStart: '',
|
timeEnd: ''
|
}
|
}
|
|
export function createBasStationFormState() {
|
return {
|
id: void 0,
|
stationName: '',
|
stationId: '',
|
type: 0,
|
area: void 0,
|
useStatus: '',
|
isCrossZone: 0,
|
areaIds: [],
|
isWcs: 0,
|
wcsData: '',
|
containerTypes: [],
|
barcode: '',
|
autoTransfer: 0,
|
inAble: 0,
|
outAble: 0,
|
status: 1,
|
memo: ''
|
}
|
}
|
|
export function getBasStationPaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
export function getBasStationStatusOptions() {
|
return [
|
{ label: '正常', value: 1 },
|
{ label: '冻结', value: 0 }
|
]
|
}
|
|
export function getBasStationTypeOptions() {
|
return [
|
{ label: '智能站点', value: 0 },
|
{ label: '普通站点', value: 1 }
|
]
|
}
|
|
export function getBasStationBooleanOptions() {
|
return [
|
{ label: '否', value: 0 },
|
{ label: '是', value: 1 }
|
]
|
}
|
|
export function getBasStationUseStatusMeta(value) {
|
if (!value) {
|
return { text: '未知', type: 'info' }
|
}
|
return {
|
text: normalizeText(value),
|
type: 'primary'
|
}
|
}
|
|
export function getBasStationStatusMeta(status) {
|
if (status === true || Number(status) === 1) {
|
return STATUS_META[1]
|
}
|
if (status === false || Number(status) === 0) {
|
return STATUS_META[0]
|
}
|
return { text: '未知', type: 'info', bool: false }
|
}
|
|
export function getBasStationTypeMeta(type) {
|
if (type === true || Number(type) === 0) {
|
return TYPE_META[0]
|
}
|
if (Number(type) === 1) {
|
return TYPE_META[1]
|
}
|
return { text: '未知', type: 'info' }
|
}
|
|
export function getBasStationBooleanMeta(value) {
|
if (value === true || Number(value) === 1) {
|
return BOOLEAN_META[1]
|
}
|
if (value === false || Number(value) === 0) {
|
return BOOLEAN_META[0]
|
}
|
return { text: '未知', type: 'info' }
|
}
|
|
export function buildBasStationSearchParams(params = {}) {
|
const searchParams = {
|
condition: normalizeText(params.condition),
|
stationName: normalizeText(params.stationName),
|
stationId: normalizeText(params.stationId),
|
type:
|
params.type !== undefined && params.type !== null && params.type !== ''
|
? Number(params.type)
|
: void 0,
|
useStatus: normalizeText(params.useStatus),
|
area:
|
params.area !== undefined && params.area !== null && params.area !== ''
|
? Number(params.area)
|
: void 0,
|
isCrossZone:
|
params.isCrossZone !== undefined && params.isCrossZone !== null && params.isCrossZone !== ''
|
? Number(params.isCrossZone)
|
: void 0,
|
isWcs:
|
params.isWcs !== undefined && params.isWcs !== null && params.isWcs !== ''
|
? Number(params.isWcs)
|
: void 0,
|
barcode: normalizeText(params.barcode),
|
autoTransfer:
|
params.autoTransfer !== undefined && params.autoTransfer !== null && params.autoTransfer !== ''
|
? Number(params.autoTransfer)
|
: void 0,
|
status:
|
params.status !== undefined && params.status !== null && params.status !== ''
|
? Number(params.status)
|
: void 0,
|
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 buildBasStationPageQueryParams(params = {}) {
|
return {
|
current: params.current || 1,
|
pageSize: params.pageSize || params.size || 20,
|
...buildBasStationSearchParams(params)
|
}
|
}
|
|
export function buildBasStationSavePayload(formData = {}) {
|
return {
|
...(formData.id !== void 0 && formData.id !== null && formData.id !== ''
|
? { id: Number(formData.id) }
|
: {}),
|
stationName: normalizeText(formData.stationName) || '',
|
stationId: normalizeText(formData.stationId) || '',
|
...(formData.type !== void 0 && formData.type !== null && formData.type !== ''
|
? { type: Number(formData.type) }
|
: {}),
|
...(formData.area !== void 0 && formData.area !== null && formData.area !== ''
|
? { area: Number(formData.area) }
|
: {}),
|
useStatus: normalizeText(formData.useStatus) || '',
|
...(formData.isCrossZone !== void 0 && formData.isCrossZone !== null && formData.isCrossZone !== ''
|
? { isCrossZone: Number(formData.isCrossZone) }
|
: {}),
|
...(normalizeIdArray(formData.areaIds).length ? { areaIds: normalizeIdArray(formData.areaIds).map((item) => item.id) } : {}),
|
...(formData.isWcs !== void 0 && formData.isWcs !== null && formData.isWcs !== ''
|
? { isWcs: Number(formData.isWcs) }
|
: {}),
|
wcsData: normalizeText(formData.wcsData) || '',
|
...(normalizePlainIdArray(formData.containerTypes).length
|
? { containerTypes: normalizePlainIdArray(formData.containerTypes) }
|
: {}),
|
barcode: normalizeText(formData.barcode) || '',
|
...(formData.autoTransfer !== void 0 && formData.autoTransfer !== null && formData.autoTransfer !== ''
|
? { autoTransfer: Number(formData.autoTransfer) }
|
: {}),
|
...(formData.inAble !== void 0 && formData.inAble !== null && formData.inAble !== ''
|
? { inAble: Number(formData.inAble) }
|
: {}),
|
...(formData.outAble !== void 0 && formData.outAble !== null && formData.outAble !== ''
|
? { outAble: Number(formData.outAble) }
|
: {}),
|
status:
|
formData.status !== void 0 && formData.status !== null && formData.status !== ''
|
? Number(formData.status)
|
: 1,
|
memo: normalizeText(formData.memo) || ''
|
}
|
}
|
|
export function createBasStationDialogModel(record = {}) {
|
return {
|
...createBasStationFormState(),
|
...(record.id !== void 0 && record.id !== null && record.id !== '' ? { id: Number(record.id) } : {}),
|
stationName: normalizeText(record.stationName || ''),
|
stationId: normalizeText(record.stationId || ''),
|
type:
|
record.type !== void 0 && record.type !== null && record.type !== ''
|
? Number(record.type)
|
: 0,
|
area:
|
record.area !== void 0 && record.area !== null && record.area !== ''
|
? Number(record.area)
|
: void 0,
|
useStatus: normalizeText(record.useStatus || record.useStatus$ || ''),
|
isCrossZone:
|
record.isCrossZone !== void 0 && record.isCrossZone !== null && record.isCrossZone !== ''
|
? Number(record.isCrossZone)
|
: 0,
|
areaIds: normalizeIdArray(record.areaIds ?? record.crossZoneArea ?? []),
|
isWcs:
|
record.isWcs !== void 0 && record.isWcs !== null && record.isWcs !== ''
|
? Number(record.isWcs)
|
: 0,
|
wcsData: normalizeText(record.wcsData || ''),
|
containerTypes: normalizePlainIdArray(record.containerTypes ?? record.containerType ?? record.containerTypes$ ?? []),
|
barcode: normalizeText(record.barcode || ''),
|
autoTransfer:
|
record.autoTransfer !== void 0 && record.autoTransfer !== null && record.autoTransfer !== ''
|
? Number(record.autoTransfer)
|
: 0,
|
inAble: record.inAble !== void 0 && record.inAble !== null && record.inAble !== '' ? Number(record.inAble) : 0,
|
outAble:
|
record.outAble !== void 0 && record.outAble !== null && record.outAble !== ''
|
? Number(record.outAble)
|
: 0,
|
status: record.status !== void 0 && record.status !== null ? Number(record.status) : 1,
|
memo: normalizeText(record.memo || '')
|
}
|
}
|
|
export const buildBasStationDialogModel = createBasStationDialogModel
|
|
export function resolveBasStationAreaOptions(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 buildBasStationContainerTypeOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.value ?? item.id ?? item.dictValue
|
if (value === void 0 || value === null || value === '') {
|
return null
|
}
|
return {
|
value: Number(value),
|
label: normalizeText(item.label || item.name || item.dictLabel || item.value || '')
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function buildBasStationUseStatusOptions(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records
|
.map((item) => {
|
if (!item || typeof item !== 'object') {
|
return null
|
}
|
const value = item.value ?? item.id ?? item.dictValue
|
if (value === void 0 || value === null || value === '') {
|
return null
|
}
|
return {
|
value: normalizeText(value),
|
label: normalizeText(item.label || item.name || item.dictLabel || item.value || '')
|
}
|
})
|
.filter(Boolean)
|
}
|
|
function buildIdLabelText(records = [], resolveLabel, fallbackPrefix) {
|
if (!Array.isArray(records) || !records.length) {
|
return ''
|
}
|
const labels = records
|
.map((item) => {
|
if (item === null || item === undefined || item === '') {
|
return ''
|
}
|
const id = typeof item === 'object' ? item.id ?? item.areaId ?? item.value : item
|
if (typeof resolveLabel === 'function') {
|
const resolvedLabel = normalizeText(resolveLabel(id))
|
if (resolvedLabel) {
|
return resolvedLabel
|
}
|
}
|
if (typeof item === 'object') {
|
return normalizeText(item.name || item.areaName || item.label || item.code || item.areaCode || id)
|
}
|
return normalizeText(`${fallbackPrefix} ${id}`)
|
})
|
.filter(Boolean)
|
return labels.join('、')
|
}
|
|
function buildArrayText(records = [], resolveLabel, fallbackPrefix) {
|
if (!Array.isArray(records) || !records.length) {
|
return ''
|
}
|
return records
|
.map((item) => {
|
const id = typeof item === 'object' ? item.id ?? item.value : item
|
if (typeof resolveLabel === 'function') {
|
const resolved = normalizeText(resolveLabel(id))
|
if (resolved) {
|
return resolved
|
}
|
}
|
if (typeof item === 'object') {
|
return normalizeText(item.label || item.name || item.dictLabel || item.value || id)
|
}
|
return normalizeText(`${fallbackPrefix} ${id}`)
|
})
|
.filter(Boolean)
|
.join('、')
|
}
|
|
export function normalizeBasStationDetailRecord(record = {}, resolveAreaLabel, resolveContainerTypeLabel) {
|
const areaIds = normalizeIdArray(record.areaIds ?? record.crossZoneArea ?? [])
|
const containerTypes = normalizePlainIdArray(record.containerTypes ?? record.containerType ?? record.containerTypes$ ?? [])
|
const statusMeta = getBasStationStatusMeta(record.statusBool ?? record.status)
|
const typeMeta = getBasStationTypeMeta(record.type)
|
const useStatusMeta = getBasStationUseStatusMeta(record.useStatus$ || record.useStatus)
|
|
return {
|
...record,
|
stationName: normalizeText(record.stationName || ''),
|
stationId: normalizeText(record.stationId || ''),
|
type: record.type !== void 0 && record.type !== null && record.type !== '' ? Number(record.type) : void 0,
|
typeText: typeMeta.text,
|
useStatus: normalizeText(record.useStatus || record.useStatus$ || ''),
|
useStatusText: useStatusMeta.text,
|
area: record.area !== void 0 && record.area !== null && record.area !== '' ? Number(record.area) : void 0,
|
areaText: normalizeText(resolveAreaLabel?.(record.area) || record.area$ || record.areaName || ''),
|
areaIds,
|
crossZoneAreaText: buildIdLabelText(areaIds, resolveAreaLabel, '库区'),
|
isCrossZone: record.isCrossZone !== void 0 && record.isCrossZone !== null && record.isCrossZone !== ''
|
? Number(record.isCrossZone)
|
: void 0,
|
isCrossZoneText: getBasStationBooleanMeta(record.isCrossZone).text,
|
isWcs: record.isWcs !== void 0 && record.isWcs !== null && record.isWcs !== ''
|
? Number(record.isWcs)
|
: void 0,
|
isWcsText: getBasStationBooleanMeta(record.isWcs).text,
|
wcsData: normalizeText(record.wcsData || ''),
|
containerTypes,
|
containerTypesText: buildArrayText(containerTypes, resolveContainerTypeLabel, '容器类型'),
|
barcode: normalizeText(record.barcode || ''),
|
autoTransfer: record.autoTransfer !== void 0 && record.autoTransfer !== null && record.autoTransfer !== ''
|
? Number(record.autoTransfer)
|
: void 0,
|
autoTransferText: getBasStationBooleanMeta(record.autoTransfer).text,
|
inAble: record.inAble !== void 0 && record.inAble !== null && record.inAble !== ''
|
? Number(record.inAble)
|
: void 0,
|
inAbleText: getBasStationBooleanMeta(record.inAble).text,
|
outAble: record.outAble !== void 0 && record.outAble !== null && record.outAble !== ''
|
? Number(record.outAble)
|
: void 0,
|
outAbleText: getBasStationBooleanMeta(record.outAble).text,
|
statusText: statusMeta.text,
|
statusType: statusMeta.type,
|
statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool,
|
stationAlias: Array.isArray(record.stationAlias) ? [...record.stationAlias] : record.stationAlias,
|
stationAliasText: Array.isArray(record.stationAlias)
|
? record.stationAlias.map((item) => normalizeText(item)).filter(Boolean).join('、')
|
: normalizeText(record.stationAlias || record.stationAlias$ || ''),
|
productionLineCode: normalizeText(record.productionLineCode || ''),
|
productionLineName: normalizeText(record.productionLineName || ''),
|
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 normalizeBasStationListRow(record = {}, resolveAreaLabel, resolveContainerTypeLabel) {
|
return normalizeBasStationDetailRecord(record, resolveAreaLabel, resolveContainerTypeLabel)
|
}
|
|
export function buildBasStationPrintRows(records = [], resolveAreaLabel, resolveContainerTypeLabel) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
return records.map((record) => normalizeBasStationListRow(record, resolveAreaLabel, resolveContainerTypeLabel))
|
}
|
|
export function buildBasStationReportMeta({
|
previewMeta = {},
|
count = 0,
|
orientation = BAS_STATION_REPORT_STYLE.orientation
|
} = {}) {
|
return {
|
reportTitle: BAS_STATION_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
...BAS_STATION_REPORT_STYLE,
|
orientation
|
}
|
}
|
}
|