fix: 限制手动比例输入
This commit is contained in:
@@ -656,6 +656,22 @@ export function ImageWorkbenchPage({
|
|||||||
const [ratioManual, setRatioManual] = useState(false);
|
const [ratioManual, setRatioManual] = useState(false);
|
||||||
const [ratioW, setRatioW] = useState("");
|
const [ratioW, setRatioW] = useState("");
|
||||||
const [ratioH, setRatioH] = useState("");
|
const [ratioH, setRatioH] = useState("");
|
||||||
|
const updateRatioDimension = (event: ChangeEvent<HTMLInputElement>, dimension: "width" | "height") => {
|
||||||
|
const value = event.target.value;
|
||||||
|
const next = value === "" || /^[1-9]\d*$/.test(value) ? value : "";
|
||||||
|
event.target.value = next;
|
||||||
|
|
||||||
|
if (dimension === "width") {
|
||||||
|
setRatioW(next);
|
||||||
|
if (next && ratioH) setRatio(`${next}:${ratioH}`);
|
||||||
|
} else {
|
||||||
|
setRatioH(next);
|
||||||
|
if (ratioW && next) setRatio(`${ratioW}:${next}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const blockNonIntegerKey = (event: React.KeyboardEvent<HTMLInputElement>) => {
|
||||||
|
if ([".", "+", "-", "e", "E"].includes(event.key)) event.preventDefault();
|
||||||
|
};
|
||||||
// 生图模型选择:默认火山(内衣等敏感品类不被审核拦,还原也更好),可切 gpt-image-2。持久化到 localStorage。
|
// 生图模型选择:默认火山(内衣等敏感品类不被审核拦,还原也更好),可切 gpt-image-2。持久化到 localStorage。
|
||||||
const [genModel, setGenModel] = useState<string>(() => {
|
const [genModel, setGenModel] = useState<string>(() => {
|
||||||
try { return localStorage.getItem(GEN_MODEL_KEY) || "volcano"; } catch { return "volcano"; }
|
try { return localStorage.getItem(GEN_MODEL_KEY) || "volcano"; } catch { return "volcano"; }
|
||||||
@@ -1954,26 +1970,22 @@ export function ImageWorkbenchPage({
|
|||||||
className="input"
|
className="input"
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
|
step={1}
|
||||||
placeholder="宽"
|
placeholder="宽"
|
||||||
value={ratioW}
|
value={ratioW}
|
||||||
onChange={(event) => {
|
onKeyDown={blockNonIntegerKey}
|
||||||
const w = event.target.value;
|
onChange={(event) => updateRatioDimension(event, "width")}
|
||||||
setRatioW(w);
|
|
||||||
if (w && ratioH) setRatio(`${w}:${ratioH}`);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
<span className="sep">:</span>
|
<span className="sep">:</span>
|
||||||
<input
|
<input
|
||||||
className="input"
|
className="input"
|
||||||
type="number"
|
type="number"
|
||||||
min={1}
|
min={1}
|
||||||
|
step={1}
|
||||||
placeholder="高"
|
placeholder="高"
|
||||||
value={ratioH}
|
value={ratioH}
|
||||||
onChange={(event) => {
|
onKeyDown={blockNonIntegerKey}
|
||||||
const h = event.target.value;
|
onChange={(event) => updateRatioDimension(event, "height")}
|
||||||
setRatioH(h);
|
|
||||||
if (ratioW && h) setRatio(`${ratioW}:${h}`);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user