hookehuyr

feat(profile): 添加家庭状态检查并动态调整菜单项

根据用户是否加入家庭来动态显示或隐藏家庭相关菜单项
新增has_family字段存储用户家庭状态
...@@ -115,7 +115,25 @@ ...@@ -115,7 +115,25 @@
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="isShowBtn" class="fixed bottom-0 left-0 right-0 bg-white border-t border-gray-100 p-4 z-10">
118 + <!-- 双按钮布局:大于60岁且未创建过家庭 -->
119 + <view v-if="showDoubleButtons" class="flex gap-3">
120 + <view
121 + @tap="createNewFamily"
122 + class="flex-1 bg-green-500 text-white text-center py-3 rounded-lg font-medium text-sm"
123 + >
124 + 创建家庭
125 + </view>
126 + <view
127 + @tap="joinNewFamily"
128 + class="flex-1 bg-blue-500 text-white text-center py-3 rounded-lg font-medium text-sm"
129 + >
130 + 加入家庭
131 + </view>
132 + </view>
133 +
134 + <!-- 单按钮布局:其他情况 -->
118 <view 135 <view
136 + v-else
119 @tap="joinNewFamily" 137 @tap="joinNewFamily"
120 class="w-full bg-blue-500 text-white text-center py-3 rounded-lg font-medium text-sm" 138 class="w-full bg-blue-500 text-white text-center py-3 rounded-lg font-medium text-sm"
121 > 139 >
...@@ -224,6 +242,7 @@ import { Home, Check } from '@nutui/icons-vue-taro'; ...@@ -224,6 +242,7 @@ import { Home, Check } from '@nutui/icons-vue-taro';
224 import './index.less'; 242 import './index.less';
225 // 获取接口信息 243 // 获取接口信息
226 import { getMyFamiliesAPI, switchCurrentFamilyAPI, deleteFamilyMemberAPI } from '@/api/family'; 244 import { getMyFamiliesAPI, switchCurrentFamilyAPI, deleteFamilyMemberAPI } from '@/api/family';
245 +import { getUserProfileAPI } from '@/api/user';
227 // 246 //
228 const defaultFamilyCoverSvg = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png'; 247 const defaultFamilyCoverSvg = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png';
229 // 默认头像 248 // 默认头像
...@@ -232,6 +251,8 @@ const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg' ...@@ -232,6 +251,8 @@ const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
232 251
233 // 响应式数据 252 // 响应式数据
234 const familyList = ref([]); 253 const familyList = ref([]);
254 +const userProfile = ref(null); // 用户资料信息
255 +const isOver60 = ref(false); // 是否大于60岁
235 256
236 // 成员管理相关数据 257 // 成员管理相关数据
237 const showMemberPopup = ref(false); 258 const showMemberPopup = ref(false);
...@@ -240,20 +261,60 @@ const selectedMembers = ref([]); ...@@ -240,20 +261,60 @@ const selectedMembers = ref([]);
240 const currentMembers = ref([]); 261 const currentMembers = ref([]);
241 262
242 /** 263 /**
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 +/**
243 * 初始化页面数据 284 * 初始化页面数据
244 */ 285 */
245 const initPageData = async () => { 286 const initPageData = async () => {
287 + // 获取家庭列表
246 const { code, data } = await getMyFamiliesAPI(); 288 const { code, data } = await getMyFamiliesAPI();
247 if (code) { 289 if (code) {
248 familyList.value = data; 290 familyList.value = data;
249 console.warn(data); 291 console.warn(data);
250 } 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 + }
251 }; 302 };
252 303
253 // 如果家庭列表存在时, 才显示加入新家庭的按钮 304 // 如果家庭列表存在时, 才显示加入新家庭的按钮
254 const isShowBtn = computed(() => { 305 const isShowBtn = computed(() => {
255 return familyList.value.length > 0; 306 return familyList.value.length > 0;
256 -}) 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 +});
257 318
258 /** 319 /**
259 * 切换到指定家庭 320 * 切换到指定家庭
...@@ -365,6 +426,15 @@ const joinNewFamily = () => { ...@@ -365,6 +426,15 @@ const joinNewFamily = () => {
365 }; 426 };
366 427
367 /** 428 /**
429 + * 创建新家庭
430 + */
431 +const createNewFamily = () => {
432 + Taro.navigateTo({
433 + url: '/pages/CreateFamily/index'
434 + });
435 +};
436 +
437 +/**
368 * 显示成员管理弹窗 438 * 显示成员管理弹窗
369 * @param {Object} family - 家庭对象 439 * @param {Object} family - 家庭对象
370 */ 440 */
......
1 <!-- 1 <!--
2 * @Date: 2025-08-27 17:47:46 2 * @Date: 2025-08-27 17:47:46
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-09-20 10:19:41 4 + * @LastEditTime: 2025-09-22 13:40:24
5 * @FilePath: /lls_program/src/pages/Profile/index.vue 5 * @FilePath: /lls_program/src/pages/Profile/index.vue
6 * @Description: 文件描述 6 * @Description: 文件描述
7 --> 7 -->
...@@ -52,6 +52,7 @@ import { My, Shop3, Cart, Message, Tips, Right, Ask } from '@nutui/icons-vue-tar ...@@ -52,6 +52,7 @@ import { My, Shop3, Cart, Message, Tips, Right, Ask } from '@nutui/icons-vue-tar
52 const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg' 52 const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
53 // 获取接口信息 53 // 获取接口信息
54 import { getUserProfileAPI } from '@/api/user' 54 import { getUserProfileAPI } from '@/api/user'
55 +import { getMyFamiliesAPI } from '@/api/family'
55 56
56 // 系统信息 57 // 系统信息
57 const systemInfo = ref({}); 58 const systemInfo = ref({});
...@@ -168,6 +169,7 @@ const userInfo = ref({ ...@@ -168,6 +169,7 @@ const userInfo = ref({
168 nickName: '', 169 nickName: '',
169 avatarUrl: '', 170 avatarUrl: '',
170 is_creator: false, 171 is_creator: false,
172 + has_family: false, // 新增字段:用户是否加入了家庭
171 }); 173 });
172 174
173 const goToEditProfile = () => { 175 const goToEditProfile = () => {
...@@ -185,14 +187,35 @@ const initPageData = async () => { ...@@ -185,14 +187,35 @@ const initPageData = async () => {
185 nickName: data?.user?.nickname || '临时用户', 187 nickName: data?.user?.nickname || '临时用户',
186 avatarUrl: data?.user?.avatar_url || '', 188 avatarUrl: data?.user?.avatar_url || '',
187 is_creator: data?.user?.is_creator || false, 189 is_creator: data?.user?.is_creator || false,
188 - birth_date: data?.user?.birth_date || '' 190 + birth_date: data?.user?.birth_date || '',
191 + has_family: false // 初始化为false
189 } 192 }
190 - // 根据用户身份更新菜单项 193 +
194 + // 检查用户是否加入了家庭
195 + try {
196 + const familyResponse = await getMyFamiliesAPI();
197 + if (familyResponse.code && familyResponse.data && familyResponse.data.length > 0) {
198 + userInfo.value.has_family = true;
199 + }
200 + } catch (error) {
201 + console.error('获取家庭信息失败:', error);
202 + userInfo.value.has_family = false;
203 + }
204 +
205 + // 根据用户身份和家庭状态更新菜单项
191 if (userInfo.value.is_creator) { 206 if (userInfo.value.is_creator) {
207 + // 创建者显示所有菜单项
192 menuItems.value = allMenuItems; 208 menuItems.value = allMenuItems;
193 } else { 209 } else {
194 - // 非创建者保持原有的过滤逻辑 210 + // 非创建者过滤掉积分和兑换相关菜单
195 - menuItems.value = allMenuItems.filter(item => !['points', 'rewards'].includes(item.id)); 211 + let filteredItems = allMenuItems.filter(item => !['points', 'rewards'].includes(item.id));
212 +
213 + // 如果用户没有加入家庭,也过滤掉family菜单项
214 + if (!userInfo.value.has_family) {
215 + filteredItems = filteredItems.filter(item => item.id !== 'family');
216 + }
217 +
218 + menuItems.value = filteredItems;
196 } 219 }
197 } 220 }
198 } 221 }
......