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(dashboard): add column visibility options to photo table

Timothy Yincdf4668d4eb7
diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vue
index 6856e3ef..de5827d2 100644
--- a/app/pages/dashboard/photos.vue
+++ b/app/pages/dashboard/photos.vue
@@ -6,6 +6,24 @@ import { Icon, UBadge } from '#components'
import ThumbImage from '~/components/ui/ThumbImage.vue'
const UCheckbox = resolveComponent('UCheckbox')
+const Rating = resolveComponent('Rating')
+
+// 列名显示映射
+const columnNameMap: Record<string, string> = {
+ thumbnailUrl: $t('dashboard.photos.table.columns.thumbnail.title'),
+ id: $t('dashboard.photos.table.columns.id'),
+ title: $t('dashboard.photos.table.columns.title'),
+ tags: $t('dashboard.photos.table.columns.tags'),
+ rating: $t('dashboard.photos.table.columns.rating'),
+ isLivePhoto: $t('dashboard.photos.table.columns.isLivePhoto'),
+ location: $t('dashboard.photos.table.columns.location'),
+ dateTaken: $t('dashboard.photos.table.columns.dateTaken'),
+ lastModified: $t('dashboard.photos.table.columns.lastModified'),
+ fileSize: $t('dashboard.photos.table.columns.fileSize'),
+ colorSpace: $t('dashboard.photos.table.columns.colorSpace'),
+ reactions: $t('dashboard.photos.table.columns.reactions'),
+ actions: $t('dashboard.photos.table.columns.actions'),
+}
definePageMeta({
layout: 'dashboard',
@@ -452,6 +470,23 @@ watch(isEditModalOpen, (open) => {
const rowSelection = ref({})
const table: any = useTemplateRef('table')
+// 列可见性状态
+const columnVisibility = ref({
+ thumbnailUrl: true,
+ id: true,
+ actions: true,
+ title: true,
+ tags: true,
+ rating: true,
+ isLivePhoto: true,
+ location: true,
+ dateTaken: true,
+ lastModified: true,
+ fileSize: true,
+ colorSpace: true,
+ reactions: true,
+})
+
const selectedRowsCount = computed((): number => {
return table.value?.tableApi?.getFilteredSelectedRowModel().rows.length || 0
})
@@ -692,8 +727,10 @@ const columns: TableColumn<Photo>[] = [
row.toggleSelected(!!value),
'aria-label': 'Select row',
}),
+ enableHiding: false,
},
{
+ id: 'thumbnailUrl',
accessorKey: 'thumbnailUrl',
header: $t('dashboard.photos.table.columns.thumbnail.title'),
cell: ({ row }) => {
@@ -708,10 +745,13 @@ const columns: TableColumn<Photo>[] = [
style: { cursor: url ? 'pointer' : 'default' },
})
},
+ enableHiding: false,
},
{
+ id: 'id',
accessorKey: 'id',
header: $t('dashboard.photos.table.columns.id'),
+ enableHiding: false,
},
{
accessorKey: 'title',
@@ -743,6 +783,26 @@ const columns: TableColumn<Photo>[] = [
])
},
},
+ {
+ accessorKey: 'rating',
+ header: $t('dashboard.photos.table.columns.rating'),
+ cell: ({ row }) => {
+ const rating = row.original.exif?.Rating
+ return h('div', { class: 'flex items-center' }, [
+ rating !== undefined && rating !== null
+ ? h(Rating, {
+ modelValue: rating,
+ readonly: true,
+ size: 'xs',
+ })
+ : h(
+ 'span',
+ { class: 'text-neutral-400 text-xs' },
+ $t('dashboard.photos.table.cells.noRating'),
+ ),
+ ])
+ },
+ },
{
accessorKey: 'isLivePhoto',
header: $t('dashboard.photos.table.columns.isLivePhoto'),
@@ -837,6 +897,7 @@ const columns: TableColumn<Photo>[] = [
cell: (info) => formatBytes(info.getValue() as number),
},
{
+ id: 'colorSpace',
accessorFn: (row) => row.exif?.ColorSpace,
header: $t('dashboard.photos.table.columns.colorSpace'),
},
@@ -911,8 +972,10 @@ const columns: TableColumn<Photo>[] = [
},
},
{
+ id: 'actions',
accessorKey: 'actions',
header: $t('dashboard.photos.table.columns.actions'),
+ enableHiding: false,
},
]
@@ -1071,7 +1134,8 @@ const openMetadataEditor = (photo: Photo) => {
editFormState.title = initialTitle
editFormState.description = initialDescription
editFormState.tags = [...initialTags]
- editFormState.rating = typeof photo.exif?.Rating === 'number' ? photo.exif.Rating : null
+ editFormState.rating =
+ typeof photo.exif?.Rating === 'number' ? photo.exif.Rating : null
const initialLocation = hasCoordinates
? {
@@ -1940,6 +2004,36 @@ onUnmounted(() => {
$t('dashboard.photos.toolbar.refresh')
}}</span>
</UButton>
+
+ <!-- 列可见性按钮 -->
+ <UDropdownMenu
+ :items="table?.tableApi?.getAllColumns()
+ .filter((column: any) => column.getCanHide())
+ .map((column: any) => ({
+ label: columnNameMap[column.id] || column.id,
+ type: 'checkbox' as const,
+ checked: column.getIsVisible(),
+ disabled: !column.getCanHide() || (column.id === 'thumbnailUrl' || column.id === 'id' || column.id === 'actions'),
+ onUpdateChecked(checked: boolean) {
+ table?.tableApi?.getColumn(column.id)?.toggleVisibility(!!checked)
+ },
+ onSelect(e: Event) {
+ e.preventDefault()
+ }
+ }))"
+ :content="{ align: 'end' }"
+ >
+ <UButton
+ label=""
+ color="neutral"
+ variant="outline"
+ size="sm"
+ icon="tabler:columns-3"
+ :title="$t('dashboard.photos.table.columnVisibility.description')"
+ >
+ <span class="hidden sm:inline">{{ $t('dashboard.photos.table.columnVisibility.button') }}</span>
+ </UButton>
+ </UDropdownMenu>
</div>
</div>
@@ -1950,6 +2044,7 @@ onUnmounted(() => {
<UTable
ref="table"
v-model:row-selection="rowSelection"
+ v-model:column-visibility="columnVisibility"
:column-pinning="{
right: ['actions'],
}"
@@ -2089,6 +2184,34 @@ onUnmounted(() => {
</p>
</div>
+ <div class="flex items-center justify-between space-y-2">
+ <label
+ class="text-sm font-medium text-neutral-700 dark:text-neutral-200"
+ >
+ {{ $t('dashboard.photos.editModal.fields.rating') }}
+ </label>
+ <div class="flex items-center gap-3">
+ <span
+ v-if="editFormState.rating"
+ class="text-sm text-neutral-600 dark:text-neutral-400"
+ >
+ {{ editFormState.rating }} / 5
+ </span>
+ <span
+ v-else
+ class="text-sm text-neutral-500 dark:text-neutral-500"
+ >
+ {{ $t('dashboard.photos.editModal.fields.noRating') }}
+ </span>
+ <Rating
+ :model-value="editFormState.rating || 0"
+ :allow-half="false"
+ size="lg"
+ @update:model-value="editFormState.rating = $event || null"
+ />
+ </div>
+ </div>
+
<div class="space-y-3">
<div class="flex items-center justify-between">
<label
@@ -2140,47 +2263,6 @@ onUnmounted(() => {
</div>
</div>
- <div class="space-y-2">
- <label
- class="text-sm font-medium text-neutral-700 dark:text-neutral-200"
- >
- {{ $t('dashboard.photos.editModal.fields.rating') }}
- </label>
- <div class="flex items-center gap-2">
- <div class="flex gap-1">
- <UButton
- v-for="star in 5"
- :key="star"
- variant="ghost"
- size="sm"
- :icon="
- star <= (editFormState.rating || 0)
- ? 'tabler:star-filled'
- : 'tabler:star'
- "
- :color="
- star <= (editFormState.rating || 0)
- ? 'warning'
- : 'neutral'
- "
- @click="
- editFormState.rating =
- editFormState.rating === star ? null : star
- "
- />
- </div>
- <span v-if="editFormState.rating" class="text-sm text-neutral-600 dark:text-neutral-400">
- {{ editFormState.rating }} / 5
- </span>
- <span v-else class="text-sm text-neutral-500 dark:text-neutral-500">
- {{ $t('dashboard.photos.editModal.fields.noRating') }}
- </span>
- </div>
- <p class="text-xs text-neutral-500 dark:text-neutral-400">
- {{ $t('dashboard.photos.editModal.fields.ratingHint') }}
- </p>
- </div>
-
<div
class="flex items-center justify-end gap-2 pt-4 border-t border-neutral-200 dark:border-neutral-800"
>
diff --git a/i18n/locales/en.json b/i18n/locales/en.json
index 463df336..c579ae3b 100644
--- a/i18n/locales/en.json
+++ b/i18n/locales/en.json
@@ -501,6 +501,7 @@
"id": "Photo ID",
"title": "Photo Title",
"tags": "Keywords",
+ "rating": "Rating",
"isLivePhoto": "Live Photo",
"location": "Location",
"dateTaken": "Date Taken",
@@ -512,10 +513,15 @@
},
"cells": {
"noTags": "No tags",
+ "noRating": "No rating",
"noGps": "No GPS info",
"unknown": "Unknown",
"staticPhoto": "Static Photo",
"noReactions": "No reactions"
+ },
+ "columnVisibility": {
+ "button": "Columns",
+ "description": "Toggle column visibility"
}
},
"actions": {
diff --git a/i18n/locales/ja.json b/i18n/locales/ja.json
index 43962b63..00293cdf 100644
--- a/i18n/locales/ja.json
+++ b/i18n/locales/ja.json
@@ -444,6 +444,7 @@
"id": "写真ID",
"title": "写真のタイトル",
"tags": "キーワード",
+ "rating": "評価",
"isLivePhoto": "ライブフォト",
"location": "位置情報",
"dateTaken": "撮影日",
@@ -455,10 +456,15 @@
},
"cells": {
"noTags": "タグなし",
+ "noRating": "未評価",
"noGps": "GPS情報なし",
"unknown": "不明",
"staticPhoto": "静止画",
"noReactions": "リアクションなし"
+ },
+ "columnVisibility": {
+ "button": "列設定",
+ "description": "列の表示/非表示を切り替える"
}
},
"actions": {
diff --git a/i18n/locales/zh-Hans.json b/i18n/locales/zh-Hans.json
index 200c42f8..7b080072 100644
--- a/i18n/locales/zh-Hans.json
+++ b/i18n/locales/zh-Hans.json
@@ -501,6 +501,7 @@
"id": "照片ID",
"title": "照片标题",
"tags": "关键词",
+ "rating": "评分",
"isLivePhoto": "Live Photo",
"location": "位置",
"dateTaken": "拍摄日期",
@@ -512,10 +513,15 @@
},
"cells": {
"noTags": "无标签",
+ "noRating": "未评分",
"noGps": "无 GPS 信息",
"unknown": "未知",
"staticPhoto": "一般照片",
"noReactions": "无表态"
+ },
+ "columnVisibility": {
+ "button": "列设置",
+ "description": "切换列的显示/隐藏"
}
},
"actions": {
diff --git a/i18n/locales/zh-Hant-HK.json b/i18n/locales/zh-Hant-HK.json
index b6271479..984ef742 100644
--- a/i18n/locales/zh-Hant-HK.json
+++ b/i18n/locales/zh-Hant-HK.json
@@ -444,6 +444,7 @@
"id": "相片 ID",
"title": "相片標題",
"tags": "關鍵字",
+ "rating": "評分",
"isLivePhoto": "實況相片",
"location": "位置",
"dateTaken": "拍攝日期",
@@ -455,10 +456,15 @@
},
"cells": {
"noTags": "無標籤",
+ "noRating": "未評分",
"noGps": "沒有 GPS 資料",
"unknown": "未知",
"staticPhoto": "靜態相片",
"noReactions": "無反應"
+ },
+ "columnVisibility": {
+ "button": "列設定",
+ "description": "切換列的顯示/隱藏"
}
},
"actions": {
diff --git a/i18n/locales/zh-Hant-TW.json b/i18n/locales/zh-Hant-TW.json
index 6d0d4642..c9f1cb44 100644
--- a/i18n/locales/zh-Hant-TW.json
+++ b/i18n/locales/zh-Hant-TW.json
@@ -444,6 +444,7 @@
"id": "照片 ID",
"title": "照片標題",
"tags": "關鍵字",
+ "rating": "評分",
"isLivePhoto": "原況照片",
"location": "位置",
"dateTaken": "拍攝日期",
@@ -455,10 +456,15 @@
},
"cells": {
"noTags": "無標籤",
+ "noRating": "未評分",
"noGps": "沒有 GPS 資訊",
"unknown": "未知",
"staticPhoto": "靜態照片",
"noReactions": "無反應"
+ },
+ "columnVisibility": {
+ "button": "列設定",
+ "description": "切換列的顯示/隱藏"
}
},
"actions": {