fix: 窗口选择器从循环confirm改为弹出列表modal, 用户可一次看到所有窗口并点击选择

This commit is contained in:
yu 2026-11-03 14:11:38 +08:00
parent 4a3e6e38c7
commit 6bf8e90c63

View File

@ -511,6 +511,8 @@ function FieldControl({
}) {
const raw = node.values[field.key] ?? field.defaultValue;
const [picking, setPicking] = useState(false);
const [windowList, setWindowList] = useState<{ title: string; process?: string }[]>([]);
const [windowPickerField, setWindowPickerField] = useState<string | null>(null);
const isGroundTarget = node.componentId.endsWith("Ground");
const isVisionSource = /^(OcrOffline_|CV_|Image_)/.test(node.componentId);
const isWindowTarget = /^(Window_|System_ConnectRemoteDesktop)/.test(node.componentId);
@ -636,16 +638,8 @@ function FieldControl({
onToast("未找到可见窗口", "error");
return;
}
for (let wi = 0; wi < list.length; wi++) {
const w = list[wi] as { title: string; process?: string };
const ok = confirm(`窗口 ${wi + 1}/${list.length}:${w.title}(${w.process ?? "未知"})\n\n确定选这个窗口?取消看下一个`);
if (ok) {
onChange(field.key, w.title);
onToast("已选择窗口:" + w.title);
return;
}
}
onToast("未选择窗口");
setWindowList(list as { title: string; process?: string }[]);
setWindowPickerField(field.key);
}
catch (error) {
onToast(error instanceof Error ? error.message : String(error), "error");
@ -704,6 +698,7 @@ function FieldControl({
const hint = field.description || fallbackHint;
return (
<>
<div className="field">
<label className="field-label">
{field.label}
@ -976,6 +971,26 @@ function FieldControl({
<span className="field-hint mono">{field.valueTypes.join(" · ")}</span>
)}
</div>
{windowPickerField && (
<div style={{ position: "fixed", inset: 0, zIndex: 9999, background: "rgba(0,0,0,0.4)", display: "flex", alignItems: "center", justifyContent: "center" }} onClick={() => setWindowPickerField(null)}>
<div style={{ background: "#fff", borderRadius: 8, padding: 16, minWidth: 360, maxHeight: 400, overflow: "auto", boxShadow: "0 4px 20px rgba(0,0,0,0.3)" }} onClick={(e) => e.stopPropagation()}>
<div style={{ fontSize: 14, fontWeight: 600, marginBottom: 12 }}>选择窗口</div>
{windowList.map((w, i) => (
<button key={i} type="button" style={{ display: "block", width: "100%", textAlign: "left", padding: "8px 12px", border: "1px solid #ddd", borderRadius: 6, marginBottom: 6, cursor: "pointer", background: "#fafafa", fontSize: 13 }}
onClick={() => {
if (windowPickerField) onChange(windowPickerField, w.title);
onToast("已选择窗口:" + w.title);
setWindowPickerField(null);
}}>
<div style={{ fontWeight: 500 }}>{w.title || "(无标题)"}</div>
{w.process && <div style={{ fontSize: 11, color: "#888" }}>{w.process}</div>}
</button>
))}
</div>
</div>
)}
</>
);
}