Skip to content

Commit 73c4eeb

Browse files
committed
feat: display username
1 parent 0695ec6 commit 73c4eeb

2 files changed

Lines changed: 12 additions & 4 deletions

File tree

‎components/user-dropdown.vue‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
</Button>
1212
</DropdownMenuTrigger>
1313
<DropdownMenuContent class="w-48" align="end" side="top">
14+
<DropdownMenuItem>
15+
<!-- 显示用户名 -->
16+
<Icon name="ri:user-line" class="h-4 w-4" />
17+
<span v-if="!isAdmin">{{ userInfo?.account_name }}</span>
18+
<span v-else>rustfsAdmin</span>
19+
</DropdownMenuItem>
1420
<DropdownMenuItem v-if="!isAdmin" @select="handleChangePassword">
1521
<Icon name="ri:lock-password-line" class="h-4 w-4" />
1622
<span>{{ t('Change Password') }}</span>
@@ -34,6 +40,7 @@ import AccessKeysChangePassword from '@/components/access-keys/change-password.v
3440
3541
const { t } = useI18n()
3642
const { logout, isAdmin, setIsAdmin } = useAuth()
43+
const { userInfo } = usePermissions()
3744
const router = useRouter()
3845
const { isAdminUser } = useUsers()
3946

‎composables/usePermissions.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ export const usePermissions = () => {
77

88
// Store user policy in global state
99
const userPolicy = useState<ConsolePolicy | null>('user-policy', () => null)
10+
const userInfo = useState<any>('user-info', () => null)
1011
const isLoading = useState<boolean>('user-policy-loading', () => false)
1112

1213
const fetchUserPolicy = async () => {
13-
if (isAdmin.value) return
14-
1514
isLoading.value = true
1615
try {
17-
const userInfo = await $api.get('/accountinfo')
18-
let userInfoPolicy = userInfo.policy as string
16+
const info = await $api.get('/accountinfo')
17+
userInfo.value = info
18+
let userInfoPolicy = info.policy as string
1919
userPolicy.value = JSON.parse(userInfoPolicy) as ConsolePolicy
2020
} catch (e) {
2121
console.error('Failed to fetch user policy', e)
@@ -79,6 +79,7 @@ export const usePermissions = () => {
7979

8080
return {
8181
userPolicy,
82+
userInfo,
8283
isLoading,
8384
fetchUserPolicy,
8485
hasPermission,

0 commit comments

Comments
 (0)