2025-05-02 23:56:59 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="user-info-component">
|
2025-11-25 22:34:44 +08:00
|
|
|
|
<a-dropdown :trigger="['hover']" 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">
|
|
|
|
|
|
<span class="user-menu-info">ID: {{ userStore.userIdLogin }}</span>
|
|
|
|
|
|
<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-03-24 22:37:03 +08:00
|
|
|
|
<a-modal v-model:open="profileModalVisible" :footer="null" width="420px" class="profile-modal">
|
2025-09-21 13:33:09 +08:00
|
|
|
|
<div class="profile-content">
|
|
|
|
|
|
<!-- 头像区域 -->
|
|
|
|
|
|
<div class="avatar-section">
|
|
|
|
|
|
<div class="avatar-container">
|
|
|
|
|
|
<div class="avatar-display">
|
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="large-avatar"
|
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
|
|
|
|
<div v-else class="default-avatar">
|
|
|
|
|
|
<CircleUser :size="60" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="avatar-actions">
|
|
|
|
|
|
<a-upload
|
|
|
|
|
|
:show-upload-list="false"
|
|
|
|
|
|
:before-upload="beforeUpload"
|
|
|
|
|
|
@change="handleAvatarChange"
|
|
|
|
|
|
accept="image/*"
|
|
|
|
|
|
>
|
2026-03-24 22:37:03 +08:00
|
|
|
|
<a-button
|
|
|
|
|
|
type="primary"
|
|
|
|
|
|
class="lucide-icon-btn"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
:loading="avatarUploading"
|
|
|
|
|
|
>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<template #icon><Upload size="14" /></template>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
{{ userStore.avatar ? '更换头像' : '上传头像' }}
|
|
|
|
|
|
</a-button>
|
|
|
|
|
|
</a-upload>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<div class="avatar-tips">支持 JPG、PNG 格式,文件不超过 5MB</div>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 用户信息区域 -->
|
|
|
|
|
|
<div class="info-section">
|
|
|
|
|
|
<div class="info-item">
|
|
|
|
|
|
<div class="info-label">用户名</div>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<div class="info-value" v-if="!profileEditing">
|
|
|
|
|
|
{{ userStore.username || '未设置' }}
|
|
|
|
|
|
</div>
|
2025-10-06 21:24:02 +08:00
|
|
|
|
<div class="info-value" v-else>
|
|
|
|
|
|
<a-input
|
|
|
|
|
|
v-model:value="editedProfile.username"
|
|
|
|
|
|
placeholder="请输入用户名(2-20个字符)"
|
|
|
|
|
|
:max-length="20"
|
2026-01-15 06:01:34 +08:00
|
|
|
|
style="width: 240px"
|
2025-10-06 21:24:02 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="info-item">
|
|
|
|
|
|
<div class="info-label">用户ID</div>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<div class="info-value user-id" v-if="!profileEditing">
|
|
|
|
|
|
{{ userStore.userIdLogin || '未设置' }}
|
|
|
|
|
|
</div>
|
2025-10-06 21:24:02 +08:00
|
|
|
|
<div class="info-value" v-else>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-input :value="userStore.userIdLogin || ''" disabled style="width: 240px" />
|
2025-10-06 21:24:02 +08:00
|
|
|
|
</div>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
<div class="info-item">
|
|
|
|
|
|
<div class="info-label">手机号</div>
|
|
|
|
|
|
<div class="info-value" v-if="!profileEditing">
|
|
|
|
|
|
{{ userStore.phoneNumber || '未设置' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="info-value" v-else>
|
|
|
|
|
|
<a-input
|
|
|
|
|
|
v-model:value="editedProfile.phone_number"
|
|
|
|
|
|
placeholder="请输入手机号"
|
|
|
|
|
|
:max-length="11"
|
2026-01-15 06:01:34 +08:00
|
|
|
|
style="width: 200px"
|
2025-09-21 13:33:09 +08:00
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div class="info-item">
|
|
|
|
|
|
<div class="info-label">角色</div>
|
2026-03-24 22:37:03 +08:00
|
|
|
|
<div class="info-value" :style="{ color: getRoleColor(userStore.userRole) }">
|
2026-03-24 02:32:35 +08:00
|
|
|
|
{{ userRoleText }}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2026-01-18 22:54:43 +08:00
|
|
|
|
<div class="info-item" v-if="userStore.departmentId">
|
|
|
|
|
|
<div class="info-label">部门</div>
|
|
|
|
|
|
<div class="info-value">{{ userStore.departmentName || '默认部门' }}</div>
|
|
|
|
|
|
</div>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 操作区域 -->
|
|
|
|
|
|
<div class="actions-section">
|
|
|
|
|
|
<a-space>
|
|
|
|
|
|
<template v-if="!profileEditing">
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-button type="primary" @click="startEdit"> 编辑资料 </a-button>
|
|
|
|
|
|
<a-button @click="profileModalVisible = false"> 关闭 </a-button>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
<template v-else>
|
|
|
|
|
|
<a-button type="primary" @click="saveProfile" :loading="avatarUploading">
|
|
|
|
|
|
保存
|
|
|
|
|
|
</a-button>
|
2026-01-15 06:01:34 +08:00
|
|
|
|
<a-button @click="cancelEdit"> 取消 </a-button>
|
2025-09-21 13:33:09 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
</a-space>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</a-modal>
|
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'
|
|
|
|
|
|
import {
|
|
|
|
|
|
CircleUser,
|
|
|
|
|
|
BookOpen,
|
|
|
|
|
|
Sun,
|
|
|
|
|
|
Moon,
|
|
|
|
|
|
LogOut,
|
|
|
|
|
|
Upload,
|
2026-01-20 19:12:49 +08:00
|
|
|
|
Settings,
|
|
|
|
|
|
Terminal
|
2026-01-15 06:01:34 +08:00
|
|
|
|
} 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
|
|
|
|
|
2025-09-21 13:33:09 +08:00
|
|
|
|
// 个人资料弹窗状态
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const profileModalVisible = ref(false)
|
|
|
|
|
|
const avatarUploading = ref(false)
|
|
|
|
|
|
const profileEditing = ref(false)
|
2026-04-24 22:42:51 +08:00
|
|
|
|
const avatarLoadFailed = ref(false)
|
|
|
|
|
|
const defaultAvatarLoadFailed = ref(false)
|
2025-09-21 13:33:09 +08:00
|
|
|
|
const editedProfile = ref({
|
2025-10-06 21:24:02 +08:00
|
|
|
|
username: '',
|
2025-09-21 13:33:09 +08:00
|
|
|
|
phone_number: ''
|
2026-01-15 06:01:34 +08:00
|
|
|
|
})
|
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) {
|
|
|
|
|
|
openSettingsModal()
|
|
|
|
|
|
}
|
2025-11-25 22:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-21 13:33:09 +08:00
|
|
|
|
// 打开个人资料页面
|
|
|
|
|
|
const openProfile = async () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
profileModalVisible.value = true
|
|
|
|
|
|
profileEditing.value = false
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 刷新用户信息并初始化编辑表单
|
|
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
await userStore.getCurrentUser()
|
2025-09-21 13:33:09 +08:00
|
|
|
|
editedProfile.value = {
|
2025-10-06 21:24:02 +08:00
|
|
|
|
username: userStore.username || '',
|
2025-09-21 13:33:09 +08:00
|
|
|
|
phone_number: userStore.phoneNumber || ''
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('刷新用户信息失败:', error)
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 角色标签颜色
|
|
|
|
|
|
const getRoleColor = (role) => {
|
|
|
|
|
|
switch (role) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
case 'superadmin':
|
2026-03-24 02:32:35 +08:00
|
|
|
|
return 'var(--color-error-700)'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
case 'admin':
|
2026-03-24 02:32:35 +08:00
|
|
|
|
return 'var(--color-primary-500)'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
case 'user':
|
2026-03-24 02:32:35 +08:00
|
|
|
|
return 'var(--color-success-500)'
|
2026-01-15 06:01:34 +08:00
|
|
|
|
default:
|
|
|
|
|
|
return 'default'
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 开始编辑个人资料
|
|
|
|
|
|
const startEdit = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
profileEditing.value = true
|
2025-09-21 13:33:09 +08:00
|
|
|
|
editedProfile.value = {
|
2025-10-06 21:24:02 +08:00
|
|
|
|
username: userStore.username || '',
|
2025-09-21 13:33:09 +08:00
|
|
|
|
phone_number: userStore.phoneNumber || ''
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 取消编辑
|
|
|
|
|
|
const cancelEdit = () => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
profileEditing.value = false
|
2025-09-21 13:33:09 +08:00
|
|
|
|
editedProfile.value = {
|
2025-10-06 21:24:02 +08:00
|
|
|
|
username: userStore.username || '',
|
2025-09-21 13:33:09 +08:00
|
|
|
|
phone_number: userStore.phoneNumber || ''
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 保存个人资料
|
|
|
|
|
|
const saveProfile = async () => {
|
|
|
|
|
|
try {
|
2025-10-06 21:24:02 +08:00
|
|
|
|
// 验证用户名
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
editedProfile.value.username &&
|
|
|
|
|
|
(editedProfile.value.username.trim().length < 2 ||
|
|
|
|
|
|
editedProfile.value.username.trim().length > 20)
|
|
|
|
|
|
) {
|
|
|
|
|
|
message.error('用户名长度必须在 2-20 个字符之间')
|
|
|
|
|
|
return
|
2025-10-06 21:24:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-09-21 13:33:09 +08:00
|
|
|
|
// 验证手机号格式
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (
|
|
|
|
|
|
editedProfile.value.phone_number &&
|
|
|
|
|
|
!validatePhoneNumber(editedProfile.value.phone_number)
|
|
|
|
|
|
) {
|
|
|
|
|
|
message.error('请输入正确的手机号格式')
|
|
|
|
|
|
return
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-10-06 21:24:02 +08:00
|
|
|
|
await userStore.updateProfile({
|
|
|
|
|
|
username: editedProfile.value.username?.trim() || undefined,
|
2026-01-15 06:01:34 +08:00
|
|
|
|
phone_number: editedProfile.value.phone_number || undefined
|
|
|
|
|
|
})
|
|
|
|
|
|
message.success('个人资料更新成功!')
|
|
|
|
|
|
profileEditing.value = false
|
2025-09-21 13:33:09 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('更新个人资料失败:', error)
|
|
|
|
|
|
message.error('更新失败:' + (error.message || '请稍后重试'))
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
2026-01-15 06:01:34 +08:00
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 手机号验证
|
|
|
|
|
|
const validatePhoneNumber = (phone) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
if (!phone) return true // 空手机号允许
|
|
|
|
|
|
const phoneRegex = /^1[3-9]\d{9}$/
|
|
|
|
|
|
return phoneRegex.test(phone)
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 头像上传前验证
|
|
|
|
|
|
const beforeUpload = (file) => {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const isImage = file.type.startsWith('image/')
|
2025-09-21 13:33:09 +08:00
|
|
|
|
if (!isImage) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
message.error('只能上传图片文件!')
|
|
|
|
|
|
return false
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
const isLt5M = file.size / 1024 / 1024 < 5
|
2025-09-21 13:33:09 +08:00
|
|
|
|
if (!isLt5M) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
message.error('图片大小不能超过 5MB!')
|
|
|
|
|
|
return false
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-01-15 06:01:34 +08:00
|
|
|
|
return true
|
|
|
|
|
|
}
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 处理头像上传
|
|
|
|
|
|
const handleAvatarChange = async (info) => {
|
|
|
|
|
|
if (info.file.status === 'uploading') {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
avatarUploading.value = true
|
|
|
|
|
|
return
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (info.file.status === 'done') {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
avatarUploading.value = false
|
|
|
|
|
|
return
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 手动处理文件上传
|
|
|
|
|
|
try {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
avatarUploading.value = true
|
2026-03-26 13:53:35 +08:00
|
|
|
|
await userStore.uploadAvatar(info.file.originFileObj || info.file)
|
2026-01-15 06:01:34 +08:00
|
|
|
|
message.success('头像上传成功!')
|
2025-09-21 13:33:09 +08:00
|
|
|
|
} catch (error) {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
console.error('头像上传失败:', error)
|
|
|
|
|
|
message.error('头像上传失败:' + (error.message || '请稍后重试'))
|
2025-09-21 13:33:09 +08:00
|
|
|
|
} finally {
|
2026-01-15 06:01:34 +08:00
|
|
|
|
avatarUploading.value = false
|
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;
|
2025-12-16 15:47:50 +08:00
|
|
|
|
box-shadow: 0 2px 8px var(--shadow-2);
|
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
|
|
|
|
|
|
|
|
|
|
.profile-modal {
|
|
|
|
|
|
:deep(.ant-modal-header) {
|
2026-03-24 02:32:35 +08:00
|
|
|
|
padding: 40px 24px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border-bottom: 1px solid var(--gray-150);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
:deep(.ant-modal-body) {
|
|
|
|
|
|
padding: 24px;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.profile-content {
|
|
|
|
|
|
.avatar-section {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
margin-bottom: 32px;
|
|
|
|
|
|
padding-bottom: 24px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border-bottom: 1px solid var(--gray-150);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
.avatar-container {
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-display {
|
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
|
|
|
|
|
|
|
.large-avatar {
|
|
|
|
|
|
width: 80px;
|
|
|
|
|
|
height: 80px;
|
2026-04-24 22:42:51 +08:00
|
|
|
|
display: block;
|
|
|
|
|
|
box-sizing: border-box;
|
2025-09-21 13:33:09 +08:00
|
|
|
|
border-radius: 50%;
|
|
|
|
|
|
object-fit: cover;
|
2026-04-24 22:42:51 +08:00
|
|
|
|
margin: 0 auto;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border: 3px solid var(--gray-150);
|
|
|
|
|
|
box-shadow: 0 2px 8px var(--shadow-2);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.default-avatar {
|
|
|
|
|
|
width: 80px;
|
|
|
|
|
|
height: 80px;
|
|
|
|
|
|
border-radius: 50%;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
background: var(--gray-50);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
display: flex;
|
|
|
|
|
|
margin: 0 auto;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: center;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border: 3px solid var(--gray-150);
|
|
|
|
|
|
box-shadow: 0 2px 8px var(--shadow-2);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
// 确保图标居中
|
|
|
|
|
|
:deep(svg) {
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--gray-400);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.avatar-actions {
|
|
|
|
|
|
.avatar-tips {
|
|
|
|
|
|
margin-top: 8px;
|
|
|
|
|
|
font-size: 12px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--gray-500);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
line-height: 1.4;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-section {
|
|
|
|
|
|
margin-bottom: 24px;
|
|
|
|
|
|
|
|
|
|
|
|
.info-item {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
2026-03-24 02:32:35 +08:00
|
|
|
|
padding: 12px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border-bottom: 1px solid var(--gray-50);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
|
|
|
|
|
|
&:last-child {
|
|
|
|
|
|
border-bottom: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-label {
|
2026-03-24 02:32:35 +08:00
|
|
|
|
width: 120px;
|
2025-09-21 13:33:09 +08:00
|
|
|
|
font-weight: 500;
|
2026-03-24 02:32:35 +08:00
|
|
|
|
color: var(--gray-600);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.info-value {
|
|
|
|
|
|
flex: 1;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
color: var(--gray-900);
|
2025-09-21 13:33:09 +08:00
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
|
|
|
|
|
|
&.user-id {
|
|
|
|
|
|
font-family: 'Monaco', 'Consolas', monospace;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
// background: var(--gray-50);
|
2025-10-06 21:24:02 +08:00
|
|
|
|
// padding: 4px 8px;
|
2025-09-21 13:33:09 +08:00
|
|
|
|
border-radius: 4px;
|
|
|
|
|
|
display: inline-block;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.actions-section {
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
padding-top: 16px;
|
2025-11-23 01:39:44 +08:00
|
|
|
|
border-top: 1px solid var(--gray-150);
|
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>
|