From b1fc8c25b85eb15ceb4cef4165670956247d0642 Mon Sep 17 00:00:00 2001 From: yu <191972707@qq.com> Date: Mon, 2 Nov 2026 14:15:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=96=87=E4=BB=B6=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E5=AF=B9=E8=AF=9D=E6=A1=86=E8=BF=87=E6=BB=A4=E5=99=A8=E6=8C=89?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=8A=E4=B8=8B=E6=96=87=E6=99=BA=E8=83=BD?= =?UTF-8?q?=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 原先所有文件选择框都写死 Excel 过滤器, 选图片/PDF/Word 等均显示 Excel 类型, 且无法直接看到目标文件 - 现按 字段键/标签关键词 + 组件类别 推导: Excel/Word/PDF/图片/压缩/音频/视频/JSON 各归其类, 均附带「全部文件」兜底 - 无法识别的字段退回「全部文件」; 目录选择不受影响 --- src/renderer/src/panels/Properties.tsx | 50 ++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/src/renderer/src/panels/Properties.tsx b/src/renderer/src/panels/Properties.tsx index 8eb788c..967fb96 100644 --- a/src/renderer/src/panels/Properties.tsx +++ b/src/renderer/src/panels/Properties.tsx @@ -438,6 +438,49 @@ function PropertyTab({ ); } +interface FileFilterOption { + name: string; + extensions: string[]; +} + +/** + * 按组件与字段上下文推导文件选择对话框的类型过滤器。 + * 先匹配字段本身的含义(字段键/标签),再匹配组件类别;无法识别时退回「全部文件」。 + */ +function fileFiltersFor(componentId: string, field: CatalogField): FileFilterOption[] { + const haystack = `${componentId} ${field.key} ${field.label ?? ""}`; + const filters: FileFilterOption[] = []; + if (/excel|bivartable|databook|工作簿|表格/i.test(haystack)) { + filters.push({ name: "Excel 表格", extensions: ["xlsx", "xlsm", "xls", "csv"] }); + } + if (/word|文档/i.test(haystack)) { + filters.push({ name: "Word 文档", extensions: ["docx", "doc"] }); + } + if (/pdf/i.test(haystack)) { + filters.push({ name: "PDF 文档", extensions: ["pdf"] }); + } + if (/image|ocr|CV_|vision|图片|图像|截图|模板|照片/i.test(haystack)) { + filters.push({ name: "图片文件", extensions: ["png", "jpg", "jpeg", "bmp", "gif", "webp"] }); + } + if (/zip|compress|archive|压缩/i.test(haystack)) { + filters.push({ name: "压缩文件", extensions: ["zip", "rar", "7z", "gz"] }); + } + if (/audio|speech|音频|语音|录音/i.test(haystack)) { + filters.push({ name: "音频文件", extensions: ["wav", "mp3", "flac", "ogg"] }); + } + if (/video|视频/i.test(haystack)) { + filters.push({ name: "视频文件", extensions: ["mp4", "avi", "mkv", "mov"] }); + } + if (/json/i.test(haystack)) { + filters.push({ name: "JSON 文件", extensions: ["json"] }); + } + if (!filters.length) { + return [{ name: "全部文件", extensions: ["*"] }]; + } + filters.push({ name: "全部文件", extensions: ["*"] }); + return filters; +} + function FieldControl({ field, node, @@ -486,12 +529,7 @@ function FieldControl({ const selected = await window.rpa.dialog.open({ title: field.label, directories, - filters: directories - ? undefined - : [ - { name: "Excel", extensions: ["xlsx", "xlsm", "xls"] }, - { name: "全部文件", extensions: ["*"] } - ] + filters: directories ? undefined : fileFiltersFor(node.componentId, field) }); if (selected) onChange(field.key, selected); } catch (error) {