货盘页导航栏去除,修复奇数个商品样式错误,修改触底加载
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
+1
View File
@@ -12,6 +12,7 @@
"path": "pages/products/products", "path": "pages/products/products",
"style": { "style": {
"navigationBarTitleText": "产品中心", "navigationBarTitleText": "产品中心",
"navigationStyle": "custom",
"usingComponents": {} "usingComponents": {}
} }
}, },
+20 -83
View File
@@ -13,7 +13,7 @@
</view> </view>
<!-- 商品网格滚动区 --> <!-- 商品网格滚动区 -->
<scroll-view scroll-y class="product-scroll"> <scroll-view scroll-y class="product-scroll" :lower-threshold="100" :scroll-top="scrollTopVal" :scroll-with-animation="false" @scrolltolower="onScrollToLower">
<view class="product-grid" v-if="list.length > 0"> <view class="product-grid" v-if="list.length > 0">
<view <view
class="product-card" class="product-card"
@@ -51,24 +51,11 @@
<text class="empty-text">没有找到相关商品</text> <text class="empty-text">没有找到相关商品</text>
</view> </view>
<!-- 分页 --> <!-- 底部加载提示 -->
<view class="pagination" v-if="total > 0"> <view class="load-tip" v-if="list.length > 0">
<text class="page-info">显示 {{ start }}-{{ end }} {{ total }} 个产品</text> <text v-if="loading">加载中...</text>
<view class="page-controls"> <text v-else-if="!hasMore">没有更多了</text>
<view class="page-btn" :class="{ disabled: current === 1 }" @tap="onPrev">上一页</view>
<view
class="page-num"
:class="{ active: current === item }"
v-for="(item, index) in pageNumbers"
:key="index"
@tap="onGoPage(item)"
>{{ item }}</view>
<view class="page-btn" :class="{ disabled: current === totalPages }" @tap="onNext">下一页</view>
</view> </view>
<view class="page-size"><text>{{ pageSize }}/</text></view>
</view>
<view class="loading-more" v-if="loading"><text>加载中...</text></view>
</scroll-view> </scroll-view>
</view> </view>
</template> </template>
@@ -80,31 +67,25 @@ export default {
list: { type: Array, default: () => [] }, list: { type: Array, default: () => [] },
subCategories: { type: Array, default: () => [] }, subCategories: { type: Array, default: () => [] },
activeSubId: { type: [String, Number], default: '' }, activeSubId: { type: [String, Number], default: '' },
total: { type: Number, default: 0 }, hasMore: { type: Boolean, default: true },
current: { type: Number, default: 1 }, loading: { type: Boolean, default: false },
pageSize: { type: Number, default: 10 }, scrollTopVal: { type: Number, default: 0 }
totalPages: { type: Number, default: 1 },
pageNumbers: { type: Array, default: () => [] },
start: { type: Number, default: 1 },
end: { type: Number, default: 10 },
loading: { type: Boolean, default: false }
}, },
methods: { methods: {
selectSub(id) { this.$emit('sub-select', id) }, selectSub(id) { this.$emit('sub-select', id) },
onTapProduct(item) { this.$emit('product-click', item) }, onTapProduct(item) { this.$emit('product-click', item) },
onPrev() { if (this.current > 1) this.$emit('page-change', this.current - 1) }, onScrollToLower() { this.$emit('scroll-to-lower') }
onNext() { if (this.current < this.totalPages) this.$emit('page-change', this.current + 1) },
onGoPage(page) { this.$emit('page-change', page) }
} }
} }
</script> </script>
<style scoped> <style scoped>
/* 右侧内容区 - 上下分:顶部条件 + 下方滚动 */ /* 右侧内容区 - 上下分:顶部条件 + 下方滚动
flex:1 与 height:100% 冲突,二选一(保留 flex:1 */
.right-content { .right-content {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
height: 100%; min-height: 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
background: #f2f2f2; background: #f2f2f2;
@@ -135,22 +116,23 @@ export default {
color: #ff6800; color: #ff6800;
} }
/* 滚动商品区 */ /* 滚动商品区 - uni-app scroll-view 在 flex 布局里必须同时有 flex:1 + height:0
仅 min-height:0 无法让部分端的 scroll-view 正确计算内部 viewport 高度 */
.product-scroll { .product-scroll {
flex: 1; flex: 1;
height: 0;
min-height: 0; min-height: 0;
overflow: hidden; overflow: hidden;
} }
/* 商品网格 - 2列自适应(避免宽度+间距同时固定导致挤压) */ /* 商品网格 - 固定2列 grid,不会因商品个数变化而拉伸占行 */
.product-grid { .product-grid {
display: flex; display: grid;
flex-wrap: wrap; grid-template-columns: repeat(2, 1fr);
gap: 16rpx; gap: 16rpx;
padding: 20rpx; padding: 20rpx;
} }
.product-card { .product-card {
flex: 1 1 calc(50% - 8rpx);
min-width: 0; min-width: 0;
background: #ffffff; background: #ffffff;
border-radius: 12rpx; border-radius: 12rpx;
@@ -212,53 +194,8 @@ export default {
line-height: 1.2; line-height: 1.2;
} }
/* 分页 */ /* 底部加载提示 */
.pagination { .load-tip {
padding: 32rpx 20rpx;
display: flex;
flex-direction: column;
align-items: center;
gap: 20rpx;
}
.page-info {
font-size: 22rpx;
color: #999999;
}
.page-controls {
display: flex;
align-items: center;
gap: 12rpx;
}
.page-btn {
padding: 10rpx 20rpx;
font-size: 24rpx;
color: #666666;
background: #f5f5f5;
border-radius: 8rpx;
}
.page-btn.disabled {
color: #cccccc;
}
.page-num {
width: 56rpx;
height: 56rpx;
display: flex;
align-items: center;
justify-content: center;
font-size: 24rpx;
color: #666666;
background: #f5f5f5;
border-radius: 8rpx;
}
.page-num.active {
background: #ff6800;
color: #ffffff;
}
.page-size {
font-size: 22rpx;
color: #999999;
}
.loading-more {
padding: 32rpx; padding: 32rpx;
text-align: center; text-align: center;
font-size: 24rpx; font-size: 24rpx;
+15 -1
View File
@@ -1,6 +1,6 @@
<template> <template>
<!-- 搜索栏 --> <!-- 搜索栏 -->
<view class="search-bar"> <view class="search-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
<view class="search-input-wrap"> <view class="search-input-wrap">
<text class="search-icon">🔍</text> <text class="search-icon">🔍</text>
<input <input
@@ -28,6 +28,19 @@ export default {
default: '' default: ''
} }
}, },
data() {
return {
statusBarHeight: 20
}
},
created() {
try {
const sysInfo = uni.getSystemInfoSync()
this.statusBarHeight = sysInfo.statusBarHeight || 20
} catch (e) {
this.statusBarHeight = 20
}
},
methods: { methods: {
onInput(e) { onInput(e) {
this.$emit('input', e.detail.value) this.$emit('input', e.detail.value)
@@ -50,6 +63,7 @@ export default {
padding: 20rpx 32rpx; padding: 20rpx 32rpx;
background: #ffffff; background: #ffffff;
border-bottom: 2rpx solid #f5f5f5; border-bottom: 2rpx solid #f5f5f5;
box-sizing: border-box;
} }
.search-input-wrap { .search-input-wrap {
flex: 1; flex: 1;
+4 -3
View File
@@ -4,7 +4,7 @@
.products-page { .products-page {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100vh; overflow: hidden; /* 唯一滚动源 = scroll-view,整页绝不兜底滚动 */
background: #f2f2f2; background: #f2f2f2;
} }
@@ -16,12 +16,13 @@
min-height: 0; min-height: 0;
} }
/* 右侧容器 - 自动占满剩余宽度(高度自动撑开,内部由 ProductGrid 自己滚动) */ /* 右侧容器 - 自动占满剩余宽度(高度自动撑开,内部由 ProductGrid 自己滚动)
flex:1 与 height:100% 冲突,必须二选一,否则 flex 链路断裂 */
.right-wrap { .right-wrap {
flex: 1; flex: 1;
min-width: 0; min-width: 0;
min-height: 0;
display: flex; display: flex;
flex-direction: column; flex-direction: column;
height: 100%;
overflow: hidden; overflow: hidden;
} }
+48 -26
View File
@@ -1,6 +1,6 @@
<template> <template>
<!-- 产品列表页 - 印美达 Inkreach --> <!-- 产品列表页 - 印美达 Inkreach -->
<view class="products-page"> <view class="products-page" :style="{ height: windowHeight + 'px' }">
<!-- 搜索栏 --> <!-- 搜索栏 -->
<SearchBar <SearchBar
:keyword="searchKeyword" :keyword="searchKeyword"
@@ -39,17 +39,12 @@
:list="products" :list="products"
:sub-categories="subCategories" :sub-categories="subCategories"
:active-sub-id="activeSubCategory" :active-sub-id="activeSubCategory"
:total="pagination.total" :has-more="hasMore"
:current="pagination.current"
:page-size="pagination.pageSize"
:total-pages="pagination.totalPages"
:page-numbers="pageNumbers"
:start="pagination.start"
:end="pagination.end"
:loading="loadingMore" :loading="loadingMore"
:scroll-top-val="scrollTopVal"
@sub-select="selectSubCategory" @sub-select="selectSubCategory"
@product-click="goDetail" @product-click="goDetail"
@page-change="loadGoods" @scroll-to-lower="onScrollToLower"
/> />
</view> </view>
</view> </view>
@@ -104,19 +99,26 @@ export default {
showFilter: false, showFilter: false,
filterGroups: [], filterGroups: [],
pagination: { pagination: {
start: 1,
end: 10,
total: 0, total: 0,
current: 1, current: 1,
pageSize: 10, pageSize: 10
totalPages: 0
}, },
pageNumbers: [], hasMore: true,
loadingMore: false, loadingMore: false,
products: [] products: [],
windowHeight: 667,
scrollTopVal: 0
} }
}, },
async onLoad() { 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() await this.initData()
this.loadSubCategories('all') this.loadSubCategories('all')
await this.loadGoods(1) await this.loadGoods(1)
@@ -232,28 +234,30 @@ export default {
})) }))
const total = data.total || 0 const total = data.total || 0
const totalPages = Math.ceil(total / pageSize) || 1
var pageNumbers = [] if (currentPage === 1) {
for (var i = Math.max(1, currentPage - 2); i <= Math.min(totalPages, currentPage + 2); i++) { // 整表替换 = 筛选/分类/国家/搜索/初始化 等切换 → 滚动条回顶部
pageNumbers.push(i) this.products = products
this.resetScrollToTop()
} else {
// 分页追加(触底加载)→ 保持滚动位置,不回到顶部
this.products = this.products.concat(products)
} }
this.products = products
this.pagination = { this.pagination = {
start: total === 0 ? 0 : (currentPage - 1) * pageSize + 1,
end: Math.min(currentPage * pageSize, total),
total: total, total: total,
current: currentPage, current: currentPage,
pageSize: pageSize, pageSize: pageSize
totalPages: totalPages
} }
this.pageNumbers = pageNumbers this.hasMore = this.products.length < total
this.loadingMore = false this.loadingMore = false
console.log( console.log(
'[loadGoods] total=' + total + '[loadGoods] total=' + total +
', page=' + currentPage + ', page=' + currentPage +
', items=' + products.length ', items=' + products.length +
', loaded=' + this.products.length +
', hasMore=' + this.hasMore
) )
} catch (err) { } catch (err) {
console.error('[loadGoods Error]', err) console.error('[loadGoods Error]', err)
@@ -329,6 +333,24 @@ export default {
this.loadGoods(1) 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) { async selectCountry(id) {
// 如果点击的是已选中的国家 → 取消选中 // 如果点击的是已选中的国家 → 取消选中
if (this.selectedCountry === id) { if (this.selectedCountry === id) {