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(dashboard): persist photo table column visibility
Ahmet Ömer6707dbd9f3d2
diff --git a/app/composables/useDashboardPhotoColumnVisibility.ts b/app/composables/useDashboardPhotoColumnVisibility.tsnew file mode 100644index 00000000..4ad78fba--- /dev/null+++ b/app/composables/useDashboardPhotoColumnVisibility.ts@@ -0,0 +1,70 @@+import { useLocalStorage } from '@vueuse/core'++const DASHBOARD_PHOTO_COLUMN_VISIBILITY_STORAGE_KEY =+ 'dashboard-photos-column-visibility'++const dashboardPhotoColumnIds = [+ 'thumbnailUrl',+ 'id',+ 'actions',+ 'title',+ 'tags',+ 'rating',+ 'isLivePhoto',+ 'location',+ 'dateTaken',+ 'lastModified',+ 'fileSize',+ 'colorSpace',+ 'reactions',+] as const++const lockedVisibleColumnIds = ['thumbnailUrl', 'id', 'actions'] as const++type DashboardPhotoColumnId = (typeof dashboardPhotoColumnIds)[number]+type DashboardPhotoColumnVisibility = Record<DashboardPhotoColumnId, boolean>++function createDefaultColumnVisibility(): DashboardPhotoColumnVisibility {+ return Object.fromEntries(+ dashboardPhotoColumnIds.map((columnId) => [columnId, true]),+ ) as DashboardPhotoColumnVisibility+}++function mergeColumnVisibility(+ storageValue: DashboardPhotoColumnVisibility,+ defaults: DashboardPhotoColumnVisibility,+): DashboardPhotoColumnVisibility {+ const merged: DashboardPhotoColumnVisibility = { ...defaults }++ if (+ !storageValue ||+ typeof storageValue !== 'object' ||+ Array.isArray(storageValue)+ ) {+ return merged+ }++ for (const columnId of dashboardPhotoColumnIds) {+ const value = storageValue[columnId]+ if (typeof value === 'boolean') {+ merged[columnId] = value+ }+ }++ for (const columnId of lockedVisibleColumnIds) {+ merged[columnId] = true+ }++ return merged+}++export function useDashboardPhotoColumnVisibility() {+ return useLocalStorage<DashboardPhotoColumnVisibility>(+ DASHBOARD_PHOTO_COLUMN_VISIBILITY_STORAGE_KEY,+ createDefaultColumnVisibility,+ {+ mergeDefaults: mergeColumnVisibility,+ initOnMounted: true,+ },+ )+}diff --git a/app/pages/dashboard/photos.vue b/app/pages/dashboard/photos.vueindex 468cd9e7..7e654566 100644--- a/app/pages/dashboard/photos.vue+++ b/app/pages/dashboard/photos.vue@@ -552,22 +552,8 @@ 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,-})+// 列可见性状态,选择结果保存在 localStorage,刷新后恢复+const columnVisibility = useDashboardPhotoColumnVisibility()const selectedRowsCount = computed((): number => {return table.value?.tableApi?.getFilteredSelectedRowModel().rows.length || 0