From a80053a21b46d6a2beb70b1ff0e1d3bed8c4533e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=A3=9E=E6=B4=8B?= <15778543+xufeiyang6017@user.noreply.gitee.com> Date: Sat, 24 Jan 2026 11:38:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96goods=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E6=80=A7=E8=83=BD=EF=BC=9A=E7=A6=81=E7=94=A8=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E6=92=AD=E6=94=BE=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=88=86=E9=A1=B5?= =?UTF-8?q?=E4=B8=BA10=E4=B8=AA=EF=BC=8C=E4=BC=98=E5=8C=96=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/goods/index.js | 39 +++++++++++++++++++++------------------ pages/goods/index.wxml | 13 ------------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/pages/goods/index.js b/pages/goods/index.js index 846828d..ba95b17 100644 --- a/pages/goods/index.js +++ b/pages/goods/index.js @@ -51,7 +51,7 @@ Page({ total: 0, // 总数据条数 searchTimer: null, // 搜索防抖定时器 // 分页相关字段 - pageSize: 20, // 每页数量 + pageSize: 7, // 每页数量 publishedCurrentPage: 1, // 已上架商品当前页码 publishedHasMore: true, // 已上架商品是否有更多 soldOutCurrentPage: 1, // 售空商品当前页码 @@ -332,13 +332,9 @@ Page({ const sellerNickName = item.seller?.nickName || item.seller?.sellerNickName || item.seller?.name || '未知'; const creatorName = sellerNickName; - // 处理媒体URL + // 处理媒体URL - 简化处理,只保留图片URL const imageUrls = item.imageUrls || item.images || [] const formattedImageUrls = Array.isArray(imageUrls) ? imageUrls : [imageUrls] - const mediaItems = formattedImageUrls.map(url => ({ - url: url, - type: isVideoUrl(url) ? 'video' : 'image' - })) // 处理商品状态 let status = item.status @@ -346,7 +342,7 @@ Page({ status === 'sold' || status === 'out_of_stock' || (item.supplyStatus && item.supplyStatus.includes('售空')); - + if (isSoldOut) { status = 'sold_out' } else if (status !== 'published') { @@ -373,8 +369,7 @@ Page({ price: processedPrice, formattedCreatedAt: this.formatDateTime(displayTime), creatorName: creatorName, - imageUrls: formattedImageUrls, - mediaItems: mediaItems + imageUrls: formattedImageUrls } }) @@ -388,7 +383,7 @@ Page({ /** * 加载已上架(published)状态的货源 - 支持分页 */ - async loadPublishedGoods(page = 1, pageSize = this.data.pageSize) { + async loadPublishedGoods(page = 1, pageSize = this.data.pageSize, allGoodsData = null) { if (this.data.isLoadingPublished) return { goods: [], hasMore: true } this.setData({ @@ -403,8 +398,8 @@ Page({ }) try { - // 先获取所有商品数据 - const allGoods = await this.loadAllGoodsData() + // 使用传入的商品数据或获取所有商品数据 + const allGoods = allGoodsData || await this.loadAllGoodsData() // 过滤出已上架状态的商品 let publishedGoods = allGoods.filter(item => item.status === 'published') @@ -456,7 +451,7 @@ Page({ /** * 加载售空(sold_out)状态的货源 - 支持分页 */ - async loadSoldOutGoods(page = 1, pageSize = this.data.pageSize) { + async loadSoldOutGoods(page = 1, pageSize = this.data.pageSize, allGoodsData = null) { if (this.data.isLoadingSoldOut) return { goods: [], hasMore: true } this.setData({ @@ -471,8 +466,8 @@ Page({ }) try { - // 先获取所有商品数据 - const allGoods = await this.loadAllGoodsData() + // 使用传入的商品数据或获取所有商品数据 + const allGoods = allGoodsData || await this.loadAllGoodsData() // 过滤出售空状态的商品 let soldOutGoods = allGoods.filter(item => item.status === 'sold_out') @@ -590,12 +585,19 @@ Page({ let updatedPublishedHasMore = this.data.publishedHasMore let updatedSoldOutHasMore = this.data.soldOutHasMore + // 只在初始加载时获取所有商品数据 + let allGoodsData = null + if (!isLoadMore) { + allGoodsData = await this.loadAllGoodsData() + } + // 1. 如果已上架商品还有更多,继续加载已上架商品 if (this.data.publishedHasMore) { console.log('加载已上架商品第', this.data.publishedCurrentPage, '页') const publishedResult = await this.loadPublishedGoods( this.data.publishedCurrentPage, - this.data.pageSize + this.data.pageSize, + allGoodsData ) newGoods = publishedResult.goods @@ -621,7 +623,7 @@ Page({ } // 添加缓冲,避免请求太快 - await new Promise(resolve => setTimeout(resolve, 500)) + await new Promise(resolve => setTimeout(resolve, 300)) } // 2. 如果已上架商品加载完,开始加载售空商品 @@ -629,7 +631,8 @@ Page({ console.log('加载售空商品第', this.data.soldOutCurrentPage, '页') const soldOutResult = await this.loadSoldOutGoods( this.data.soldOutCurrentPage, - this.data.pageSize + this.data.pageSize, + allGoodsData ) newGoods = soldOutResult.goods diff --git a/pages/goods/index.wxml b/pages/goods/index.wxml index a49906a..143beaa 100644 --- a/pages/goods/index.wxml +++ b/pages/goods/index.wxml @@ -85,20 +85,7 @@ > -