gallery.ts 3.5 KB
import { localGalleryByIndex } from "@/utils/localGalleryImages";
import { staticAsset } from "@/utils/staticAsset";

export interface GalleryPhoto {
  id: number;
  imageUrl: string;
  title: string;
  /** 接口会返回,离线演示可为空 */
  description?: string;
  likes: number;
  author: string;
  /** 列表日期(Y-m-d),用于时间范围筛选 */
  date?: string;
  /** 接口列表:当前登录/游客 token 对应用户是否已点赞 */
  liked?: boolean;
  /** 接口列表/榜单附带,与 work_category 一致 */
  categories?: string[];
}

export const bannerImages = [
  {
    id: 1,
    url: staticAsset("home-top-banner.png"),
    title: "云雾山海",
    subtitle: "四川·稻城亚丁",
  },
  {
    id: 2,
    url: staticAsset("home-top-banner-2.png"),
    title: "溪谷漫步",
    subtitle: "草甸流水,雪山为幕",
  },
  {
    id: 3,
    url: staticAsset("home-top-banner-3.png"),
    title: "碧蓝海子",
    subtitle: "雪峰倒映,静坐湖岸",
  },
];

export const mockPhotos: GalleryPhoto[] = [
  {
    id: 1,
    imageUrl: staticAsset("photo-xiannairi-xuefeng.png"),
    title: "仙乃日雪峰",
    likes: 156,
    author: "山行者",
  },
  {
    id: 2,
    imageUrl: staticAsset("photo-niunaihai.png"),
    title: "牛奶海",
    likes: 528,
    author: "云游四方",
  },
  {
    id: 3,
    imageUrl: staticAsset("photo-sangdui-caoyuan.png"),
    title: "桑堆草原",
    likes: 189,
    author: "摄影师小李",
  },
  {
    id: 4,
    imageUrl: localGalleryByIndex(4),
    title: "经幡祈福",
    likes: 203,
    author: "藏地风情",
  },
  {
    id: 5,
    imageUrl: localGalleryByIndex(5),
    title: "秋色森林",
    likes: 178,
    author: "四季光影",
  },
  {
    id: 6,
    imageUrl: localGalleryByIndex(6),
    title: "央迈勇神山",
    likes: 267,
    author: "雪域探险",
  },
  {
    id: 7,
    imageUrl: staticAsset("photo-xueyu-simiao.png"),
    title: "雪域寺庙",
    likes: 298,
    author: "信仰之光",
  },
  {
    id: 8,
    imageUrl: localGalleryByIndex(8),
    title: "冰川雪顶",
    likes: 312,
    author: "冰雪世界",
  },
  {
    id: 9,
    imageUrl: localGalleryByIndex(9),
    title: "高山草甸",
    likes: 145,
    author: "草原之歌",
  },
  {
    id: 10,
    imageUrl: localGalleryByIndex(10),
    title: "山谷溪流",
    likes: 221,
    author: "流水潺潺",
  },
  {
    id: 11,
    imageUrl: localGalleryByIndex(11),
    title: "金秋森林",
    likes: 256,
    author: "秋天童话",
  },
  {
    id: 12,
    imageUrl: localGalleryByIndex(12),
    title: "冰川奇观",
    likes: 289,
    author: "极地探索",
  },
  {
    id: 13,
    imageUrl: localGalleryByIndex(13),
    title: "高原之境",
    likes: 167,
    author: "高原追梦",
  },
  {
    id: 14,
    imageUrl: localGalleryByIndex(14),
    title: "日照金山",
    likes: 423,
    author: "晨曦守望",
  },
  {
    id: 15,
    imageUrl: localGalleryByIndex(15),
    title: "野花盛开",
    likes: 192,
    author: "花海寻梦",
  },
  {
    id: 16,
    imageUrl: localGalleryByIndex(16),
    title: "飞瀑流泉",
    likes: 208,
    author: "水之灵",
  },
];

/** 未排序副本,供按筛选条件排序 */
export function photosUnsorted(): GalleryPhoto[] {
  return [...mockPhotos];
}

export function photosSortedByLikes(): GalleryPhoto[] {
  return [...mockPhotos].sort((a, b) => b.likes - a.likes || a.id - b.id);
}

export function getPhotoById(id: number): GalleryPhoto | undefined {
  return mockPhotos.find((p) => p.id === id);
}