hookehuyr

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

添加步数状态管理store,用于记录更新失败状态和时间
在同步成功/失败时更新状态,并根据状态决定是否显示手动更新按钮
......@@ -198,6 +198,7 @@ import TotalPointsDisplay from '@/components/TotalPointsDisplay.vue';
import PointsCollector from '@/components/PointsCollector.vue'
import WeRunAuth from '@/components/WeRunAuth.vue'
import { useMediaPreview } from '@/composables/useMediaPreview';
import { useStepsStore } from '@/stores/steps';
// 默认家庭封面图
const defaultFamilyCover = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png';
// 默认头像
......@@ -205,6 +206,9 @@ const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
// 接口信息
import { getMyFamiliesAPI, getFamilyDashboardAPI } from '@/api/family'
// 使用步数状态管理
const stepsStore = useStepsStore();
const todaySteps = ref(0);
const isWeRunAuthorized = ref(false);
const pointsCollectorRef = ref(null)
......@@ -302,6 +306,8 @@ const handleAuthChange = (authorized) => {
*/
const handleStepsSynced = async (data) => {
console.log('微信步数同步完成:', data)
// 同步成功后重置失败状态
stepsStore.resetUpdateFailed()
// 同步成功后隐藏手动更新按钮
showManualUpdateButton.value = false
// 步数同步完成后,重新获取家庭数据
......@@ -314,6 +320,8 @@ const handleStepsSynced = async (data) => {
*/
const handleSyncFailed = (data) => {
console.log('微信步数同步失败:', data)
// 记录更新失败状态到store
stepsStore.setUpdateFailed()
// 显示手动更新按钮
if (data.showManualUpdate) {
showManualUpdateButton.value = true
......@@ -393,14 +401,20 @@ useDidShow(async () => {
family_id.value = data[0].id;
// 先初始化基础页面数据(不包含步数相关数据)
await initPageData();
// 然后刷新微信步数数据(只有在已加入家庭时才获取)
if (weRunAuthRef.value) {
weRunAuthRef.value.checkAuthStatus(true);
// 检查是否应该显示手动更新按钮
if (stepsStore.shouldShowManualUpdate()) {
// 如果之前有更新失败记录,直接显示手动更新按钮,不自动获取步数
showManualUpdateButton.value = true;
console.log('检测到之前步数更新失败,显示手动更新按钮');
} else {
// 没有失败记录,正常刷新微信步数数据
if (weRunAuthRef.value) {
weRunAuthRef.value.checkAuthStatus(true);
}
}
}
}
})
useReady(async () => {
......
/*
* @Description: 步数更新状态管理
*/
import { defineStore } from 'pinia'
export const useStepsStore = defineStore('steps', {
state: () => {
return {
hasUpdateFailed: false, // 是否曾经更新失败过
lastFailedTime: null, // 最后一次失败的时间
}
},
actions: {
/**
* 设置更新失败状态
*/
setUpdateFailed() {
this.hasUpdateFailed = true
this.lastFailedTime = new Date().getTime()
},
/**
* 重置更新失败状态
*/
resetUpdateFailed() {
this.hasUpdateFailed = false
this.lastFailedTime = null
},
/**
* 检查是否需要显示手动更新按钮
*/
shouldShowManualUpdate() {
return this.hasUpdateFailed
}
},
})
\ No newline at end of file