Update App.jsx via upload script - 2026-07-24 10:50:36
This commit is contained in:
parent
22b4033253
commit
e3121d945b
14
App.jsx
14
App.jsx
|
|
@ -3034,6 +3034,16 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage }
|
||||||
function updateOutputPort(t, patch) {
|
function updateOutputPort(t, patch) {
|
||||||
set({ outputPorts: (draft.outputPorts || []).map(p => (p.type === t ? { ...p, ...patch } : p)) });
|
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 (
|
return (
|
||||||
<div className="panel">
|
<div className="panel">
|
||||||
<div className="panel-header"><div className="panel-title"><Edit2 size={14} />{draft.name ? '编辑产品' : '新建产品'}</div></div>
|
<div className="panel-header"><div className="panel-title"><Edit2 size={14} />{draft.name ? '编辑产品' : '新建产品'}</div></div>
|
||||||
|
|
@ -3173,8 +3183,8 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage }
|
||||||
{draft.outputPorts.map(p => (
|
{draft.outputPorts.map(p => (
|
||||||
<div key={p.type} style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 6 }}>
|
<div key={p.type} style={{ display: 'flex', gap: 8, alignItems: 'center', marginBottom: 6 }}>
|
||||||
<div style={{ width: 90, fontSize: 12.5, fontWeight: 700, flexShrink: 0 }}>{p.type}</div>
|
<div style={{ width: 90, fontSize: 12.5, fontWeight: 700, flexShrink: 0 }}>{p.type}</div>
|
||||||
<input className="input" style={{ flex: 1 }} placeholder="输出电压,如 5Vdc" value={p.voltage} onChange={e => updateOutputPort(p.type, { voltage: e.target.value })} />
|
<input className="input" style={{ flex: 1 }} value={p.voltage} onChange={e => updateOutputPort(p.type, { voltage: e.target.value })} onBlur={e => normalizeOutputVoltageOnBlur(p.type, e.target.value)} />
|
||||||
<input className="input" style={{ flex: 1 }} placeholder="电流,如 3.0A" value={p.current} onChange={e => updateOutputPort(p.type, { current: e.target.value })} />
|
<input className="input" style={{ flex: 1 }} value={p.current} onChange={e => updateOutputPort(p.type, { current: e.target.value })} onBlur={e => normalizeOutputCurrentOnBlur(p.type, e.target.value)} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue