Skip to content

Commit 86ff016

Browse files
committed
refactor: update image order handling to support page-based display in ImageMatrix component
1 parent 857f435 commit 86ff016

2 files changed

Lines changed: 30 additions & 19 deletions

File tree

src/components/Main.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,22 +64,22 @@ export default {
6464
}
6565
},
6666
computed: {
67-
// 四页按顺序拼成一条列表传给矩阵(第 1 页 0–15,第 2 页 16–31,第 3 页 32–47,第 4 页 48–63)
68-
imageOrder() {
67+
// 按页传:每一页只显示该页自己的图像列表,不混用
68+
imageOrderPages() {
6969
return [
70-
...this.imageOrderPage1,
71-
...this.imageOrderPage2,
72-
// ...this.imageOrderPage3,
73-
// ...this.imageOrderPage4,
74-
]
70+
this.imageOrderPage1,
71+
this.imageOrderPage2,
72+
// this.imageOrderPage3,
73+
// this.imageOrderPage4,
74+
].filter((page) => Array.isArray(page) && page.length > 0)
7575
},
7676
},
7777
}
7878
</script>
7979

8080
<template>
8181
<Title/>
82-
<ImageMatrix :order-list="imageOrder" />
82+
<ImageMatrix :order-pages="imageOrderPages" />
8383
<Abstract/>
8484
<Markdown/>
8585
<BibTeX/>

src/components/sections/ImageMatrix.vue

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
import { ref, computed, onMounted, onBeforeUnmount } from 'vue'
33
import OutfitDetailModal from './OutfitDetailModal.vue'
44
5-
// 展示顺序由父组件传入,例如:['P01006072_b1', 'P00787009_b1', ...]
5+
// 按页传入:每一页一个数组,例如 [[page1_ids...], [page2_ids...]]
66
const props = defineProps<{
7-
orderList: string[]
7+
orderPages: string[][]
88
}>()
99
1010
// 本地 dev 时 public 在根路径;部署到 GitHub Pages 时用 BASE_URL(/Garments2Look/),保证末尾有斜杠
@@ -75,8 +75,8 @@ onBeforeUnmount(() => {
7575
// 计算两行展示所需的格子数量
7676
const 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))
8080
const currentPage = ref(0)
8181
// 记录最近一次翻页方向:1 表示向右(下一页),-1 表示向左(上一页)
8282
const lastDirection = ref<1 | -1>(1)
@@ -106,14 +106,14 @@ const startPageTransition = (updatePage: () => void) => {
106106
const 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
113113
const 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)
135135
const isTransitioning = ref(false)
136136
137137
// 使用 loading 占位图补齐两行,每页固定显示同样数量的格子
138+
// 每页只使用当前页的 ids,不混用其他页。N = 当前页图像总数;第一行 = 第 0~x-1 个,第二行 = 第 N/2~N/2+x-1 个
138139
const 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

Comments
 (0)