diff --git a/backend/src/users/users.service.ts b/backend/src/users/users.service.ts index a5a890e..f923258 100644 --- a/backend/src/users/users.service.ts +++ b/backend/src/users/users.service.ts @@ -125,7 +125,7 @@ export class UsersService { select: { id: true, name: true, code: true, tenantType: true, isSuper: true }, }; include._count = { - select: { children: true, contestRegistrations: true }, + select: { parentRelations: true, contestRegistrations: true }, }; } @@ -194,8 +194,18 @@ export class UsersService { tenant: { select: { id: true, name: true, code: true, tenantType: true, isSuper: true }, }, - children: isSuperTenant - ? { where: { isDeleted: 0 }, orderBy: { createTime: 'desc' } } + parentRelations: isSuperTenant + ? { + include: { + child: { + select: { + id: true, username: true, nickname: true, avatar: true, + gender: true, birthday: true, city: true, status: true, createTime: true, + }, + }, + }, + orderBy: { createTime: 'desc' }, + } : false, contestRegistrations: isSuperTenant ? { diff --git a/docs/design/super-admin/unified-user-management.md b/docs/design/super-admin/unified-user-management.md index a648d6a..5bacfd7 100644 --- a/docs/design/super-admin/unified-user-management.md +++ b/docs/design/super-admin/unified-user-management.md @@ -1,9 +1,9 @@ # 统一用户管理 — 设计方案 > 所属端:超管端 -> 状态:已实现(待验收) +> 状态:已实现(迭代中) > 创建日期:2026-03-27 -> 最后更新:2026-03-27 +> 最后更新:2026-03-30 --- @@ -101,6 +101,7 @@ GET /api/public/users/:id — 公众用户详情(含子女+报名) #### 统计卡片 - 5 张卡片横排,每张显示:类型图标 + 类型名称 + 数量 +- 类型命名:全部 / **运营团队** / 机构 / 评委 / 公众(~~平台~~ → 运营团队,2026-03-30 更名) - 选中的卡片高亮(主色边框),点击 = 设置 userType 筛选 - 点"全部"清除类型筛选 - 数据来源:`GET /api/users/stats` @@ -151,8 +152,8 @@ GET /api/public/users/:id — 公众用户详情(含子女+报名) **公众用户额外区域**: ``` -子女信息(N个) -├── 姓名 / 年龄 / 年级 / 城市 / 学校 +子女账号(N个)— 基于 UserParentChild 关系,子女为独立 User +├── 头像 / 昵称 / @用户名 / 性别 / 城市 / 关系(父亲/母亲/监护人) / 状态 报名记录(近20条) ├── 活动名称 / 报名状态 / 参与者(本人/子女名) / 报名时间 @@ -188,7 +189,7 @@ GET /api/public/users/:id — 公众用户详情(含子女+报名) - 返回字段增加: - `tenant: { id, name, code, tenantType, isSuper }`(用于前端推导用户类型) - - `_count: { children, contestRegistrations }`(公众用户的子女数和报名数) + - `_count: { parentRelations, contestRegistrations }`(公众用户的子女账号数和报名数) 普通租户调用时:保持现有逻辑不变。 @@ -220,7 +221,7 @@ public → tenant.code = 'public' 超管调用时: - 不做 tenantId 过滤 -- 公众用户额外返回:`children`(子女列表)、`contestRegistrations`(近20条报名记录,含活动名和子女名) +- 公众用户额外返回:`parentRelations`(子女账号列表,含 child User 信息)、`contestRegistrations`(近20条报名记录,含活动名和子女名) - 评委额外返回:`contestJudges`(参与的评审活动列表) #### 3.3.4 新增 PATCH /api/users/:id/status @@ -292,3 +293,18 @@ public → tenant.code = 'public' **验证结果:** - 后端 TSC 编译通过,NestJS 启动成功,/api/users/stats 和 /api/users/:id/status 路由注册正常 - 前端无新增 TS 错误(原有错误均为已有代码) + +### 2026-03-30 — 命名优化 + 子女账号独立化适配 + +**问题:** +1. 统计卡片和 Tag 中「平台」命名易误解为"平台全部用户",实际指运营管理人员 +2. 公众用户详情仍展示旧版 `Child` 模型(姓名/年级/学校),子女已独立为 `User` 后应使用 `UserParentChild` 关系 + +**改动(3 个文件):** +- `backend/src/users/users.service.ts` — findOne 详情查询:`children`(旧 Child 表)→ `parentRelations`(UserParentChild + child User);列表 `_count.children` → `_count.parentRelations` +- `frontend/src/api/users.ts` — User 类型定义:`children` 数组 → `parentRelations` 数组(含 child 独立用户信息 + relationship + controlMode) +- `frontend/src/views/system/users/Index.vue` — 统计卡片和 Tag 标签:「平台」→「运营团队」;详情 Drawer 子女区域:旧版姓名/年级/学校列表 → 新版子女账号卡片(头像+昵称+用户名+关系+状态) + +**验证结果:** +- 后端重启成功,编译无错误 +- 前端 HMR 热更新生效,无新增 TS 错误 diff --git a/frontend/src/api/users.ts b/frontend/src/api/users.ts index f0481c0..a74dcdf 100644 --- a/frontend/src/api/users.ts +++ b/frontend/src/api/users.ts @@ -48,18 +48,25 @@ export interface User { }; }>; _count?: { - children: number; + parentRelations: number; contestRegistrations: number; }; - // 详情接口返回 - children?: Array<{ + // 详情接口返回 — 子女账号(独立用户) + parentRelations?: Array<{ id: number; - name: string; - gender?: string; - birthday?: string; - grade?: string; - city?: string; - schoolName?: string; + relationship?: string; + controlMode: string; + child: { + id: number; + username: string; + nickname: string; + avatar?: string; + gender?: string; + birthday?: string; + city?: string; + status?: string; + createTime?: string; + }; }>; contestRegistrations?: Array<{ id: number; diff --git a/frontend/src/views/system/users/Index.vue b/frontend/src/views/system/users/Index.vue index d5fc3c7..d907063 100644 --- a/frontend/src/views/system/users/Index.vue +++ b/frontend/src/views/system/users/Index.vue @@ -194,19 +194,29 @@ {{ detailData.organization }} - +