重构:统一文件类型配置管理,移除重复硬编码
新增: - 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:
@@ -118,6 +118,11 @@ export function useFilePreview(options: UseFilePreviewOptions = {}) {
|
||||
return 'Code' as FileType
|
||||
}
|
||||
|
||||
// 配置文件(返回 Code 类型,因为它们也是可编辑的文本格式)
|
||||
if (FILE_EXTENSIONS.CONFIG.includes(ext)) {
|
||||
return 'Code' as FileType
|
||||
}
|
||||
|
||||
// 文本
|
||||
if (FILE_EXTENSIONS.TEXT.includes(ext)) {
|
||||
return 'Text' as FileType
|
||||
@@ -227,7 +232,8 @@ export function useFilePreview(options: UseFilePreviewOptions = {}) {
|
||||
const ext = filename.split('.').pop()?.toLowerCase() || ''
|
||||
return FILE_EXTENSIONS.CODE.includes(ext) ||
|
||||
FILE_EXTENSIONS.TEXT.includes(ext) ||
|
||||
['html', 'htm', 'md', 'markdown', 'json', 'xml'].includes(ext)
|
||||
FILE_EXTENSIONS.CONFIG.includes(ext) ||
|
||||
['html', 'htm', 'md', 'markdown'].includes(ext)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user