Files
suixinkan_ios_new/suixinkan/Features/Profile/Profile.md
2026-06-22 11:28:01 +08:00

76 lines
2.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.

# Profile 模块业务逻辑
## 模块职责
Profile 模块负责“我的/个人信息”页面,包括用户资料展示、昵称编辑、密码修改、实名认证状态展示和退出登录。
该模块聚焦个人资料业务:
- 拉取用户基础资料。
- 拉取实名认证信息。
- 展示头像、昵称、UID、手机号、账号状态和实名认证状态。
- 修改昵称。
- 修改密码。
- 退出登录入口。
登录态清理和缓存清理由 App 模块的 `AuthSessionCoordinator` 统一处理。
## 核心对象
- `ProfileView`:个人信息页 UI负责展示资料、编辑入口、密码弹窗和退出确认。
- `ProfileViewModel`:维护资料加载状态、编辑状态、保存状态和展示文案。
- `ProfileAPI`:封装用户资料、实名认证和资料更新接口。
- `UserInfoResponse`:用户基础资料。
- `RealNameInfoResponse` / `RealNameInfo`:实名认证信息。
- `UpdateInfoRequest`:昵称、密码或头像更新请求体。
## 加载流程
1. `ProfileView.task` 进入页面时调用 `reloadProfile(showToast: false)`
2. 下拉刷新时调用 `reloadProfile(showToast: true)`
3. `ProfileViewModel.reload` 并发请求:
- `ProfileAPI.userInfo`
- `ProfileAPI.realNameInfo`
4. 请求成功后更新 `userInfo``realNameInfo`
5. `ProfileView` 将最新 `userInfo` 交给 `AuthSessionCoordinator.refreshCachedProfile`
6. 协调器更新 `AccountContext.profile`,并同步刷新账号快照。
## 昵称编辑流程
1. 用户点击编辑按钮。
2. `ProfileViewModel.beginEditing` 进入编辑状态,并把当前昵称写入编辑框。
3. 用户提交后,`ProfileViewModel.saveProfile` 校验昵称非空。
4. 昵称未变化时直接退出编辑状态。
5. 昵称变化时调用 `ProfileAPI.updateUserInfo(nickname:)`
6. 接口成功后本地更新 `userInfo.nickname`
7. `ProfileView` 刷新全局账号资料和账号快照。
## 密码修改流程
1. 用户打开 `PasswordUpdateSheet`
2. 输入新密码并点击完成。
3. `ProfileViewModel.updatePassword` 校验密码至少 6 位。
4. 校验通过后调用 `ProfileAPI.updateUserInfo(password:)`
5. 成功后关闭弹窗并展示 Toast。
密码不会写入本地缓存。
## 退出登录流程
1. 用户点击退出登录。
2. `ProfileView` 展示确认弹窗。
3. 用户确认后调用 `AuthSessionCoordinator.logout`
4. 协调器清空正式 token、账号快照、账号上下文、路由栈和 Toast。
5. `AppSession` 切换为 `loggedOut`,根视图回到登录页。
6. 上次手机号和协议状态等非敏感偏好保留。
## 状态展示规则
- 昵称为空时展示“未设置昵称”。
- 真实姓名、手机号和账号状态为空时展示 `--`
- 实名认证状态:
- `auditStatus == 2`:已实名认证。
- `auditStatus == 3`:审核不通过。
- 其他状态:审核中。
- 无实名认证信息时:点击去实名认证。