hookehuyr

fix(家庭功能): 修复家庭相关功能并移除模拟数据

- 修复Dashboard页面获取家庭数据时未传递family_id的问题
- 更新家庭API文档,将member_user_id参数改为支持数组的user_ids
- 移除MyFamily页面的模拟数据,使用真实API数据
- 为成员头像添加默认头像处理
- 实现退出家庭和移除成员的实际API调用
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-03 11:25:11 4 + * @LastEditTime: 2025-09-03 16:51:51
5 * @FilePath: /lls_program/src/api/family.js 5 * @FilePath: /lls_program/src/api/family.js
6 * @Description: 家庭相关接口 6 * @Description: 家庭相关接口
7 */ 7 */
...@@ -168,7 +168,7 @@ export const switchCurrentFamilyAPI = (params) => fn(fetch.post(Api.SWITCH_CURRE ...@@ -168,7 +168,7 @@ export const switchCurrentFamilyAPI = (params) => fn(fetch.post(Api.SWITCH_CURRE
168 * @description: 退出或移出家庭成员 168 * @description: 退出或移出家庭成员
169 * @param {Object} params - 请求参数 169 * @param {Object} params - 请求参数
170 * @param {number} params.family_id - 家庭ID 170 * @param {number} params.family_id - 家庭ID
171 - * @param {number} [params.member_user_id] - 成员用户ID(主动退出时不传,创建者移出时传递) 171 + * @param {number|Array} [params.user_ids] - 成员用户ID(主动退出时不传,创建者移出时传递)
172 * @returns {Promise} 返回操作结果 172 * @returns {Promise} 返回操作结果
173 * @returns {Object} response - 响应对象 173 * @returns {Object} response - 响应对象
174 * @returns {string} response.code - 响应状态码 174 * @returns {string} response.code - 响应状态码
......
...@@ -329,7 +329,7 @@ const family_id = ref(''); ...@@ -329,7 +329,7 @@ const family_id = ref('');
329 const totalFamilySteps = ref(0); 329 const totalFamilySteps = ref(0);
330 330
331 const initPageData = async () => { 331 const initPageData = async () => {
332 - const { code, data } = await getFamilyDashboardAPI({ family_id: family_id.value }); 332 + const { code, data } = await getFamilyDashboardAPI();
333 if (code) { 333 if (code) {
334 // 获取用户信息 334 // 获取用户信息
335 console.warn(data); 335 console.warn(data);
......
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-03 11:34:55 4 + * @LastEditTime: 2025-09-03 16:18:16
5 * @FilePath: /lls_program/src/pages/MyFamily/index.vue 5 * @FilePath: /lls_program/src/pages/MyFamily/index.vue
6 * @Description: 我的家庭页面 - 展示用户加入的家庭列表 6 * @Description: 我的家庭页面 - 展示用户加入的家庭列表
7 --> 7 -->
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
56 <image 56 <image
57 v-for="(member, index) in family?.users?.slice(0, 4) || []" 57 v-for="(member, index) in family?.users?.slice(0, 4) || []"
58 :key="member.id" 58 :key="member.id"
59 - :src="member.avatar" 59 + :src="member.avatar_url || defaultAvatar"
60 class="avatar-item w-8 h-8 rounded-full border-2 border-white object-cover" 60 class="avatar-item w-8 h-8 rounded-full border-2 border-white object-cover"
61 :style="{ zIndex: 10 - index }" 61 :style="{ zIndex: 10 - index }"
62 /> 62 />
...@@ -165,7 +165,7 @@ ...@@ -165,7 +165,7 @@
165 165
166 <!-- 头像 --> 166 <!-- 头像 -->
167 <image 167 <image
168 - :src="member.avatar" 168 + :src="member.avatar_url || defaultAvatar"
169 class="w-10 h-10 rounded-full ml-3 object-cover flex-shrink-0" 169 class="w-10 h-10 rounded-full ml-3 object-cover flex-shrink-0"
170 /> 170 />
171 171
...@@ -221,9 +221,11 @@ import Taro, { useDidShow } from '@tarojs/taro'; ...@@ -221,9 +221,11 @@ import Taro, { useDidShow } from '@tarojs/taro';
221 import { Home } from '@nutui/icons-vue-taro'; 221 import { Home } from '@nutui/icons-vue-taro';
222 import './index.less'; 222 import './index.less';
223 // 获取接口信息 223 // 获取接口信息
224 -import { getMyFamiliesAPI, switchCurrentFamilyAPI } from '@/api/family'; 224 +import { getMyFamiliesAPI, switchCurrentFamilyAPI, deleteFamilyMemberAPI } from '@/api/family';
225 // 225 //
226 const defaultFamilyCoverSvg = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png'; 226 const defaultFamilyCoverSvg = 'https://cdn.ipadbiz.cn/lls_prog/images/default-family-cover.png';
227 +// 默认头像
228 +const defaultAvatar = 'https://cdn.ipadbiz.cn/mlaj/images/icon_1.jpeg'
227 // 获取接口数据 229 // 获取接口数据
228 230
229 // 响应式数据 231 // 响应式数据
...@@ -244,46 +246,6 @@ const initPageData = async () => { ...@@ -244,46 +246,6 @@ const initPageData = async () => {
244 familyList.value = data; 246 familyList.value = data;
245 console.warn(data); 247 console.warn(data);
246 } 248 }
247 - // 模拟家庭数据 - 添加is_my字段用于测试
248 - familyList.value = [
249 - {
250 - id: 1,
251 - name: '幸福之家',
252 - created_by_nickname: '张明明',
253 - avatar_url: 'https://images.unsplash.com/photo-1511895426328-dc8714191300?w=400&h=200&fit=crop',
254 - is_current_family: true,
255 - is_my: true, // 当前用户是家长,可以管理成员
256 - users: [
257 - { id: 1, avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=100&h=100&fit=crop&crop=face' },
258 - { id: 2, avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=100&h=100&fit=crop&crop=face' },
259 - { id: 3, avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=100&h=100&fit=crop&crop=face' }
260 - ]
261 - },
262 - {
263 - id: 2,
264 - name: '欢乐之家',
265 - created_by_nickname: '李志强',
266 - avatar_url: 'https://images.unsplash.com/photo-1502086223501-7ea6ecd79368?w=400&h=200&fit=crop',
267 - is_current_family: false,
268 - is_my: false, // 当前用户不是家长
269 - users: [
270 - { id: 4, avatar: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=100&h=100&fit=crop&crop=face' },
271 - { id: 5, avatar: 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=100&h=100&fit=crop&crop=face' }
272 - ]
273 - },
274 - {
275 - id: 3,
276 - name: '快乐之家',
277 - created_by_nickname: '王芳',
278 - avatar_url: 'https://images.unsplash.com/photo-1502086223501-7ea6ecd79368?w=400&h=200&fit=crop',
279 - is_current_family: false,
280 - is_my: true, // 当前用户是家长,但不在此家庭
281 - users: [
282 - { id: 6, avatar: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=100&h=100&fit=crop&crop=face' },
283 - { id: 7, avatar: 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=100&h=100&fit=crop&crop=face' }
284 - ]
285 - }
286 - ];
287 }; 249 };
288 250
289 // 如果家庭列表存在时, 才显示加入新家庭的按钮 251 // 如果家庭列表存在时, 才显示加入新家庭的按钮
...@@ -304,7 +266,7 @@ const switchToFamily = async (familyId) => { ...@@ -304,7 +266,7 @@ const switchToFamily = async (familyId) => {
304 content: `确定要切换到「${family.name}」吗?`, 266 content: `确定要切换到「${family.name}」吗?`,
305 success: async (res) => { 267 success: async (res) => {
306 if (res.confirm) { 268 if (res.confirm) {
307 - const { code } = await switchCurrentFamilyAPI(familyId); 269 + const { code } = await switchCurrentFamilyAPI({ family_id: familyId });
308 if (code) { 270 if (code) {
309 // 切换家庭逻辑 - 先清除所有当前标记,再设置新的当前家庭 271 // 切换家庭逻辑 - 先清除所有当前标记,再设置新的当前家庭
310 familyList.value = familyList.value.map(f => ({ 272 familyList.value = familyList.value.map(f => ({
...@@ -327,7 +289,7 @@ const switchToFamily = async (familyId) => { ...@@ -327,7 +289,7 @@ const switchToFamily = async (familyId) => {
327 * 退出家庭 289 * 退出家庭
328 * @param {number} familyId - 家庭ID 290 * @param {number} familyId - 家庭ID
329 */ 291 */
330 -const exitFamily = (familyId) => { 292 +const exitFamily = async (familyId) => {
331 const family = familyList.value.find(f => f.id === familyId); 293 const family = familyList.value.find(f => f.id === familyId);
332 if (!family) return; 294 if (!family) return;
333 295
...@@ -343,9 +305,15 @@ const exitFamily = (familyId) => { ...@@ -343,9 +305,15 @@ const exitFamily = (familyId) => {
343 Taro.showModal({ 305 Taro.showModal({
344 title: '退出家庭', 306 title: '退出家庭',
345 content: `确定要退出「${family.name}」吗?退出后将无法查看该家庭的相关信息。`, 307 content: `确定要退出「${family.name}」吗?退出后将无法查看该家庭的相关信息。`,
346 - success: (res) => { 308 + success: async (res) => {
347 if (res.confirm) { 309 if (res.confirm) {
348 - // 退出家庭逻辑 310 + try {
311 + // 调用退出家庭API(主动退出时不传user_ids)
312 + const { code } = await deleteFamilyMemberAPI({
313 + family_id: familyId
314 + });
315 +
316 + if (code) {
349 const exitingFamily = familyList.value.find(f => f.id === familyId); 317 const exitingFamily = familyList.value.find(f => f.id === familyId);
350 318
351 if (exitingFamily?.is_current_family) { 319 if (exitingFamily?.is_current_family) {
...@@ -371,6 +339,14 @@ const exitFamily = (familyId) => { ...@@ -371,6 +339,14 @@ const exitFamily = (familyId) => {
371 }); 339 });
372 } 340 }
373 } 341 }
342 + } catch (error) {
343 + console.error('退出家庭失败:', error);
344 + Taro.showToast({
345 + title: '退出失败,请重试',
346 + icon: 'none'
347 + });
348 + }
349 + }
374 } 350 }
375 }); 351 });
376 }; 352 };
...@@ -392,44 +368,12 @@ const joinNewFamily = () => { ...@@ -392,44 +368,12 @@ const joinNewFamily = () => {
392 */ 368 */
393 const showMemberManagement = (family) => { 369 const showMemberManagement = (family) => {
394 currentFamily.value = family; 370 currentFamily.value = family;
395 - // 生成模拟成员数据 371 + // 生成成员数据
396 - currentMembers.value = [ 372 + currentMembers.value = family.users.map(user => ({
397 - { 373 + ...user,
398 - id: 1, 374 + is_my: user.is_creator
399 - nickname: '张明明', 375 + }));
400 - avatar: 'https://images.unsplash.com/photo-1507003211169-0a1dd7228f2d?w=100&h=100&fit=crop&crop=face', 376 + //
401 - role: '父亲',
402 - is_my: true
403 - },
404 - {
405 - id: 2,
406 - nickname: '李美丽',
407 - avatar: 'https://images.unsplash.com/photo-1438761681033-6461ffad8d80?w=100&h=100&fit=crop&crop=face',
408 - role: '母亲',
409 - is_my: false
410 - },
411 - {
412 - id: 3,
413 - nickname: '张小明',
414 - avatar: 'https://images.unsplash.com/photo-1500648767791-00dcc994a43e?w=100&h=100&fit=crop&crop=face',
415 - role: '儿子',
416 - is_my: false
417 - },
418 - {
419 - id: 4,
420 - nickname: '张小花',
421 - avatar: 'https://images.unsplash.com/photo-1494790108755-2616b612b786?w=100&h=100&fit=crop&crop=face',
422 - role: '女儿',
423 - is_my: false
424 - },
425 - {
426 - id: 5,
427 - nickname: '王奶奶',
428 - avatar: 'https://images.unsplash.com/photo-1551836022-d5d88e9218df?w=100&h=100&fit=crop&crop=face',
429 - role: '奶奶',
430 - is_my: false
431 - }
432 - ];
433 selectedMembers.value = []; 377 selectedMembers.value = [];
434 showMemberPopup.value = true; 378 showMemberPopup.value = true;
435 }; 379 };
...@@ -471,7 +415,7 @@ const toggleMemberSelection = (memberId) => { ...@@ -471,7 +415,7 @@ const toggleMemberSelection = (memberId) => {
471 /** 415 /**
472 * 移除选中的成员 416 * 移除选中的成员
473 */ 417 */
474 -const removeSelectedMembers = () => { 418 +const removeSelectedMembers = async () => {
475 if (selectedMembers.value.length === 0) { 419 if (selectedMembers.value.length === 0) {
476 Taro.showToast({ 420 Taro.showToast({
477 title: '请选择要移除的成员', 421 title: '请选择要移除的成员',
...@@ -488,10 +432,27 @@ const removeSelectedMembers = () => { ...@@ -488,10 +432,27 @@ const removeSelectedMembers = () => {
488 Taro.showModal({ 432 Taro.showModal({
489 title: '移除成员', 433 title: '移除成员',
490 content: `确定要移除「${selectedNames}」吗?移除后他们将无法访问家庭信息。`, 434 content: `确定要移除「${selectedNames}」吗?移除后他们将无法访问家庭信息。`,
491 - success: (res) => { 435 + success: async (res) => {
492 if (res.confirm) { 436 if (res.confirm) {
493 - // 从模拟数据中移除选中的成员 437 + try {
438 + // 调用移除成员API(创建者移除时传递user_ids)
439 + const { code } = await deleteFamilyMemberAPI({
440 + family_id: currentFamily.value.id,
441 + user_ids: selectedMembers.value
442 + });
443 +
444 + if (code) {
445 + // 从当前成员列表中移除选中的成员
494 currentMembers.value = currentMembers.value.filter(m => !selectedMembers.value.includes(m.id)); 446 currentMembers.value = currentMembers.value.filter(m => !selectedMembers.value.includes(m.id));
447 +
448 + // 同时更新家庭列表中对应家庭的成员数据
449 + const familyIndex = familyList.value.findIndex(f => f.id === currentFamily.value.id);
450 + if (familyIndex !== -1) {
451 + familyList.value[familyIndex].users = familyList.value[familyIndex].users.filter(
452 + user => !selectedMembers.value.includes(user.id)
453 + );
454 + }
455 +
495 selectedMembers.value = []; 456 selectedMembers.value = [];
496 457
497 Taro.showToast({ 458 Taro.showToast({
...@@ -499,6 +460,14 @@ const removeSelectedMembers = () => { ...@@ -499,6 +460,14 @@ const removeSelectedMembers = () => {
499 icon: 'success' 460 icon: 'success'
500 }); 461 });
501 } 462 }
463 + } catch (error) {
464 + console.error('移除成员失败:', error);
465 + Taro.showToast({
466 + title: '移除失败,请重试',
467 + icon: 'none'
468 + });
469 + }
470 + }
502 } 471 }
503 }); 472 });
504 }; 473 };
......