From f28b5ffc5e1abf8c0d915ec09641d0ea38eb7e4b Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Fri, 30 Oct 2026 11:26:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B5=8F=E8=A7=88=E5=99=A8=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=AD=97=E6=AE=B5=E6=94=B9=E4=B8=BA=E4=B8=8B=E6=8B=89?= =?UTF-8?q?=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - catalog.json: WebBrowser_Create/V2/V3/CreateBackground 的 type 字段补 options(内置运行浏览器/Chrome/Edge,label 与存储值分离) - shared/types.ts: CatalogField.options 支持字符串或 {label,value} 对象 - Properties.tsx: select/radio 选项归一化渲染 label;当前值不在选项中时追加显示(兼容历史手填值如 zexplorer) - typecheck 通过;全量 vitest 除 4 项依赖真实 COM 的历史失败外全部通过 --- resources/catalog.json | 66 ++++++++++++++++++++++++-- src/renderer/src/panels/Properties.tsx | 33 +++++++++---- src/shared/types.ts | 3 +- 3 files changed, 88 insertions(+), 14 deletions(-) diff --git a/resources/catalog.json b/resources/catalog.json index 2a428a3..02d1313 100644 --- a/resources/catalog.json +++ b/resources/catalog.json @@ -100005,7 +100005,21 @@ "placeholder": "", "description": "", "advanced": false, - "valueTypes": [] + "valueTypes": [], + "options": [ + { + "label": "内置运行浏览器", + "value": "zexplorer" + }, + { + "label": "Chrome 浏览器", + "value": "chrome" + }, + { + "label": "Edge 浏览器", + "value": "edge" + } + ] }, { "key": "url", @@ -101046,7 +101060,21 @@ "placeholder": "", "description": "选择浏览器类型", "advanced": false, - "valueTypes": [] + "valueTypes": [], + "options": [ + { + "label": "内置运行浏览器", + "value": "zexplorer" + }, + { + "label": "Chrome 浏览器", + "value": "chrome" + }, + { + "label": "Edge 浏览器", + "value": "edge" + } + ] }, { "key": "url", @@ -103389,7 +103417,21 @@ "placeholder": "", "description": "选择浏览器类型", "advanced": false, - "valueTypes": [] + "valueTypes": [], + "options": [ + { + "label": "内置运行浏览器", + "value": "zexplorer" + }, + { + "label": "Chrome 浏览器", + "value": "chrome" + }, + { + "label": "Edge 浏览器", + "value": "edge" + } + ] }, { "key": "url", @@ -106333,7 +106375,21 @@ "placeholder": "", "description": "选择浏览器类型", "advanced": false, - "valueTypes": [] + "valueTypes": [], + "options": [ + { + "label": "内置运行浏览器", + "value": "zexplorer" + }, + { + "label": "Chrome 浏览器", + "value": "chrome" + }, + { + "label": "Edge 浏览器", + "value": "edge" + } + ] }, { "key": "url", @@ -113804,4 +113860,4 @@ "slots": [] } ] -} \ No newline at end of file +} diff --git a/src/renderer/src/panels/Properties.tsx b/src/renderer/src/panels/Properties.tsx index cc28ca0..c89f9d0 100644 --- a/src/renderer/src/panels/Properties.tsx +++ b/src/renderer/src/panels/Properties.tsx @@ -46,6 +46,23 @@ function numberOr(value: unknown, fallback: number): number { return Number.isFinite(parsed) ? parsed : fallback; } +interface SelectOption { + label: string; + value: string; +} + +/** 归一化下拉/单选选项:字符串 → {label,value};当前值不在选项中时追加进去(兼容历史手填值) */ +function selectOptionsWith(field: CatalogField, rawValue: unknown): SelectOption[] { + const normalized = (field.options ?? []).map((option): SelectOption => + typeof option === "string" ? { label: option, value: option } : { label: option.label, value: option.value } + ); + const current = textOf(rawValue); + if (current && !normalized.some((option) => option.value === current)) { + normalized.unshift({ label: `${current}(当前值)`, value: current }); + } + return normalized; +} + export function Properties({ catalog, onToast }: PropertiesProps) { const [tab, setTab] = useState("props"); const flow = useEditorStore((state) => state.flow); @@ -575,22 +592,22 @@ function FieldControl({ ) : field.widget === "select" && field.options?.length ? ( ) : field.widget === "radio" && field.options?.length ? (
- {field.options.map((option) => ( + {selectOptionsWith(field, raw).map((option) => ( ))}
diff --git a/src/shared/types.ts b/src/shared/types.ts index e174e55..c570bc9 100644 --- a/src/shared/types.ts +++ b/src/shared/types.ts @@ -25,7 +25,8 @@ export interface CatalogField { description: string; advanced: boolean; valueTypes: string[]; - options?: string[]; + /** 下拉/单选选项:字符串(显示=存储值)或 { label, value }(显示与存储分离) */ + options?: Array; unit?: string; }