From a3e203306c46fb6e1718249d45410c0a9f261455 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: Fri, 9 Jan 2026 12:12:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=A6=96=E9=A1=B5=E5=95=86?= =?UTF-8?q?=E5=93=81=E5=9B=BE=E7=89=87=E6=97=A0=E6=B3=95=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=9A=E4=B8=BAprocessRefreshData?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E5=92=8C=E5=B9=BF=E5=91=8A=E5=95=86=E5=93=81?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0mediaItems=E6=95=B0=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/index/index.js | 71 ++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/pages/index/index.js b/pages/index/index.js index e198a11..302bfde 100644 --- a/pages/index/index.js +++ b/pages/index/index.js @@ -735,6 +735,7 @@ Page({ id: 'ad_slot_1', name: '广告位1', imageUrls: ['/images/轮播图1.jpg'], + mediaItems: [{ url: '/images/轮播图1.jpg', type: 'image' }], price: 0, adType: 'full_card', isAd: true @@ -743,6 +744,7 @@ Page({ id: 'ad_slot_2', name: '广告位2', imageUrls: ['/images/轮播图1.jpg'], + mediaItems: [{ url: '/images/轮播图1.jpg', type: 'image' }], price: 0, adType: 'half_image', isAd: true @@ -803,6 +805,14 @@ Page({ // 确保商品ID的一致性 const productId = product.productId || product.id; + // 预处理媒体URL,添加类型信息 + const mediaItems = formattedImageUrls.map(url => { + return { + url: url, + type: isVideoUrl(url) ? 'video' : 'image' + }; + }); + return { ...product, id: productId, // 统一使用id字段 @@ -825,7 +835,9 @@ Page({ isReserved: false, isFavorite: false, currentImageIndex: 0, - imageUrls: formattedImageUrls + imageUrls: formattedImageUrls, + // 添加预处理后的媒体数据,包含类型信息 + mediaItems: mediaItems } }) @@ -894,6 +906,7 @@ Page({ id: 'ad_slot_1', name: '广告位1', imageUrls: ['/images/轮播图1.jpg'], + mediaItems: [{ url: '/images/轮播图1.jpg', type: 'image' }], price: 0, adType: 'full_card', isAd: true @@ -903,6 +916,7 @@ Page({ id: 'ad_slot_2', name: '广告位2', imageUrls: ['/images/轮播图1.jpg'], + mediaItems: [{ url: '/images/轮播图1.jpg', type: 'image' }], price: 0, adType: 'half_image', isAd: true @@ -1568,22 +1582,8 @@ Page({ // 如果本地过滤结果不足,或者没有匹配的商品,则重新加载数据 if (filteredGoods.length < 3 && this.data.searchKeyword) { console.log('searchGoods - 本地过滤结果不足3个,将重新加载数据'); - this.setData({ - page: 1, - hasMoreData: true, - goods: [], - filteredGoods: [], - loadingMore: false, - // 清除相关缓存以获取最新数据 - lastDataTimestamp: 0, - categoryQueryCache: {}, - isQueryingSoldOut: false, - publishedHasMore: true, - soldOutPage: 1 - }, () => { - console.log('searchGoods:本地商品不足,重新加载数据,搜索关键词:', this.data.searchKeyword); - this.loadGoods(false, true); // 第二个参数true表示强制刷新 - }); + // 调用下拉刷新函数实现自动刷新 + this.onRefresh(); } else { // 本地商品足够,直接使用本地过滤结果 console.log('searchGoods:使用本地商品过滤结果,数量:', filteredGoods.length); @@ -1606,7 +1606,7 @@ Page({ selectRegion: function (e) { const region = e.currentTarget.dataset.region - // 立即关闭弹窗 + // 立即关闭弹窗并设置新的地区 this.setData({ selectedRegion: region, searchKeyword: '', // 清除搜索关键词,筛选框优先级更高 @@ -1619,21 +1619,8 @@ Page({ app.globalData.showTabBar = true; } - // 清除缓存并重新加载数据 - 仿照下拉刷新机制 - this.setData({ - page: 1, - hasMoreData: true, - goods: [], - filteredGoods: [], - loadingMore: false, - // 清除所有缓存以获取最新数据 - categoryQueryCache: {}, - lastDataTimestamp: 0, - goodsCache: [] - }); - - - this.loadGoods(false, true); // 强制刷新 + // 调用下拉刷新函数实现自动刷新 + this.onRefresh(); }, // 阻止事件冒泡 @@ -1654,26 +1641,14 @@ Page({ return // 如果选择的分类和当前相同,不重复加载 } - // 清除缓存并重新加载数据 - 筛选时不显示骨架屏,直接显示内容 + // 设置新的分类并清除搜索关键词 this.setData({ selectedCategory: category, searchKeyword: '', // 清除搜索关键词,筛选框优先级更高 - loadingMore: false, - page: 1, - hasMoreData: true, - goods: [], - filteredGoods: [], - isLoading: false, // 筛选时不显示骨架屏 - isRefreshing: false, // 筛选时不显示下拉刷新状态 - // 清除所有缓存以获取最新数据 - categoryQueryCache: {}, - lastDataTimestamp: 0, - goodsCache: [] }); - // 强制刷新:从数据库重新加载数据 - - this.loadGoods(false, true); // 第二个参数true表示强制刷新 + // 调用下拉刷新函数实现自动刷新 + this.onRefresh(); }, // 查看商品详情