Browse Source

修复首页商品图片无法显示的问题:为processRefreshData函数和广告商品添加mediaItems数组

pull/11/head
徐飞洋 2 months ago
parent
commit
a3e203306c
  1. 71
      pages/index/index.js

71
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();
},
// 查看商品详情

Loading…
Cancel
Save