Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
lls_program
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2025-09-20 11:29:12 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4169440bdb32b8f72a968a732a91fb56fdb04569
4169440b
1 parent
a135fa49
fix: 修复微信步数同步失败处理和401重试逻辑
处理微信步数同步失败时的错误提示,改为静默失败 添加401重试成功后的全局事件通知 更新相关文件的时间戳
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
8 deletions
src/components/WeRunAuth.vue
src/pages/Dashboard/index.vue
src/utils/request.js
src/components/WeRunAuth.vue
View file @
4169440
...
...
@@ -201,10 +201,10 @@ const getWeRunData = async () => {
}
} catch (apiError) {
console.error('同步微信步数API调用失败:', apiError);
Taro.showToast({
title: '网络请求失败',
icon: 'none'
});
//
Taro.showToast({
//
title: '网络请求失败',
//
icon: 'none'
//
});
}
} catch (error) {
console.error('获取微信运动数据失败:', error)
...
...
src/pages/Dashboard/index.vue
View file @
4169440
<!--
* @Date: 2025-08-27 17:43:45
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-20 1
0:26:33
* @LastEditTime: 2025-09-20 1
1:27:21
* @FilePath: /lls_program/src/pages/Dashboard/index.vue
* @Description: 首页
-->
...
...
@@ -167,7 +167,7 @@
<script setup>
import "./index.less";
import { ref, computed, onMounted } from 'vue';
import { ref, computed, onMounted
, onUnmounted
} from 'vue';
import Taro, { useDidShow, useReady, useLoad } from '@tarojs/taro';
import { handleSharePageAuth, addShareFlag } from '@/utils/authRedirect';
import { Setting, Photograph, IconFont } from '@nutui/icons-vue-taro';
...
...
@@ -249,6 +249,19 @@ const handleSyncFailed = (data) => {
console.log('微信步数同步失败:', data)
}
// 监听全局的微信步数同步成功事件(用于处理401重试后的成功情况)
onMounted(() => {
if (Taro.eventCenter) {
Taro.eventCenter.on('wx-steps-sync-success', handleStepsSynced);
}
});
onUnmounted(() => {
if (Taro.eventCenter) {
Taro.eventCenter.off('wx-steps-sync-success', handleStepsSynced);
}
});
/**
* 计算总步数(包含用户步数和家庭成员步数)
* @returns {string} 格式化后的总步数
...
...
src/utils/request.js
View file @
4169440
/*
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-09-
12 22:05:53
* @LastEditTime: 2025-09-
20 11:18:35
* @FilePath: /lls_program/src/utils/request.js
* @Description: 简单axios封装,后续按实际处理
*/
...
...
@@ -9,6 +9,7 @@
import
axios
from
'axios-miniprogram'
;
// // import qs from 'Qs'
import
{
silentAuth
}
from
'@/utils/authRedirect'
import
Taro
from
'@tarojs/taro'
;
// import { ProgressStart, ProgressEnd } from '@/components/axios-progress/progress';
// import store from '@/store'
...
...
@@ -170,7 +171,19 @@ service.interceptors.response.use(
()
=>
{
// 授权成功后重新发起原始请求
const
originalRequest
=
response
.
config
;
return
service
.
request
(
originalRequest
);
return
service
.
request
(
originalRequest
).
then
(
retryResponse
=>
{
// 检查是否是微信步数同步请求
if
(
originalRequest
.
url
&&
originalRequest
.
url
.
includes
(
'sync_wx_step'
))
{
// 如果是步数同步请求且成功,触发全局事件
if
(
retryResponse
.
data
&&
retryResponse
.
data
.
code
==
1
)
{
// 使用Taro的事件系统触发全局事件
if
(
typeof
Taro
!==
'undefined'
&&
Taro
.
eventCenter
)
{
Taro
.
eventCenter
.
trigger
(
'wx-steps-sync-success'
);
}
}
}
return
retryResponse
;
});
},
()
=>
{
// 静默授权失败,直接返回错误,不跳转页面
...
...
Please
register
or
login
to post a comment