mirror of
https://github.com/jxxghp/MoviePilot-Frontend.git
synced 2026-09-05 15:36:49 +08:00
feat: add wildcard glob support to file manager filter (#467)
This commit is contained in:
@@ -119,6 +119,15 @@ const dropdownItems = ref<{ [key: string]: any }[]>([])
|
|||||||
// 进度是否激活
|
// 进度是否激活
|
||||||
const progressActive = ref(false)
|
const progressActive = ref(false)
|
||||||
|
|
||||||
|
// 将 glob 模式转换为正则表达式
|
||||||
|
function globToRegex(pattern: string, flags: string = ''): RegExp {
|
||||||
|
const regexStr = pattern
|
||||||
|
.replace(/[.+^${}()|[\]\\]/g, '\\$&')
|
||||||
|
.replace(/\*/g, '.*')
|
||||||
|
.replace(/\?/g, '.')
|
||||||
|
return new RegExp(`^${regexStr}$`, flags)
|
||||||
|
}
|
||||||
|
|
||||||
// 通用过滤
|
// 通用过滤
|
||||||
const getFilteredItems = (type: 'dir' | 'file') => {
|
const getFilteredItems = (type: 'dir' | 'file') => {
|
||||||
const filterValue = filter.value
|
const filterValue = filter.value
|
||||||
@@ -126,11 +135,19 @@ const getFilteredItems = (type: 'dir' | 'file') => {
|
|||||||
return items.value.filter(item => item.type === type)
|
return items.value.filter(item => item.type === type)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 通配符模式
|
||||||
|
if (filterValue.includes('*') || filterValue.includes('?')) {
|
||||||
|
const flags = ignoreCase.value ? 'i' : ''
|
||||||
|
const regex = globToRegex(filterValue, flags)
|
||||||
|
return items.value.filter(item => item.type === type && regex.test(item.name ?? ''))
|
||||||
|
}
|
||||||
|
|
||||||
|
// 子字符串模式
|
||||||
if (ignoreCase.value) {
|
if (ignoreCase.value) {
|
||||||
const lowerCaseFilter = filterValue.toLowerCase()
|
const lowerCaseFilter = filterValue.toLowerCase()
|
||||||
return items.value.filter(item => item.type === type && item.name.toLowerCase().includes(lowerCaseFilter))
|
return items.value.filter(item => item.type === type && (item.name ?? '').toLowerCase().includes(lowerCaseFilter))
|
||||||
} else {
|
} else {
|
||||||
return items.value.filter(item => item.type === type && item.name.includes(filterValue))
|
return items.value.filter(item => item.type === type && (item.name ?? '').includes(filterValue))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -639,8 +656,8 @@ onUnmounted(() => {
|
|||||||
flat
|
flat
|
||||||
density="compact"
|
density="compact"
|
||||||
variant="plain"
|
variant="plain"
|
||||||
:placeholder="t('common.search')"
|
:placeholder="t('file.filterPlaceholder')"
|
||||||
prepend-inner-icon="mdi-filter-outline"
|
:prepend-inner-icon="(filter.includes('*') || filter.includes('?')) ? 'mdi-asterisk' : 'mdi-filter-outline'"
|
||||||
class="mx-2"
|
class="mx-2"
|
||||||
rounded
|
rounded
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2727,6 +2727,7 @@ export default {
|
|||||||
close: 'Close',
|
close: 'Close',
|
||||||
loadingDirectoryStructure: 'Loading directory structure...',
|
loadingDirectoryStructure: 'Loading directory structure...',
|
||||||
reorganize: 'Reorganize',
|
reorganize: 'Reorganize',
|
||||||
|
filterPlaceholder: 'Filter (supports * ? wildcards)',
|
||||||
},
|
},
|
||||||
person: {
|
person: {
|
||||||
alias: 'Also Known As:',
|
alias: 'Also Known As:',
|
||||||
|
|||||||
@@ -2682,6 +2682,7 @@ export default {
|
|||||||
close: '关闭',
|
close: '关闭',
|
||||||
loadingDirectoryStructure: '加载目录结构...',
|
loadingDirectoryStructure: '加载目录结构...',
|
||||||
reorganize: '整理',
|
reorganize: '整理',
|
||||||
|
filterPlaceholder: '搜索(支持 * ? 通配符)',
|
||||||
},
|
},
|
||||||
person: {
|
person: {
|
||||||
alias: '别名:',
|
alias: '别名:',
|
||||||
|
|||||||
@@ -2684,6 +2684,7 @@ export default {
|
|||||||
close: '關閉',
|
close: '關閉',
|
||||||
loadingDirectoryStructure: '加載目錄結構...',
|
loadingDirectoryStructure: '加載目錄結構...',
|
||||||
reorganize: '整理',
|
reorganize: '整理',
|
||||||
|
filterPlaceholder: '搜尋(支援 * ? 萬用字元)',
|
||||||
},
|
},
|
||||||
person: {
|
person: {
|
||||||
alias: '別名:',
|
alias: '別名:',
|
||||||
|
|||||||
Reference in New Issue
Block a user