2025-05-02 23:56:59 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="user-info-component">
|
2026-05-17 13:47:43 +08:00
|
|
|
|
<a-dropdown :trigger="['click']" v-if="userStore.isLoggedIn">
|
2025-05-04 21:04:01 +08:00
|
|
|
|
<div class="user-info-dropdown" :data-align="showRole ? 'left' : 'center'">
|
|
|
|
|
|
<div class="user-avatar">
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<img
|
2026-04-24 22:42:51 +08:00
|
|
|
|
v-if="avatarSrc"
|
|
|
|
|
|
:src="avatarSrc"
|
2026-01-15 06:01:34 +08:00
|
|
|
|
:alt="userStore.username"
|
|
|
|
|
|
class="avatar-image"
|
2026-04-24 22:42:51 +08:00
|
|
|
|
@error="handleAvatarError"
|
2026-01-15 06:01:34 +08:00
|
|
|
|
/>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
<CircleUser v-else />
|
2025-05-05 16:31:35 +08:00
|
|
|
|
<!-- <div class="user-role-badge" :class="userRoleClass"></div> -->
|
2025-05-04 21:04:01 +08:00
|
|
|
|
</div>
|
2026-04-24 22:42:51 +08:00
|
|
|
|
<div v-if="showRole" class="user-name">{{ userStore.username }}</div>
|
|
|
|
|
|
<div v-if="slots.actions" class="user-info-actions">
|
|
|
|
|
|
<slot name="actions" />
|
|
|
|
|
|
</div>
|
2025-05-02 23:56:59 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<template #overlay>
|
2025-11-23 01:39:44 +08:00
|
|
|
|
<a-menu>
|
|
|
|
|
|
<a-menu-item key="user-info" @click="openProfile">
|
|
|
|
|
|
<div class="user-info-display">
|
|
|
|
|
|
<div class="user-menu-username">{{ userStore.username }}</div>
|
|
|
|
|
|
<div class="user-menu-details">
|
2026-05-17 22:44:05 +08:00
|
|
|
|
<span class="user-menu-info">ID: {{ userStore.uid }}</span>
|
2025-11-23 01:39:44 +08:00
|
|
|
|
<span class="user-menu-role">{{ userRoleText }}</span>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2025-05-02 23:56:59 +08:00
|
|
|
|
</a-menu-item>
|
2025-11-23 01:39:44 +08:00
|
|
|
|
<a-menu-divider />
|
2026-05-17 13:06:25 +08:00
|
|
|
|
<a-menu-item key="docs" @click="openDocs">
|
|
|
|
|
|
<template #icon><BookOpen :size="16" /></template>
|
2025-11-23 01:39:44 +08:00
|
|
|
|
<span class="menu-text">文档中心</span>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</a-menu-item>
|
2026-05-17 13:06:25 +08:00
|
|
|
|
<a-menu-item key="theme" @click="toggleTheme">
|
|
|
|
|
|
<template #icon>
|
|
|
|
|
|
<Sun v-if="themeStore.isDark" :size="16" />
|
|
|
|
|
|
<Moon v-else :size="16" />
|
|
|
|
|
|
</template>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<span class="menu-text">{{
|
|
|
|
|
|
themeStore.isDark ? '切换到浅色模式' : '切换到深色模式 (Beta)'
|
|
|
|
|
|
}}</span>
|
2025-05-02 23:56:59 +08:00
|
|
|
|
</a-menu-item>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-menu-divider v-if="userStore.isAdmin" />
|
2026-05-17 13:06:25 +08:00
|
|
|
|
<a-menu-item v-if="userStore.isSuperAdmin" key="debug" @click="showDebug = true">
|
|
|
|
|
|
<template #icon><Terminal :size="16" /></template>
|
2026-01-20 19:12:49 +08:00
|
|
|
|
<span class="menu-text">调试面板(非生产环境)</span>
|
|
|
|
|
|
</a-menu-item>
|
2026-05-17 13:06:25 +08:00
|
|
|
|
<a-menu-item v-if="userStore.isAdmin" key="setting" @click="goToSetting">
|
|
|
|
|
|
<template #icon><Settings :size="16" /></template>
|
2025-11-25 22:34:44 +08:00
|
|
|
|
<span class="menu-text">系统设置</span>
|
|
|
|
|
|
</a-menu-item>
|
2026-05-17 13:06:25 +08:00
|
|
|
|
<a-menu-item key="logout" @click="logout">
|
|
|
|
|
|
<template #icon><LogOut :size="16" /></template>
|
2025-11-23 01:39:44 +08:00
|
|
|
|
<span class="menu-text">退出登录</span>
|
2025-05-02 23:56:59 +08:00
|
|
|
|
</a-menu-item>
|
|
|
|
|
|
</a-menu>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</a-dropdown>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-button v-else-if="showButton" type="primary" @click="goToLogin"> 登录 </a-button>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
2026-01-20 19:12:49 +08:00
|
|
|
|
<!-- 调试面板 Modal -->
|
|
|
|
|
|
<DebugComponent v-model:show="showDebug" />
|
2025-05-02 23:56:59 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2026-05-17 13:06:25 +08:00
|
|
|
|
import { computed, ref, inject, useSlots, watch } from 'vue'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
import { useRouter } from 'vue-router'
|
|
|
|
|
|
import { useUserStore } from '@/stores/user'
|
2026-01-20 19:12:49 +08:00
|
|
|
|
import DebugComponent from '@/components/DebugComponent.vue'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
import { message } from 'ant-design-vue'
|
2026-05-19 21:32:57 +08:00
|
|
|
|
import { CircleUser, BookOpen, Sun, Moon, LogOut, Settings, Terminal } from 'lucide-vue-next'
|
2025-11-23 01:39:44 +08:00
|
|
|
|
import { useThemeStore } from '@/stores/theme'
|
2025-05-02 23:56:59 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const router = useRouter()
|
|
|
|
|
|
const userStore = useUserStore()
|
|
|
|
|
|
const themeStore = useThemeStore()
|
2026-04-24 22:42:51 +08:00
|
|
|
|
const slots = useSlots()
|
2025-05-02 23:56:59 +08:00
|
|
|
|
|
2026-04-24 22:42:51 +08:00
|
|
|
|
const DEFAULT_AVATAR_URL = 'https://xerrors.oss-cn-shanghai.aliyuncs.com/github/default.jpeg'
|
2026-01-20 19:12:49 +08:00
|
|
|
|
|
|
|
|
|
|
// 调试面板状态
|
|
|
|
|
|
const showDebug = ref(false)
|
|
|
|
|
|
|
2025-12-19 14:41:23 +08:00
|
|
|
|
// Inject settings modal methods
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const { openSettingsModal } = inject('settingsModal', {})
|
2025-12-19 14:41:23 +08:00
|
|
|
|
|
2026-04-24 22:42:51 +08:00
|
|
|
|
const avatarLoadFailed = ref(false)
|
|
|
|
|
|
const defaultAvatarLoadFailed = ref(false)
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
2026-04-24 22:42:51 +08:00
|
|
|
|
// 用户头像不可用时回退到公共默认头像;默认头像异常时再显示图标占位。
|
|
|
|
|
|
const avatarSrc = computed(() => {
|
|
|
|
|
|
if (userStore.avatar && !avatarLoadFailed.value) return userStore.avatar
|
|
|
|
|
|
if (!defaultAvatarLoadFailed.value) return DEFAULT_AVATAR_URL
|
|
|
|
|
|
return ''
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const handleAvatarError = () => {
|
|
|
|
|
|
if (userStore.avatar && !avatarLoadFailed.value) {
|
|
|
|
|
|
avatarLoadFailed.value = true
|
|
|
|
|
|
return
|
|
|
|
|
|
}
|
|
|
|
|
|
defaultAvatarLoadFailed.value = true
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
|
() => userStore.avatar,
|
|
|
|
|
|
() => {
|
|
|
|
|
|
avatarLoadFailed.value = false
|
|
|
|
|
|
defaultAvatarLoadFailed.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2026-03-26 13:53:35 +08:00
|
|
|
|
defineProps({
|
2025-05-04 21:04:01 +08:00
|
|
|
|
showRole: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: false
|
2025-08-04 18:31:25 +08:00
|
|
|
|
},
|
|
|
|
|
|
showButton: {
|
|
|
|
|
|
type: Boolean,
|
|
|
|
|
|
default: false
|
2025-05-04 21:04:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2025-05-02 23:56:59 +08:00
|
|
|
|
// 用户角色显示文本
|
|
|
|
|
|
const userRoleText = computed(() => {
|
|
|
|
|
|
switch (userStore.userRole) {
|
|
|
|
|
|
case 'superadmin':
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return '超级管理员'
|
2025-05-02 23:56:59 +08:00
|
|
|
|
case 'admin':
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return '管理员'
|
2025-05-02 23:56:59 +08:00
|
|
|
|
case 'user':
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return '普通用户'
|
2025-05-02 23:56:59 +08:00
|
|
|
|
default:
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return '未知角色'
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
2025-05-02 23:56:59 +08:00
|
|
|
|
|
|
|
|
|
|
// 退出登录
|
|
|
|
|
|
const logout = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
userStore.logout()
|
|
|
|
|
|
message.success('已退出登录')
|
2025-05-02 23:56:59 +08:00
|
|
|
|
// 跳转到首页
|
2026-01-15 06:01:34 +08:00
|
|
|
|
router.push('/login')
|
|
|
|
|
|
}
|
2025-05-02 23:56:59 +08:00
|
|
|
|
|
|
|
|
|
|
// 前往登录页
|
|
|
|
|
|
const goToLogin = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
router.push('/login')
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
2025-11-23 01:39:44 +08:00
|
|
|
|
const openDocs = () => {
|
2026-03-27 02:00:22 +08:00
|
|
|
|
window.open('https://xerrors.github.io/Yuxi/', '_blank', 'noopener,noreferrer')
|
2025-11-23 01:39:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const toggleTheme = () => {
|
|
|
|
|
|
themeStore.toggleTheme()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-25 22:34:44 +08:00
|
|
|
|
// 前往设置页
|
|
|
|
|
|
const goToSetting = () => {
|
2025-12-19 14:41:23 +08:00
|
|
|
|
if (openSettingsModal) {
|
2026-05-19 21:32:57 +08:00
|
|
|
|
openSettingsModal('base')
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
2026-05-19 21:32:57 +08:00
|
|
|
|
const openProfile = () => {
|
|
|
|
|
|
if (openSettingsModal) {
|
|
|
|
|
|
openSettingsModal('account')
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-05-02 23:56:59 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
|
.user-info-component {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2025-05-20 20:49:50 +08:00
|
|
|
|
color: var(--gray-800);
|
2026-04-24 22:42:51 +08:00
|
|
|
|
font-family:
|
|
|
|
|
|
-apple-system, BlinkMacSystemFont, 'Noto Sans SC', 'Roboto', 'HarmonyOS Sans SC', 'Segoe UI',
|
|
|
|
|
|
'Helvetica Neue', Arial, sans-serif;
|
2025-05-04 21:04:01 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.user-info-dropdown {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
gap: 8px;
|
2026-04-24 22:42:51 +08:00
|
|
|
|
min-width: 0;
|
2025-05-04 21:04:01 +08:00
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
&[data-align='center'] {
|
2025-05-04 21:04:01 +08:00
|
|
|
|
justify-content: center;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
&[data-align='left'] {
|
2025-05-04 21:04:01 +08:00
|
|
|
|
justify-content: flex-start;
|
|
|
|
|
|
}
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-04-24 22:42:51 +08:00
|
|
|
|
.user-name {
|
|
|
|
|
|
min-width: 0;
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.user-info-actions {
|
|
|
|
|
|
display: inline-flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
margin-left: auto;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-02 23:56:59 +08:00
|
|
|
|
.user-avatar {
|
2026-04-24 22:42:51 +08:00
|
|
|
|
@avatar-size: 32px;
|
|
|
|
|
|
width: @avatar-size;
|
|
|
|
|
|
height: @avatar-size;
|
|
|
|
|
|
min-width: @avatar-size;
|
|
|
|
|
|
flex: 0 0 @avatar-size;
|
2025-05-02 23:56:59 +08:00
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
font-weight: bold;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
font-size: 16px;
|
2025-05-02 23:56:59 +08:00
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
position: relative;
|
2025-09-21 13:33:09 +08:00
|
|
|
|
overflow: hidden;
|
2026-05-17 18:06:25 +08:00
|
|
|
|
box-shadow: 0 2px 8px var(--shadow-1);
|
2025-05-02 23:56:59 +08:00
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
|
opacity: 0.9;
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
.avatar-image {
|
|
|
|
|
|
width: 100%;
|
|
|
|
|
|
height: 100%;
|
2026-04-24 22:42:51 +08:00
|
|
|
|
display: block;
|
|
|
|
|
|
box-sizing: border-box;
|
|
|
|
|
|
object-fit: cover;
|
2025-09-21 13:33:09 +08:00
|
|
|
|
border-radius: 50%;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border: 2px solid var(--gray-150);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.user-role-badge {
|
|
|
|
|
|
position: absolute;
|
|
|
|
|
|
width: 12px;
|
|
|
|
|
|
height: 12px;
|
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
right: 0;
|
|
|
|
|
|
bottom: 0;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border: 2px solid var(--gray-0);
|
2025-05-02 23:56:59 +08:00
|
|
|
|
|
|
|
|
|
|
&.superadmin {
|
2025-11-25 22:34:44 +08:00
|
|
|
|
background-color: var(--color-warning-500);
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
&.admin {
|
2025-11-25 22:34:44 +08:00
|
|
|
|
background-color: var(--color-info-500); /* 蓝色,管理员 */
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
&.user {
|
2025-11-25 22:34:44 +08:00
|
|
|
|
background-color: var(--color-success-500); /* 绿色,普通用户 */
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-11-23 01:39:44 +08:00
|
|
|
|
.user-info-display {
|
|
|
|
|
|
line-height: 1.4;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-02 23:56:59 +08:00
|
|
|
|
.user-menu-username {
|
2025-11-23 01:39:44 +08:00
|
|
|
|
font-weight: 600;
|
|
|
|
|
|
color: var(--gray-900);
|
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
display: block;
|
|
|
|
|
|
margin-bottom: 2px;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.user-menu-details {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
gap: 12px;
|
|
|
|
|
|
align-items: center;
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-21 13:33:09 +08:00
|
|
|
|
.user-menu-info {
|
|
|
|
|
|
font-size: 12px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--gray-600);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-02 23:56:59 +08:00
|
|
|
|
.user-menu-role {
|
|
|
|
|
|
font-size: 12px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--gray-500);
|
2025-05-02 23:56:59 +08:00
|
|
|
|
}
|
2025-08-04 18:31:25 +08:00
|
|
|
|
|
|
|
|
|
|
.login-icon {
|
|
|
|
|
|
width: 30px;
|
|
|
|
|
|
height: 30px;
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
|
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
border-radius: 50%;
|
2026-01-15 06:01:34 +08:00
|
|
|
|
transition:
|
|
|
|
|
|
background-color 0.2s,
|
|
|
|
|
|
color 0.2s;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--gray-900);
|
2025-08-04 18:31:25 +08:00
|
|
|
|
|
|
|
|
|
|
&:hover {
|
2025-11-23 01:39:44 +08:00
|
|
|
|
background-color: var(--main-10);
|
|
|
|
|
|
color: var(--main-color);
|
2025-08-04 18:31:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
2025-11-23 01:39:44 +08:00
|
|
|
|
:deep(.ant-dropdown-menu) {
|
|
|
|
|
|
padding: 8px 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.ant-dropdown-menu-title-content) {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
gap: 8px;
|
|
|
|
|
|
font-size: 13px;
|
|
|
|
|
|
color: var(--gray-900);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.ant-dropdown-menu-item svg) {
|
|
|
|
|
|
margin-right: 4px;
|
|
|
|
|
|
color: var(--gray-900);
|
|
|
|
|
|
vertical-align: middle;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.menu-text {
|
|
|
|
|
|
line-height: 20px;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|