From f4877acf21949c1f534a509654c95b3b913135f7 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:51:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=95=86=E5=93=81=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E5=92=8C=E7=BB=93=E7=AE=97=E9=A1=B5=E9=9D=A2?= 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 +++++++++++++ pages/settlement/index.js | 4 ++-- 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/pages/goods/index.js b/pages/goods/index.js index ba95b17..846828d 100644 --- a/pages/goods/index.js +++ b/pages/goods/index.js @@ -51,7 +51,7 @@ Page({ total: 0, // 总数据条数 searchTimer: null, // 搜索防抖定时器 // 分页相关字段 - pageSize: 7, // 每页数量 + pageSize: 20, // 每页数量 publishedCurrentPage: 1, // 已上架商品当前页码 publishedHasMore: true, // 已上架商品是否有更多 soldOutCurrentPage: 1, // 售空商品当前页码 @@ -332,9 +332,13 @@ 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 @@ -342,7 +346,7 @@ Page({ status === 'sold' || status === 'out_of_stock' || (item.supplyStatus && item.supplyStatus.includes('售空')); - + if (isSoldOut) { status = 'sold_out' } else if (status !== 'published') { @@ -369,7 +373,8 @@ Page({ price: processedPrice, formattedCreatedAt: this.formatDateTime(displayTime), creatorName: creatorName, - imageUrls: formattedImageUrls + imageUrls: formattedImageUrls, + mediaItems: mediaItems } }) @@ -383,7 +388,7 @@ Page({ /** * 加载已上架(published)状态的货源 - 支持分页 */ - async loadPublishedGoods(page = 1, pageSize = this.data.pageSize, allGoodsData = null) { + async loadPublishedGoods(page = 1, pageSize = this.data.pageSize) { if (this.data.isLoadingPublished) return { goods: [], hasMore: true } this.setData({ @@ -398,8 +403,8 @@ Page({ }) try { - // 使用传入的商品数据或获取所有商品数据 - const allGoods = allGoodsData || await this.loadAllGoodsData() + // 先获取所有商品数据 + const allGoods = await this.loadAllGoodsData() // 过滤出已上架状态的商品 let publishedGoods = allGoods.filter(item => item.status === 'published') @@ -451,7 +456,7 @@ Page({ /** * 加载售空(sold_out)状态的货源 - 支持分页 */ - async loadSoldOutGoods(page = 1, pageSize = this.data.pageSize, allGoodsData = null) { + async loadSoldOutGoods(page = 1, pageSize = this.data.pageSize) { if (this.data.isLoadingSoldOut) return { goods: [], hasMore: true } this.setData({ @@ -466,8 +471,8 @@ Page({ }) try { - // 使用传入的商品数据或获取所有商品数据 - const allGoods = allGoodsData || await this.loadAllGoodsData() + // 先获取所有商品数据 + const allGoods = await this.loadAllGoodsData() // 过滤出售空状态的商品 let soldOutGoods = allGoods.filter(item => item.status === 'sold_out') @@ -585,19 +590,12 @@ 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, - allGoodsData + this.data.pageSize ) newGoods = publishedResult.goods @@ -623,7 +621,7 @@ Page({ } // 添加缓冲,避免请求太快 - await new Promise(resolve => setTimeout(resolve, 300)) + await new Promise(resolve => setTimeout(resolve, 500)) } // 2. 如果已上架商品加载完,开始加载售空商品 @@ -631,8 +629,7 @@ Page({ console.log('加载售空商品第', this.data.soldOutCurrentPage, '页') const soldOutResult = await this.loadSoldOutGoods( this.data.soldOutCurrentPage, - this.data.pageSize, - allGoodsData + this.data.pageSize ) newGoods = soldOutResult.goods diff --git a/pages/goods/index.wxml b/pages/goods/index.wxml index 143beaa..d98a2e8 100644 --- a/pages/goods/index.wxml +++ b/pages/goods/index.wxml @@ -85,7 +85,20 @@ > +