hookehuyr

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

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

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

更新二维码描述为更友好的提示语
移除多余的空格保持代码整洁
...@@ -201,7 +201,7 @@ const defaultFamilyCover = 'https://cdn.ipadbiz.cn/lls_prog/images/default-famil ...@@ -201,7 +201,7 @@ const defaultFamilyCover = 'https://cdn.ipadbiz.cn/lls_prog/images/default-famil
201 // 默认头像 201 // 默认头像
202 const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg' 202 const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
203 // 接口信息 203 // 接口信息
204 -import { getMyFamiliesAPI, getFamilyDashboardAPI } from '@/api/family' 204 +import { getFamilyDashboardAPI } from '@/api/family'
205 205
206 // 使用步数状态管理 206 // 使用步数状态管理
207 const stepsStore = useStepsStore(); 207 const stepsStore = useStepsStore();
...@@ -284,7 +284,20 @@ const handleAuthChange = (authorized) => { ...@@ -284,7 +284,20 @@ const handleAuthChange = (authorized) => {
284 const handleStepsSynced = async () => { 284 const handleStepsSynced = async () => {
285 console.log('微信步数同步完成') 285 console.log('微信步数同步完成')
286 // 步数同步完成后,重新获取家庭数据 286 // 步数同步完成后,重新获取家庭数据
287 - await initPageData() 287 + const { code, data } = await getFamilyDashboardAPI();
288 + if (code) {
289 + // 更新页面数据
290 + pendingPoints.value = data.pending_points || [];
291 + familyMembers.value = data.step_ranking || [];
292 + showTotalPointsOnly.value = !data.pending_points?.length;
293 + finalTotalPoints.value = data.family.total_points || 0;
294 + familyName.value = data.family.name;
295 + familySlogn.value = data.family.note;
296 + familyCover.value = data.family.avatar_url || defaultFamilyCover;
297 + familyOwner.value = data.family.is_my;
298 + todaySteps.value = data.my_today_step;
299 + totalFamilySteps.value = data.family_today_step;
300 + }
288 } 301 }
289 302
290 /** 303 /**
...@@ -331,49 +344,33 @@ const openFamilyRank = () => { ...@@ -331,49 +344,33 @@ const openFamilyRank = () => {
331 const family_id = ref(''); 344 const family_id = ref('');
332 const totalFamilySteps = ref(0); 345 const totalFamilySteps = ref(0);
333 346
334 -const initPageData = async () => { 347 +useDidShow(async () => {
348 + // 直接获取家庭首页数据,同时判断是否加入家庭
335 const { code, data } = await getFamilyDashboardAPI(); 349 const { code, data } = await getFamilyDashboardAPI();
336 if (code) { 350 if (code) {
337 - // 获取用户信息 351 + // 获取家庭ID
338 - console.warn(data); 352 + family_id.value = data.family.id;
339 - // 设置待收集的积分数据 353 +
354 + // 设置页面数据(数据已经在getFamilyDashboardAPI中获取到了)
340 pendingPoints.value = data.pending_points || []; 355 pendingPoints.value = data.pending_points || [];
341 - // 获取今日家庭总步数
342 familyMembers.value = data.step_ranking || []; 356 familyMembers.value = data.step_ranking || [];
343 - // 根据是否有待收集积分决定显示模式
344 showTotalPointsOnly.value = !data.pending_points?.length; 357 showTotalPointsOnly.value = !data.pending_points?.length;
345 - // 总积分数量从接口获取
346 finalTotalPoints.value = data.family.total_points || 0; 358 finalTotalPoints.value = data.family.total_points || 0;
347 - // 获取用户信息
348 familyName.value = data.family.name; 359 familyName.value = data.family.name;
349 familySlogn.value = data.family.note; 360 familySlogn.value = data.family.note;
350 familyCover.value = data.family.avatar_url || defaultFamilyCover; 361 familyCover.value = data.family.avatar_url || defaultFamilyCover;
351 familyOwner.value = data.family.is_my; 362 familyOwner.value = data.family.is_my;
352 - // 获取今日我的步数
353 todaySteps.value = data.my_today_step; 363 todaySteps.value = data.my_today_step;
354 - // 获取家庭总步数
355 totalFamilySteps.value = data.family_today_step; 364 totalFamilySteps.value = data.family_today_step;
356 - }
357 -}
358 365
359 -useDidShow(async () => { 366 + // 正常刷新微信步数数据
360 - // 获取用户是否加入家庭 367 + if (weRunAuthRef.value) {
361 - const { code, data } = await getMyFamiliesAPI() 368 + weRunAuthRef.value.checkAuthStatus(true);
362 - if (code) {
363 - // 如果没有加入家庭
364 - if (!data?.length) {
365 - Taro.redirectTo({ url: '/pages/Welcome/index' });
366 - return; // 直接返回,不执行后续逻辑
367 - } else {
368 - family_id.value = data[0].id;
369 - // 先初始化基础页面数据(不包含步数相关数据)
370 - await initPageData();
371 -
372 - // 正常刷新微信步数数据
373 - if (weRunAuthRef.value) {
374 - weRunAuthRef.value.checkAuthStatus(true);
375 - }
376 } 369 }
370 + } else {
371 + // 如果没有加入家庭(code为0),跳转到欢迎页面
372 + Taro.redirectTo({ url: '/pages/Welcome/index' });
373 + return; // 直接返回,不执行后续逻辑
377 } 374 }
378 }) 375 })
379 376
......
...@@ -236,7 +236,7 @@ const posterList = ref([ ...@@ -236,7 +236,7 @@ const posterList = ref([
236 name: '第二关卡' 236 name: '第二关卡'
237 }, 237 },
238 qrcode: 'https://cdn.ipadbiz.cn/space/068a790496c87cb8d2ed6e551401c544.png', 238 qrcode: 'https://cdn.ipadbiz.cn/space/068a790496c87cb8d2ed6e551401c544.png',
239 - qrcodeDesc: '扫码加入我们的队伍!' 239 + qrcodeDesc: '长按识别,来,我们一起打卡!'
240 }, 240 },
241 ]) 241 ])
242 242
...@@ -498,7 +498,7 @@ const generateCurrentPosterIfNeeded = () => { ...@@ -498,7 +498,7 @@ const generateCurrentPosterIfNeeded = () => {
498 const currentHash = generateConfigHash() 498 const currentHash = generateConfigHash()
499 const isGenerated = posterGeneratedFlags.value[currentIndex] 499 const isGenerated = posterGeneratedFlags.value[currentIndex]
500 const lastHash = posterConfigHashes.value[currentIndex] 500 const lastHash = posterConfigHashes.value[currentIndex]
501 - 501 +
502 // 如果海报未生成过,或者配置发生了变化,则需要重新生成 502 // 如果海报未生成过,或者配置发生了变化,则需要重新生成
503 if (!isGenerated || lastHash !== currentHash) { 503 if (!isGenerated || lastHash !== currentHash) {
504 posterConfigHashes.value[currentIndex] = currentHash 504 posterConfigHashes.value[currentIndex] = currentHash
...@@ -631,13 +631,13 @@ const onPosterSuccess = (result) => { ...@@ -631,13 +631,13 @@ const onPosterSuccess = (result) => {
631 const currentIndex = currentPosterIndex.value 631 const currentIndex = currentPosterIndex.value
632 posterPath.value = result.tempFilePath 632 posterPath.value = result.tempFilePath
633 posterGenerateFailed.value = false 633 posterGenerateFailed.value = false
634 - 634 +
635 // 更新当前海报的路径和生成状态 635 // 更新当前海报的路径和生成状态
636 if (posterList.value[currentIndex]) { 636 if (posterList.value[currentIndex]) {
637 posterList.value[currentIndex].path = result.tempFilePath 637 posterList.value[currentIndex].path = result.tempFilePath
638 } 638 }
639 posterGeneratedFlags.value[currentIndex] = true 639 posterGeneratedFlags.value[currentIndex] = true
640 - 640 +
641 shouldGeneratePoster.value = false 641 shouldGeneratePoster.value = false
642 Taro.showToast({ title: '海报生成成功', icon: 'success' }) 642 Taro.showToast({ title: '海报生成成功', icon: 'success' })
643 } 643 }
...@@ -650,10 +650,10 @@ const onPosterFail = (error) => { ...@@ -650,10 +650,10 @@ const onPosterFail = (error) => {
650 shouldGeneratePoster.value = false 650 shouldGeneratePoster.value = false
651 posterGenerateFailed.value = true 651 posterGenerateFailed.value = true
652 posterPath.value = '' 652 posterPath.value = ''
653 - 653 +
654 // 标记当前海报生成失败,下次仍需重新生成 654 // 标记当前海报生成失败,下次仍需重新生成
655 posterGeneratedFlags.value[currentIndex] = false 655 posterGeneratedFlags.value[currentIndex] = false
656 - 656 +
657 Taro.showToast({ title: '海报生成失败', icon: 'none' }) 657 Taro.showToast({ title: '海报生成失败', icon: 'none' })
658 console.error('海报生成失败:', error) 658 console.error('海报生成失败:', error)
659 } 659 }
......