Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.
TypeScript albumsexif-extractiongeocodinglive-photomotion-photophoto-galleryphoto-sharingwebgl-viewer
feat(FilterPanel): 新增筛选面板和管理页面中的模糊搜索
Timothy Yin0a7816f77f86
diff --git a/app/components/overlay/FilterPanel.vue b/app/components/overlay/FilterPanel.vueindex 9bb4c077..0ba334b9 100644--- a/app/components/overlay/FilterPanel.vue+++ b/app/components/overlay/FilterPanel.vue@@ -12,6 +12,14 @@ const {} = usePhotoFilters()const currentTab = ref('labels')+const isSearchMode = ref(false)++const searchQuery = computed({+ get: () => activeFilters.value.search,+ set: (value: string) => {+ activeFilters.value.search = value+ },+})const selectedRating = computed({get: () => activeFilters.value.ratings,@@ -69,16 +77,48 @@ const handleToggleFilter = (type: string, value: string | number) => {<h3 class="text-sm font-bold text-neutral-900 dark:text-white p-2">{{ $t('ui.action.filter.title') }}</h3>- <UButton- v-if="hasActiveFilters"- size="sm"- variant="ghost"- color="neutral"- icon="tabler:filter-x"- @click="clearAllFilters"- >- {{ $t('ui.action.filter.clearAll') }}- </UButton>+ <div class="flex items-center gap-1">+ <UButton+ v-if="hasActiveFilters"+ size="sm"+ variant="ghost"+ color="neutral"+ icon="tabler:filter-x"+ @click="() => {+ clearAllFilters()+ isSearchMode = false+ searchQuery = ''+ }"+ >+ {{ $t('ui.action.filter.clearAll') }}+ </UButton>+ <!-- 搜索功能 -->+ <div v-if="isSearchMode" class="flex items-center gap-1">+ <UInput+ v-model="searchQuery"+ size="sm"+ icon="tabler:search"+ placeholder="搜索文件名等..."+ class="w-32"+ @keydown.escape="isSearchMode = false"+ />+ <UButton+ size="sm"+ variant="ghost"+ color="neutral"+ icon="tabler:x"+ @click="isSearchMode = false; searchQuery = ''"+ />+ </div>+ <UButton+ v-else+ size="sm"+ variant="ghost"+ color="neutral"+ icon="tabler:search"+ @click="isSearchMode = true"+ />+ </div></div><!-- 标签页 --><UTabsdiff --git a/app/composables/usePhotoFilters.ts b/app/composables/usePhotoFilters.tsindex f2416bf8..19a35410 100644--- a/app/composables/usePhotoFilters.ts+++ b/app/composables/usePhotoFilters.ts@@ -4,6 +4,7 @@ interface FilterOptions {lenses: string[]cities: string[]ratings: number // 改为单个数字,表示最低评分+ search: string // 搜索关键词}interface FilterStats {@@ -20,7 +21,8 @@ const globalFilters = ref<FilterOptions>({cameras: [],lenses: [],cities: [],- ratings: 0+ ratings: 0,+ search: ''})export function usePhotoFilters() {@@ -110,7 +112,8 @@ export function usePhotoFilters() {cameras: activeFilters.value.cameras.length,lenses: activeFilters.value.lenses.length,cities: activeFilters.value.cities.length,- ratings: activeFilters.value.ratings > 0 ? 1 : 0+ ratings: activeFilters.value.ratings > 0 ? 1 : 0,+ search: activeFilters.value.search.length > 0 ? 1 : 0}})@@ -118,6 +121,28 @@ export function usePhotoFilters() {const filteredPhotos = computed(() => {// 先获取排序后的照片,再应用筛选return sortedPhotos.value.filter(photo => {+ // 搜索筛选+ if (activeFilters.value.search) {+ const searchTerm = activeFilters.value.search.toLowerCase()+ const searchableFields = [+ photo.tags?.join(' ') || '',+ photo.exif?.Make || '',+ photo.exif?.Model || '',+ photo.exif?.LensMake || '',+ photo.exif?.LensModel || '',+ photo.city || '',+ photo.country || '',+ photo.title || '',+ photo.description || '',+ photo.storageKey || '',+ photo.locationName || '',+ ].join(' ').toLowerCase()++ if (!searchableFields.includes(searchTerm)) {+ return false+ }+ }+// 标签筛选if (activeFilters.value.tags.length > 0) {const photoTags = photo.tags || []@@ -185,13 +210,18 @@ export function usePhotoFilters() {cameras: [],lenses: [],cities: [],- ratings: 0+ ratings: 0,+ search: ''}}// 清除指定类型的筛选const clearFilterType = (type: keyof FilterOptions) => {- activeFilters.value[type] = [] as any+ if (type === 'ratings' || type === 'search') {+ (activeFilters.value as any)[type] = type === 'ratings' ? 0 : ''+ } else {+ (activeFilters.value as any)[type] = []+ }}// 检查筛选项是否被选中@@ -201,9 +231,12 @@ export function usePhotoFilters() {// 检查是否有任何筛选项被激活const hasActiveFilters = computed(() => {- return Object.values(activeFilters.value).some(filters =>- Array.isArray(filters) ? filters.length > 0 : filters > 0- )+ return activeFilters.value.tags.length > 0 ||+ activeFilters.value.cameras.length > 0 ||+ activeFilters.value.lenses.length > 0 ||+ activeFilters.value.cities.length > 0 ||+ activeFilters.value.ratings > 0 ||+ activeFilters.value.search.length > 0})return {diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vueindex b5c00f61..8259f9c4 100644--- a/app/pages/dashboard/photos.vue+++ b/app/pages/dashboard/photos.vue@@ -19,6 +19,7 @@ const dayjs = useDayjs()const { localizeExif } = useExifLocalization()const { photos: data, status, refresh } = usePhotos()+const { filteredPhotos, activeFilters } = usePhotoFilters()// 当前上传的文件信息interface UploadingFile {@@ -202,10 +203,10 @@ const totalRowsCount = computed((): number => {// 计算 LivePhoto 统计const livePhotoStats = computed(() => {- if (!data.value) return { total: 0, livePhotos: 0, staticPhotos: 0 }+ if (!filteredPhotos.value) return { total: 0, livePhotos: 0, staticPhotos: 0 }- const total = data.value.length- const livePhotos = data.value.filter(+ const total = filteredPhotos.value.length+ const livePhotos = filteredPhotos.value.filter((photo: Photo) => photo.isLivePhoto,).lengthconst staticPhotos = total - livePhotos@@ -218,15 +219,15 @@ const photoFilter = ref<'all' | 'livephoto' | 'static'>('all')// 过滤后的数据const filteredData = computed(() => {- if (!data.value) return []+ if (!filteredPhotos.value) return []switch (photoFilter.value) {case 'livephoto':- return data.value.filter((photo: Photo) => photo.isLivePhoto)+ return filteredPhotos.value.filter((photo: Photo) => photo.isLivePhoto)case 'static':- return data.value.filter((photo: Photo) => !photo.isLivePhoto)+ return filteredPhotos.value.filter((photo: Photo) => !photo.isLivePhoto)default:- return data.value+ return filteredPhotos.value}})@@ -261,6 +262,7 @@ const columns: TableColumn<Photo>[] = [return h(ThumbImage, {src: url || row.original.originalUrl || '',alt: row.original.title || 'Photo Thumbnail',+ key: row.original.id,thumbhash: row.original.thumbnailHash || '',class: 'size-16 min-w-[100px] object-cover rounded-md shadow',onClick: () => openInNewTab(url || row.original.originalUrl || ''),@@ -1024,6 +1026,15 @@ onUnmounted(() => {></USelectMenu>+ <!-- 模糊搜索 -->+ <UInput+ v-model="activeFilters.search"+ size="sm"+ icon="tabler:search"+ placeholder="搜索照片..."+ class="w-32"+ />+<!-- 刷新按钮 --><UButtonvariant="soft"