22import { ref , computed , onMounted , onBeforeUnmount } from ' vue'
33import OutfitDetailModal from ' ./OutfitDetailModal.vue'
44
5- // 展示顺序由父组件传入 ,例如:['P01006072_b1', 'P00787009_b1', ...]
5+ // 按页传入:每一页一个数组 ,例如 [[page1_ids...], [page2_ids ...] ]
66const props = defineProps <{
7- orderList : string []
7+ orderPages : string [] []
88}>()
99
1010// 本地 dev 时 public 在根路径;部署到 GitHub Pages 时用 BASE_URL(/Garments2Look/),保证末尾有斜杠
@@ -75,8 +75,8 @@ onBeforeUnmount(() => {
7575// 计算两行展示所需的格子数量
7676const cells = computed (() => cols .value * 2 )
7777
78- // 固定总页数为 4 页
79- const TOTAL_PAGES = 2
78+ // 总页数 = 传入的 orderPages 长度
79+ const TOTAL_PAGES = computed (() => Math . max ( 1 , ( props . orderPages || []). length ))
8080const currentPage = ref (0 )
8181// 记录最近一次翻页方向:1 表示向右(下一页),-1 表示向左(上一页)
8282const lastDirection = ref < 1 | - 1 > (1 )
@@ -106,14 +106,14 @@ const startPageTransition = (updatePage: () => void) => {
106106const goToPrevPage = () => {
107107 lastDirection .value = - 1
108108 startPageTransition (() => {
109- currentPage .value = (currentPage .value - 1 + TOTAL_PAGES ) % TOTAL_PAGES
109+ currentPage .value = (currentPage .value - 1 + TOTAL_PAGES . value ) % TOTAL_PAGES . value
110110 })
111111}
112112
113113const goToNextPage = () => {
114114 lastDirection .value = 1
115115 startPageTransition (() => {
116- currentPage .value = (currentPage .value + 1 ) % TOTAL_PAGES
116+ currentPage .value = (currentPage .value + 1 ) % TOTAL_PAGES . value
117117 })
118118}
119119
@@ -135,19 +135,30 @@ const prevItems = ref<DisplayItem[] | null>(null)
135135const isTransitioning = ref (false )
136136
137137// 使用 loading 占位图补齐两行,每页固定显示同样数量的格子
138+ // 每页只使用当前页的 ids,不混用其他页。N = 当前页图像总数;第一行 = 第 0~x-1 个,第二行 = 第 N/2~N/2+x-1 个
138139const displayItems = computed <DisplayItem []>(() => {
139- const ids = props .orderList || []
140+ const pages = props .orderPages || []
141+ const ids = pages [currentPage .value ] || []
140142 const totalPerPage = cells .value
143+ const x = cols .value
144+ const N = ids .length
141145
142146 if (totalPerPage <= 0 ) return []
143147
144148 const items: DisplayItem [] = []
145149
146150 for (let i = 0 ; i < totalPerPage ; i ++ ) {
147- // 每页用 totalPerPage 个格子(两行×列数),按页取 orderList 的连续一段
148- const globalIndex = currentPage .value * totalPerPage + i
149- if (globalIndex < ids .length ) {
150- const id = ids [globalIndex ]
151+ let indexInPage: number
152+ if (i < x ) {
153+ // 第一行:当前页的第 0 个到第 x-1 个
154+ indexInPage = i
155+ } else {
156+ // 第二行:当前页的第 N/2 个到第 N/2+x-1 个
157+ const half = Math .floor (N / 2 )
158+ indexInPage = half + (i - x )
159+ }
160+ if (indexInPage < N ) {
161+ const id = ids [indexInPage ]
151162 if (id ) {
152163 const mainSrc = ` ${baseUrl }dataset/${id }/images/look/${id }.jpg `
153164 const overlaySrc = ` ${baseUrl }dataset/${id }/images/segment/color_segmentation.png `
0 commit comments