From 43dc65836ddfdf96bbfb6f2af813f8459b8bb78c Mon Sep 17 00:00:00 2001 From: ISFP_T <68358856@qq.com> Date: Mon, 10 Nov 2025 09:15:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/api/system.js | 2 +- config/url.js | 4 +- pages/index/index.vue | 188 +++++++++++++++++++++++++++++++++++------- 3 files changed, 160 insertions(+), 34 deletions(-) diff --git a/config/api/system.js b/config/api/system.js index 67e88a6..361ff6c 100644 --- a/config/api/system.js +++ b/config/api/system.js @@ -30,7 +30,7 @@ export const getCommonByBrand = (brandName) => { // 查询激活的且临近关闭时间最近的活动 export const getActiveActivity = () => { return request({ - url: '/app/activity/nearest-active', + url: '/device/activity/agent/list', method: 'get', hideLoading: true }) diff --git a/config/url.js b/config/url.js index fe70554..cb4e171 100644 --- a/config/url.js +++ b/config/url.js @@ -1,5 +1,5 @@ -// export const URL = "https://my.gxfs123.com/api" //正式服务器 -export const URL = "https://fansdev.gxfs123.com/api" //测试服务器 +export const URL = "https://my.gxfs123.com/api" //正式服务器 +// export const URL = "https://fansdev.gxfs123.com/api" //测试服务器 // export const URL = "http://192.168.5.149:8080" //本地调试 // export const URL = "http://127.0.0.1:8080" //本地调试 diff --git a/pages/index/index.vue b/pages/index/index.vue index 0a07dc1..b104397 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -151,21 +151,43 @@ - - - - + + + + + + - - - + + + + + + + + + + {{ $t('common.close') }} + @@ -234,7 +256,9 @@ const isRelocating = ref(false) // 防抖标志:是否正在重新定位 const showGuidePopup = ref(false) // 使用指南弹窗显示状态 const showNoticePopup = ref(false) // 通知详情弹窗显示状态 const showActivityPopup = ref(false) // 活动弹窗显示状态 -const activityData = ref(null) // 活动数据 +const activityList = ref([]) // 活动列表 +const currentActivityIndex = ref(0) // 当前活动索引 +const hasShownActivityThisSession = ref(false) // 本次会话是否已显示过活动(内存变量) // 导航栏高度相关 const statusBarHeight = ref(0) @@ -292,22 +316,50 @@ const statusBarHeight = ref(0) // 查询最近的活动 const checkActiveActivity = async () => { try { - // 检查是否已经显示过活动弹窗(本次会话) - const hasShownActivity = uni.getStorageSync('hasShownActivityInSession'); - if (hasShownActivity) { + // 检查本次会话是否已经显示过活动弹窗(使用内存变量) + if (hasShownActivityThisSession.value) { console.log('本次会话已显示过活动弹窗,跳过'); return; } const res = await getActiveActivity(); - if (res.code === 200 && res.data) { - activityData.value = res.data; - // 延迟一下显示,避免与其他弹窗冲突 - setTimeout(() => { - openActivityPopup(); - // 标记本次会话已显示过活动弹窗 - uni.setStorageSync('hasShownActivityInSession', true); - }, 500); + console.log('活动接口返回:', res); + + if (res.code === 200) { + let activities = []; + + // 处理活动数据:兼容多种返回格式 + if (res.rows && Array.isArray(res.rows)) { + // 格式1: { code: 200, rows: [...] } + activities = res.rows; + } else if (res.data && res.data.rows && Array.isArray(res.data.rows)) { + // 格式2: { code: 200, data: { rows: [...] } } + activities = res.data.rows; + } else if (Array.isArray(res.data)) { + // 格式3: { code: 200, data: [...] } + activities = res.data; + } else if (res.data && typeof res.data === 'object') { + // 格式4: { code: 200, data: {...} } 单个对象 + activities = [res.data]; + } + + // 过滤有效的活动(必须有封面图) + activityList.value = activities.filter(item => { + return item && (item.coverImageUrl || item.imageUrl || item.posterUrl); + }); + + console.log('过滤后的活动列表:', activityList.value); + + // 如果有活动数据,则显示弹窗 + if (activityList.value.length > 0) { + currentActivityIndex.value = 0; // 重置索引 + // 延迟一下显示,避免与其他弹窗冲突 + setTimeout(() => { + openActivityPopup(); + // 标记本次会话已显示过活动弹窗(内存变量,小程序重启后自动重置) + hasShownActivityThisSession.value = true; + }, 500); + } } } catch (e) { console.warn('查询活动失败:', e); @@ -379,6 +431,14 @@ const activityPopup = ref(null) const init = async () => { isLoading.value = true try { + // 清理旧版本的缓存键(兼容性处理) + try { + uni.removeStorageSync('hasShownActivityInSession'); + uni.removeStorageSync('activityLastShownDate'); + } catch (e) { + console.warn('清理旧缓存失败:', e); + } + // 开发环境测试距离计算 if (process.env.NODE_ENV === 'development') { testDistanceCalculation() @@ -903,8 +963,15 @@ const closeActivityPopup = () => { try { showActivityPopup.value = false activityPopup.value && typeof activityPopup.value.close === 'function' && activityPopup.value.close() + // 重置索引 + currentActivityIndex.value = 0 } catch (e) {} } + +// 活动轮播图切换 +const onActivitySwiperChange = (e) => { + currentActivityIndex.value = e.detail.current +}