fix: 桌面拾取按钮判定与重复函数清理

This commit is contained in:
yu 2026-10-29 16:38:11 +08:00
parent 0694bd45d3
commit c2b09f39e6

View File

@ -443,8 +443,10 @@ function FieldControl({
}) {
const raw = node.values[field.key] ?? field.defaultValue;
const [picking, setPicking] = useState(false);
const isVisionTarget = /^(OcrOffline_|CV_)/.test(node.componentId);
const isGroundTarget = node.componentId.endsWith("Ground");
const isVisionSource = /^(OcrOffline_|CV_|Image_)/.test(node.componentId);
const isWindowTarget = /^(Window_|System_ConnectRemoteDesktop)/.test(node.componentId);
const isVisionTarget = /^(OcrOffline_|CV_)/.test(node.componentId);
const insertVariable = (expression: string) => {
const current = textOf(raw).trim();
@ -452,6 +454,23 @@ function FieldControl({
onChange(field.key, current === "" || known ? expression : `${textOf(raw)}${expression}`);
};
const pickDesktop = async () => {
setPicking(true);
try {
const picked = await window.rpa.desktop.pickElement();
if (picked.cancelled) {
onToast("已取消拾取");
return;
}
onChange(field.key, picked.selector);
onToast("已拾取:" + (picked.name || picked.controlType || "元素"));
} catch (error) {
onToast(error instanceof Error ? error.message : String(error), "error");
} finally {
setPicking(false);
}
};
const pickPath = async (directories: boolean) => {
try {
const selected = await window.rpa.dialog.open({
@ -616,9 +635,15 @@ function FieldControl({
placeholder="css:#submit / aria:button"
onChange={(event) => onChange(field.key, event.target.value)}
/>
<button type="button" className="mini-btn" disabled={picking} onClick={() => void pickElement()} title="从运行浏览器拾取元素">
{isGroundTarget ? (
<button type="button" className="mini-btn" disabled={picking} onClick={() => void pickDesktop()} title="从桌面拾取元素(移到目标按空格)">
{picking ? "桌面拾取中" : "桌面拾取"}
</button>
) : (
<button type="button" className="mini-btn" disabled={picking} onClick={() => void pickElement()} title="从运行浏览器拾取元素">
{picking ? "拾取中" : "拾取"}
</button>
</button>
)}
</div>
) : field.widget === "secret" ? (
<div className="field-row">