fix:修复bug

This commit is contained in:
2025-11-10 09:15:31 +08:00
parent 50a711bba8
commit 43dc65836d
3 changed files with 160 additions and 34 deletions
+1 -1
View File
@@ -30,7 +30,7 @@ export const getCommonByBrand = (brandName) => {
// 查询激活的且临近关闭时间最近的活动 // 查询激活的且临近关闭时间最近的活动
export const getActiveActivity = () => { export const getActiveActivity = () => {
return request({ return request({
url: '/app/activity/nearest-active', url: '/device/activity/agent/list',
method: 'get', method: 'get',
hideLoading: true hideLoading: true
}) })
+2 -2
View File
@@ -1,5 +1,5 @@
// export const URL = "https://my.gxfs123.com/api" //正式服务器 export const URL = "https://my.gxfs123.com/api" //正式服务器
export const URL = "https://fansdev.gxfs123.com/api" //测试服务器 // export const URL = "https://fansdev.gxfs123.com/api" //测试服务器
// export const URL = "http://192.168.5.149:8080" //本地调试 // export const URL = "http://192.168.5.149:8080" //本地调试
// export const URL = "http://127.0.0.1:8080" //本地调试 // export const URL = "http://127.0.0.1:8080" //本地调试
+157 -31
View File
@@ -151,21 +151,43 @@
</view> </view>
</uv-popup> </uv-popup>
<!-- 活动弹窗居中弹出主要展示海报 --> <!-- 活动弹窗居中弹出支持多个活动轮播 -->
<uv-popup ref="activityPopup" mode="center" round="16" :overlay="true" :closeOnClickOverlay="false" :safeAreaInsetBottom="false"> <uv-popup ref="activityPopup" mode="center" round="16" :overlay="true" :closeOnClickOverlay="false" :safeAreaInsetBottom="false" :customStyle="{ background: 'transparent' }">
<view class="activity-popup" v-if="activityData"> <view class="activity-popup" v-if="activityList && activityList.length > 0">
<!-- 活动海报图片 --> <!-- 轮播图 -->
<swiper
class="activity-swiper"
:indicator-dots="activityList.length > 1"
:autoplay="false"
:circular="false"
@change="onActivitySwiperChange"
:current="currentActivityIndex"
>
<swiper-item v-for="(activity, index) in activityList" :key="index">
<view class="activity-poster-wrapper"> <view class="activity-poster-wrapper">
<image <image
:src="activityData.imageUrl || activityData.posterUrl" :src="activity.coverImageUrl || activity.imageUrl || activity.posterUrl"
mode="widthFix" mode="aspectFit"
class="activity-poster" class="activity-poster"
></image> ></image>
</view> </view>
<!-- 关闭按钮 --> </swiper-item>
<view class="activity-close-btn" @click="closeActivityPopup"> </swiper>
<uv-icon name="close-circle-fill" size="40" color="#ffffff"></uv-icon>
<!-- 自定义指示器 -->
<view class="activity-indicators" v-if="activityList.length > 1">
<view
v-for="(item, index) in activityList"
:key="index"
class="indicator-dot"
:class="{ active: index === currentActivityIndex }"
></view>
</view> </view>
<!-- 关闭按钮 -->
<view class="activity-close-btn" @click="closeActivityPopup">
<text class="close-text">{{ $t('common.close') }}</text>
</view>
</view> </view>
</uv-popup> </uv-popup>
</view> </view>
@@ -234,7 +256,9 @@ const isRelocating = ref(false) // 防抖标志:是否正在重新定位
const showGuidePopup = ref(false) // 使用指南弹窗显示状态 const showGuidePopup = ref(false) // 使用指南弹窗显示状态
const showNoticePopup = ref(false) // 通知详情弹窗显示状态 const showNoticePopup = ref(false) // 通知详情弹窗显示状态
const showActivityPopup = 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) const statusBarHeight = ref(0)
@@ -292,22 +316,50 @@ const statusBarHeight = ref(0)
// 查询最近的活动 // 查询最近的活动
const checkActiveActivity = async () => { const checkActiveActivity = async () => {
try { try {
// 检查是否已经显示过活动弹窗(本次会话 // 检查本次会话是否已经显示过活动弹窗(使用内存变量
const hasShownActivity = uni.getStorageSync('hasShownActivityInSession'); if (hasShownActivityThisSession.value) {
if (hasShownActivity) {
console.log('本次会话已显示过活动弹窗,跳过'); console.log('本次会话已显示过活动弹窗,跳过');
return; return;
} }
const res = await getActiveActivity(); const res = await getActiveActivity();
if (res.code === 200 && res.data) { console.log('活动接口返回:', res);
activityData.value = res.data;
// 延迟一下显示,避免与其他弹窗冲突 if (res.code === 200) {
setTimeout(() => { let activities = [];
openActivityPopup();
// 标记本次会话已显示过活动弹窗 // 处理活动数据:兼容多种返回格式
uni.setStorageSync('hasShownActivityInSession', true); if (res.rows && Array.isArray(res.rows)) {
}, 500); // 格式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) { } catch (e) {
console.warn('查询活动失败:', e); console.warn('查询活动失败:', e);
@@ -379,6 +431,14 @@ const activityPopup = ref(null)
const init = async () => { const init = async () => {
isLoading.value = true isLoading.value = true
try { try {
// 清理旧版本的缓存键(兼容性处理)
try {
uni.removeStorageSync('hasShownActivityInSession');
uni.removeStorageSync('activityLastShownDate');
} catch (e) {
console.warn('清理旧缓存失败:', e);
}
// 开发环境测试距离计算 // 开发环境测试距离计算
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV === 'development') {
testDistanceCalculation() testDistanceCalculation()
@@ -903,8 +963,15 @@ const closeActivityPopup = () => {
try { try {
showActivityPopup.value = false showActivityPopup.value = false
activityPopup.value && typeof activityPopup.value.close === 'function' && activityPopup.value.close() activityPopup.value && typeof activityPopup.value.close === 'function' && activityPopup.value.close()
// 重置索引
currentActivityIndex.value = 0
} catch (e) {} } catch (e) {}
} }
// 活动轮播图切换
const onActivitySwiperChange = (e) => {
currentActivityIndex.value = e.detail.current
}
</script> </script>
<script> <script>
@@ -1736,7 +1803,7 @@ const closeActivityPopup = () => {
margin-top: 20rpx; margin-top: 20rpx;
} }
/* 活动弹窗样式 - 简洁海报模式 */ /* 活动弹窗样式 - 支持轮播 */
.activity-popup { .activity-popup {
position: relative; position: relative;
width: 600rpx; width: 600rpx;
@@ -1744,38 +1811,97 @@ const closeActivityPopup = () => {
background: transparent; background: transparent;
border-radius: 16rpx; border-radius: 16rpx;
overflow: visible; overflow: visible;
padding-bottom: 120rpx;
}
/* 覆盖 uv-popup 的默认背景色 */
:deep(.uv-popup__content) {
background: transparent !important;
}
.activity-swiper {
width: 100%;
height: 800rpx;
max-height: 70vh;
border-radius: 16rpx;
background: transparent;
:deep(swiper) {
background: transparent;
}
:deep(swiper-item) {
background: transparent;
}
} }
.activity-poster-wrapper { .activity-poster-wrapper {
width: 100%; width: 100%;
height: 100%;
border-radius: 16rpx; border-radius: 16rpx;
overflow: hidden; overflow: visible;
background: #fff; background: transparent;
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.15); display: flex;
align-items: center;
justify-content: center;
} }
.activity-poster { .activity-poster {
width: 100%; width: 100%;
height: auto; height: 100%;
display: block; display: block;
vertical-align: middle; object-fit: contain;
}
/* 自定义指示器 */
.activity-indicators {
position: absolute;
bottom: 140rpx;
left: 50%;
transform: translateX(-50%);
display: flex;
gap: 12rpx;
z-index: 10;
}
.indicator-dot {
width: 16rpx;
height: 16rpx;
border-radius: 50%;
background: rgba(255, 255, 255, 0.5);
transition: all 0.3s;
}
.indicator-dot.active {
width: 32rpx;
border-radius: 8rpx;
background: #ffffff;
} }
.activity-close-btn { .activity-close-btn {
position: absolute; position: absolute;
bottom: -100rpx; bottom: 20rpx;
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
width: 80rpx; padding: 16rpx 48rpx;
height: 80rpx;
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
z-index: 999;
cursor: pointer; cursor: pointer;
transition: all 0.3s ease; transition: all 0.3s ease;
background: rgba(0, 0, 0, 0.6);
border-radius: 40rpx;
.close-text {
font-size: 28rpx;
color: #ffffff;
font-weight: 500;
}
&:active { &:active {
transform: translateX(-50%) scale(0.9); transform: translateX(-50%) scale(0.95);
background: rgba(0, 0, 0, 0.8);
} }
} }
</style> </style>