hookehuyr

feat(ActivitiesDetail): 支持小程序码 scene 参数解析并优化日志

- 新增 parseSceneParams 函数解析小程序码 scene 参数
- 支持 activityId%3D835370 格式的 scene 参数解码
- 在 useLoad 中优先处理 scene 参数(小程序码入口)
- 清理冗余的调试日志,保留关键业务日志和错误日志
- 提升代码简洁度和可维护性

影响文件: src/pages/ActivitiesDetail/index.vue

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
......@@ -303,7 +303,6 @@ const checkLocationAuth = async () => {
try {
const authSetting = await Taro.getSetting()
hasLocationAuth.value = authSetting.authSetting['scope.userLocation'] === true
console.log('定位授权状态:', hasLocationAuth.value)
} catch (error) {
console.error('检查定位授权失败:', error)
hasLocationAuth.value = false
......@@ -344,7 +343,6 @@ const getUserLocation = async (skipAuthCheck = false) => {
lat: location.latitude,
}
console.log('获取到用户位置:', userLocation.value)
// 获取位置成功后隐藏提示
showLocationPrompt.value = false
hasLocationAuth.value = true
......@@ -544,7 +542,6 @@ const onLocationConfirm = async () => {
lat: location.latitude,
}
console.log('获取到用户位置:', userLocation.value)
showLocationPrompt.value = false
hasLocationAuth.value = true
......@@ -1022,15 +1019,13 @@ const fetchActivityDetail = async () => {
return
}
console.log('[ActivitiesDetail] 开始获取活动详情, ID:', activityId.value)
// 根据环境选择真实 API 或 mock API
const response = USE_MOCK_DATA
? await mockMapActivityDetailAPI({ id: activityId.value })
: await detailAPI({ id: activityId.value })
if (response.code === 1 && response.data) {
console.log('[ActivitiesDetail] 活动详情获取成功:', response.data)
console.log('[ActivitiesDetail] 活动详情获取成功')
// 转换 API 数据为页面格式
const transformedData = transformApiDataToActivityData(response.data)
......@@ -1040,9 +1035,6 @@ const fetchActivityDetail = async () => {
// 更新默认海报图:如果 cover 为空,使用默认封面
if (response.data.cover && response.data.cover.trim() !== '') {
defaultPoster.value = response.data.cover
} else {
// cover 为空,保持默认封面不变
console.log('[ActivitiesDetail] cover 为空,使用默认封面图')
}
// 更新活动状态
......@@ -1058,6 +1050,38 @@ const fetchActivityDetail = async () => {
}
/**
* 解析小程序码 scene 参数
* @param {string} scene - scene 参数值(例如:activityId%3D835370)
* @returns {Object} 解析后的参数对象
*/
const parseSceneParams = scene => {
try {
if (!scene || typeof scene !== 'string' || scene.trim() === '') {
return {}
}
// URL 解码:activityId%3D835370 → activityId=835370
const decodedScene = decodeURIComponent(scene)
// 解析 key=value 格式的参数
const params = {}
const pairs = decodedScene.split('&')
for (const pair of pairs) {
const [key, value] = pair.split('=')
if (key && value) {
params[key] = value
}
}
return params
} catch (error) {
console.error('[ActivitiesDetail] 解析 scene 参数失败:', error)
return {}
}
}
/**
* 初始化页面数据
*/
const initPageData = async () => {
......@@ -1079,7 +1103,23 @@ const initPageData = async () => {
// 处理页面加载时的授权检查
useLoad(options => {
console.log('[ActivitiesDetail] 页面加载, 参数:', options)
// 优先处理 scene 参数(小程序码入口)
if (options.scene) {
// 解析 scene 参数
const sceneParams = parseSceneParams(options.scene)
// 从 scene 参数中提取 activityId
if (sceneParams.activityId) {
activityId.value = sceneParams.activityId
console.log('[ActivitiesDetail] 小程序码进入 - activityId:', activityId.value)
// 处理分享页面的授权逻辑
handleSharePageAuth(options, () => {
initPageData()
})
return
}
}
// 获取活动 ID(必须有)
if (options.id) {
......