diff --git a/App.jsx b/App.jsx index 3997d4f..05b8a7d 100644 --- a/App.jsx +++ b/App.jsx @@ -3034,6 +3034,16 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage } function updateOutputPort(t, patch) { set({ outputPorts: (draft.outputPorts || []).map(p => (p.type === t ? { ...p, ...patch } : p)) }); } + // 失焦时自动补单位:纯数字才补(比如"5"变"5Vdc"、"2.4"变"2.4A"), + // 如果用户已经手动填了完整格式(比如POE常见的"24Vdc/48Vdc"),保持原样不动,避免破坏。 + function normalizeOutputVoltageOnBlur(t, rawValue) { + const trimmed = (rawValue || '').trim(); + if (/^\d+(\.\d+)?$/.test(trimmed)) updateOutputPort(t, { voltage: trimmed + 'Vdc' }); + } + function normalizeOutputCurrentOnBlur(t, rawValue) { + const trimmed = (rawValue || '').trim(); + if (/^\d+(\.\d+)?$/.test(trimmed)) updateOutputPort(t, { current: trimmed + 'A' }); + } return (
{draft.name ? '编辑产品' : '新建产品'}
@@ -3173,8 +3183,8 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage } {draft.outputPorts.map(p => (
{p.type}
- updateOutputPort(p.type, { voltage: e.target.value })} /> - updateOutputPort(p.type, { current: e.target.value })} /> + updateOutputPort(p.type, { voltage: e.target.value })} onBlur={e => normalizeOutputVoltageOnBlur(p.type, e.target.value)} /> + updateOutputPort(p.type, { current: e.target.value })} onBlur={e => normalizeOutputCurrentOnBlur(p.type, e.target.value)} />
))}