hookehuyr

refactor(Dashboard): 优化家庭数据获取逻辑并移除冗余代码

简化家庭数据获取流程,直接使用getFamilyDashboardAPI获取所有数据
移除冗余的initPageData方法和getMyFamiliesAPI调用
```

```msg
style(PosterCheckin): 调整二维码描述文本和代码格式

更新二维码描述为更友好的提示语
移除多余的空格保持代码整洁
......@@ -201,7 +201,7 @@ const defaultFamilyCover = 'https://cdn.ipadbiz.cn/lls_prog/images/default-famil
// 默认头像
const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
// 接口信息
import { getMyFamiliesAPI, getFamilyDashboardAPI } from '@/api/family'
import { getFamilyDashboardAPI } from '@/api/family'
// 使用步数状态管理
const stepsStore = useStepsStore();
......@@ -284,7 +284,20 @@ const handleAuthChange = (authorized) => {
const handleStepsSynced = async () => {
console.log('微信步数同步完成')
// 步数同步完成后,重新获取家庭数据
await initPageData()
const { code, data } = await getFamilyDashboardAPI();
if (code) {
// 更新页面数据
pendingPoints.value = data.pending_points || [];
familyMembers.value = data.step_ranking || [];
showTotalPointsOnly.value = !data.pending_points?.length;
finalTotalPoints.value = data.family.total_points || 0;
familyName.value = data.family.name;
familySlogn.value = data.family.note;
familyCover.value = data.family.avatar_url || defaultFamilyCover;
familyOwner.value = data.family.is_my;
todaySteps.value = data.my_today_step;
totalFamilySteps.value = data.family_today_step;
}
}
/**
......@@ -331,49 +344,33 @@ const openFamilyRank = () => {
const family_id = ref('');
const totalFamilySteps = ref(0);
const initPageData = async () => {
useDidShow(async () => {
// 直接获取家庭首页数据,同时判断是否加入家庭
const { code, data } = await getFamilyDashboardAPI();
if (code) {
// 获取用户信息
console.warn(data);
// 设置待收集的积分数据
// 获取家庭ID
family_id.value = data.family.id;
// 设置页面数据(数据已经在getFamilyDashboardAPI中获取到了)
pendingPoints.value = data.pending_points || [];
// 获取今日家庭总步数
familyMembers.value = data.step_ranking || [];
// 根据是否有待收集积分决定显示模式
showTotalPointsOnly.value = !data.pending_points?.length;
// 总积分数量从接口获取
finalTotalPoints.value = data.family.total_points || 0;
// 获取用户信息
familyName.value = data.family.name;
familySlogn.value = data.family.note;
familyCover.value = data.family.avatar_url || defaultFamilyCover;
familyOwner.value = data.family.is_my;
// 获取今日我的步数
todaySteps.value = data.my_today_step;
// 获取家庭总步数
totalFamilySteps.value = data.family_today_step;
}
}
useDidShow(async () => {
// 获取用户是否加入家庭
const { code, data } = await getMyFamiliesAPI()
if (code) {
// 如果没有加入家庭
if (!data?.length) {
Taro.redirectTo({ url: '/pages/Welcome/index' });
return; // 直接返回,不执行后续逻辑
} else {
family_id.value = data[0].id;
// 先初始化基础页面数据(不包含步数相关数据)
await initPageData();
// 正常刷新微信步数数据
if (weRunAuthRef.value) {
weRunAuthRef.value.checkAuthStatus(true);
}
// 正常刷新微信步数数据
if (weRunAuthRef.value) {
weRunAuthRef.value.checkAuthStatus(true);
}
} else {
// 如果没有加入家庭(code为0),跳转到欢迎页面
Taro.redirectTo({ url: '/pages/Welcome/index' });
return; // 直接返回,不执行后续逻辑
}
})
......
......@@ -236,7 +236,7 @@ const posterList = ref([
name: '第二关卡'
},
qrcode: 'https://cdn.ipadbiz.cn/space/068a790496c87cb8d2ed6e551401c544.png',
qrcodeDesc: '扫码加入我们的队伍!'
qrcodeDesc: '长按识别,来,我们一起打卡!'
},
])
......@@ -498,7 +498,7 @@ const generateCurrentPosterIfNeeded = () => {
const currentHash = generateConfigHash()
const isGenerated = posterGeneratedFlags.value[currentIndex]
const lastHash = posterConfigHashes.value[currentIndex]
// 如果海报未生成过,或者配置发生了变化,则需要重新生成
if (!isGenerated || lastHash !== currentHash) {
posterConfigHashes.value[currentIndex] = currentHash
......@@ -631,13 +631,13 @@ const onPosterSuccess = (result) => {
const currentIndex = currentPosterIndex.value
posterPath.value = result.tempFilePath
posterGenerateFailed.value = false
// 更新当前海报的路径和生成状态
if (posterList.value[currentIndex]) {
posterList.value[currentIndex].path = result.tempFilePath
}
posterGeneratedFlags.value[currentIndex] = true
shouldGeneratePoster.value = false
Taro.showToast({ title: '海报生成成功', icon: 'success' })
}
......@@ -650,10 +650,10 @@ const onPosterFail = (error) => {
shouldGeneratePoster.value = false
posterGenerateFailed.value = true
posterPath.value = ''
// 标记当前海报生成失败,下次仍需重新生成
posterGeneratedFlags.value[currentIndex] = false
Taro.showToast({ title: '海报生成失败', icon: 'none' })
console.error('海报生成失败:', error)
}
......