货盘页导航栏去除,修复奇数个商品样式错误,修改触底加载
Test Runner / hello (push) Successful in 5s

This commit is contained in:
2026-08-25 11:21:21 +08:00
parent 1313f20bdf
commit 075928124c
5 changed files with 88 additions and 113 deletions
+48 -26
View File
@@ -1,6 +1,6 @@
<template>
<!-- 产品列表页 - 印美达 Inkreach -->
<view class="products-page">
<view class="products-page" :style="{ height: windowHeight + 'px' }">
<!-- 搜索栏 -->
<SearchBar
:keyword="searchKeyword"
@@ -39,17 +39,12 @@
:list="products"
:sub-categories="subCategories"
:active-sub-id="activeSubCategory"
:total="pagination.total"
:current="pagination.current"
:page-size="pagination.pageSize"
:total-pages="pagination.totalPages"
:page-numbers="pageNumbers"
:start="pagination.start"
:end="pagination.end"
:has-more="hasMore"
:loading="loadingMore"
:scroll-top-val="scrollTopVal"
@sub-select="selectSubCategory"
@product-click="goDetail"
@page-change="loadGoods"
@scroll-to-lower="onScrollToLower"
/>
</view>
</view>
@@ -104,19 +99,26 @@ export default {
showFilter: false,
filterGroups: [],
pagination: {
start: 1,
end: 10,
total: 0,
current: 1,
pageSize: 10,
totalPages: 0
pageSize: 10
},
pageNumbers: [],
hasMore: true,
loadingMore: false,
products: []
products: [],
windowHeight: 667,
scrollTopVal: 0
}
},
async onLoad() {
try {
const sysInfo = uni.getSystemInfoSync()
// windowHeight 已自动扣除 uni-app 默认导航栏 & TabBar 高度
// 当前页是 navigationStyle:custom + TabBar 页,正好匹配可视区
this.windowHeight = sysInfo.windowHeight || 667
} catch (e) {
this.windowHeight = 667
}
await this.initData()
this.loadSubCategories('all')
await this.loadGoods(1)
@@ -232,28 +234,30 @@ export default {
}))
const total = data.total || 0
const totalPages = Math.ceil(total / pageSize) || 1
var pageNumbers = []
for (var i = Math.max(1, currentPage - 2); i <= Math.min(totalPages, currentPage + 2); i++) {
pageNumbers.push(i)
if (currentPage === 1) {
// 整表替换 = 筛选/分类/国家/搜索/初始化 等切换 → 滚动条回顶部
this.products = products
this.resetScrollToTop()
} else {
// 分页追加(触底加载)→ 保持滚动位置,不回到顶部
this.products = this.products.concat(products)
}
this.products = products
this.pagination = {
start: total === 0 ? 0 : (currentPage - 1) * pageSize + 1,
end: Math.min(currentPage * pageSize, total),
total: total,
current: currentPage,
pageSize: pageSize,
totalPages: totalPages
pageSize: pageSize
}
this.pageNumbers = pageNumbers
this.hasMore = this.products.length < total
this.loadingMore = false
console.log(
'[loadGoods] total=' + total +
', page=' + currentPage +
', items=' + products.length
', items=' + products.length +
', loaded=' + this.products.length +
', hasMore=' + this.hasMore
)
} catch (err) {
console.error('[loadGoods Error]', err)
@@ -329,6 +333,24 @@ export default {
this.loadGoods(1)
},
onScrollToLower() {
if (this.loadingMore || !this.hasMore) return
this.loadingMore = true
this.loadGoods(this.pagination.current + 1)
},
/**
* 把商品列表滚动条回到顶部。
* uni-app scroll-view 的 :scroll-top 仅在值变化时触发滚动,
* 所以先写到一个大值(必定变化),再 nextTick 写 0,保证每次都能回到顶部。
*/
resetScrollToTop() {
this.scrollTopVal = 99999
this.$nextTick(() => {
this.scrollTopVal = 0
})
},
async selectCountry(id) {
// 如果点击的是已选中的国家 → 取消选中
if (this.selectedCountry === id) {