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(exif): 评分展示和筛选使用星式选择器
Timothy Yinda6dc35fdc70
diff --git a/app/components/icon/TablerStar.vue b/app/components/icon/TablerStar.vuenew file mode 100644index 00000000..c4a44aa0--- /dev/null+++ b/app/components/icon/TablerStar.vue@@ -0,0 +1,10 @@++<template>+ <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --><path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m12 17.75l-6.172 3.245l1.179-6.873l-5-4.867l6.9-1l3.086-6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873z" /></svg>+</template>++<script>+export default {+ name: 'TablerStar'+}+</script>\ No newline at end of filediff --git a/app/components/icon/TablerStarFilled.vue b/app/components/icon/TablerStarFilled.vuenew file mode 100644index 00000000..959bb018--- /dev/null+++ b/app/components/icon/TablerStarFilled.vue@@ -0,0 +1,10 @@++<template>+ <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --><path fill="currentColor" d="m8.243 7.34l-6.38.925l-.113.023a1 1 0 0 0-.44 1.684l4.622 4.499l-1.09 6.355l-.013.11a1 1 0 0 0 1.464.944l5.706-3l5.693 3l.1.046a1 1 0 0 0 1.352-1.1l-1.091-6.355l4.624-4.5l.078-.085a1 1 0 0 0-.633-1.62l-6.38-.926l-2.852-5.78a1 1 0 0 0-1.794 0z" /></svg>+</template>++<script>+export default {+ name: 'TablerStarFilled'+}+</script>\ No newline at end of filediff --git a/app/components/icon/TablerStarHalfFilled.vue b/app/components/icon/TablerStarHalfFilled.vuenew file mode 100644index 00000000..08d2eefb--- /dev/null+++ b/app/components/icon/TablerStarHalfFilled.vue@@ -0,0 +1,10 @@++<template>+ <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24"><!-- Icon from Tabler Icons by Paweł Kuna - https://github.com/tabler/tabler-icons/blob/master/LICENSE --><path fill="currentColor" d="M12 1a1 1 0 0 1 .823.443l.067.116l2.852 5.781l6.38.925c.741.108 1.08.94.703 1.526l-.07.095l-.078.086l-4.624 4.499l1.09 6.355a1 1 0 0 1-1.249 1.135l-.101-.035l-.101-.046l-5.693-3l-5.706 3q-.158.082-.32.106l-.106.01a1.003 1.003 0 0 1-1.038-1.06l.013-.11l1.09-6.355l-4.623-4.5a1 1 0 0 1 .328-1.647l.113-.036l.114-.023l6.379-.925l2.853-5.78A.97.97 0 0 1 12 1m0 3.274V16.75a1 1 0 0 1 .239.029l.115.036l.112.05l4.363 2.299l-.836-4.873a1 1 0 0 1 .136-.696l.07-.099l.082-.09l3.546-3.453l-4.891-.708a1 1 0 0 1-.62-.344l-.073-.097l-.06-.106z" /></svg>+</template>++<script>+export default {+ name: 'TablerStarHalfFilled'+}+</script>\ No newline at end of filediff --git a/app/components/overlay/FilterPanel.vue b/app/components/overlay/FilterPanel.vueindex 348f6527..6b37cb96 100644--- a/app/components/overlay/FilterPanel.vue+++ b/app/components/overlay/FilterPanel.vue@@ -8,10 +8,18 @@ const {isFilterSelected,clearAllFilters,hasActiveFilters,+ activeFilters,} = usePhotoFilters()const currentTab = ref('labels')+const selectedRating = computed({+ get: () => activeFilters.value.ratings,+ set: (value: number) => {+ activeFilters.value.ratings = value+ },+})+const tabItems = computed<TabsItem[]>(() => [{label: '标签',@@ -96,9 +104,7 @@ const handleToggleFilter = (type: string, value: string | number) => {v-for="tag in availableFilters.tags":key="tag.label":label="tag.label"- :color="- isFilterSelected('tags', tag.label) ? 'info' : 'neutral'- "+ :color="isFilterSelected('tags', tag.label) ? 'info' : 'neutral'":trailing-icon="isFilterSelected('tags', tag.label) ? 'tabler:check' : ''"@@ -215,32 +221,22 @@ const handleToggleFilter = (type: string, value: string | number) => {<!-- 评分面板 --><template #ratings>- <div class="space-y-0.5 max-h-64 overflow-y-auto">+ <div+ class="max-h-64 overflow-y-auto flex flex-col items-center gap-3 py-4"+ >+ <UiRating+ v-model="selectedRating"+ size="xl"+ :allow-half="false"+ /><div- v-for="rating in availableFilters.ratings"- :key="rating.label"- class="flex items-center justify-between cursor-pointer select-none hover:bg-neutral-400/30 dark:hover:bg-info-800/30 rounded-lg px-2 py-2"- :class="- isFilterSelected('ratings', rating.label)- ? 'bg-neutral-400/30 dark:bg-info-800/30'- : ''- "- @click="handleToggleFilter('ratings', rating.label)"- >- <span class="text-sm text-default font-medium truncate">- {{ rating.label }} 星- </span>- <Icon- v-if="isFilterSelected('ratings', rating.label)"- name="tabler:check"- class="size-4 text-green-500"- />- </div>- <div- v-if="availableFilters.ratings.length === 0"- class="text-center text-sm text-neutral-500 dark:text-neutral-400 py-4"+ class="text-xs font-semibold text-neutral-900/90 dark:text-white/90">- 暂无评分信息+ {{+ selectedRating+ ? `展示 ${selectedRating} 星及以上的照片`+ : '展示所有照片'+ }}</div></div></template>diff --git a/app/components/photo/InfoPanel.vue b/app/components/photo/InfoPanel.vueindex 1aef8763..6a012593 100644--- a/app/components/photo/InfoPanel.vue+++ b/app/components/photo/InfoPanel.vue@@ -487,12 +487,26 @@ const onTagClick = (tag: string) => {@click="onMinimapClick(currentPhoto.id)"/>- <!-- EXIF/对象信息渲染器 --><PhotoKVRendererv-if="formatedExifData.basicInfo":data="formatedExifData.basicInfo"/>+ <div+ v-if="currentPhoto.exif?.Rating"+ class="flex items-center gap-2 justify-between"+ >+ <h4 class="text-sm font-medium text-white uppercase tracking-wide">+ 评分+ </h4>++ <UiRating+ :model-value="currentPhoto.exif.Rating"+ readonly+ size="sm"+ />+ </div>+<!-- 标签 --><divv-if="currentPhoto.tags && currentPhoto.tags.length > 0"diff --git a/app/components/ui/Rating.vue b/app/components/ui/Rating.vuenew file mode 100644index 00000000..e4e3e744--- /dev/null+++ b/app/components/ui/Rating.vue@@ -0,0 +1,125 @@+<script lang="ts" setup>+import TablerStar from '~/components/icon/TablerStar.vue'+import TablerStarFilled from '~/components/icon/TablerStarFilled.vue'+import TablerStarHalfFilled from '~/components/icon/TablerStarHalfFilled.vue'++interface Props {+ modelValue: number+ allowHalf?: boolean+ allowClear?: boolean+ size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'+ readonly?: boolean+}++const props = withDefaults(defineProps<Props>(), {+ allowHalf: true,+ allowClear: true,+ size: 'md',+ readonly: false,+})++const emit = defineEmits<{+ 'update:modelValue': [value: number]+}>()++const sizeClasses = {+ xs: 'text-sm',+ sm: 'text-base',+ md: 'text-lg',+ lg: 'text-xl',+ xl: 'text-2xl',+}++const handleClick = (index: number, isHalf: boolean = false) => {+ if (props.readonly) return+ let newValue = index + (isHalf ? 0.5 : 1)+ if (props.allowClear && props.modelValue === newValue) {+ newValue = 0+ }+ emit('update:modelValue', newValue)+}++const getStarType = (index: number) => {+ const value = props.modelValue+ if (value >= index + 1) {+ return 'filled'+ } else if (props.allowHalf && value >= index + 0.5) {+ return 'half'+ } else {+ return 'empty'+ }+}+</script>++<template>+ <div+ class="rating flex items-center gap-1"+ :class="[sizeClasses[props.size], { 'cursor-pointer': !props.readonly }]"+ >+ <template v-if="!props.allowHalf">+ <div+ v-for="i in 5"+ :key="`no-half-${i}`"+ class="star relative"+ :class="{ readonly: props.readonly }"+ @click="handleClick(i - 1)"+ >+ <TablerStar+ v-if="getStarType(i - 1) === 'empty'"+ class="text-neutral-300"+ />+ <TablerStarFilled+ v-else-if="getStarType(i - 1) === 'filled'"+ class="text-yellow-400"+ />+ <TablerStarHalfFilled+ v-else+ class="text-yellow-400"+ />+ </div>+ </template>+ <template v-else>+ <div+ v-for="i in 5"+ :key="`half-${i}`"+ class="star relative"+ :class="{ readonly: props.readonly }"+ >+ <TablerStar+ v-if="getStarType(i - 1) === 'empty'"+ class="text-neutral-300"+ />+ <TablerStarFilled+ v-else-if="getStarType(i - 1) === 'filled'"+ class="text-yellow-400"+ />+ <TablerStarHalfFilled+ v-else+ class="text-yellow-400"+ />+ <div class="absolute inset-0 flex">+ <div+ class="w-1/2"+ @click.stop="handleClick(i - 1, true)"+ ></div>+ <div+ class="w-1/2"+ @click.stop="handleClick(i - 1)"+ ></div>+ </div>+ </div>+ </template>+ </div>+</template>++<style scoped>+.star {+ transition: transform 0.2s;+}+.star:hover {+ transform: scale(1.1);+}+.star.readonly:hover {+ transform: none;+}+</style>diff --git a/app/composables/usePhotoFilters.ts b/app/composables/usePhotoFilters.tsindex 54140b02..f2416bf8 100644--- a/app/composables/usePhotoFilters.ts+++ b/app/composables/usePhotoFilters.ts@@ -3,7 +3,7 @@ interface FilterOptions {cameras: string[]lenses: string[]cities: string[]- ratings: number[]+ ratings: number // 改为单个数字,表示最低评分}interface FilterStats {@@ -20,7 +20,7 @@ const globalFilters = ref<FilterOptions>({cameras: [],lenses: [],cities: [],- ratings: []+ ratings: 0})export function usePhotoFilters() {@@ -110,7 +110,7 @@ export function usePhotoFilters() {cameras: activeFilters.value.cameras.length,lenses: activeFilters.value.lenses.length,cities: activeFilters.value.cities.length,- ratings: activeFilters.value.ratings.length+ ratings: activeFilters.value.ratings > 0 ? 1 : 0}})@@ -155,9 +155,9 @@ export function usePhotoFilters() {}// 评分筛选- if (activeFilters.value.ratings.length > 0) {+ if (activeFilters.value.ratings > 0) {const photoRating = photo.exif?.Rating || 0- if (!activeFilters.value.ratings.includes(photoRating)) {+ if (photoRating < activeFilters.value.ratings) {return false}}@@ -185,7 +185,7 @@ export function usePhotoFilters() {cameras: [],lenses: [],cities: [],- ratings: []+ ratings: 0}}@@ -201,11 +201,13 @@ export function usePhotoFilters() {// 检查是否有任何筛选项被激活const hasActiveFilters = computed(() => {- return Object.values(activeFilters.value).some(filters => filters.length > 0)+ return Object.values(activeFilters.value).some(filters =>+ Array.isArray(filters) ? filters.length > 0 : filters > 0+ )})return {- activeFilters: readonly(activeFilters),+ activeFilters: activeFilters,availableFilters,selectedCounts,filteredPhotos,