Private
Public Access
1
0

重构:统一文件类型配置管理,移除重复硬编码

新增:
- constants.js 添加 CONFIG 数组(json、xml、yaml、toml、ini、cfg、conf、props、env 等)
- fileTypeHelpers.js 添加 isConfigFile() 函数

优化:
- 移除 6 处重复的文件类型硬编码
- 统一使用 FILE_EXTENSIONS.CONFIG
- 移除 3 处重复的 isOfficeFile() 定义

修改文件:
- web/src/utils/constants.js
- web/src/utils/fileTypeHelpers.js
- web/src/components/FileSystem/composables/useFileEdit.ts
- web/src/components/FileSystem/composables/useFilePreview.ts
- web/src/components/FileSystem/components/ContextMenu.vue
- web/src/composables/useFilePreview.js
This commit is contained in:
2026-02-04 12:37:09 +08:00
parent edd5b7c869
commit ce2698f245
6 changed files with 48 additions and 30 deletions

View File

@@ -73,11 +73,23 @@ export const FILE_EXTENSIONS = {
CODE: [
'js', 'ts', 'jsx', 'tsx', 'cts', 'mts', 'cjs', 'mjs',
'vue', 'py', 'java', 'c', 'cpp', 'h', 'go', 'rs', 'php', 'rb', 'cs', 'swift', 'kt',
'scala', 'css', 'scss', 'sass', 'less', 'json', 'xml', 'yaml', 'yml', 'sql', 'sh', 'bat', 'ps1',
'flow', 'props', 'pch', 'cc', 'cxx', 'hpp', 'hxx', 'tcc', 'defs', 'makefile', 'mk', 'cmake',
'scala', 'css', 'scss', 'sass', 'less', 'sql', 'sh', 'bat', 'ps1',
'flow', 'pch', 'cc', 'cxx', 'hpp', 'hxx', 'tcc', 'defs', 'makefile', 'mk', 'cmake',
'tex', 'm', 'r', 'matlab', 'latex', 'rst', 'adoc'
],
// 配置文件(可编辑的文本格式)
CONFIG: [
// 数据格式
'json', 'xml', 'yaml', 'yml',
// 配置文件
'toml', 'ini', 'cfg', 'conf',
// 环境变量/属性
'props', 'env', 'dotenv',
// 其他
'manifest', 'lock', 'ignore'
],
// 纯文本文件
TEXT: ['txt', 'text', 'log', 'md', 'markdown', 'rst', 'adoc', 'tex', 'msg', 'csv', 'tsv'],
@@ -193,6 +205,17 @@ const initIconMap = () => {
// 代码文件(通用)
FILE_EXTENSIONS.CODE.forEach(ext => FILE_ICON_MAP.set(ext, FILE_ICONS.CODE))
// 配置文件(使用特定图标)
const configIcons = {
'json': FILE_ICONS.JSON,
'xml': FILE_ICONS.XML,
'yaml': FILE_ICONS.YAML,
'yml': FILE_ICONS.YAML
}
FILE_EXTENSIONS.CONFIG.forEach(ext => {
FILE_ICON_MAP.set(ext, configIcons[ext] || FILE_ICONS.YAML)
})
// 编程语言特定图标
const langIcons = {
// Java
@@ -219,11 +242,6 @@ const initIconMap = () => {
'scss': FILE_ICONS.CSS,
'sass': FILE_ICONS.CSS,
'less': FILE_ICONS.CSS,
// Data
'json': FILE_ICONS.JSON,
'xml': FILE_ICONS.XML,
'yaml': FILE_ICONS.YAML,
'yml': FILE_ICONS.YAML,
// Shell
'sh': FILE_ICONS.SHELL,
'bash': FILE_ICONS.SHELL,