38 lines
1.2 KiB
TypeScript
38 lines
1.2 KiB
TypeScript
/** 设备 ID 列表与逗号字符串互转(与 sopIds 一致,不含空格) */
|
|
export function parseEquipmentIds(value: string | string[] | null | undefined): string[] {
|
|
if (!value) return []
|
|
if (Array.isArray(value)) return value.filter(Boolean)
|
|
return String(value)
|
|
.split(',')
|
|
.map((s) => s.trim())
|
|
.filter(Boolean)
|
|
}
|
|
|
|
export function joinEquipmentIds(ids: string[] | null | undefined): string {
|
|
return (ids || []).filter(Boolean).join(',')
|
|
}
|
|
|
|
export function equipmentOptionLabel(row: {
|
|
equipmentCode?: string
|
|
equipmentName?: string
|
|
}) {
|
|
const code = row.equipmentCode || ''
|
|
const name = row.equipmentName || ''
|
|
return code && name ? `${code} / ${name}` : name || code || '-'
|
|
}
|
|
|
|
/** 根据所选 ID 列表,从选项中拼出名称快照(逗号分隔) */
|
|
export function syncEquipmentNamesFromOptions(
|
|
equipmentIds: string[] | null | undefined,
|
|
options: Array<{ id?: string; equipmentName?: string; equipmentCode?: string }>
|
|
) {
|
|
return parseEquipmentIds(equipmentIds || [])
|
|
.map((id) => {
|
|
const eq = options.find((item) => item.id === id)
|
|
if (!eq) return ''
|
|
return (eq.equipmentName || '').trim() || eq.equipmentCode || ''
|
|
})
|
|
.filter(Boolean)
|
|
.join(',')
|
|
}
|