diff --git a/App.jsx b/App.jsx index 31a0555..e7e51c9 100644 --- a/App.jsx +++ b/App.jsx @@ -5210,6 +5210,12 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, const maxKW = computeMaxPowerKW(draft.ratedPower, draft.ratedPowerUnit, draft.powerFactor); const extraNames = draft.extraNames || []; const [imageUploading, setImageUploading] = useState(false); + const [dragExtraSpecIdx, setDragExtraSpecIdx] = useState(null); + function handleExtraSpecDrop(dropIdx) { + if (dragExtraSpecIdx === null || dragExtraSpecIdx === dropIdx) { setDragExtraSpecIdx(null); return; } + set({ extraSpecs: reorderArray(draft.extraSpecs || [], dragExtraSpecIdx, dropIdx) }); + setDragExtraSpecIdx(null); + } async function handleImagePick(file) { if (!file) return; setImageUploading(true); @@ -5263,18 +5269,27 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, }); } } - function updateOutputPort(t, patch) { - set({ outputPorts: (draft.outputPorts || []).map(p => (p.type === t ? { ...p, ...patch } : p)) }); + // 各输出口那份列表按数组下标操作(不再靠type字段去重定位),这样同一个type(比如多个"DC"口, + // 电压不同)可以并存多行,用户可以自由增加/删除/改类型名,不受"输出口类型"勾选框数量限制。 + function updateOutputPortAt(idx, patch) { + set({ outputPorts: (draft.outputPorts || []).map((p, i) => (i === idx ? { ...p, ...patch } : p)) }); + } + function addOutputPort() { + const lastType = (draft.outputPorts && draft.outputPorts.length) ? draft.outputPorts[draft.outputPorts.length - 1].type : 'DC'; + set({ outputPorts: [...(draft.outputPorts || []), { type: lastType, voltage: '', current: '' }] }); + } + function removeOutputPortAt(idx) { + set({ outputPorts: (draft.outputPorts || []).filter((_, i) => i !== idx) }); } // 失焦时自动补单位:纯数字才补(比如"5"变"5Vdc"、"2.4"变"2.4A"), // 如果用户已经手动填了完整格式(比如POE常见的"24Vdc/48Vdc"),保持原样不动,避免破坏。 - function normalizeOutputVoltageOnBlur(t, rawValue) { + function normalizeOutputVoltageOnBlur(idx, rawValue) { const trimmed = (rawValue || '').trim(); - if (/^\d+(\.\d+)?$/.test(trimmed)) updateOutputPort(t, { voltage: trimmed + 'Vdc' }); + if (/^\d+(\.\d+)?$/.test(trimmed)) updateOutputPortAt(idx, { voltage: trimmed + 'Vdc' }); } - function normalizeOutputCurrentOnBlur(t, rawValue) { + function normalizeOutputCurrentOnBlur(idx, rawValue) { const trimmed = (rawValue || '').trim(); - if (/^\d+(\.\d+)?$/.test(trimmed)) updateOutputPort(t, { current: trimmed + 'A' }); + if (/^\d+(\.\d+)?$/.test(trimmed)) updateOutputPortAt(idx, { current: trimmed + 'A' }); } return (
@@ -5643,18 +5658,22 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage, ))}
- {(draft.outputPorts || []).length > 0 && ( -
- 各输出口的输出电压 / 电流 - {draft.outputPorts.map(p => ( -
-
{p.type}
- 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)} /> -
- ))} -
- )} +
+ 各输出口的输出电压 / 电流 + {(draft.outputPorts || []).map((p, idx) => ( +
+ updateOutputPortAt(idx, { type: e.target.value })} + placeholder="类型" + /> + updateOutputPortAt(idx, { voltage: e.target.value })} onBlur={e => normalizeOutputVoltageOnBlur(idx, e.target.value)} /> + updateOutputPortAt(idx, { current: e.target.value })} onBlur={e => normalizeOutputCurrentOnBlur(idx, e.target.value)} /> + +
+ ))} + +
尺寸(mm) set({ dimensions: spaceToAsterisk(e.target.value) })} placeholder="如:210*130*40" />
净重(kg) set({ netWeight: e.target.value })} placeholder="如:0.73" />
@@ -5730,9 +5749,18 @@ function ProductForm({ draft, setDraft, onSave, onCancel, categories, onManage,
- 其他参数(AI识别到、但暂未收录成正式字段的参数,原样保留,也会显示在详情页和多语言PDF导出里) + 其他参数(AI识别到、但暂未收录成正式字段的参数,原样保留,也会显示在详情页和多语言PDF导出里;拖动左侧圆点可调整顺序) {(draft.extraSpecs || []).map((item, idx) => ( -
+
setDragExtraSpecIdx(idx)} + onDragOver={e => e.preventDefault()} + onDrop={() => handleExtraSpecDrop(idx)} + onDragEnd={() => setDragExtraSpecIdx(null)} + > +