feat(user): 全局身份展示改用姓名 display_name

- UserInfo 下发 display_name(/auth/me、登录等返回 UserInfo 的接口一并下发):
  工号式 IdP 的 username 是工号,界面展示姓名用
- 左下角用户菜单:多空间身份行优先姓名(未设置回落账号),单空间行显示姓名
  (未设置回落邮箱);头像占位首字优先取姓名首字
This commit is contained in:
runny committed 2026-11-24 10:04:04 +08:00
1 parent 0819f8c4d1
commit 6594f97e3c
3 files changed
+22 -7

No files matched your search

+3
View File
@@ -118,6 +118,8 @@ export interface UserInfo {
username: string
email: string
avatar?: string
// 姓名/显示名(工号式账号的 username 是工号,界面展示姓名用;未设置为空串)
display_name?: string
tenant_id: string
can_access_all_tenants?: boolean
preferences?: UserPreferences
@@ -158,6 +160,7 @@ export function userInfoFromApi(
username: u?.username || '',
email: u?.email || '',
avatar: u?.avatar,
display_name: u?.display_name || '',
tenant_id: String(tid) || '',
can_access_all_tenants: u?.can_access_all_tenants === true,
is_system_admin: u?.is_system_admin === true,
+15 -7
View File
@@ -8,12 +8,12 @@
<span v-else class="avatar-placeholder">{{ userInitial }}</span>
</div>
<div v-if="!showCollapsedLayout" class="user-info">
<!-- 多空间 / superuser:首行空间名,次行 username · 角色。单空间:昵称 + 邮箱。 -->
<!-- 多空间 / superuser:首行空间名,次行 姓名(未设置回落账号) · 角色。单空间:账号 + 姓名(未设置回落邮箱)。 -->
<template v-if="showTenantIdentityLine">
<div class="user-tenant-name" :title="activeTenantName">{{ activeTenantName }}</div>
<div class="user-tenant-meta">
<span v-if="userName && userName !== activeTenantName" class="user-tenant-meta-name">{{ userName }}</span>
<span v-if="(userName && userName !== activeTenantName) && currentRoleLabel"
<span v-if="userDisplayLabel && userDisplayLabel !== activeTenantName" class="user-tenant-meta-name">{{ userDisplayLabel }}</span>
<span v-if="(userDisplayLabel && userDisplayLabel !== activeTenantName) && currentRoleLabel"
class="user-tenant-meta-sep">·</span>
<t-icon v-if="currentRoleIcon" :name="currentRoleIcon" size="12px" class="user-tenant-meta-icon" />
<span v-if="currentRoleLabel" class="user-tenant-meta-role">{{ currentRoleLabel }}</span>
@@ -21,7 +21,7 @@
</template>
<template v-else>
<div class="user-name">{{ userName }}</div>
<div class="user-email">{{ userEmail }}</div>
<div class="user-email">{{ userDisplayName }}</div>
</template>
</div>
</div>
@@ -67,7 +67,7 @@
</button>
</t-tooltip>
</div>
<span v-if="userEmail" class="dropdown-user-email">{{ userEmail }}</span>
<span v-if="userDisplayName" class="dropdown-user-email">{{ userDisplayName }}</span>
</div>
</div>
@@ -198,6 +198,7 @@ const menuVisible = ref(false)
const userInfo = computed(() => ({
username: authStore.user?.username || t('common.defaultUser'),
email: authStore.user?.email || 'user@example.com',
displayName: authStore.user?.display_name || '',
avatar: authStore.user?.avatar || '',
}))
@@ -205,9 +206,16 @@ const userName = computed(() => userInfo.value.username)
const userEmail = computed(() => userInfo.value.email)
const userAvatar = computed(() => userInfo.value.avatar)
// 用户名首字母(用于无头像时显示)
// 侧栏第二行:工号式账号的 username 是工号,优先展示姓名;未设置姓名时回落邮箱
const userDisplayName = computed(() => userInfo.value.displayName || userInfo.value.email)
// 多空间身份行的姓名标签:优先姓名,未设置姓名时回落账号(工号/用户名)
const userDisplayLabel = computed(() => userInfo.value.displayName || userInfo.value.username)
// 用户名首字母(用于无头像时显示):优先取姓名首字(如「刘义亮」→「刘」),
// 未设置姓名时回落账号首字符
const userInitial = computed(() => {
return userName.value.charAt(0).toUpperCase()
return userDisplayLabel.value.charAt(0).toUpperCase()
})
// 切换菜单显示
+4
View File
@@ -308,6 +308,9 @@ type UserInfo struct {
Username string `json:"username" extensions:"x-agent"`
Email string `json:"email" extensions:"x-agent"`
Avatar string `json:"avatar"`
// DisplayName 姓名/显示名。工号式 IdP 的 username 是工号,前端左下角等
// 位置展示姓名用;随 /auth/me、登录等返回 UserInfo 的接口一并下发。
DisplayName string `json:"display_name"`
TenantID uint64 `json:"tenant_id" extensions:"x-agent"`
IsActive bool `json:"is_active" extensions:"x-agent"`
CanAccessAllTenants bool `json:"can_access_all_tenants"`
@@ -324,6 +327,7 @@ func (u *User) ToUserInfo() *UserInfo {
Username: u.Username,
Email: u.Email,
Avatar: u.Avatar,
DisplayName: u.DisplayName,
TenantID: u.TenantID,
IsActive: u.IsActive,
CanAccessAllTenants: u.CanAccessAllTenants,