Skip to content

Self-hosted personal gallery application with online photo management and albums, supporting Live/Motion Photos, EXIF parsing, geolocation recognition, and an explore map.

feat(photos): show reactions data in dashboard

HoshinoSuzumi5a8975861ed7
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vue
index 596566aa..92d17319 100644
--- a/app/pages/dashboard/photos.vue
+++ b/app/pages/dashboard/photos.vue
@@ -29,6 +29,27 @@ const totalSelectedFilters = computed(() => {
)
})
+// 表态数据
+const reactionsData = ref<Record<string, Record<string, number>>>({})
+const reactionsLoading = ref(false)
+
+// 获取表态数据
+const fetchReactions = async (photoIds: string[]) => {
+ if (photoIds.length === 0) return
+
+ reactionsLoading.value = true
+ try {
+ const data = await $fetch('/api/photos/reactions', {
+ query: { ids: photoIds },
+ })
+ reactionsData.value = data as Record<string, Record<string, number>>
+ } catch (error) {
+ console.error('获取表态数据失败:', error)
+ } finally {
+ reactionsLoading.value = false
+ }
+}
+
interface UploadingFile {
file: File
fileName: string
@@ -245,6 +266,18 @@ const filteredData = computed(() => {
}
})
+// 监听过滤后的照片变化,自动获取表态数据
+watch(
+ () => filteredData.value,
+ async (photos) => {
+ if (photos && photos.length > 0) {
+ const photoIds = photos.map((p: Photo) => p.id)
+ await fetchReactions(photoIds)
+ }
+ },
+ { immediate: true },
+)
+
// 状态检查间隔 Map,每个任务对应一个定时器
const statusIntervals = ref<Map<number, NodeJS.Timeout>>(new Map())
@@ -568,6 +601,75 @@ const columns: TableColumn<Photo>[] = [
accessorFn: (row) => row.exif?.ColorSpace,
header: '颜色空间',
},
+ {
+ accessorKey: 'reactions',
+ header: '表态',
+ cell: ({ row }) => {
+ const photoId = row.original.id
+ const reactions = reactionsData.value[photoId] || {}
+ const totalReactions = Object.values(reactions).reduce(
+ (sum: number, count) => sum + (count as number),
+ 0,
+ )
+
+ if (totalReactions === 0) {
+ return h(
+ 'span',
+ { class: 'text-neutral-400 text-xs' },
+ '无表态',
+ )
+ }
+
+ const reactionIcons: Record<string, string> = {
+ like: 'fluent-emoji-flat:thumbs-up',
+ love: 'fluent-emoji-flat:red-heart',
+ amazing: 'fluent-emoji-flat:smiling-face-with-heart-eyes',
+ funny: 'fluent-emoji-flat:face-with-tears-of-joy',
+ wow: 'fluent-emoji-flat:face-with-open-mouth',
+ sad: 'fluent-emoji-flat:crying-face',
+ fire: 'fluent-emoji-flat:fire',
+ sparkle: 'fluent-emoji-flat:sparkles',
+ }
+
+ // 显示前3个有数据的表态
+ const topReactions = Object.entries(reactions)
+ .filter(([_, count]) => (count as number) > 0)
+ .sort((a, b) => (b[1] as number) - (a[1] as number))
+ .slice(0, 3)
+
+ return h(
+ 'div',
+ { class: 'flex items-center gap-2' },
+ [
+ ...topReactions.map(([type, count]) =>
+ h(
+ 'div',
+ { class: 'flex items-center gap-0.5' },
+ [
+ h(Icon, {
+ name: reactionIcons[type] || 'fluent-emoji-flat:face-with-tears-of-joy',
+ class: 'size-4',
+ mode: 'svg',
+ }),
+ h(
+ 'span',
+ { class: 'text-xs font-medium text-neutral-700 dark:text-neutral-300' },
+ count,
+ ),
+ ],
+ ),
+ ),
+ totalReactions > topReactions.length
+ ? h(
+ 'span',
+ { class: 'text-xs text-neutral-400' },
+ `+${totalReactions - topReactions.reduce((sum, [_, count]) => sum + (count as number), 0)}`,
+ )
+ : null,
+ ].filter(Boolean),
+ )
+ },
+ },
{
accessorKey: 'actions',
header: '操作',
@@ -1089,7 +1191,13 @@ onUnmounted(() => {
color="info"
size="sm"
icon="tabler:refresh"
- @click="() => refresh()"
+ :loading="reactionsLoading"
+ @click="async () => {
+ await refresh()
+ if (filteredData.length > 0) {
+ await fetchReactions(filteredData.map((p: Photo) => p.id))
+ }
+ }"
>
<span class="hidden sm:inline">刷新</span>
</UButton>
diff --git a/package.json b/package.json
index 3f8f0f7f..7a5b0f14 100644
--- a/package.json
+++ b/package.json
@@ -81,6 +81,7 @@
"@iconify-json/material-symbols": "^1.2.33",
"@iconify-json/mdi": "^1.2.3",
"@iconify-json/streamline": "^1.2.5",
+ "@iconify-json/svg-spinners": "^1.2.4",
"@iconify-json/tabler": "^1.2.22",
"@nuxt/eslint": "1.9.0",
"@nuxt/test-utils": "3.19.2",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index e55e1c50..ff646949 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -165,6 +165,9 @@ importers:
'@iconify-json/streamline':
specifier: ^1.2.5
version: 1.2.5
+ '@iconify-json/svg-spinners':
+ specifier: ^1.2.4
+ version: 1.2.4
'@iconify-json/tabler':
specifier: ^1.2.22
version: 1.2.23
@@ -1027,6 +1030,9 @@ packages:
'@iconify-json/[email protected]':
resolution: {integrity: sha512-u6l9BOJoIIPjjDXWl6D/hPDzeBk5WiaEHZ+U9SbkQ14N9hgotaYyIZVMfgF175CG1TTS06j8k15D3FM2OYaFIw==}
+ '@iconify-json/[email protected]':
+ resolution: {integrity: sha512-ayn0pogFPwJA1WFZpDnoq9/hjDxN+keeCMyThaX4d3gSJ3y0mdKUxIA/b1YXWGtY9wVtZmxwcvOIeEieG4+JNg==}
+
'@iconify-json/[email protected]':
resolution: {integrity: sha512-Knb8ykgMwB5uSoqrDv1xIdJYM03OP06OXjN6QvGXaTNtdHkW9ciKA+aftz6lwM2jwJA+bsUWeDzLBlPt2uJm4w==}
@@ -8617,6 +8623,10 @@ snapshots:
dependencies:
'@iconify/types': 2.0.0
+ '@iconify-json/[email protected]':
+ dependencies:
+ '@iconify/types': 2.0.0
+
'@iconify-json/[email protected]':
dependencies:
'@iconify/types': 2.0.0