hookehuyr

feat(步数同步): 添加步数更新状态管理及失败处理逻辑

添加步数状态管理store,用于记录更新失败状态和时间
在同步成功/失败时更新状态,并根据状态决定是否显示手动更新按钮
...@@ -198,6 +198,7 @@ import TotalPointsDisplay from '@/components/TotalPointsDisplay.vue'; ...@@ -198,6 +198,7 @@ import TotalPointsDisplay from '@/components/TotalPointsDisplay.vue';
198 import PointsCollector from '@/components/PointsCollector.vue' 198 import PointsCollector from '@/components/PointsCollector.vue'
199 import WeRunAuth from '@/components/WeRunAuth.vue' 199 import WeRunAuth from '@/components/WeRunAuth.vue'
200 import { useMediaPreview } from '@/composables/useMediaPreview'; 200 import { useMediaPreview } from '@/composables/useMediaPreview';
201 +import { useStepsStore } from '@/stores/steps';
201 // 默认家庭封面图 202 // 默认家庭封面图
202 const defaultFamilyCover = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png'; 203 const defaultFamilyCover = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png';
203 // 默认头像 204 // 默认头像
...@@ -205,6 +206,9 @@ const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg' ...@@ -205,6 +206,9 @@ const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
205 // 接口信息 206 // 接口信息
206 import { getMyFamiliesAPI, getFamilyDashboardAPI } from '@/api/family' 207 import { getMyFamiliesAPI, getFamilyDashboardAPI } from '@/api/family'
207 208
209 +// 使用步数状态管理
210 +const stepsStore = useStepsStore();
211 +
208 const todaySteps = ref(0); 212 const todaySteps = ref(0);
209 const isWeRunAuthorized = ref(false); 213 const isWeRunAuthorized = ref(false);
210 const pointsCollectorRef = ref(null) 214 const pointsCollectorRef = ref(null)
...@@ -302,6 +306,8 @@ const handleAuthChange = (authorized) => { ...@@ -302,6 +306,8 @@ const handleAuthChange = (authorized) => {
302 */ 306 */
303 const handleStepsSynced = async (data) => { 307 const handleStepsSynced = async (data) => {
304 console.log('微信步数同步完成:', data) 308 console.log('微信步数同步完成:', data)
309 + // 同步成功后重置失败状态
310 + stepsStore.resetUpdateFailed()
305 // 同步成功后隐藏手动更新按钮 311 // 同步成功后隐藏手动更新按钮
306 showManualUpdateButton.value = false 312 showManualUpdateButton.value = false
307 // 步数同步完成后,重新获取家庭数据 313 // 步数同步完成后,重新获取家庭数据
...@@ -314,6 +320,8 @@ const handleStepsSynced = async (data) => { ...@@ -314,6 +320,8 @@ const handleStepsSynced = async (data) => {
314 */ 320 */
315 const handleSyncFailed = (data) => { 321 const handleSyncFailed = (data) => {
316 console.log('微信步数同步失败:', data) 322 console.log('微信步数同步失败:', data)
323 + // 记录更新失败状态到store
324 + stepsStore.setUpdateFailed()
317 // 显示手动更新按钮 325 // 显示手动更新按钮
318 if (data.showManualUpdate) { 326 if (data.showManualUpdate) {
319 showManualUpdateButton.value = true 327 showManualUpdateButton.value = true
...@@ -393,14 +401,20 @@ useDidShow(async () => { ...@@ -393,14 +401,20 @@ useDidShow(async () => {
393 family_id.value = data[0].id; 401 family_id.value = data[0].id;
394 // 先初始化基础页面数据(不包含步数相关数据) 402 // 先初始化基础页面数据(不包含步数相关数据)
395 await initPageData(); 403 await initPageData();
396 - // 然后刷新微信步数数据(只有在已加入家庭时才获取) 404 +
405 + // 检查是否应该显示手动更新按钮
406 + if (stepsStore.shouldShowManualUpdate()) {
407 + // 如果之前有更新失败记录,直接显示手动更新按钮,不自动获取步数
408 + showManualUpdateButton.value = true;
409 + console.log('检测到之前步数更新失败,显示手动更新按钮');
410 + } else {
411 + // 没有失败记录,正常刷新微信步数数据
397 if (weRunAuthRef.value) { 412 if (weRunAuthRef.value) {
398 weRunAuthRef.value.checkAuthStatus(true); 413 weRunAuthRef.value.checkAuthStatus(true);
399 } 414 }
400 } 415 }
401 } 416 }
402 - 417 + }
403 -
404 }) 418 })
405 419
406 useReady(async () => { 420 useReady(async () => {
......
1 +/*
2 + * @Description: 步数更新状态管理
3 + */
4 +import { defineStore } from 'pinia'
5 +
6 +export const useStepsStore = defineStore('steps', {
7 + state: () => {
8 + return {
9 + hasUpdateFailed: false, // 是否曾经更新失败过
10 + lastFailedTime: null, // 最后一次失败的时间
11 + }
12 + },
13 + actions: {
14 + /**
15 + * 设置更新失败状态
16 + */
17 + setUpdateFailed() {
18 + this.hasUpdateFailed = true
19 + this.lastFailedTime = new Date().getTime()
20 + },
21 + /**
22 + * 重置更新失败状态
23 + */
24 + resetUpdateFailed() {
25 + this.hasUpdateFailed = false
26 + this.lastFailedTime = null
27 + },
28 + /**
29 + * 检查是否需要显示手动更新按钮
30 + */
31 + shouldShowManualUpdate() {
32 + return this.hasUpdateFailed
33 + }
34 + },
35 +})
...\ No newline at end of file ...\ No newline at end of file