feat(家庭): 添加家庭列表可添加字段并优化按钮显示逻辑
添加返回字段 can_add 以控制是否显示创建家庭按钮 移除基于年龄的按钮显示逻辑,改为使用 can_add 字段
Showing
2 changed files
with
10 additions
and
54 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2024-01-01 00:00:00 | 2 | * @Date: 2024-01-01 00:00:00 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-22 15:35:23 | 4 | + * @LastEditTime: 2025-09-23 09:37:24 |
| 5 | * @FilePath: /lls_program/src/api/family.js | 5 | * @FilePath: /lls_program/src/api/family.js |
| 6 | * @Description: 家庭相关接口 | 6 | * @Description: 家庭相关接口 |
| 7 | */ | 7 | */ |
| ... | @@ -43,6 +43,7 @@ export const searchFamilyByPassphraseAPI = (params) => fn(fetch.get(Api.SEARCH_B | ... | @@ -43,6 +43,7 @@ export const searchFamilyByPassphraseAPI = (params) => fn(fetch.get(Api.SEARCH_B |
| 43 | * @returns {string} response.code - 响应状态码 | 43 | * @returns {string} response.code - 响应状态码 |
| 44 | * @returns {string} response.msg - 响应消息 | 44 | * @returns {string} response.msg - 响应消息 |
| 45 | * @returns {Array} response.data.families - 家庭列表 | 45 | * @returns {Array} response.data.families - 家庭列表 |
| 46 | + * @returns {boolean} response.data.can_add - 是否可以添加家庭 | ||
| 46 | * @returns {number} response.data.families[].id - 家庭ID | 47 | * @returns {number} response.data.families[].id - 家庭ID |
| 47 | * @returns {string} response.data.families[].name - 家庭名称 | 48 | * @returns {string} response.data.families[].name - 家庭名称 |
| 48 | * @returns {string} response.data.families[].avatar_url - 家庭头像 | 49 | * @returns {string} response.data.families[].avatar_url - 家庭头像 | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-09-19 14:11:06 | 2 | * @Date: 2022-09-19 14:11:06 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-09-20 22:26:29 | 4 | + * @LastEditTime: 2025-09-23 09:45:30 |
| 5 | * @FilePath: /lls_program/src/pages/MyFamily/index.vue | 5 | * @FilePath: /lls_program/src/pages/MyFamily/index.vue |
| 6 | * @Description: 我的家庭页面 - 展示用户加入的家庭列表 | 6 | * @Description: 我的家庭页面 - 展示用户加入的家庭列表 |
| 7 | --> | 7 | --> |
| ... | @@ -114,9 +114,9 @@ | ... | @@ -114,9 +114,9 @@ |
| 114 | </view> | 114 | </view> |
| 115 | 115 | ||
| 116 | <!-- 底部固定按钮 --> | 116 | <!-- 底部固定按钮 --> |
| 117 | - <view v-if="isShowBtn" class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-100 p-4 z-10"> | 117 | + <view v-if="familyList.length > 0" class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-100 p-4 z-10"> |
| 118 | - <!-- 双按钮布局:大于60岁且未创建过家庭 --> | 118 | + <!-- 双按钮布局:可以创建家庭时 --> |
| 119 | - <view v-if="showDoubleButtons" class="flex gap-3"> | 119 | + <view v-if="canAddFamily" class="flex gap-3"> |
| 120 | <view | 120 | <view |
| 121 | @tap="createNewFamily" | 121 | @tap="createNewFamily" |
| 122 | class="flex-1 bg-green-500 text-white text-center py-3 rounded-lg font-medium text-sm" | 122 | class="flex-1 bg-green-500 text-white text-center py-3 rounded-lg font-medium text-sm" |
| ... | @@ -131,7 +131,7 @@ | ... | @@ -131,7 +131,7 @@ |
| 131 | </view> | 131 | </view> |
| 132 | </view> | 132 | </view> |
| 133 | 133 | ||
| 134 | - <!-- 单按钮布局:其他情况 --> | 134 | + <!-- 单按钮布局:只能加入家庭时 --> |
| 135 | <view | 135 | <view |
| 136 | v-else | 136 | v-else |
| 137 | @tap="joinNewFamily" | 137 | @tap="joinNewFamily" |
| ... | @@ -242,7 +242,6 @@ import { Home, Check } from '@nutui/icons-vue-taro'; | ... | @@ -242,7 +242,6 @@ import { Home, Check } from '@nutui/icons-vue-taro'; |
| 242 | import './index.less'; | 242 | import './index.less'; |
| 243 | // 获取接口信息 | 243 | // 获取接口信息 |
| 244 | import { getMyFamiliesAPI, switchCurrentFamilyAPI, deleteFamilyMemberAPI } from '@/api/family'; | 244 | import { getMyFamiliesAPI, switchCurrentFamilyAPI, deleteFamilyMemberAPI } from '@/api/family'; |
| 245 | -import { getUserProfileAPI } from '@/api/user'; | ||
| 246 | // | 245 | // |
| 247 | const defaultFamilyCoverSvg = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png'; | 246 | const defaultFamilyCoverSvg = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png'; |
| 248 | // 默认头像 | 247 | // 默认头像 |
| ... | @@ -251,8 +250,6 @@ const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg' | ... | @@ -251,8 +250,6 @@ const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg' |
| 251 | 250 | ||
| 252 | // 响应式数据 | 251 | // 响应式数据 |
| 253 | const familyList = ref([]); | 252 | const familyList = ref([]); |
| 254 | -const userProfile = ref(null); // 用户资料信息 | ||
| 255 | -const isOver60 = ref(false); // 是否大于60岁 | ||
| 256 | 253 | ||
| 257 | // 成员管理相关数据 | 254 | // 成员管理相关数据 |
| 258 | const showMemberPopup = ref(false); | 255 | const showMemberPopup = ref(false); |
| ... | @@ -261,61 +258,19 @@ const selectedMembers = ref([]); | ... | @@ -261,61 +258,19 @@ const selectedMembers = ref([]); |
| 261 | const currentMembers = ref([]); | 258 | const currentMembers = ref([]); |
| 262 | 259 | ||
| 263 | /** | 260 | /** |
| 264 | - * 计算年龄 | ||
| 265 | - * @param {string} birthDate - 生日日期字符串 | ||
| 266 | - * @returns {number} 年龄 | ||
| 267 | - */ | ||
| 268 | -const calculateAge = (birthDate) => { | ||
| 269 | - if (!birthDate) return 0; | ||
| 270 | - | ||
| 271 | - const birth = new Date(birthDate); | ||
| 272 | - const today = new Date(); | ||
| 273 | - let age = today.getFullYear() - birth.getFullYear(); | ||
| 274 | - const monthDiff = today.getMonth() - birth.getMonth(); | ||
| 275 | - | ||
| 276 | - if (monthDiff < 0 || (monthDiff === 0 && today.getDate() < birth.getDate())) { | ||
| 277 | - age--; | ||
| 278 | - } | ||
| 279 | - | ||
| 280 | - return age; | ||
| 281 | -}; | ||
| 282 | - | ||
| 283 | -/** | ||
| 284 | * 初始化页面数据 | 261 | * 初始化页面数据 |
| 285 | */ | 262 | */ |
| 263 | +const canAddFamily = ref(false); | ||
| 264 | + | ||
| 286 | const initPageData = async () => { | 265 | const initPageData = async () => { |
| 287 | // 获取家庭列表 | 266 | // 获取家庭列表 |
| 288 | const { code, data } = await getMyFamiliesAPI(); | 267 | const { code, data } = await getMyFamiliesAPI(); |
| 289 | if (code) { | 268 | if (code) { |
| 290 | familyList.value = data?.families || []; | 269 | familyList.value = data?.families || []; |
| 291 | - console.warn(data); | 270 | + canAddFamily.value = data?.can_add || false; |
| 292 | - } | ||
| 293 | - | ||
| 294 | - // 获取用户资料 | ||
| 295 | - const userRes = await getUserProfileAPI(); | ||
| 296 | - if (userRes.code && userRes.data?.user) { | ||
| 297 | - userProfile.value = userRes.data.user; | ||
| 298 | - const age = calculateAge(userRes.data.user.birth_date); | ||
| 299 | - isOver60.value = age > 60; | ||
| 300 | - console.log('用户年龄:', age, '是否大于60岁:', isOver60.value); | ||
| 301 | } | 271 | } |
| 302 | }; | 272 | }; |
| 303 | 273 | ||
| 304 | -// 如果家庭列表存在时, 才显示加入新家庭的按钮 | ||
| 305 | -const isShowBtn = computed(() => { | ||
| 306 | - return familyList.value.length > 0; | ||
| 307 | -}); | ||
| 308 | - | ||
| 309 | -// 判断用户是否创建过家庭 | ||
| 310 | -const hasCreatedFamily = computed(() => { | ||
| 311 | - return familyList.value.some(family => family.is_my); | ||
| 312 | -}); | ||
| 313 | - | ||
| 314 | -// 判断是否显示双按钮(创建家庭 + 加入家庭) | ||
| 315 | -const showDoubleButtons = computed(() => { | ||
| 316 | - return isOver60.value && !hasCreatedFamily.value; | ||
| 317 | -}); | ||
| 318 | - | ||
| 319 | /** | 274 | /** |
| 320 | * 切换到指定家庭 | 275 | * 切换到指定家庭 |
| 321 | * @param {number} familyId - 家庭ID | 276 | * @param {number} familyId - 家庭ID | ... | ... |
-
Please register or login to post a comment