hookehuyr

refactor(Activities): 优化地图URL传递方式

- ActivitiesDetail页面通过detailAPI获取地图URL并保留
- 导航时通过URL参数传递地图URL,避免Activities页面重复调用API
- Activities页面从URL参数读取地图URL,移除getMapUrlAPI调用
- 提升性能,减少不必要的网络请求

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
...@@ -39,7 +39,6 @@ import Taro from '@tarojs/taro' ...@@ -39,7 +39,6 @@ import Taro from '@tarojs/taro'
39 import BottomNav from '../../components/BottomNav.vue' 39 import BottomNav from '../../components/BottomNav.vue'
40 // 获取接口信息 40 // 获取接口信息
41 import { getUserProfileAPI } from '@/api/user' 41 import { getUserProfileAPI } from '@/api/user'
42 -import { getMapUrlAPI } from '@/api/map'
43 42
44 /** 43 /**
45 * 活动页面WebView组件 44 * 活动页面WebView组件
...@@ -131,18 +130,22 @@ const initPageData = async () => { ...@@ -131,18 +130,22 @@ const initPageData = async () => {
131 try { 130 try {
132 console.log('=== WebView 初始化开始 ===') 131 console.log('=== WebView 初始化开始 ===')
133 132
134 - // 获取地图URL 133 + // 从 URL 参数中获取地图 URL(由 ActivitiesDetail 页面传递)
135 - const mapUrlResponse = await getMapUrlAPI() 134 + const instance = Taro.getCurrentInstance()
136 - if (mapUrlResponse.code && mapUrlResponse.data?.url) { 135 + const { mapUrl, current_lng, current_lat, discount_title, activityId } =
137 - baseUrl.value = mapUrlResponse.data.url 136 + instance.router?.params || {}
138 - console.log('✅ 获取到的地图URL:', baseUrl.value) 137 +
138 + // 解码地图 URL
139 + if (mapUrl) {
140 + baseUrl.value = decodeURIComponent(mapUrl)
141 + console.log('✅ 从 URL 参数获取到的地图URL:', baseUrl.value)
139 } else { 142 } else {
140 - console.error('❌ 获取地图URL失败:', mapUrlResponse.msg) 143 + console.error('❌ 未接收到地图URL参数')
141 - // 显示错误提示,不使用默认URL 144 + // 显示错误提示
142 error.value = true 145 error.value = true
143 loading.value = false 146 loading.value = false
144 Taro.showToast({ 147 Taro.showToast({
145 - title: mapUrlResponse.msg || '获取地图信息失败', 148 + title: '缺少地图信息',
146 icon: 'none', 149 icon: 'none',
147 }) 150 })
148 return 151 return
...@@ -151,10 +154,6 @@ const initPageData = async () => { ...@@ -151,10 +154,6 @@ const initPageData = async () => {
151 // 获取用户信息 154 // 获取用户信息
152 const { code, data } = await getUserProfileAPI() 155 const { code, data } = await getUserProfileAPI()
153 if (code) { 156 if (code) {
154 - // 获取路由参数中的经纬度信息
155 - const instance = Taro.getCurrentInstance()
156 - const { current_lng, current_lat, discount_title, activityId } = instance.router?.params || {}
157 -
158 console.log('✅ 接收到的位置参数:', { current_lng, current_lat, discount_title, activityId }) 157 console.log('✅ 接收到的位置参数:', { current_lng, current_lat, discount_title, activityId })
159 // 处理用户信息 158 // 处理用户信息
160 const openid = data?.user.openid || '' 159 const openid = data?.user.openid || ''
......
...@@ -579,9 +579,9 @@ const handleJoinActivity = async () => { ...@@ -579,9 +579,9 @@ const handleJoinActivity = async () => {
579 } 579 }
580 } 580 }
581 581
582 - // 跳转到Activities页面,并传递位置参数 582 + // 跳转到Activities页面,并传递位置参数和地图 URL
583 await Taro.navigateTo({ 583 await Taro.navigateTo({
584 - url: `/pages/Activities/index?current_lng=${userLocation.value.lng}&current_lat=${userLocation.value.lat}&discount_title=${activityData.value.discount_title}&activityId=${activityId.value}`, 584 + url: `/pages/Activities/index?current_lng=${userLocation.value.lng}&current_lat=${userLocation.value.lat}&discount_title=${activityData.value.discount_title}&activityId=${activityId.value}&mapUrl=${encodeURIComponent(activityData.value.mapUrl)}`,
585 }) 585 })
586 } catch (error) { 586 } catch (error) {
587 console.error('参加活动失败:', error) 587 console.error('参加活动失败:', error)
...@@ -975,6 +975,7 @@ const transformApiDataToActivityData = apiData => { ...@@ -975,6 +975,7 @@ const transformApiDataToActivityData = apiData => {
975 rewards: rewards, 975 rewards: rewards,
976 discount_title: apiData.discount_title || '打卡点专属优惠', 976 discount_title: apiData.discount_title || '打卡点专属优惠',
977 activityId: apiData.id || '', 977 activityId: apiData.id || '',
978 + mapUrl: apiData.url || '', // 保留地图 URL
978 } 979 }
979 } 980 }
980 981
......