From c022c02f2fadafeb803edbed7f55132a43163661 Mon Sep 17 00:00:00 2001 From: davy Date: Thu, 10 Apr 2025 00:38:18 +0800 Subject: [PATCH] =?UTF-8?q?feat:=201.=20=E4=BC=98=E5=8C=96=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=A0=B7=E5=BC=8F=E5=92=8C=E4=BA=A4=E4=BA=92=202.=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=B0=E7=9A=84=E5=9B=BE=E6=A0=87=E8=B5=84?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/rowBeer.vue | 2 +- pages/activityList/details.vue | 59 ++++++++++++----- pages/activityList/index.vue | 29 +++++++-- pages/index/index.vue | 112 +++++++++++++++++++++++++-------- static/arrow-right.svg | 1 + 5 files changed, 158 insertions(+), 45 deletions(-) create mode 100644 static/arrow-right.svg diff --git a/components/rowBeer.vue b/components/rowBeer.vue index dffec84..7e32b7b 100644 --- a/components/rowBeer.vue +++ b/components/rowBeer.vue @@ -73,7 +73,7 @@ width: 208rpx; background: #FFFFFF; margin-right: 16rpx; - margin-bottom: 36rpx; + margin-bottom: 24rpx; box-sizing: border-box; display: flex; flex-direction: column; diff --git a/pages/activityList/details.vue b/pages/activityList/details.vue index 3ad0627..f4d3485 100644 --- a/pages/activityList/details.vue +++ b/pages/activityList/details.vue @@ -9,8 +9,8 @@ - {{activityInfo.title || 'TasteRoom 风味屋 · 风味之旅系列'}} - {{activityInfo.description || '探索啤酒风味新边界'}} + {{featureInfo.pageName || '专辑详情'}} + {{featureInfo.subTitle || '探索啤酒风味新边界'}} @@ -50,8 +50,8 @@ }, data() { return { - activityId: '', - activityInfo: {}, + featureId: '', + featureInfo: {}, beerList: [], queryForm: { search: '' @@ -61,28 +61,45 @@ }; }, onLoad(options) { + console.log('专辑详情页 onLoad options:', options) if (options.id) { - this.activityId = options.id - this.getActivityDetail() + this.featureId = options.id + console.log('专辑ID:', this.featureId) + this.getFeatureDetail() + } else { + console.error('未传递专辑ID') + uni.showToast({ + title: '参数错误', + icon: 'none' + }) } }, onShow(){ // uni.showTabBar() }, methods: { - // 获取活动详情 - async getActivityDetail() { + // 获取专辑详情 + async getFeatureDetail() { try { - const res = await getFeaturePage(this.activityId) + console.log('开始获取专辑详情,ID:', this.featureId) + const res = await getFeaturePage(this.featureId) + console.log('专辑详情接口返回数据:', res) if (res.code === 200 && res.data) { - this.activityInfo = res.data - // 获取活动相关的酒款列表 + this.featureInfo = res.data + console.log('专辑详情数据:', this.featureInfo) + // 获取专辑相关的酒款列表 this.getBeerList() + } else { + console.error('获取专辑详情失败,返回码:', res.code) + uni.showToast({ + title: '获取专辑详情失败', + icon: 'none' + }) } } catch (error) { - console.error('获取活动详情失败:', error) + console.error('获取专辑详情失败:', error) uni.showToast({ - title: '获取活动详情失败', + title: '获取专辑详情失败', icon: 'none' }) } @@ -91,9 +108,23 @@ // 获取酒款列表 async getBeerList() { try { - const res = await getBeerList(this.activityInfo.keyword || '') + // 使用专辑的关键词或ID来获取相关酒款 + const params = { + featurePageId: this.featureId + } + console.log('开始获取酒款列表,参数:', params) + + const res = await getBeerList(params) + console.log('酒款列表接口返回数据:', res) if (res.code === 200 && res.data) { this.beerList = res.data + console.log('酒款列表数据:', this.beerList) + } else { + console.error('获取酒款列表失败,返回码:', res.code) + uni.showToast({ + title: '获取酒款列表失败', + icon: 'none' + }) } } catch (error) { console.error('获取酒款列表失败:', error) diff --git a/pages/activityList/index.vue b/pages/activityList/index.vue index 34d065e..7c20a95 100644 --- a/pages/activityList/index.vue +++ b/pages/activityList/index.vue @@ -28,13 +28,13 @@ - + {{ item.pageName }} {{ item.subTitle}} - + @@ -192,12 +192,14 @@ \ No newline at end of file diff --git a/pages/index/index.vue b/pages/index/index.vue index f62c510..256e55d 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -146,6 +146,7 @@ finished: false, navItems: ['新酒上市', '生成酒单', '酒币换购', '关注厂牌'], currentAdIndex: 0, // 当前广告索引 + adLoading: false, // 广告加载状态 }; }, created() { @@ -160,6 +161,8 @@ if (this.featurePageList.length === 0) { this.getActivityList() } + // 预加载广告数据 + this.preloadAdData() }, watch: { featurePageList: { @@ -181,7 +184,6 @@ // }) // }, 500) this.statusBaeHeight = uni.getWindowInfo.statusBarHeight - this.getBannerListFun() // 广告轮播图 uni.showShareMenu({ menus: ['shareAppMessage', 'shareTimeline'] }) @@ -198,6 +200,9 @@ // 只在用户状态变化时重新加载数据 this.resetAndLoadData() } + + // 检查是否需要显示广告 + this.checkAndShowAd() }, methods: { loginSuccess() { @@ -300,13 +305,30 @@ url: "/pages/index/review?beerId=" + it.id }) }, + // 预加载广告数据 + async preloadAdData() { + try { + this.adLoading = true + await this.getBannerListFun() + } catch (error) { + console.error('广告预加载失败:', error) + } finally { + this.adLoading = false + } + }, + // 查询广告弹窗 banner列表 - getBannerListFun() { + async getBannerListFun() { this.ADList = [] this.homeBanner = [] this.bannerJoin = null - getBannerList().then(res => { - if (!res.data || !Array.isArray(res.data)) return + + try { + const res = await getBannerList() + if (!res.data || !Array.isArray(res.data)) { + console.error('广告数据格式错误') + return + } res.data.forEach(it => { if (it.bannerType === 'homeAD') { // 开屏广告 @@ -317,20 +339,46 @@ this.homeBanner.push(it) } }) - - // 检查是否需要显示开屏广告 - const lastShowTime = uni.getStorageSync('lastShowHomeADTime') - const currentTime = new Date().getTime() - // 如果从未显示过或者距离上次显示超过24小时 - if (!lastShowTime || (currentTime - lastShowTime > 24 * 60 * 60 * 1000)) { - if (this.ADList.length > 0) { + } catch (err) { + console.error('获取banner列表失败:', err) + uni.showToast({ + title: '广告加载失败', + icon: 'none' + }) + } + }, + + // 检查并显示广告 + checkAndShowAd() { + if (this.ADList.length === 0) { + // 如果没有广告数据,先获取广告数据 + this.getBannerListFun().then(() => { + this.showAdIfNeeded() + }) + return + } + + this.showAdIfNeeded() + }, + + // 判断是否需要显示广告 + showAdIfNeeded() { + if (this.ADList.length === 0) return + + const lastShowTime = uni.getStorageSync('lastShowHomeADTime') + const currentTime = new Date().getTime() + + // 如果从未显示过或者距离上次显示超过1小时 + if (!lastShowTime || (currentTime - lastShowTime > 60 * 60 * 1000)) { + this.$nextTick(() => { + if (this.$refs.ADRef) { this.$refs.ADRef.open() } - } - }).catch(err => { - console.error('获取banner列表失败:', err) - }) + }) + } }, + + // 关闭广告 closeAd() { // 记录广告显示时间 uni.setStorageSync('lastShowHomeADTime', new Date().getTime()) @@ -338,7 +386,12 @@ backgroundColor: '#ffffff' }) this.$refs.ADRef.close() + + // 添加关闭动画 + this.currentAdIndex = 0 }, + + // 处理广告点击 handleAD(item) { if (!item || !item.bannerLink) return @@ -363,12 +416,29 @@ } }) } else if (item.bannerLink.startsWith('http')) { - // 外部链接,可以使用web-view页面打开 + // 外部链接,使用web-view页面打开 uni.navigateTo({ url: `/pages/webview/webview?url=${encodeURIComponent(item.bannerLink)}` }) } }, + + // 处理广告轮播切换 + handleAdSwiperChange(e) { + this.currentAdIndex = e.detail.current + }, + + // 处理弹窗状态变化 + handlePopupChange(e) { + if (!e.show) { + this.closeAd() + } else { + // 检查广告数据是否有效 + if (this.ADList.length === 0) { + this.closeAd() + } + } + }, // 立即认证门店 toJoin() { if (!this.bannerJoin || !this.bannerJoin.bannerLink) return @@ -430,16 +500,6 @@ break; } }, - // 处理广告轮播切换 - handleAdSwiperChange(e) { - this.currentAdIndex = e.detail.current - }, - // 处理弹窗状态变化 - handlePopupChange(e) { - if (!e.show) { - this.closeAd() - } - }, // 跳转到生成酒单页面 toBeerList() { uni.switchTab({ diff --git a/static/arrow-right.svg b/static/arrow-right.svg new file mode 100644 index 0000000..d1daad4 --- /dev/null +++ b/static/arrow-right.svg @@ -0,0 +1 @@ + \ No newline at end of file