Compare commits
2 Commits
0.0.17-dev
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 775344bb09 | |||
| defd931c6b |
@@ -3,15 +3,12 @@ import { onBeforeUnmount, onMounted, ref, computed, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import gsap from 'gsap'
|
||||
import { ScrollTrigger } from 'gsap/ScrollTrigger'
|
||||
import { useAppStore } from '~/stores/app'
|
||||
import { useUserStore } from '~/stores/user'
|
||||
import { useAuthModalStore } from '~/stores/authModal'
|
||||
import AppLogo from '~/components/common/AppLogo.vue'
|
||||
import LoginModal from '~/components/common/LoginModal.vue'
|
||||
|
||||
gsap.registerPlugin(ScrollTrigger)
|
||||
|
||||
const { t, locale, setLocale } = useI18n()
|
||||
const route = useRoute()
|
||||
const appStore = useAppStore()
|
||||
@@ -38,93 +35,93 @@ const bottomHeaderRef = ref<HTMLElement | null>(null)
|
||||
const mobileMenuRef = ref<HTMLElement | null>(null)
|
||||
const isMobileMenuOpen = ref(false)
|
||||
const isUserMenuOpen = ref(false)
|
||||
let topHeaderTween: gsap.core.Tween | null = null
|
||||
let bottomHeaderScrollTrigger: ReturnType<typeof ScrollTrigger.create> | null = null
|
||||
|
||||
// 滚动后为顶部导航加毛玻璃背景(内容不再与页面文字叠压)
|
||||
const isScrolled = ref(false)
|
||||
let lastScrollY = 0
|
||||
let isBottomHeaderVisible = false
|
||||
let fallbackTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
const setBottomHeaderVisible = (visible: boolean) => {
|
||||
if (!bottomHeaderRef.value || isBottomHeaderVisible === visible) return
|
||||
isBottomHeaderVisible = visible
|
||||
|
||||
gsap.to(bottomHeaderRef.value, {
|
||||
yPercent: visible ? 0 : 150,
|
||||
autoAlpha: visible ? 1 : 0,
|
||||
duration: 0.45,
|
||||
ease: 'power2.out',
|
||||
overwrite: 'auto',
|
||||
force3D: true,
|
||||
})
|
||||
}
|
||||
|
||||
const onPageScroll = () => {
|
||||
const y = window.scrollY || window.pageYOffset || 0
|
||||
isScrolled.value = y > 20
|
||||
|
||||
// 深入页面后向上滚动时,从底部弹出快捷导航;继续向下滚动/回到顶部则收回。
|
||||
if (y > 1000 && y < lastScrollY) {
|
||||
setBottomHeaderVisible(true)
|
||||
} else if (y <= 1000 || y > lastScrollY) {
|
||||
setBottomHeaderVisible(false)
|
||||
}
|
||||
|
||||
lastScrollY = y
|
||||
}
|
||||
let scrollPending = false
|
||||
const scheduleScrollCheck = () => {
|
||||
if (scrollPending) return
|
||||
scrollPending = true
|
||||
requestAnimationFrame(() => {
|
||||
scrollPending = false
|
||||
onPageScroll()
|
||||
})
|
||||
}
|
||||
|
||||
// 语言切换
|
||||
const switchLocale = () => {
|
||||
setLocale(locale.value === 'zh' ? 'en' : 'zh')
|
||||
}
|
||||
|
||||
// 切换用户菜单
|
||||
const toggleUserMenu = () => {
|
||||
isUserMenuOpen.value = !isUserMenuOpen.value
|
||||
}
|
||||
|
||||
// 关闭用户菜单
|
||||
const closeUserMenu = () => {
|
||||
isUserMenuOpen.value = false
|
||||
}
|
||||
|
||||
// 处理登出
|
||||
const handleLogout = () => {
|
||||
userStore.logout()
|
||||
closeUserMenu()
|
||||
}
|
||||
|
||||
const setBottomHeaderVisible = (visible: boolean) => {
|
||||
if (!bottomHeaderRef.value || isBottomHeaderVisible === visible) {
|
||||
return
|
||||
}
|
||||
|
||||
isBottomHeaderVisible = visible
|
||||
|
||||
gsap.to(bottomHeaderRef.value, {
|
||||
yPercent: visible ? 0 : 150,
|
||||
autoAlpha: visible ? 1 : 0,
|
||||
duration: 0.45,
|
||||
ease: 'power2.out',
|
||||
overwrite: 'auto',
|
||||
force3D: true,
|
||||
})
|
||||
}
|
||||
|
||||
// 定义一个供外部或延迟调用的入场动画方法
|
||||
// 供外部或延迟调用的入场动画方法
|
||||
const playHeaderIntro = () => {
|
||||
if (!topHeaderRef.value) return
|
||||
|
||||
// 如果已经触发过,清理可能存在的保底定时器
|
||||
if (fallbackTimer) {
|
||||
clearTimeout(fallbackTimer)
|
||||
fallbackTimer = null
|
||||
}
|
||||
|
||||
gsap.fromTo(topHeaderRef.value,
|
||||
{
|
||||
y: '100vh',
|
||||
opacity: 0 // 恢复初始透明度为0,让它在屏幕最底部时是隐形的
|
||||
},
|
||||
{ y: '100vh', opacity: 0 },
|
||||
{
|
||||
y: 0,
|
||||
opacity: 1, // 伴随飞入的过程逐渐完全显示
|
||||
opacity: 1,
|
||||
duration: 1.4,
|
||||
ease: 'power4.out',
|
||||
delay: 0,
|
||||
overwrite: 'auto',
|
||||
clearProps: 'transform',
|
||||
onComplete: () => {
|
||||
// 动画完成时,强制把 style 的 opacity 移除,防止被内联样式锁死
|
||||
if (topHeaderRef.value) {
|
||||
topHeaderRef.value.style.opacity = ''
|
||||
}
|
||||
// 进场动画完毕后,再将滚动消失动画挂载到 ScrollTrigger
|
||||
if (topHeaderTween) {
|
||||
topHeaderTween.scrollTrigger?.kill()
|
||||
ScrollTrigger.create({
|
||||
animation: topHeaderTween,
|
||||
start: 0,
|
||||
end: 200,
|
||||
scrub: true,
|
||||
})
|
||||
ScrollTrigger.refresh()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 监听自定义事件,当首页的 Hero 动画完成或到达特定阶段时触发导航栏入场
|
||||
const handleHeroReady = () => {
|
||||
playHeaderIntro()
|
||||
}
|
||||
@@ -146,20 +143,8 @@ const hideTopHeader = () => {
|
||||
|
||||
const showTopHeaderInstant = () => {
|
||||
if (!topHeaderRef.value) return
|
||||
|
||||
gsap.set(topHeaderRef.value, { y: 0, opacity: 1 })
|
||||
topHeaderRef.value.style.opacity = ''
|
||||
|
||||
if (topHeaderTween) {
|
||||
topHeaderTween.scrollTrigger?.kill()
|
||||
ScrollTrigger.create({
|
||||
animation: topHeaderTween,
|
||||
start: 0,
|
||||
end: 200,
|
||||
scrub: true,
|
||||
})
|
||||
ScrollTrigger.refresh()
|
||||
}
|
||||
}
|
||||
|
||||
// 切换移动端菜单
|
||||
@@ -169,24 +154,20 @@ const toggleMobileMenu = () => {
|
||||
if (!mobileMenuRef.value) return
|
||||
|
||||
if (isMobileMenuOpen.value) {
|
||||
// 打开菜单
|
||||
gsap.set(mobileMenuRef.value, { display: 'flex' })
|
||||
gsap.fromTo(mobileMenuRef.value,
|
||||
{ opacity: 0, backdropFilter: 'blur(0px)' },
|
||||
{ opacity: 1, backdropFilter: 'blur(12px)', duration: 0.3, ease: 'power2.out' }
|
||||
)
|
||||
|
||||
// 菜单项依次出现
|
||||
const menuItems = gsap.utils.toArray<HTMLElement>('.mobile-menu-item', mobileMenuRef.value)
|
||||
gsap.fromTo(menuItems,
|
||||
{ y: 30, opacity: 0 },
|
||||
{ y: 0, opacity: 1, duration: 0.4, stagger: 0.05, ease: 'power3.out', delay: 0.1 }
|
||||
)
|
||||
|
||||
// 禁止背景滚动
|
||||
document.body.style.overflow = 'hidden'
|
||||
} else {
|
||||
// 关闭菜单
|
||||
gsap.to(mobileMenuRef.value,
|
||||
{
|
||||
opacity: 0,
|
||||
@@ -201,55 +182,32 @@ const toggleMobileMenu = () => {
|
||||
}
|
||||
)
|
||||
|
||||
// 恢复滚动
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
}
|
||||
|
||||
// 关闭移动端菜单
|
||||
const closeMobileMenu = () => {
|
||||
if (isMobileMenuOpen.value) {
|
||||
toggleMobileMenu()
|
||||
}
|
||||
}
|
||||
|
||||
let fallbackTimer: ReturnType<typeof setTimeout> | null = null
|
||||
|
||||
onMounted(() => {
|
||||
// 顶部导航在页面刚开始滚动的前 200px 内逐渐上移并隐藏。
|
||||
topHeaderTween = gsap.to(topHeaderRef.value, {
|
||||
yPercent: -140,
|
||||
autoAlpha: 0,
|
||||
ease: 'none',
|
||||
paused: true, // 初始不执行,等进场动画完毕再绑定到 ScrollTrigger
|
||||
})
|
||||
scheduleScrollCheck()
|
||||
window.addEventListener('scroll', scheduleScrollCheck, { passive: true })
|
||||
window.addEventListener('resize', scheduleScrollCheck, { passive: true })
|
||||
|
||||
// 底部导航默认藏在视口下方,只有滚动到深处并向上滚时才出现。
|
||||
gsap.set(bottomHeaderRef.value, {
|
||||
xPercent: -50,
|
||||
yPercent: 150,
|
||||
autoAlpha: 0,
|
||||
force3D: true
|
||||
})
|
||||
|
||||
bottomHeaderScrollTrigger = ScrollTrigger.create({
|
||||
start: 0,
|
||||
end: 'max',
|
||||
onUpdate: (self) => {
|
||||
const scrollY = self.scroll()
|
||||
|
||||
// 深度超过 1000px 后向上滚,显示底部导航。
|
||||
if (scrollY > 1000 && self.direction === -1) {
|
||||
setBottomHeaderVisible(true)
|
||||
return
|
||||
}
|
||||
|
||||
// 回到 1000px 以内,或继续向下滚时,底部导航收回。
|
||||
if (scrollY <= 1000 || self.direction === 1) {
|
||||
setBottomHeaderVisible(false)
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
ScrollTrigger.refresh()
|
||||
// 底部快捷导航默认藏在视口下方
|
||||
if (bottomHeaderRef.value) {
|
||||
gsap.set(bottomHeaderRef.value, {
|
||||
xPercent: -50,
|
||||
yPercent: 150,
|
||||
autoAlpha: 0,
|
||||
force3D: true,
|
||||
})
|
||||
}
|
||||
|
||||
if (!appStore.isAppLoading && route.path !== '/') {
|
||||
showTopHeaderInstant()
|
||||
@@ -263,9 +221,7 @@ watch([() => appStore.isAppLoading, () => route.path], ([isLoading, path]) => {
|
||||
|
||||
if (path === '/') {
|
||||
hideTopHeader()
|
||||
|
||||
window.addEventListener('hero-intro-done', handleHeroReady, { once: true })
|
||||
|
||||
fallbackTimer = setTimeout(() => {
|
||||
window.removeEventListener('hero-intro-done', handleHeroReady)
|
||||
playHeaderIntro()
|
||||
@@ -277,23 +233,21 @@ watch([() => appStore.isAppLoading, () => route.path], ([isLoading, path]) => {
|
||||
}, { immediate: true })
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
cleanupHeroReadyHook()
|
||||
topHeaderTween?.scrollTrigger?.kill()
|
||||
topHeaderTween?.kill()
|
||||
bottomHeaderScrollTrigger?.kill()
|
||||
topHeaderTween = null
|
||||
bottomHeaderScrollTrigger = null
|
||||
isBottomHeaderVisible = false
|
||||
if (topHeaderRef.value && bottomHeaderRef.value) {
|
||||
gsap.killTweensOf([topHeaderRef.value, bottomHeaderRef.value])
|
||||
}
|
||||
// 清理移动端菜单
|
||||
if (isMobileMenuOpen.value) {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
})
|
||||
cleanupHeroReadyHook()
|
||||
window.removeEventListener('scroll', scheduleScrollCheck)
|
||||
window.removeEventListener('resize', scheduleScrollCheck)
|
||||
if (topHeaderRef.value) {
|
||||
gsap.killTweensOf(topHeaderRef.value)
|
||||
}
|
||||
if (bottomHeaderRef.value) {
|
||||
gsap.killTweensOf(bottomHeaderRef.value)
|
||||
}
|
||||
isBottomHeaderVisible = false
|
||||
if (isMobileMenuOpen.value) {
|
||||
document.body.style.overflow = ''
|
||||
}
|
||||
})
|
||||
|
||||
// 监听路由变化,关闭移动端菜单
|
||||
watch(() => route.path, () => {
|
||||
closeMobileMenu()
|
||||
closeUserMenu()
|
||||
@@ -319,9 +273,12 @@ if (typeof window !== 'undefined') {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<header ref="topHeaderRef"
|
||||
class="site-header-top fixed left-0 right-0 top-0 z-50 mx-auto flex h-[100px] w-page-container max-w-[calc(100%-2rem)] items-center justify-between px-4 py-5"
|
||||
style="opacity: 0; transform: translateY(100vh);">
|
||||
<header
|
||||
ref="topHeaderRef"
|
||||
class="site-header-top fixed left-0 right-0 top-2 md:top-3 z-50 mx-auto flex w-full items-center justify-between rounded-[18px] px-3 py-2 md:w-page-container md:max-w-[calc(100%-2rem)] md:px-6 md:py-3 transition-all duration-300"
|
||||
:class="isScrolled ? 'scrolled' : ''"
|
||||
style="opacity: 0; transform: translateY(100vh);"
|
||||
>
|
||||
<!-- 左侧:Logo 和 标题 -->
|
||||
<AppLogo />
|
||||
|
||||
@@ -365,7 +322,7 @@ if (typeof window !== 'undefined') {
|
||||
class="flex items-center gap-3 px-4 py-2 rounded-full hover:bg-gray-100 transition-all duration-300"
|
||||
>
|
||||
<img
|
||||
:src="userStore.user?.avatar"
|
||||
:src="userStore.user?.avatar ?? ''"
|
||||
:alt="userStore.user?.username"
|
||||
class="w-9 h-9 rounded-full object-cover border-2 border-gray-200"
|
||||
/>
|
||||
@@ -445,7 +402,6 @@ if (typeof window !== 'undefined') {
|
||||
|
||||
<!-- 移动端登录/用户信息 -->
|
||||
<div class="mobile-menu-item mt-8 pt-8 border-t border-gray-200 w-full flex flex-col items-center gap-4">
|
||||
<!-- 语言切换 -->
|
||||
<button
|
||||
@click="switchLocale"
|
||||
class="px-8 py-3 rounded-full border-2 border-black text-black text-base font-semibold hover:bg-gray-100 transition-all duration-300"
|
||||
@@ -453,7 +409,6 @@ if (typeof window !== 'undefined') {
|
||||
{{ locale === 'zh' ? t('lang.toEnglish') : t('lang.toChinese') }}
|
||||
</button>
|
||||
|
||||
<!-- 未登录 -->
|
||||
<button
|
||||
v-if="!userStore.isAuthenticated"
|
||||
@click="authModal.openLogin()"
|
||||
@@ -462,11 +417,10 @@ if (typeof window !== 'undefined') {
|
||||
{{ t('auth.login') }}
|
||||
</button>
|
||||
|
||||
<!-- 已登录 -->
|
||||
<div v-else class="flex flex-col items-center gap-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<img
|
||||
:src="userStore.user?.avatar"
|
||||
:src="userStore.user?.avatar ?? ''"
|
||||
:alt="userStore.user?.username"
|
||||
class="w-12 h-12 rounded-full object-cover border-2 border-gray-200"
|
||||
/>
|
||||
@@ -487,49 +441,54 @@ if (typeof window !== 'undefined') {
|
||||
</nav>
|
||||
</div>
|
||||
|
||||
<!-- 底部快捷导航(深入页面后向上滚动时出现) -->
|
||||
<header ref="bottomHeaderRef" class="site-header-bottom z-50 bg-white/80 backdrop-blur-md">
|
||||
<nav class="flex items-center justify-evenly md:justify-end gap-3 md:gap-4 w-full">
|
||||
<NuxtLink v-for="item in navItems.slice(0, 2)" :key="'bottom-' + item.name" :to="item.path"
|
||||
class="group flex items-center font-semibold tracking-[-0.7px] text-black text-sm md:text-base whitespace-nowrap md:overflow-hidden"
|
||||
style="justify-content: flex-start; position: relative;">
|
||||
<div
|
||||
class="flex items-center transition-transform duration-300 md:group-hover:translate-x-0 md:-translate-x-[18px] md:pr-[18px]">
|
||||
<span class="hidden md:block mr-1 md:mr-2 h-1.5 w-1.5 md:h-2.5 md:w-2.5 rounded-full bg-black shrink-0"></span>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</nav>
|
||||
|
||||
<div class="flex items-center justify-center px-1 md:px-6">
|
||||
<AppLogo compact click-action="top" />
|
||||
</div>
|
||||
|
||||
<nav class="flex items-center justify-evenly md:justify-start gap-3 md:gap-4 w-full">
|
||||
<NuxtLink v-for="item in navItems.slice(2, navItems.length - 1)" :key="'bottom-' + item.name" :to="item.path"
|
||||
class="group flex items-center font-semibold tracking-[-0.7px] text-black text-sm md:text-base whitespace-nowrap md:overflow-hidden"
|
||||
style="justify-content: flex-start; position: relative;">
|
||||
<div
|
||||
class="flex items-center transition-transform duration-300 md:group-hover:translate-x-0 md:-translate-x-[18px] md:pr-[18px]">
|
||||
<span class="hidden md:block mr-1 md:mr-2 h-1.5 w-1.5 md:h-2.5 md:w-2.5 rounded-full bg-black shrink-0"></span>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<!-- 登录弹窗(由 authModal store 控制开关) -->
|
||||
<LoginModal />
|
||||
|
||||
<header ref="bottomHeaderRef" class="site-header-bottom z-50 bg-white/80 backdrop-blur-md">
|
||||
<!-- 左侧菜单 (前两个菜单项) -->
|
||||
<nav class="flex items-center justify-evenly md:justify-end gap-3 md:gap-4 w-full">
|
||||
<NuxtLink v-for="item in navItems.slice(0, 2)" :key="'bottom-' + item.name" :to="item.path"
|
||||
class="group flex items-center font-semibold tracking-[-0.7px] text-black text-sm md:text-base whitespace-nowrap md:overflow-hidden"
|
||||
style="justify-content: flex-start; position: relative;">
|
||||
<div
|
||||
class="flex items-center transition-transform duration-300 md:group-hover:translate-x-0 md:-translate-x-[18px] md:pr-[18px]">
|
||||
<span class="hidden md:block mr-1 md:mr-2 h-1.5 w-1.5 md:h-2.5 md:w-2.5 rounded-full bg-black shrink-0"></span>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</nav>
|
||||
|
||||
<!-- 中间 Logo (组件内部自带跳转和动画) -->
|
||||
<div class="flex items-center justify-center px-1 md:px-6">
|
||||
<AppLogo compact click-action="top" />
|
||||
</div>
|
||||
|
||||
<!-- 右侧菜单 (去除左侧两个和最后contact菜单后的所有菜单) -->
|
||||
<nav class="flex items-center justify-evenly md:justify-start gap-3 md:gap-4 w-full">
|
||||
<NuxtLink v-for="item in navItems.slice(2, navItems.length - 1)" :key="'bottom-' + item.name" :to="item.path"
|
||||
class="group flex items-center font-semibold tracking-[-0.7px] text-black text-sm md:text-base whitespace-nowrap md:overflow-hidden"
|
||||
style="justify-content: flex-start; position: relative;">
|
||||
<div
|
||||
class="flex items-center transition-transform duration-300 md:group-hover:translate-x-0 md:-translate-x-[18px] md:pr-[18px]">
|
||||
<span class="hidden md:block mr-1 md:mr-2 h-1.5 w-1.5 md:h-2.5 md:w-2.5 rounded-full bg-black shrink-0"></span>
|
||||
<span>{{ item.name }}</span>
|
||||
</div>
|
||||
</NuxtLink>
|
||||
</nav>
|
||||
</header>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.site-header-top.scrolled {
|
||||
background: rgba(255, 255, 255, 0.72);
|
||||
-webkit-backdrop-filter: saturate(180%) blur(16px);
|
||||
backdrop-filter: saturate(180%) blur(16px);
|
||||
box-shadow: 0 8px 28px rgba(0, 0, 0, 0.06);
|
||||
border-bottom: 1px solid rgba(0, 0, 0, 0.06);
|
||||
}
|
||||
|
||||
.site-header-bottom {
|
||||
border: 1px solid #ffffff47;
|
||||
border-radius: 12px;
|
||||
grid-template-rows: auto;
|
||||
/* 移动端恢复三列,靠 flex 让菜单均匀铺开 */
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
grid-auto-columns: 1fr;
|
||||
place-items: center;
|
||||
|
||||
+67
-93
@@ -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>
|
||||
|
||||
+3
-53
@@ -359,71 +359,21 @@
|
||||
"profile": "Profile",
|
||||
"favorites": "Favorites",
|
||||
"comments": "My Comments",
|
||||
"adminTitle": "Admin",
|
||||
"username": "Username",
|
||||
"nickname": "Nickname",
|
||||
"avatarHint": "Your avatar is synced to the unified identity provider. Supported: png/jpg/gif/webp/svg/avif, up to 8MB",
|
||||
"email": "Email",
|
||||
"phone": "Phone",
|
||||
"joinedAt": "Joined",
|
||||
"role": "Role",
|
||||
"roleAdmin": "Admin",
|
||||
"roleUser": "User",
|
||||
"save": "Save Changes",
|
||||
"saving": "Saving...",
|
||||
"saved": "Saved",
|
||||
"saveFailed": "Failed to save. Please try again.",
|
||||
"ssoAccount": "Unified SSO Account",
|
||||
"ssoAccountHint": "Changes to your nickname, avatar and email here are synced back to the unified identity provider (Casdoor) and stay consistent across all sites using it.",
|
||||
"emptyFavorites": "No favorites yet. Go to the Work page to explore.",
|
||||
"emptyComments": "No comments posted yet",
|
||||
"admin": {
|
||||
"contacts": "Contact Messages",
|
||||
"subscribers": "Newsletter Subscribers",
|
||||
"emptyContacts": "No contact messages",
|
||||
"emptySubscribers": "No subscribers yet",
|
||||
"name": "Name",
|
||||
"email": "Email",
|
||||
"subject": "Subject",
|
||||
"message": "Message",
|
||||
"date": "Date",
|
||||
"delivered": "Delivered to inbox",
|
||||
"notDelivered": "Not delivered (SMTP not configured)"
|
||||
},
|
||||
"adminEntry": "Admin Panel",
|
||||
"changePassword": {
|
||||
"title": "Change Password",
|
||||
"currentPassword": "Current Password",
|
||||
"newPassword": "New Password",
|
||||
"confirmPassword": "Confirm New Password",
|
||||
"submit": "Update Password",
|
||||
"saving": "Updating...",
|
||||
"success": "Password updated",
|
||||
"failed": "Failed to update password",
|
||||
"wrongPassword": "Current password is incorrect",
|
||||
"tooShort": "New password must be at least 8 characters",
|
||||
"mismatch": "Passwords do not match"
|
||||
},
|
||||
"deleteAccount": {
|
||||
"title": "Delete Account",
|
||||
"hint": "This cannot be undone. Your comments and favorites will be removed.",
|
||||
"passwordPlaceholder": "Enter your password to confirm",
|
||||
"confirmButton": "Delete",
|
||||
"cancelButton": "Cancel",
|
||||
"success": "Account deleted",
|
||||
"wrongPassword": "Incorrect password",
|
||||
"confirmText": "Delete your account permanently? This cannot be undone."
|
||||
},
|
||||
"statFavorites": "Favorites",
|
||||
"statComments": "Comments",
|
||||
"statJoined": "Joined",
|
||||
"avatar": {
|
||||
"change": "Change Avatar",
|
||||
"uploading": "Uploading...",
|
||||
"remove": "Remove Avatar",
|
||||
"error": "Failed to update avatar",
|
||||
"success": "Avatar updated"
|
||||
}
|
||||
},
|
||||
"emptyFavorites": "No favorites yet. Go to the Work page to explore.",
|
||||
"emptyComments": "No comments posted yet"
|
||||
},
|
||||
"comments": {
|
||||
"title": "Comments",
|
||||
|
||||
+4
-54
@@ -359,71 +359,21 @@
|
||||
"profile": "个人资料",
|
||||
"favorites": "我的收藏",
|
||||
"comments": "我的评论",
|
||||
"adminTitle": "管理面板",
|
||||
"username": "用户名",
|
||||
"nickname": "昵称",
|
||||
"avatarHint": "头像会同步到统一认证中心,支持 png/jpg/gif/webp/svg/avif,大小不超过 8MB",
|
||||
"email": "邮箱",
|
||||
"phone": "手机号",
|
||||
"joinedAt": "注册时间",
|
||||
"role": "角色",
|
||||
"roleAdmin": "管理员",
|
||||
"roleUser": "普通用户",
|
||||
"joinedAt": "加入时间",
|
||||
"save": "保存修改",
|
||||
"saving": "保存中...",
|
||||
"saved": "已保存",
|
||||
"saveFailed": "保存失败,请重试",
|
||||
"ssoAccount": "统一身份认证账号",
|
||||
"ssoAccountHint": "昵称、头像与邮箱在此修改后会同步回统一身份认证中心(Casimir),在其他接入统一认证的站点也会保持一致。",
|
||||
"emptyFavorites": "还没有收藏任何作品,去「作品」页看看吧",
|
||||
"emptyComments": "还没有发表过评论",
|
||||
"admin": {
|
||||
"contacts": "联系消息",
|
||||
"subscribers": "邮箱订阅",
|
||||
"emptyContacts": "暂无联系消息",
|
||||
"emptySubscribers": "暂无订阅用户",
|
||||
"name": "姓名",
|
||||
"email": "邮箱",
|
||||
"subject": "主题",
|
||||
"message": "留言内容",
|
||||
"date": "时间",
|
||||
"delivered": "已送达邮箱",
|
||||
"notDelivered": "未送达(SMTP 未配置)"
|
||||
},
|
||||
"adminEntry": "进入后台管理",
|
||||
"changePassword": {
|
||||
"title": "修改密码",
|
||||
"currentPassword": "当前密码",
|
||||
"newPassword": "新密码",
|
||||
"confirmPassword": "确认新密码",
|
||||
"submit": "确认修改",
|
||||
"saving": "提交中...",
|
||||
"success": "密码已修改",
|
||||
"failed": "修改失败,请重试",
|
||||
"wrongPassword": "当前密码不正确",
|
||||
"tooShort": "新密码至少需要 8 位",
|
||||
"mismatch": "两次输入的新密码不一致"
|
||||
},
|
||||
"deleteAccount": {
|
||||
"title": "删除账号",
|
||||
"hint": "删除后无法恢复,将同时清除你的评论与收藏。",
|
||||
"passwordPlaceholder": "输入当前密码确认",
|
||||
"confirmButton": "确认删除",
|
||||
"cancelButton": "取消",
|
||||
"success": "账号已删除",
|
||||
"wrongPassword": "密码不正确",
|
||||
"confirmText": "确定要永久删除账号吗?此操作不可撤销。"
|
||||
},
|
||||
"statFavorites": "收藏",
|
||||
"statComments": "评论",
|
||||
"statJoined": "加入于",
|
||||
"avatar": {
|
||||
"change": "更换头像",
|
||||
"uploading": "上传中...",
|
||||
"remove": "移除头像",
|
||||
"error": "头像更新失败",
|
||||
"success": "头像已更新"
|
||||
}
|
||||
},
|
||||
"emptyFavorites": "还没有收藏任何作品,去「作品」页看看吧",
|
||||
"emptyComments": "还没有发表过评论"
|
||||
},
|
||||
"comments": {
|
||||
"title": "评论",
|
||||
|
||||
Reference in New Issue
Block a user