- 新增全局 TabArea 组件及 tab-area.scss,替换 11 处页面内重复实现, 统一标签样式、排序入口与本地排序偏好 - 新增 51 个业务 SVG 图标,侧边栏/顶栏菜单支持图标展示, 调整收藏星标与展开箭头的间距、配色,避免图标重叠 - 顶部区域高度改为 ResizeObserver 实测,并输出 --app-header-height 变量, 移除 97/134 魔法数字与各页面 calc(100vh - N) 的高度计算 - TaskView 快捷区与标签行重构:Map 索引定位当前标签、v-memo 减少重渲染、 仅监听 route.fullPath 触发更新 - 打印组件连接初始化改为会话内只执行一次;路由树调试日志仅在开发环境输出 - 引入 unplugin-auto-import / unplugin-vue-components 依赖, 补充布局性能分析、菜单图标体系、顶部区域优化三份设计文档
220 lines
5.7 KiB
Vue
220 lines
5.7 KiB
Vue
<template>
|
||
<div class="profile-container">
|
||
<!-- 主要内容区 -->
|
||
<div v-loading="profileLoading" class="profile-content">
|
||
<!-- 左侧账号信息卡片 -->
|
||
<div class="left-sidebar">
|
||
<UserInfoCard
|
||
:user="userInfo"
|
||
@change-username="handleChangeUsername"
|
||
/>
|
||
</div>
|
||
<!-- 右侧内容区 -->
|
||
<div class="right-content">
|
||
<el-card class="tabs-card">
|
||
<el-tabs v-model="activeTab" class="profile-tabs">
|
||
<!-- 账户安全 -->
|
||
<el-tab-pane label="账户安全" name="security">
|
||
<AccountSecurity
|
||
:security-info="securityInfo"
|
||
:has-password="Boolean(userInfo.isCustomPassword)"
|
||
@refresh="handleRefreshSecurity"
|
||
@change-password="openPasswordDialog"
|
||
/>
|
||
</el-tab-pane>
|
||
|
||
<!-- 加入公司 -->
|
||
<el-tab-pane label="加入公司" name="joinStore">
|
||
<WelcomCard />
|
||
</el-tab-pane>
|
||
|
||
<!-- 微信绑定 -->
|
||
<el-tab-pane label="微信绑定" name="bind">
|
||
<Bind v-if="activeTab === 'bind'" />
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
</el-card>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 修改/设置密码对话框 -->
|
||
<ChangePasswordDialog
|
||
v-model="showPasswordDialog"
|
||
:first-set="passwordFirstSet"
|
||
@success="handlePasswordChangeSuccess"
|
||
/>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, computed } from 'vue'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
import { ElMessage } from 'element-plus'
|
||
import dayjs from 'dayjs'
|
||
import { getAccountInfo, updateUsername } from '@/api/user/user'
|
||
|
||
import UserInfoCard from './components/UserInfoCard.vue'
|
||
import AccountSecurity from './components/AccountSecurity.vue'
|
||
import ChangePasswordDialog from './components/ChangePasswordDialog.vue'
|
||
import WelcomCard from '../dashboard/components/WelcomCard.vue'
|
||
import Bind from './components/Bind.vue'
|
||
|
||
// 引入配置文件
|
||
import { MOCK_SECURITY_INFO, PROFILE_TABS } from './profile-config'
|
||
|
||
interface AccountInfo {
|
||
id?: number
|
||
username?: string
|
||
real_name?: string
|
||
phone?: string
|
||
email?: string
|
||
status?: number
|
||
/** 是否已设置过登录密码(is_custom_password === 1) */
|
||
isCustomPassword?: boolean
|
||
lastLogin?: string
|
||
createdAt?: string
|
||
}
|
||
|
||
const userStore = useUserStore()
|
||
|
||
const activeTab = ref<string>(PROFILE_TABS?.[0]?.name ?? 'security')
|
||
const showPasswordDialog = ref(false)
|
||
|
||
// User Info
|
||
const userInfo = ref<AccountInfo>({})
|
||
const profileLoading = ref(false)
|
||
|
||
// Security Info (From Config)
|
||
const securityInfo = reactive({ ...MOCK_SECURITY_INFO })
|
||
|
||
const passwordFirstSet = computed(() => !userInfo.value.isCustomPassword)
|
||
|
||
const formatDateTime = (value?: string) => (value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-')
|
||
|
||
const applyAccountInfo = (data: Record<string, unknown>) => {
|
||
userInfo.value = {
|
||
id: data.id as number,
|
||
username: (data.username as string) ?? '',
|
||
real_name: (data.real_name as string) ?? '',
|
||
phone: (data.phone as string) ?? '',
|
||
email: (data.email as string) ?? '',
|
||
status: data.status === undefined || data.status === null ? undefined : Number(data.status),
|
||
isCustomPassword: Number(data.is_custom_password) === 1,
|
||
lastLogin: formatDateTime(data.last_login_at as string | undefined),
|
||
createdAt: formatDateTime(data.created_at as string | undefined)
|
||
}
|
||
}
|
||
|
||
const loadAccountInfo = async () => {
|
||
profileLoading.value = true
|
||
try {
|
||
const resp = await getAccountInfo()
|
||
const payload = resp?.data
|
||
if (payload && typeof payload === 'object') {
|
||
applyAccountInfo(payload as Record<string, unknown>)
|
||
if (userStore.user && payload.username) {
|
||
userStore.user.username = payload.username
|
||
}
|
||
}
|
||
return true
|
||
} catch {
|
||
// 错误提示由 request 拦截器统一处理
|
||
return false
|
||
} finally {
|
||
profileLoading.value = false
|
||
}
|
||
}
|
||
|
||
const handleChangeUsername = async (username: string) => {
|
||
const previous = userInfo.value.username
|
||
userInfo.value = { ...userInfo.value, username }
|
||
try {
|
||
await updateUsername({ username })
|
||
if (userStore.user) {
|
||
userStore.user.username = username
|
||
}
|
||
ElMessage.success('账号修改成功')
|
||
await loadAccountInfo()
|
||
} catch {
|
||
userInfo.value = { ...userInfo.value, username: previous }
|
||
}
|
||
}
|
||
|
||
const openPasswordDialog = () => {
|
||
showPasswordDialog.value = true
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadAccountInfo()
|
||
})
|
||
|
||
const handleRefreshSecurity = async () => {
|
||
if (await loadAccountInfo()) {
|
||
ElMessage.success('安全信息已刷新')
|
||
}
|
||
}
|
||
|
||
const handlePasswordChangeSuccess = async () => {
|
||
await loadAccountInfo()
|
||
}
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.profile-container {
|
||
height: 100%;
|
||
padding: 20px;
|
||
width: 100%;
|
||
background-color: var(--el-bg-color-page);
|
||
/* 顶部高度已由布局层提供,不再用 84px 旧值估算 */
|
||
min-height: 0;
|
||
|
||
.profile-content {
|
||
display: flex;
|
||
gap: 20px;
|
||
height: 100%;
|
||
|
||
@media (max-width: 1200px) {
|
||
flex-direction: column;
|
||
}
|
||
|
||
.left-sidebar {
|
||
width: 350px;
|
||
flex-shrink: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 20px;
|
||
|
||
@media (max-width: 1200px) {
|
||
width: 100%;
|
||
}
|
||
}
|
||
|
||
.right-content {
|
||
flex: 1;
|
||
min-height: 0;
|
||
|
||
.tabs-card {
|
||
height: 100%;
|
||
:deep(.el-card__body) {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
}
|
||
|
||
.profile-tabs {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
:deep(.el-tabs__content) {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
padding: 20px 0;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
</style>
|