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>
Showing
1 changed file
with
50 additions
and
10 deletions
| ... | @@ -303,7 +303,6 @@ const checkLocationAuth = async () => { | ... | @@ -303,7 +303,6 @@ const checkLocationAuth = async () => { |
| 303 | try { | 303 | try { |
| 304 | const authSetting = await Taro.getSetting() | 304 | const authSetting = await Taro.getSetting() |
| 305 | hasLocationAuth.value = authSetting.authSetting['scope.userLocation'] === true | 305 | hasLocationAuth.value = authSetting.authSetting['scope.userLocation'] === true |
| 306 | - console.log('定位授权状态:', hasLocationAuth.value) | ||
| 307 | } catch (error) { | 306 | } catch (error) { |
| 308 | console.error('检查定位授权失败:', error) | 307 | console.error('检查定位授权失败:', error) |
| 309 | hasLocationAuth.value = false | 308 | hasLocationAuth.value = false |
| ... | @@ -344,7 +343,6 @@ const getUserLocation = async (skipAuthCheck = false) => { | ... | @@ -344,7 +343,6 @@ const getUserLocation = async (skipAuthCheck = false) => { |
| 344 | lat: location.latitude, | 343 | lat: location.latitude, |
| 345 | } | 344 | } |
| 346 | 345 | ||
| 347 | - console.log('获取到用户位置:', userLocation.value) | ||
| 348 | // 获取位置成功后隐藏提示 | 346 | // 获取位置成功后隐藏提示 |
| 349 | showLocationPrompt.value = false | 347 | showLocationPrompt.value = false |
| 350 | hasLocationAuth.value = true | 348 | hasLocationAuth.value = true |
| ... | @@ -544,7 +542,6 @@ const onLocationConfirm = async () => { | ... | @@ -544,7 +542,6 @@ const onLocationConfirm = async () => { |
| 544 | lat: location.latitude, | 542 | lat: location.latitude, |
| 545 | } | 543 | } |
| 546 | 544 | ||
| 547 | - console.log('获取到用户位置:', userLocation.value) | ||
| 548 | showLocationPrompt.value = false | 545 | showLocationPrompt.value = false |
| 549 | hasLocationAuth.value = true | 546 | hasLocationAuth.value = true |
| 550 | 547 | ||
| ... | @@ -1022,15 +1019,13 @@ const fetchActivityDetail = async () => { | ... | @@ -1022,15 +1019,13 @@ const fetchActivityDetail = async () => { |
| 1022 | return | 1019 | return |
| 1023 | } | 1020 | } |
| 1024 | 1021 | ||
| 1025 | - console.log('[ActivitiesDetail] 开始获取活动详情, ID:', activityId.value) | ||
| 1026 | - | ||
| 1027 | // 根据环境选择真实 API 或 mock API | 1022 | // 根据环境选择真实 API 或 mock API |
| 1028 | const response = USE_MOCK_DATA | 1023 | const response = USE_MOCK_DATA |
| 1029 | ? await mockMapActivityDetailAPI({ id: activityId.value }) | 1024 | ? await mockMapActivityDetailAPI({ id: activityId.value }) |
| 1030 | : await detailAPI({ id: activityId.value }) | 1025 | : await detailAPI({ id: activityId.value }) |
| 1031 | 1026 | ||
| 1032 | if (response.code === 1 && response.data) { | 1027 | if (response.code === 1 && response.data) { |
| 1033 | - console.log('[ActivitiesDetail] 活动详情获取成功:', response.data) | 1028 | + console.log('[ActivitiesDetail] 活动详情获取成功') |
| 1034 | 1029 | ||
| 1035 | // 转换 API 数据为页面格式 | 1030 | // 转换 API 数据为页面格式 |
| 1036 | const transformedData = transformApiDataToActivityData(response.data) | 1031 | const transformedData = transformApiDataToActivityData(response.data) |
| ... | @@ -1040,9 +1035,6 @@ const fetchActivityDetail = async () => { | ... | @@ -1040,9 +1035,6 @@ const fetchActivityDetail = async () => { |
| 1040 | // 更新默认海报图:如果 cover 为空,使用默认封面 | 1035 | // 更新默认海报图:如果 cover 为空,使用默认封面 |
| 1041 | if (response.data.cover && response.data.cover.trim() !== '') { | 1036 | if (response.data.cover && response.data.cover.trim() !== '') { |
| 1042 | defaultPoster.value = response.data.cover | 1037 | defaultPoster.value = response.data.cover |
| 1043 | - } else { | ||
| 1044 | - // cover 为空,保持默认封面不变 | ||
| 1045 | - console.log('[ActivitiesDetail] cover 为空,使用默认封面图') | ||
| 1046 | } | 1038 | } |
| 1047 | 1039 | ||
| 1048 | // 更新活动状态 | 1040 | // 更新活动状态 |
| ... | @@ -1058,6 +1050,38 @@ const fetchActivityDetail = async () => { | ... | @@ -1058,6 +1050,38 @@ const fetchActivityDetail = async () => { |
| 1058 | } | 1050 | } |
| 1059 | 1051 | ||
| 1060 | /** | 1052 | /** |
| 1053 | + * 解析小程序码 scene 参数 | ||
| 1054 | + * @param {string} scene - scene 参数值(例如:activityId%3D835370) | ||
| 1055 | + * @returns {Object} 解析后的参数对象 | ||
| 1056 | + */ | ||
| 1057 | +const parseSceneParams = scene => { | ||
| 1058 | + try { | ||
| 1059 | + if (!scene || typeof scene !== 'string' || scene.trim() === '') { | ||
| 1060 | + return {} | ||
| 1061 | + } | ||
| 1062 | + | ||
| 1063 | + // URL 解码:activityId%3D835370 → activityId=835370 | ||
| 1064 | + const decodedScene = decodeURIComponent(scene) | ||
| 1065 | + | ||
| 1066 | + // 解析 key=value 格式的参数 | ||
| 1067 | + const params = {} | ||
| 1068 | + const pairs = decodedScene.split('&') | ||
| 1069 | + | ||
| 1070 | + for (const pair of pairs) { | ||
| 1071 | + const [key, value] = pair.split('=') | ||
| 1072 | + if (key && value) { | ||
| 1073 | + params[key] = value | ||
| 1074 | + } | ||
| 1075 | + } | ||
| 1076 | + | ||
| 1077 | + return params | ||
| 1078 | + } catch (error) { | ||
| 1079 | + console.error('[ActivitiesDetail] 解析 scene 参数失败:', error) | ||
| 1080 | + return {} | ||
| 1081 | + } | ||
| 1082 | +} | ||
| 1083 | + | ||
| 1084 | +/** | ||
| 1061 | * 初始化页面数据 | 1085 | * 初始化页面数据 |
| 1062 | */ | 1086 | */ |
| 1063 | const initPageData = async () => { | 1087 | const initPageData = async () => { |
| ... | @@ -1079,7 +1103,23 @@ const initPageData = async () => { | ... | @@ -1079,7 +1103,23 @@ const initPageData = async () => { |
| 1079 | 1103 | ||
| 1080 | // 处理页面加载时的授权检查 | 1104 | // 处理页面加载时的授权检查 |
| 1081 | useLoad(options => { | 1105 | useLoad(options => { |
| 1082 | - console.log('[ActivitiesDetail] 页面加载, 参数:', options) | 1106 | + // 优先处理 scene 参数(小程序码入口) |
| 1107 | + if (options.scene) { | ||
| 1108 | + // 解析 scene 参数 | ||
| 1109 | + const sceneParams = parseSceneParams(options.scene) | ||
| 1110 | + | ||
| 1111 | + // 从 scene 参数中提取 activityId | ||
| 1112 | + if (sceneParams.activityId) { | ||
| 1113 | + activityId.value = sceneParams.activityId | ||
| 1114 | + console.log('[ActivitiesDetail] 小程序码进入 - activityId:', activityId.value) | ||
| 1115 | + | ||
| 1116 | + // 处理分享页面的授权逻辑 | ||
| 1117 | + handleSharePageAuth(options, () => { | ||
| 1118 | + initPageData() | ||
| 1119 | + }) | ||
| 1120 | + return | ||
| 1121 | + } | ||
| 1122 | + } | ||
| 1083 | 1123 | ||
| 1084 | // 获取活动 ID(必须有) | 1124 | // 获取活动 ID(必须有) |
| 1085 | if (options.id) { | 1125 | if (options.id) { | ... | ... |
-
Please register or login to post a comment