/** 与后端 generate_uuid 一致:32 位大写、无连字符。子表行从创建起就带稳定 ID。 */ export function createStableRowId() { const uuid = typeof globalThis.crypto?.randomUUID === 'function' ? globalThis.crypto.randomUUID() : `${Date.now().toString(16)}${Math.random().toString(16).slice(2)}` return uuid.replace(/-/g, '').toUpperCase() } export function createStepOutputId() { return createStableRowId() } /** 工艺步骤「产出物」新增行:条码默认实验室入库编码。 */ export function createEmptyStepOutputRow(labStorageCode?: string | null) { return { id: createStepOutputId(), outputTypeId: '', outputName: '', outputBarcode: String(labStorageCode || '').trim(), remark: '' } } /** 保存步骤产出物:带上原行 ID,避免后端整表换 ID。 */ export function toStepOutputReplaceItem(row: Record) { const id = String(row.id || '').trim() || createStepOutputId() row.id = id return { id, output_type_id: row.outputTypeId, output_name: row.outputName, output_barcode: row.outputBarcode, remark: row.remark || '' } }