hookehuyr

fix(Activities): 优化活动详情展示和参数传递

- CheckinMap: 添加日期格式化函数,将 YYYY-MM-DD 转换为 YYYY.MM.DD 格式
- ActivitiesDetail: 添加 discount_title 字段支持,并在跳转时传递该参数
- Activities: 接收并处理 discount_title 参数,构建完整的活动 URL

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
......@@ -53,7 +53,7 @@ const baseUrl = ref('') // 动态获取的基础URL
/**
* 处理WebView加载完成
*/
const handleLoad = (e) => {
const handleLoad = e => {
console.log('WebView加载完成:', e)
loading.value = false
error.value = false
......@@ -62,21 +62,21 @@ const handleLoad = (e) => {
/**
* 处理WebView加载错误
*/
const handleError = (e) => {
const handleError = e => {
console.error('WebView加载错误:', e)
loading.value = false
error.value = true
Taro.showToast({
title: '页面加载失败',
icon: 'none'
icon: 'none',
})
}
/**
* 处理WebView消息
*/
const handleMessage = (e) => {
const handleMessage = e => {
console.log('WebView消息:', e)
// 可以在这里处理来自WebView的消息
}
......@@ -96,11 +96,11 @@ const handleRetry = () => {
*/
const handleGoBack = () => {
Taro.navigateBack({
delta: 1
delta: 1,
}).catch(() => {
// 如果无法返回,则跳转到首页
Taro.redirectTo({
url: '/pages/Dashboard/index'
url: '/pages/Dashboard/index',
})
})
}
......@@ -108,10 +108,10 @@ const handleGoBack = () => {
/**
* 构建包含位置参数的URL
*/
const buildUrlWithLocation = (lng, lat, openid) => {
const buildUrlWithLocation = (lng, lat, openid, discount_title) => {
if (lng && lat && baseUrl.value) {
const separator = baseUrl.value.includes('?') ? '&' : '?'
return `${baseUrl.value}${separator}current_lng=${lng}&current_lat=${lat}&openid=${openid}`
return `${baseUrl.value}${separator}current_lng=${lng}&current_lat=${lat}&openid=${openid}&discount_title=${discount_title}`
}
return baseUrl.value || ''
}
......@@ -133,7 +133,7 @@ const initPageData = async () => {
loading.value = false
Taro.showToast({
title: mapUrlResponse.msg || '获取地图信息失败',
icon: 'none'
icon: 'none',
})
return
}
......@@ -143,13 +143,13 @@ const initPageData = async () => {
if (code) {
// 获取路由参数中的经纬度信息
const instance = Taro.getCurrentInstance()
const { current_lng, current_lat } = instance.router?.params || {}
const { current_lng, current_lat, discount_title } = instance.router?.params || {}
console.log('接收到的位置参数:', { current_lng, current_lat })
console.log('接收到的位置参数:', { current_lng, current_lat, discount_title })
// 处理用户信息
const openid = data?.user.openid || ''
// 构建完整的URL
webUrl.value = buildUrlWithLocation(current_lng, current_lat, openid)
webUrl.value = buildUrlWithLocation(current_lng, current_lat, openid, discount_title)
console.log('最终WebView URL:', webUrl.value)
}
......@@ -161,7 +161,7 @@ const initPageData = async () => {
Taro.showToast({
title: '获取地图信息失败',
icon: 'none'
icon: 'none',
})
}
}
......@@ -214,8 +214,12 @@ onMounted(async () => {
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
.error-container {
......
<!--
* @Date: 2026-02-09
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-02-09
* @LastEditTime: 2026-02-09 18:55:56
* @FilePath: /lls_program/src/pages/ActivitiesDetail/index.vue
* @Description: 活动详情页面 - 完全使用 map_activity.js 新接口,支持多活动详情展示
-->
......@@ -580,7 +580,7 @@ const handleJoinActivity = async () => {
// 跳转到Activities页面,并传递位置参数
await Taro.navigateTo({
url: `/pages/Activities/index?current_lng=${userLocation.value.lng}&current_lat=${userLocation.value.lat}`,
url: `/pages/Activities/index?current_lng=${userLocation.value.lng}&current_lat=${userLocation.value.lat}&discount_title=${activityData.value.discount_title}`,
})
} catch (error) {
console.error('参加活动失败:', error)
......@@ -971,6 +971,7 @@ const transformApiDataToActivityData = apiData => {
description: `欢迎参加${apiData.title}活动!`,
rules: rules,
rewards: rewards,
discount_title: apiData.discount_title || '打卡点专属优惠',
}
}
......
......@@ -55,6 +55,23 @@ const mapList = ref([])
const loading = ref(false)
/**
* 格式化日期显示
* @description 将后端返回的 YYYY-MM-DD 格式转换为 YYYY.MM.DD 格式
* @param {string} dateStr - 原始日期字符串(如 "2026-02-28")
* @returns {string} 格式化后的日期(如 "2026.02.28")
*
* @example
* formatDate("2026-02-28") // 返回 "2026.02.28"
*/
const formatDate = dateStr => {
if (!dateStr) {
return ''
}
// 将 "-" 替换为 "."
return dateStr.replace(/-/g, '.')
}
/**
* 格式化 API 数据为页面所需格式
* @param {Array} list - API 返回的活动列表
* @returns {Array} 格式化后的活动列表
......@@ -65,7 +82,8 @@ const formatMapList = list => {
title: item.title,
// 如果 cover 为空,使用默认封面图
cover: item.cover && item.cover.trim() !== '' ? item.cover : DEFAULT_COVER,
timeRange: `${item.begin_date}~${item.end_date}`,
// 格式化日期:2026-02-28 → 2026.02.28
timeRange: `${formatDate(item.begin_date)}~${formatDate(item.end_date)}`,
activityId: item.id,
}))
}
......