diff --git a/src/App.vue b/src/App.vue index d585cde..f31df30 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,8 +1,10 @@ + + diff --git a/src/components/ui/drawer.vue b/src/components/ui/drawer.vue new file mode 100644 index 0000000..5bd8d56 --- /dev/null +++ b/src/components/ui/drawer.vue @@ -0,0 +1,85 @@ + + + + + + diff --git a/src/composables/use-photo-columns.ts b/src/composables/use-photo-columns.ts new file mode 100644 index 0000000..22a98f6 --- /dev/null +++ b/src/composables/use-photo-columns.ts @@ -0,0 +1,38 @@ +import { computed, type Ref } from "vue"; + +interface MediaItem { + id: number; + title: string; + content: string; + url: string; + thumb_url: string; + meta: string; + take_time: string; + width?: number; + height?: number; +} + +/** + * 计算宫格图片对象的 hooks + * @param photos 照片数组 + * @param gridCount 宫格数量,可以是数字或 Ref,默认为 4 + * @returns 返回一个 computed,包含按宫格数分配的图片数组 + */ +export function usePhotoColumns( + photos: Ref, + gridCount: number | Ref = 4 +) { + const columns = computed(() => { + const count = typeof gridCount === 'number' ? gridCount : gridCount.value; + const result: MediaItem[][] = Array.from({ length: count }, () => []); + + photos.value.forEach((photo, index) => { + const columnIndex = index % count; + result[columnIndex].push(photo); + }); + + return result; + }); + + return columns; +}