Files
easygoadmin-wiki/EasyGoAdmin_Gin_NaiveVue/zh/modules/user.md
T
2026-10-25 17:24:27 +08:00

42 lines
1.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 6.1 用户管理
:::tip 概述
用户是组织权限体系的核心表(gin_user,租户级)。除标准 CRUD 外,承载角色分配、密码重置、导入导出与(租户场景的)开户逻辑,并挂接数据权限过滤。
:::
## 功能清单
| 接口 | 说明 |
|---|---|
| Page / List / Detail | 标准查询(分页支持关键字/部门/状态过滤) |
| Add | 新增(租户场景经 addWithTenant 归属租户) |
| Update | 修改(全量表单语义) |
| Status | 启停单列更新 |
| ResetPwd | 重置密码(手写逻辑,管理员操作留痕) |
| Delete / BatchDelete | 软删除 |
| Import / Export | Excel 导入导出 |
| Document | 用户打印信息(打印视图数据) |
## 特色机制
- **角色随表单写入**:Add/Update 请求带 `roles []int64`(json 名 `roles`),事务内 rewriteUserRoles 先清后写 gin_user_role——没有独立的"分配角色"接口;service 层 AssignRoles 是事务复用的内部方法
- **数据权限挂接**:userSpec 声明 `DataScope: ApplyDataScope("dept_id")`(user.go:77 注释:角色数据权限(Page/List/导出生效))——本模块是数据权限的典型示范(行级部门过滤)
- **租户级表**:写侧自动补 tenant_id,读侧自动隔离
- **密码安全**:重置与新增均走 crypto 哈希(外部 salt + bcrypt),永不落明文
- **导入导出**:标准 Excel 契约(列头、逐行校验、结果汇总)
## 数据要点
- 用户名在租户内唯一(UniqueFields 预检 + 数据库 uk 兜底)
- 部门列 dept_id 与 gin_dept 关联,数据权限与组织展示都依赖它
- 状态非 1 视为禁用(登录校验同口径)
## 管理界面
`system/user`:列表 + 搜索 + 新增/编辑弹窗 + 分配角色 + 重置密码 + 导入导出。
## 相关
- 机制:[5.4 权限管理](/zh/core/rbac.html)、[5.10 数据权限](/zh/core/data-scope.html)
- 开发:[第 3 章 模块开发实战](/zh/guide/overview.html)