feat: 重设计个人中心并精简文案,顶部导航改滚动毛玻璃

This commit is contained in:
2026-08-09 05:13:19 +08:00
parent 56f56d127d
commit defd931c6b
4 changed files with 127 additions and 394 deletions
+68 -94
View File
@@ -1,10 +1,9 @@
<script setup lang="ts">
/**
* 个人中心(重新设计)—— 对齐站点黑白编辑风:极简、大排版、充足留白。
* - 资料区:头像 + 大号姓名 + 邮箱 + 角色/加入时间 + 三项统计(细分隔线)
* - 导航:下划线页签
* - profile:资料编辑(昵称/头像/邮箱,改后同步回统一认证中心)
* - favorites:作品封面网格;comments:评论列表
* 个人中心 —— 用站点一以贯之的黑白编辑风:克制、留白、无冗余。
* - 头部:头像 + 昵称 + 邮箱 + 加入时间(不重复展示收藏/评论数、不展示角色徽章)
* - 页签:个人资料 / 我的收藏 / 我的评论(计数只在页签出现一次)
* - profile:仅三类可编辑信息——头像/昵称/邮箱,改后同步回统一认证中心
*/
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
import { useI18n } from 'vue-i18n'
@@ -61,7 +60,6 @@ const saveProfile = async () => {
const result = await userStore.updateProfile({
username: profileForm.username,
email: profileEmail.value,
avatar: profileAvatar.value || undefined,
})
profileSaving.value = false
profileMsg.value = result.success
@@ -69,7 +67,7 @@ const saveProfile = async () => {
: { ok: false, text: apiError({ data: { code: result.code } }) }
}
/* 头像选择并上传,成功后写入表单待保存 */
/* 头像:选择后上传(直连统一认证中心),即时生效并落库 */
const profileFileInput = ref<HTMLInputElement | null>(null)
const triggerAvatarPick = () => profileFileInput.value?.click()
const onAvatarPick = async (event: Event) => {
@@ -88,6 +86,7 @@ const onAvatarPick = async (event: Event) => {
fd.append('file', file)
const data = await $fetch<{ url: string }>('/api/auth/avatar', { method: 'POST', body: fd })
profileAvatar.value = data.url
if (userStore.user) userStore.user.avatar = data.url
profileMsg.value = { ok: true, text: t('account.avatar.success') }
} catch (err) {
profileMsg.value = { ok: false, text: apiError({ data: { code: (err as any)?.data?.code ?? 'VALIDATION_ERROR' } }) }
@@ -179,57 +178,29 @@ onBeforeUnmount(() => ctx?.revert())
</section>
<template v-else>
<!-- 资料区(黑白极简) -->
<header data-animate class="rounded-3xl border border-gray-100 bg-white shadow-sm">
<div class="px-6 py-8 md:px-10 md:py-10">
<div class="flex flex-col md:flex-row md:items-start gap-6 md:gap-8">
<img
:src="userStore.avatar"
:alt="userStore.user?.username"
class="w-20 h-20 md:w-24 md:h-24 rounded-2xl object-cover ring-1 ring-black/10 flex-shrink-0"
/>
<div class="flex-1 min-w-0">
<div class="flex items-center gap-3 flex-wrap">
<h1 class="text-3xl md:text-4xl font-bold tracking-tight text-black">{{ userStore.user?.username }}</h1>
<span class="inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full text-xs font-semibold bg-gray-100 text-gray-600">
<Icon name="ph:user" class="w-3 h-3" />
{{ t('account.roleUser') }}
</span>
</div>
<p class="mt-2 text-gray-500">{{ userStore.user?.email }}</p>
<p class="mt-1 text-sm text-gray-400">
{{ t('account.joinedAt') }} · {{ formatDate(userStore.user?.createdAt) }}
</p>
</div>
</div>
<!-- 统计(细分隔线) -->
<div class="mt-8 grid grid-cols-3 divide-x divide-gray-200 border-t border-gray-100 pt-6">
<div class="text-center">
<p class="text-2xl md:text-3xl font-bold text-black leading-none">{{ favorites.length }}</p>
<p class="mt-1.5 text-[11px] uppercase tracking-wider text-gray-400">{{ t('account.statFavorites') }}</p>
</div>
<div class="text-center">
<p class="text-2xl md:text-3xl font-bold text-black leading-none">{{ myComments.length }}</p>
<p class="mt-1.5 text-[11px] uppercase tracking-wider text-gray-400">{{ t('account.statComments') }}</p>
</div>
<div class="text-center">
<p class="text-lg md:text-2xl font-bold text-black leading-none">{{ formatDate(userStore.user?.createdAt, true) }}</p>
<p class="mt-1.5 text-[11px] uppercase tracking-wider text-gray-400">{{ t('account.statJoined') }}</p>
</div>
</div>
<!-- 身份信息 -->
<header data-animate class="flex items-center gap-6 md:gap-8 border-b border-gray-200 pb-10">
<img
:src="userStore.avatar"
:alt="userStore.user?.username"
class="w-20 h-20 md:w-24 md:h-24 rounded-2xl object-cover ring-1 ring-black/10 flex-shrink-0"
/>
<div class="min-w-0">
<h1 class="text-3xl md:text-4xl font-bold tracking-tight text-black truncate">{{ userStore.user?.username }}</h1>
<p class="mt-2 text-gray-500 truncate">{{ userStore.user?.email }}</p>
<p class="mt-1.5 text-sm text-gray-400">{{ t('account.joinedAt') }} · {{ formatDate(userStore.user?.createdAt) }}</p>
</div>
</header>
<!-- 页签(下划线) -->
<nav data-animate class="mt-10 border-b border-gray-200">
<!-- 页签 -->
<nav data-animate class="mt-6 border-b border-gray-200">
<div class="flex gap-8 overflow-x-auto">
<button
v-for="tab in tabs"
:key="tab.key"
type="button"
@click="switchTab(tab.key)"
class="flex items-center gap-2 py-3 text-sm font-semibold border-b-2 -mb-px whitespace-nowrap transition-colors"
class="flex items-center gap-2 py-3.5 text-sm font-semibold border-b-2 -mb-px whitespace-nowrap transition-colors"
:class="activeTab === tab.key ? 'border-black text-black' : 'border-transparent text-gray-400 hover:text-black'"
>
{{ tab.label }}
@@ -241,55 +212,58 @@ onBeforeUnmount(() => ctx?.revert())
<!-- 内容 -->
<div class="mt-8 md:mt-10">
<Transition name="panel" mode="out-in">
<!-- 个人资料(单一设置面板,内部分区) -->
<!-- 个人资料 -->
<section v-if="activeTab === 'profile'" key="profile" class="max-w-2xl mx-auto">
<div class="rounded-3xl border border-gray-100 bg-white shadow-sm overflow-hidden divide-y divide-gray-100">
<!-- 基本信息 -->
<div class="px-6 md:px-8 py-7">
<h3 class="text-lg font-bold text-black">{{ t('account.profile') }}</h3>
<p class="text-sm text-gray-400 mt-0.5">个人基本信息与头像</p>
<div class="rounded-3xl border border-gray-100 bg-white shadow-sm px-6 md:px-8 py-8">
<div class="mt-6 flex items-center gap-6">
<img :src="profileAvatar || userStore.avatar" :alt="userStore.user?.username"
class="w-20 h-20 rounded-2xl object-cover ring-1 ring-black/10 flex-shrink-0" />
<div>
<button type="button" @click="triggerAvatarPick" :disabled="avatarUploading"
class="inline-flex items-center gap-2 px-4 py-2 rounded-full border border-gray-200 text-sm font-semibold hover:border-black hover:text-black transition-colors disabled:opacity-50">
<Icon v-if="avatarUploading" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
<Icon v-else name="ph:user-circle" class="w-4 h-4" />
{{ avatarUploading ? t('account.avatar.uploading') : t('account.avatar.change') }}
</button>
<input ref="profileFileInput" type="file" accept="image/*" class="hidden" @change="onAvatarPick" />
<p class="text-xs text-gray-400 mt-2">{{ t('account.avatarHint') }}</p>
</div>
</div>
<div class="mt-7 space-y-5">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.nickname') }}</label>
<input v-model="profileForm.username" type="text"
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.email') }}</label>
<input v-model="profileEmail" type="email"
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
</div>
<p v-if="profileMsg" class="text-sm" :class="profileMsg.ok ? 'text-green-600' : 'text-red-600'">{{ profileMsg.text }}</p>
<div class="flex justify-end">
<button @click="saveProfile" :disabled="profileSaving"
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors disabled:opacity-50">
<Icon v-if="profileSaving" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
{{ profileSaving ? t('account.saving') : t('account.save') }}
</button>
</div>
<!-- 头像 -->
<div class="flex items-center gap-5">
<img
:src="profileAvatar || userStore.avatar"
:alt="userStore.user?.username"
class="w-16 h-16 md:w-20 md:h-20 rounded-2xl object-cover ring-1 ring-black/10 flex-shrink-0"
/>
<div>
<button
type="button"
@click="triggerAvatarPick"
:disabled="avatarUploading"
class="inline-flex items-center gap-2 px-4 py-2 rounded-full border border-gray-200 text-sm font-semibold hover:border-black hover:text-black transition-colors disabled:opacity-50"
>
<Icon v-if="avatarUploading" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
<Icon v-else name="ph:user-circle" class="w-4 h-4" />
{{ avatarUploading ? t('account.avatar.uploading') : t('account.avatar.change') }}
</button>
<input ref="profileFileInput" type="file" accept="image/*" class="hidden" @change="onAvatarPick" />
<p class="text-xs text-gray-400 mt-2 max-w-xs">{{ t('account.avatarHint') }}</p>
</div>
</div>
<!-- 账号说明 -->
<div class="px-6 md:px-8 py-7 bg-gray-50/60">
<h3 class="text-lg font-bold text-black">{{ t('account.ssoAccount') }}</h3>
<p class="text-sm text-gray-500 mt-1 leading-relaxed">{{ t('account.ssoAccountHint') }}</p>
<!-- 昵称 / 邮箱 -->
<div class="mt-8 space-y-6 border-t border-gray-100 pt-8">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.nickname') }}</label>
<input v-model="profileForm.username" type="text"
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.email') }}</label>
<input v-model="profileEmail" type="email"
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
</div>
<p v-if="profileMsg" class="text-sm" :class="profileMsg.ok ? 'text-green-600' : 'text-red-600'">{{ profileMsg.text }}</p>
<div class="flex justify-end pt-2">
<button
@click="saveProfile"
:disabled="profileSaving"
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors disabled:opacity-50"
>
<Icon v-if="profileSaving" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
{{ profileSaving ? t('account.saving') : t('account.save') }}
</button>
</div>
</div>
</div>
</section>
@@ -377,4 +351,4 @@ onBeforeUnmount(() => ctx?.revert())
.panel-enter-active, .panel-leave-active { transition: opacity 0.25s ease, transform 0.25s ease; }
.panel-enter-from { opacity: 0; transform: translateY(12px); }
.panel-leave-to { opacity: 0; transform: translateY(-8px); }
</style>
</style>