hookehuyr

feat(ActivitiesCover): 改进位置授权和错误处理逻辑

添加位置获取失败状态和重试功能
优化位置授权提示样式和交互
隐藏图片预览组件的索引显示
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
52 52
53 .location-tip { 53 .location-tip {
54 display: flex; 54 display: flex;
55 + flex-direction: column;
55 align-items: center; 56 align-items: center;
56 justify-content: center; 57 justify-content: center;
57 padding: 24rpx; 58 padding: 24rpx;
...@@ -60,6 +61,20 @@ ...@@ -60,6 +61,20 @@
60 border-radius: 12rpx; 61 border-radius: 12rpx;
61 margin-bottom: 32rpx; 62 margin-bottom: 32rpx;
62 backdrop-filter: blur(10rpx); 63 backdrop-filter: blur(10rpx);
64 + cursor: pointer;
65 + transition: all 0.3s ease;
66 +
67 + &:active {
68 + background-color: rgba(255, 247, 230, 0.7);
69 + transform: scale(0.98);
70 + }
71 +
72 + .tip-content {
73 + display: flex;
74 + align-items: center;
75 + justify-content: center;
76 + margin-bottom: 8rpx;
77 + }
63 } 78 }
64 79
65 .tip-icon { 80 .tip-icon {
...@@ -73,6 +88,21 @@ ...@@ -73,6 +88,21 @@
73 font-weight: 500; 88 font-weight: 500;
74 } 89 }
75 90
91 +.tip-retry {
92 + font-size: 22rpx;
93 + color: #1890ff;
94 + text-decoration: underline;
95 +}
96 +
97 +.location-error {
98 + background-color: rgba(255, 241, 240, 0.9);
99 + border: 1rpx solid rgba(255, 163, 158, 0.8);
100 +
101 + .tip-text {
102 + color: #cf1322;
103 + }
104 +}
105 +
76 .join-button { 106 .join-button {
77 width: 100%; 107 width: 100%;
78 height: 88rpx; 108 height: 88rpx;
......
1 <!-- 1 <!--
2 * @Date: 2022-09-19 14:11:06 2 * @Date: 2022-09-19 14:11:06
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-09-04 15:34:50 4 + * @LastEditTime: 2025-09-04 22:34:52
5 * @FilePath: /lls_program/src/pages/ActivitiesCover/index.vue 5 * @FilePath: /lls_program/src/pages/ActivitiesCover/index.vue
6 * @Description: 活动海报页面 - 展示活动信息并处理定位授权 6 * @Description: 活动海报页面 - 展示活动信息并处理定位授权
7 --> 7 -->
...@@ -24,9 +24,22 @@ ...@@ -24,9 +24,22 @@
24 24
25 <!-- 底部按钮区域 --> 25 <!-- 底部按钮区域 -->
26 <view class="bottom-section"> 26 <view class="bottom-section">
27 - <view v-if="!hasLocationAuth" class="location-tip"> 27 + <!-- 未授权定位提示 -->
28 - <view class="tip-icon">📍</view> 28 + <view v-if="!hasLocationAuth && !locationError" class="location-tip" @click="retryGetLocation">
29 - <view class="tip-text">需要获取您的位置信息来参与活动</view> 29 + <view class="tip-content">
30 + <view class="tip-icon">📍</view>
31 + <view class="tip-text">需要获取您的位置信息来参与活动</view>
32 + </view>
33 + <view class="tip-retry">点击重新获取</view>
34 + </view>
35 +
36 + <!-- 位置获取失败提示 -->
37 + <view v-if="hasLocationAuth && locationError" class="location-tip location-error" @click="retryGetLocation">
38 + <view class="tip-content">
39 + <view class="tip-icon">⚠️</view>
40 + <view class="tip-text">可能是网络问题,获取位置信息失败</view>
41 + </view>
42 + <view class="tip-retry">点击重新获取</view>
30 </view> 43 </view>
31 44
32 <nut-button 45 <nut-button
...@@ -37,7 +50,7 @@ ...@@ -37,7 +50,7 @@
37 :loading="isJoining" 50 :loading="isJoining"
38 @click="checkFamilyStatusAndJoinActivity" 51 @click="checkFamilyStatusAndJoinActivity"
39 > 52 >
40 - {{ hasLocationAuth ? '进入活动' : '参加活动' }} 53 + {{ hasLocationAuth && !locationError ? '进入活动' : '参加活动' }}
41 </nut-button> 54 </nut-button>
42 </view> 55 </view>
43 56
...@@ -100,6 +113,7 @@ const defaultPoster = 'https://cdn.ipadbiz.cn/lls_prog/images/welcome_1.png'; ...@@ -100,6 +113,7 @@ const defaultPoster = 'https://cdn.ipadbiz.cn/lls_prog/images/welcome_1.png';
100 113
101 // 页面状态 114 // 页面状态
102 const hasLocationAuth = ref(false) // 是否已授权定位 115 const hasLocationAuth = ref(false) // 是否已授权定位
116 +const locationError = ref(false) // 位置获取是否失败
103 const isJoining = ref(false) // 是否正在加入活动 117 const isJoining = ref(false) // 是否正在加入活动
104 const userLocation = ref({ lng: null, lat: null }) // 用户位置信息 118 const userLocation = ref({ lng: null, lat: null }) // 用户位置信息
105 const hasJoinedFamily = ref(false); 119 const hasJoinedFamily = ref(false);
...@@ -161,6 +175,7 @@ const checkLocationAuth = async () => { ...@@ -161,6 +175,7 @@ const checkLocationAuth = async () => {
161 */ 175 */
162 const getUserLocation = async () => { 176 const getUserLocation = async () => {
163 try { 177 try {
178 + locationError.value = false // 重置错误状态
164 const location = await Taro.getLocation({ 179 const location = await Taro.getLocation({
165 type: 'gcj02' 180 type: 'gcj02'
166 }) 181 })
...@@ -177,6 +192,8 @@ const getUserLocation = async () => { ...@@ -177,6 +192,8 @@ const getUserLocation = async () => {
177 192
178 if (error.errMsg && error.errMsg.includes('auth deny')) { 193 if (error.errMsg && error.errMsg.includes('auth deny')) {
179 // 用户拒绝授权,引导用户手动开启 194 // 用户拒绝授权,引导用户手动开启
195 + hasLocationAuth.value = false
196 + locationError.value = false
180 await Taro.showModal({ 197 await Taro.showModal({
181 title: '需要位置权限', 198 title: '需要位置权限',
182 content: '参与活动需要获取您的位置信息,请在设置中开启位置权限', 199 content: '参与活动需要获取您的位置信息,请在设置中开启位置权限',
...@@ -188,6 +205,8 @@ const getUserLocation = async () => { ...@@ -188,6 +205,8 @@ const getUserLocation = async () => {
188 } 205 }
189 }) 206 })
190 } else { 207 } else {
208 + // 网络或其他问题导致的获取失败
209 + locationError.value = true
191 Taro.showToast({ 210 Taro.showToast({
192 title: '获取位置失败', 211 title: '获取位置失败',
193 icon: 'none' 212 icon: 'none'
...@@ -224,6 +243,25 @@ const checkFamilyStatusAndJoinActivity = async () => { ...@@ -224,6 +243,25 @@ const checkFamilyStatusAndJoinActivity = async () => {
224 243
225 244
226 /** 245 /**
246 + * 重新获取位置信息
247 + */
248 +const retryGetLocation = async () => {
249 + try {
250 + const success = await getUserLocation()
251 + if (success) {
252 + hasLocationAuth.value = true
253 + locationError.value = false
254 + Taro.showToast({
255 + title: '位置获取成功',
256 + icon: 'success'
257 + })
258 + }
259 + } catch (error) {
260 + console.error('重新获取位置失败:', error)
261 + }
262 +}
263 +
264 +/**
227 * 处理参加活动按钮点击 265 * 处理参加活动按钮点击
228 */ 266 */
229 const handleJoinActivity = async () => { 267 const handleJoinActivity = async () => {
......
...@@ -112,6 +112,7 @@ ...@@ -112,6 +112,7 @@
112 v-model:show="previewVisible" 112 v-model:show="previewVisible"
113 :images="previewImages" 113 :images="previewImages"
114 :init-no="0" 114 :init-no="0"
115 + :show-index="false"
115 @close="closePreview" 116 @close="closePreview"
116 /> 117 />
117 118
......