fix: 修复微信步数同步失败处理和401重试逻辑
处理微信步数同步失败时的错误提示,改为静默失败 添加401重试成功后的全局事件通知 更新相关文件的时间戳
Showing
3 changed files
with
34 additions
and
8 deletions
| ... | @@ -201,10 +201,10 @@ const getWeRunData = async () => { | ... | @@ -201,10 +201,10 @@ const getWeRunData = async () => { |
| 201 | } | 201 | } |
| 202 | } catch (apiError) { | 202 | } catch (apiError) { |
| 203 | console.error('同步微信步数API调用失败:', apiError); | 203 | console.error('同步微信步数API调用失败:', apiError); |
| 204 | - Taro.showToast({ | 204 | + // Taro.showToast({ |
| 205 | - title: '网络请求失败', | 205 | + // title: '网络请求失败', |
| 206 | - icon: 'none' | 206 | + // icon: 'none' |
| 207 | - }); | 207 | + // }); |
| 208 | } | 208 | } |
| 209 | } catch (error) { | 209 | } catch (error) { |
| 210 | console.error('获取微信运动数据失败:', error) | 210 | console.error('获取微信运动数据失败:', error) | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2025-08-27 17:43:45 | 2 | * @Date: 2025-08-27 17:43:45 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-20 10:26:33 | 4 | + * @LastEditTime: 2025-09-20 11:27:21 |
| 5 | * @FilePath: /lls_program/src/pages/Dashboard/index.vue | 5 | * @FilePath: /lls_program/src/pages/Dashboard/index.vue |
| 6 | * @Description: 首页 | 6 | * @Description: 首页 |
| 7 | --> | 7 | --> |
| ... | @@ -167,7 +167,7 @@ | ... | @@ -167,7 +167,7 @@ |
| 167 | 167 | ||
| 168 | <script setup> | 168 | <script setup> |
| 169 | import "./index.less"; | 169 | import "./index.less"; |
| 170 | -import { ref, computed, onMounted } from 'vue'; | 170 | +import { ref, computed, onMounted, onUnmounted } from 'vue'; |
| 171 | import Taro, { useDidShow, useReady, useLoad } from '@tarojs/taro'; | 171 | import Taro, { useDidShow, useReady, useLoad } from '@tarojs/taro'; |
| 172 | import { handleSharePageAuth, addShareFlag } from '@/utils/authRedirect'; | 172 | import { handleSharePageAuth, addShareFlag } from '@/utils/authRedirect'; |
| 173 | import { Setting, Photograph, IconFont } from '@nutui/icons-vue-taro'; | 173 | import { Setting, Photograph, IconFont } from '@nutui/icons-vue-taro'; |
| ... | @@ -249,6 +249,19 @@ const handleSyncFailed = (data) => { | ... | @@ -249,6 +249,19 @@ const handleSyncFailed = (data) => { |
| 249 | console.log('微信步数同步失败:', data) | 249 | console.log('微信步数同步失败:', data) |
| 250 | } | 250 | } |
| 251 | 251 | ||
| 252 | +// 监听全局的微信步数同步成功事件(用于处理401重试后的成功情况) | ||
| 253 | +onMounted(() => { | ||
| 254 | + if (Taro.eventCenter) { | ||
| 255 | + Taro.eventCenter.on('wx-steps-sync-success', handleStepsSynced); | ||
| 256 | + } | ||
| 257 | +}); | ||
| 258 | + | ||
| 259 | +onUnmounted(() => { | ||
| 260 | + if (Taro.eventCenter) { | ||
| 261 | + Taro.eventCenter.off('wx-steps-sync-success', handleStepsSynced); | ||
| 262 | + } | ||
| 263 | +}); | ||
| 264 | + | ||
| 252 | /** | 265 | /** |
| 253 | * 计算总步数(包含用户步数和家庭成员步数) | 266 | * 计算总步数(包含用户步数和家庭成员步数) |
| 254 | * @returns {string} 格式化后的总步数 | 267 | * @returns {string} 格式化后的总步数 | ... | ... |
| 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-12 22:05:53 | 4 | + * @LastEditTime: 2025-09-20 11:18:35 |
| 5 | * @FilePath: /lls_program/src/utils/request.js | 5 | * @FilePath: /lls_program/src/utils/request.js |
| 6 | * @Description: 简单axios封装,后续按实际处理 | 6 | * @Description: 简单axios封装,后续按实际处理 |
| 7 | */ | 7 | */ |
| ... | @@ -9,6 +9,7 @@ | ... | @@ -9,6 +9,7 @@ |
| 9 | import axios from 'axios-miniprogram'; | 9 | import axios from 'axios-miniprogram'; |
| 10 | // // import qs from 'Qs' | 10 | // // import qs from 'Qs' |
| 11 | import { silentAuth } from '@/utils/authRedirect' | 11 | import { silentAuth } from '@/utils/authRedirect' |
| 12 | +import Taro from '@tarojs/taro'; | ||
| 12 | 13 | ||
| 13 | // import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress'; | 14 | // import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress'; |
| 14 | // import store from '@/store' | 15 | // import store from '@/store' |
| ... | @@ -170,7 +171,19 @@ service.interceptors.response.use( | ... | @@ -170,7 +171,19 @@ service.interceptors.response.use( |
| 170 | () => { | 171 | () => { |
| 171 | // 授权成功后重新发起原始请求 | 172 | // 授权成功后重新发起原始请求 |
| 172 | const originalRequest = response.config; | 173 | const originalRequest = response.config; |
| 173 | - return service.request(originalRequest); | 174 | + return service.request(originalRequest).then(retryResponse => { |
| 175 | + // 检查是否是微信步数同步请求 | ||
| 176 | + if (originalRequest.url && originalRequest.url.includes('sync_wx_step')) { | ||
| 177 | + // 如果是步数同步请求且成功,触发全局事件 | ||
| 178 | + if (retryResponse.data && retryResponse.data.code == 1) { | ||
| 179 | + // 使用Taro的事件系统触发全局事件 | ||
| 180 | + if (typeof Taro !== 'undefined' && Taro.eventCenter) { | ||
| 181 | + Taro.eventCenter.trigger('wx-steps-sync-success'); | ||
| 182 | + } | ||
| 183 | + } | ||
| 184 | + } | ||
| 185 | + return retryResponse; | ||
| 186 | + }); | ||
| 174 | }, | 187 | }, |
| 175 | () => { | 188 | () => { |
| 176 | // 静默授权失败,直接返回错误,不跳转页面 | 189 | // 静默授权失败,直接返回错误,不跳转页面 | ... | ... |
-
Please register or login to post a comment