Skip to content

feat(user): 优化getInfo接口,添加用户部门、岗位和角色信息,更新相关接口和组件#729

Merged
kanyxmo merged 1 commit into
masterfrom
feat-user-getInfo
Jun 12, 2026
Merged

feat(user): 优化getInfo接口,添加用户部门、岗位和角色信息,更新相关接口和组件#729
kanyxmo merged 1 commit into
masterfrom
feat-user-getInfo

Conversation

@kanyxmo

@kanyxmo kanyxmo commented Jun 12, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • 新功能

    • 用户信息页面现新增部门、岗位、角色的完整结构化数据展示
  • 缺陷修复

    • 增强了应用对用户信息缺失情况的容错处理机制,提升系统稳定性和可靠性

@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jun 12, 2026
@dosubot dosubot Bot added the enhancement label Jun 12, 2026
@kanyxmo kanyxmo enabled auto-merge (squash) June 12, 2026 06:22
@coderabbitai

coderabbitai Bot commented Jun 12, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cd091785-6f8c-4534-9616-621421fa8cdc

📥 Commits

Reviewing files that changed from the base of the PR and between ca41902 and 6e4537b.

📒 Files selected for processing (12)
  • app/Http/Admin/Controller/PassportController.php
  • app/Schema/UserSchema.php
  • app/Service/PassportService.php
  • web/src/layouts/components/bars/toolbar/components/user-bar.tsx
  • web/src/layouts/uc.tsx
  • web/src/modules/base/api/user.ts
  • web/src/modules/base/views/uc/components/modify-info.vue
  • web/src/modules/base/views/uc/components/userinfo-form.vue
  • web/src/modules/base/views/uc/index.vue
  • web/src/modules/base/views/welcome/index.vue
  • web/src/store/modules/useUserStore.ts
  • web/src/utils/permission/hasUser.ts

📝 Walkthrough

Walkthrough

该 PR 在后端新增用户部门、岗位、角色的结构化返回能力,并在前端强化了对空值用户信息的访问容错。后端通过 PassportService 格式化方法集中处理数据映射;前端统一了 TypeScript 类型定义,存储与组件普遍采用可选链与计算属性来避免运行时异常。

Changes

用户信息充实与空安全性重构

Layer / File(s) Summary
后端用户数据格式化(Schema 与 Service)
app/Schema/UserSchema.php, app/Service/PassportService.php
UserSchema 新增 departmentspositionsroles 数组属性及其从 User 关联的映射逻辑;PassportService 新增 formatUserInfo() 及三个私有方法,从关联中提取字段、按条件过滤(角色过滤 Status::Normal)并排序。
后端 Passport 控制器委托
app/Http/Admin/Controller/PassportController.php
PassportController::getInfo 的返回逻辑改为调用 PassportService::formatUserInfo(),移除 Arr::only 工具类依赖。
前端 API 类型定义(enriched user VO)
web/src/modules/base/api/user.ts
新增 CurrentUserDepartmentVo、CurrentUserPositionVo、CurrentUserRoleVo 与聚合 CurrentUserInfo;扩展 UserVo 允许字段为 null、新增可选的 departments/positions/roles VO 数组。
前端存储类型安全与派生访问器
web/src/store/modules/useUserStore.ts
导入后端 VO 类型建立别名、收窄 userInfo 为 UserInfo | null、新增 getUserDepartments/getUserPositions/getUserRoleList 派生 getter,refactor setLanguage 验证逻辑。
前端组件空安全(工具栏与布局)
web/src/layouts/components/bars/toolbar/components/user-bar.tsx, web/src/layouts/uc.tsx, web/src/utils/permission/hasUser.ts
user-bar 与 uc.tsx 改用 computed 包装用户信息、可选链与空值合并处理头像和用户名;hasUser 访问 username 时增加可选链。
前端视图空安全(表单与个人资料)
web/src/modules/base/views/uc/components/modify-info.vue, web/src/modules/base/views/uc/components/userinfo-form.vue, web/src/modules/base/views/uc/index.vue, web/src/modules/base/views/welcome/index.vue
modify-info 与 userinfo-form 增加 userInfo 缓存与判空;uc/index 新增 displayUserInfo 兜底计算属性;welcome 头像回退首字符取值改用可选链;模板遍历改向兜底对象。

Sequence Diagram(s)

sequenceDiagram
  participant Client as 前端组件
  participant Store as useUserStore
  participant API as /admin/passport/getInfo
  participant Service as PassportService
  participant DB as 数据库
  Client->>Store: getUserInfo()
  Store->>API: useHttp().get()
  API->>Service: formatUserInfo(user)
  Service->>DB: 加载 user.department/position/roles
  DB-->>Service: 关联数据集合
  Service->>Service: 映射字段、过滤排序
  Service-->>API: 返回含 departments/positions/roles 的数组
  API-->>Store: ResponseStruct<UserInfo>
  Store-->>Client: userInfo | null
  Client->>Client: computed(()=>getUserInfo())
  Client->>Client: 可选链与空值合并安全渲染
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

size:M, type:refactor, backend, frontend, type-safety

Poem

🐰 部门岗位角色齐,后端数据来整理,
前端链式守安全,可选无惧空值现,
兜底计算作防线,用户信息永不乱!

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat-user-getInfo

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kanyxmo kanyxmo disabled auto-merge June 12, 2026 06:22
@kanyxmo kanyxmo merged commit a3cbae8 into master Jun 12, 2026
4 of 9 checks passed
@kanyxmo kanyxmo deleted the feat-user-getInfo branch June 12, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Authentication enhancement Frontend Http Schema Service size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant