fix: 文件选择对话框过滤器按字段上下文智能匹配
- 原先所有文件选择框都写死 Excel 过滤器, 选图片/PDF/Word 等均显示 Excel 类型, 且无法直接看到目标文件 - 现按 字段键/标签关键词 + 组件类别 推导: Excel/Word/PDF/图片/压缩/音频/视频/JSON 各归其类, 均附带「全部文件」兜底 - 无法识别的字段退回「全部文件」; 目录选择不受影响
This commit is contained in:
parent
1c85a90f1f
commit
b1fc8c25b8
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user