5a7ad8de11
- OSS 文件存储(RustFS / S3 v4 兼容,零依赖手写 SigV4): 上传/列表/删除走桶 arcticnewone,/uploads 代理服务 + 本地回退; server/utils/sigv4.ts 纯函数 + AWS 测试向量验证 - 业务动态配置:settings 表 + /api/settings(公开) + /api/admin/settings(PATCH), useSiteSettings 组合式,footer/contact/tools/app.vue/侧边栏/工具页全部接入, 后台 /admin/settings 修改前台即时生效(站点/联系/社交/工具箱/页脚/SEO) - 后台全面优化:Admin* 设计系统(按钮/输入/表单/卡片/徽标/弹窗/确认/空态/骨架/ 分页/页头/Toast)14 组件;Dashboard 增强;各列表页搜索/筛选/批量删除/分页; 布局与侧边栏分组;统一 toast/确认反馈 - 个人中心全新重设计:顶部资料卡 + 统计、精致化改密/删号(二次确认)、 收藏封面网格、评论卡片、移动端适配 - deploy.sh 支持 OSS 凭据注入(NUXT_OSS_*);.env.example 更新 - 测试 17 例全过(含 SigV4 AWS 向量、settings 默认结构)
639 lines
25 KiB
Vue
639 lines
25 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* 个人中心(全新设计)。
|
||
* - 顶部深色渐变资料卡:头像 / 用户名 / 邮箱 / 角色徽标 / 注册时间 / 三项统计
|
||
* - pill 页签:profile / favorites / comments
|
||
* - profile:资料编辑、修改密码、删除账号(危险区 + 确认弹窗)
|
||
* - favorites:作品封面网格卡(封面 / 标题 / 年份 / 分类 / 取消收藏)
|
||
* - comments:评论卡片列表
|
||
* - 数据:favorites = /api/favorites + /api/work;comments = /api/account/comments
|
||
*/
|
||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||
import { useI18n } from 'vue-i18n'
|
||
import { useSeoMeta } from '#imports'
|
||
import gsap from 'gsap'
|
||
import { useUserStore } from '~/stores/user'
|
||
import { useAuthModalStore } from '~/stores/authModal'
|
||
import { useToastStore } from '~/stores/toast'
|
||
import { useApiError } from '~/composables/useApiError'
|
||
|
||
const { t, locale } = useI18n()
|
||
const userStore = useUserStore()
|
||
const authModal = useAuthModalStore()
|
||
const toast = useToastStore()
|
||
const apiError = useApiError()
|
||
|
||
useSeoMeta({ title: () => t('account.title') })
|
||
|
||
const isAdmin = computed(() => userStore.user?.role === 'admin')
|
||
|
||
const formatDate = (raw?: string) => {
|
||
if (!raw) return ''
|
||
const d = new Date(String(raw).replace(' ', 'T') + 'Z')
|
||
if (Number.isNaN(d.getTime())) return raw
|
||
const loc = locale.value === 'zh' ? 'zh-CN' : 'en-US'
|
||
return new Intl.DateTimeFormat(loc, { year: 'numeric', month: 'short', day: 'numeric' }).format(d)
|
||
}
|
||
|
||
// 统计卡「加入于」用紧凑格式(仅年月)
|
||
const formatMonth = (raw?: string) => {
|
||
if (!raw) return ''
|
||
const d = new Date(String(raw).replace(' ', 'T') + 'Z')
|
||
if (Number.isNaN(d.getTime())) return formatDate(raw)
|
||
const loc = locale.value === 'zh' ? 'zh-CN' : 'en-US'
|
||
return new Intl.DateTimeFormat(loc, { year: 'numeric', month: 'short' }).format(d)
|
||
}
|
||
|
||
/* ---------- 页签 ---------- */
|
||
const activeTab = ref('profile')
|
||
|
||
const tabs = computed(() => [
|
||
{ key: 'profile', label: t('account.profile'), count: null as number | null },
|
||
{ key: 'favorites', label: t('account.favorites'), count: favorites.value.length },
|
||
{ key: 'comments', label: t('account.comments'), count: myComments.value.length },
|
||
])
|
||
|
||
const switchTab = (key: string) => {
|
||
if (key === activeTab.value) return
|
||
activeTab.value = key
|
||
if (key === 'favorites') loadFavorites()
|
||
if (key === 'comments') loadComments()
|
||
}
|
||
|
||
/* ---------- 个人资料 ---------- */
|
||
const profileForm = reactive({ username: '', phone: '' })
|
||
const profileSaving = ref(false)
|
||
|
||
const initProfileForm = () => {
|
||
profileForm.username = userStore.user?.username ?? ''
|
||
profileForm.phone = userStore.user?.phone ?? ''
|
||
}
|
||
|
||
const saveProfile = async () => {
|
||
profileSaving.value = true
|
||
const result = await userStore.updateProfile({
|
||
username: profileForm.username,
|
||
phone: profileForm.phone,
|
||
})
|
||
profileSaving.value = false
|
||
if (result.success) {
|
||
toast.success(t('account.saved'))
|
||
} else {
|
||
toast.error(apiError({ data: { code: result.code } }))
|
||
}
|
||
}
|
||
|
||
/* ---------- 修改密码 ---------- */
|
||
const pwForm = reactive({ currentPassword: '', newPassword: '', confirmPassword: '' })
|
||
const pwSaving = ref(false)
|
||
const pwError = ref('')
|
||
|
||
const changePassword = async () => {
|
||
pwError.value = ''
|
||
if (pwForm.newPassword.length < 8) {
|
||
pwError.value = t('account.changePassword.tooShort')
|
||
return
|
||
}
|
||
if (pwForm.newPassword !== pwForm.confirmPassword) {
|
||
pwError.value = t('account.changePassword.mismatch')
|
||
return
|
||
}
|
||
pwSaving.value = true
|
||
try {
|
||
await $fetch('/api/auth/password', {
|
||
method: 'PATCH',
|
||
body: { currentPassword: pwForm.currentPassword, newPassword: pwForm.newPassword },
|
||
})
|
||
pwForm.currentPassword = ''
|
||
pwForm.newPassword = ''
|
||
pwForm.confirmPassword = ''
|
||
toast.success(t('account.changePassword.success'))
|
||
} catch (err) {
|
||
pwError.value =
|
||
(err as any)?.data?.code === 'WRONG_PASSWORD'
|
||
? t('account.changePassword.wrongPassword')
|
||
: apiError(err, 'account.changePassword.failed')
|
||
} finally {
|
||
pwSaving.value = false
|
||
}
|
||
}
|
||
|
||
/* ---------- 删除账号 ---------- */
|
||
const deletePassword = ref('')
|
||
const deleting = ref(false)
|
||
const deleteError = ref('')
|
||
const deleteConfirmOpen = ref(false)
|
||
|
||
const askDeleteAccount = () => {
|
||
deleteError.value = ''
|
||
if (!deletePassword.value.trim()) {
|
||
deleteError.value = t('account.deleteAccount.passwordPlaceholder')
|
||
return
|
||
}
|
||
deleteConfirmOpen.value = true
|
||
}
|
||
|
||
const doDeleteAccount = async () => {
|
||
deleting.value = true
|
||
try {
|
||
await $fetch('/api/auth/me', { method: 'DELETE', body: { password: deletePassword.value } })
|
||
deleteConfirmOpen.value = false
|
||
toast.success(t('account.deleteAccount.success'))
|
||
await userStore.logout()
|
||
await navigateTo('/')
|
||
} catch (err) {
|
||
deleteConfirmOpen.value = false
|
||
deleteError.value =
|
||
(err as any)?.data?.code === 'WRONG_PASSWORD'
|
||
? t('account.deleteAccount.wrongPassword')
|
||
: apiError(err)
|
||
} finally {
|
||
deleting.value = false
|
||
}
|
||
}
|
||
|
||
/* ---------- 我的收藏 ---------- */
|
||
interface FavedWork {
|
||
slug: string
|
||
titleZh: string
|
||
titleEn: string
|
||
image: string | null
|
||
year: string
|
||
category: string
|
||
}
|
||
const favorites = ref<FavedWork[]>([])
|
||
const favLoading = ref(false)
|
||
const favLoaded = ref(false)
|
||
|
||
const favTitle = (w: FavedWork) => (locale.value === 'zh' ? w.titleZh : w.titleEn)
|
||
|
||
const CATEGORY_KEYS: Record<string, string> = {
|
||
webDesign: 'webDesign',
|
||
branding: 'branding',
|
||
development: 'development',
|
||
}
|
||
const categoryLabel = (cat: string) =>
|
||
CATEGORY_KEYS[cat] ? t(`work.categories.${CATEGORY_KEYS[cat]}`) : cat
|
||
|
||
const loadFavorites = async () => {
|
||
if (favLoaded.value) return
|
||
favLoading.value = true
|
||
try {
|
||
const [favRes, workRes] = await Promise.all([
|
||
$fetch<{ slugs: string[] }>('/api/favorites'),
|
||
$fetch<{ works: FavedWork[] }>('/api/work'),
|
||
])
|
||
const bySlug = new Map(workRes.works.map((w) => [w.slug, w]))
|
||
favorites.value = favRes.slugs.map((s) => bySlug.get(s)).filter(Boolean) as FavedWork[]
|
||
favLoaded.value = true
|
||
} catch (err) {
|
||
console.error('load favorites error:', err)
|
||
} finally {
|
||
favLoading.value = false
|
||
}
|
||
}
|
||
|
||
const removeFavorite = async (slug: string) => {
|
||
try {
|
||
await $fetch('/api/favorites', { method: 'DELETE', body: { workSlug: slug } })
|
||
favorites.value = favorites.value.filter((f) => f.slug !== slug)
|
||
toast.success(t('favorites.remove'))
|
||
} catch (err) {
|
||
toast.error(apiError(err))
|
||
}
|
||
}
|
||
|
||
/* ---------- 我的评论 ---------- */
|
||
interface MyComment {
|
||
id: number
|
||
newsSlug: string
|
||
content: string
|
||
createdAt: string
|
||
}
|
||
const myComments = ref<MyComment[]>([])
|
||
const commentLoading = ref(false)
|
||
const commentsLoaded = ref(false)
|
||
|
||
const loadComments = async () => {
|
||
if (commentsLoaded.value) return
|
||
commentLoading.value = true
|
||
try {
|
||
const data = await $fetch<{ comments: MyComment[] }>('/api/account/comments')
|
||
myComments.value = data.comments
|
||
commentsLoaded.value = true
|
||
} catch (err) {
|
||
console.error('load comments error:', err)
|
||
} finally {
|
||
commentLoading.value = false
|
||
}
|
||
}
|
||
|
||
/* ---------- 页面入场动画 ---------- */
|
||
const mainRef = ref<HTMLElement | null>(null)
|
||
let ctx: gsap.Context | null = null
|
||
|
||
const runIntro = () => {
|
||
ctx?.revert()
|
||
if (!mainRef.value) return
|
||
ctx = gsap.context(() => {
|
||
const targets = gsap.utils.toArray<HTMLElement>('[data-animate]', mainRef.value)
|
||
if (!targets.length) return
|
||
gsap.set(targets, { autoAlpha: 0, y: 24 })
|
||
gsap.to(targets, { autoAlpha: 1, y: 0, duration: 0.7, ease: 'power3.out', stagger: 0.1 })
|
||
}, mainRef.value)
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await nextTick()
|
||
initProfileForm()
|
||
runIntro()
|
||
// 统计数字依赖收藏/评论数据,异步补齐(入场动画不等待网络)
|
||
if (userStore.isAuthenticated) {
|
||
await Promise.all([loadFavorites(), loadComments()])
|
||
}
|
||
})
|
||
|
||
onBeforeUnmount(() => {
|
||
ctx?.revert()
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<main
|
||
ref="mainRef"
|
||
class="page-container min-h-screen pt-24 md:pt-32 pb-24 px-4 md:px-8 mx-auto max-w-[1100px]"
|
||
>
|
||
<AdminToast />
|
||
|
||
<!-- 未登录 -->
|
||
<section
|
||
v-if="!userStore.isAuthenticated"
|
||
data-animate
|
||
class="max-w-md mx-auto mt-10 md:mt-16 p-10 rounded-3xl bg-white border border-gray-100 shadow-xl text-center"
|
||
>
|
||
<div class="w-16 h-16 mx-auto rounded-full bg-gray-100 flex items-center justify-center mb-6">
|
||
<Icon name="ph:user-duotone" class="w-8 h-8 text-gray-400" />
|
||
</div>
|
||
<h1 class="text-2xl font-bold text-black mb-3">{{ t('account.title') }}</h1>
|
||
<p class="text-gray-500 mb-8">{{ t('auth.loginRequired') }}</p>
|
||
<AdminButton size="lg" @click="authModal.openLogin()">
|
||
<Icon name="ph:sign-in" class="w-4 h-4" />
|
||
{{ t('auth.login') }}
|
||
</AdminButton>
|
||
</section>
|
||
|
||
<template v-else>
|
||
<!-- 顶部资料卡 -->
|
||
<section data-animate class="relative overflow-hidden rounded-3xl bg-black text-white shadow-xl">
|
||
<!-- 装饰渐变 -->
|
||
<div class="pointer-events-none absolute -top-24 -right-20 w-72 h-72 rounded-full bg-gradient-to-br from-indigo-500/40 via-fuchsia-500/20 to-transparent blur-3xl"></div>
|
||
<div class="pointer-events-none absolute -bottom-28 -left-16 w-80 h-80 rounded-full bg-gradient-to-tr from-cyan-400/30 to-blue-600/10 blur-3xl"></div>
|
||
|
||
<div class="relative p-6 md:p-10">
|
||
<!-- 身份信息 -->
|
||
<div class="flex flex-col md:flex-row md:items-center gap-5 md:gap-7">
|
||
<div class="flex-shrink-0">
|
||
<div class="w-20 h-20 md:w-24 md:h-24 rounded-2xl bg-white/10 border border-white/20 p-1.5">
|
||
<img
|
||
:src="userStore.avatar"
|
||
:alt="userStore.user?.username"
|
||
class="w-full h-full rounded-xl object-cover"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="flex-1 min-w-0">
|
||
<div class="flex items-center gap-3 flex-wrap">
|
||
<h1 class="text-2xl md:text-3xl font-bold tracking-tight">{{ userStore.user?.username }}</h1>
|
||
<AdminBadge v-if="isAdmin" tone="amber">
|
||
<Icon name="ph:shield-check" class="w-3 h-3" /> {{ t('account.roleAdmin') }}
|
||
</AdminBadge>
|
||
<AdminBadge v-else tone="blue">{{ t('account.roleUser') }}</AdminBadge>
|
||
</div>
|
||
<p class="mt-2 flex items-center gap-2 text-sm md:text-base text-white/70">
|
||
<Icon name="ph:envelope-simple" class="w-4 h-4 flex-shrink-0" />
|
||
<span class="truncate">{{ userStore.user?.email }}</span>
|
||
</p>
|
||
<p class="mt-1 flex items-center gap-2 text-xs md:text-sm text-white/50">
|
||
<Icon name="ph:calendar-dots" class="w-4 h-4 flex-shrink-0" />
|
||
{{ t('account.joinedAt') }} · {{ formatDate(userStore.user?.createdAt) }}
|
||
</p>
|
||
</div>
|
||
|
||
<!-- 管理员入口 -->
|
||
<div v-if="isAdmin" class="flex-shrink-0">
|
||
<NuxtLink
|
||
to="/admin"
|
||
class="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-white text-black text-sm font-semibold hover:bg-white/90 transition-colors shadow-lg"
|
||
>
|
||
<Icon name="ph:gear-six" class="w-4 h-4" />
|
||
{{ t('account.adminEntry') }}
|
||
</NuxtLink>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 统计 -->
|
||
<div class="mt-8 grid grid-cols-3 gap-3 md:gap-5">
|
||
<div class="rounded-2xl bg-white/10 border border-white/10 px-3 py-4 md:py-5 text-center">
|
||
<p class="text-xl md:text-3xl font-bold leading-none">{{ favorites.length }}</p>
|
||
<p class="mt-2 text-[11px] md:text-xs text-white/60">{{ t('account.statFavorites') }}</p>
|
||
</div>
|
||
<div class="rounded-2xl bg-white/10 border border-white/10 px-3 py-4 md:py-5 text-center">
|
||
<p class="text-xl md:text-3xl font-bold leading-none">{{ myComments.length }}</p>
|
||
<p class="mt-2 text-[11px] md:text-xs text-white/60">{{ t('account.statComments') }}</p>
|
||
</div>
|
||
<div class="rounded-2xl bg-white/10 border border-white/10 px-3 py-4 md:py-5 text-center">
|
||
<p class="text-sm md:text-base font-bold leading-tight break-words">{{ formatMonth(userStore.user?.createdAt) }}</p>
|
||
<p class="mt-2 text-[11px] md:text-xs text-white/60">{{ t('account.statJoined') }}</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 页签 -->
|
||
<nav data-animate class="mt-8 md:mt-10 flex justify-center">
|
||
<div class="inline-flex p-1.5 rounded-full bg-white border border-gray-100 shadow-sm">
|
||
<button
|
||
v-for="tab in tabs"
|
||
:key="tab.key"
|
||
type="button"
|
||
@click="switchTab(tab.key)"
|
||
class="flex items-center gap-2 px-5 md:px-6 py-2.5 rounded-full text-sm font-semibold transition-all duration-300"
|
||
:class="activeTab === tab.key ? 'bg-black text-white shadow' : 'text-gray-500 hover:text-black'"
|
||
>
|
||
{{ tab.label }}
|
||
<span
|
||
v-if="tab.count != null"
|
||
class="text-[11px] leading-none px-1.5 py-1 rounded-full"
|
||
:class="activeTab === tab.key ? 'bg-white/20 text-white' : 'bg-gray-100 text-gray-500'"
|
||
>
|
||
{{ tab.count }}
|
||
</span>
|
||
</button>
|
||
</div>
|
||
</nav>
|
||
|
||
<!-- 内容区 -->
|
||
<div class="mt-8 md:mt-10">
|
||
<Transition name="panel" mode="out-in">
|
||
<!-- 个人资料 -->
|
||
<section v-if="activeTab === 'profile'" key="profile" class="space-y-6 max-w-2xl mx-auto">
|
||
<!-- 资料编辑 -->
|
||
<div class="rounded-3xl bg-white border border-gray-100 shadow-sm overflow-hidden">
|
||
<div class="px-6 py-4 border-b border-gray-100 flex items-center gap-3">
|
||
<div class="w-9 h-9 rounded-xl bg-gray-100 text-gray-600 flex items-center justify-center">
|
||
<Icon name="ph:user-focus" class="w-5 h-5" />
|
||
</div>
|
||
<div>
|
||
<h3 class="text-base font-bold text-black">{{ t('account.profile') }}</h3>
|
||
<p class="text-xs text-gray-400">个人基本信息</p>
|
||
</div>
|
||
</div>
|
||
<div class="p-6 space-y-5">
|
||
<AdminInput v-model="profileForm.username" :label="t('account.username')" required />
|
||
<AdminInput v-model="profileForm.phone" :label="t('account.phone')" type="tel" />
|
||
<AdminInput
|
||
:model-value="userStore.user?.email ?? ''"
|
||
:label="t('account.email')"
|
||
type="email"
|
||
disabled
|
||
/>
|
||
<div class="flex justify-end pt-1">
|
||
<AdminButton :loading="profileSaving" @click="saveProfile">
|
||
<Icon v-if="!profileSaving" name="ph:floppy-disk" class="w-4 h-4" />
|
||
{{ profileSaving ? t('account.saving') : t('account.save') }}
|
||
</AdminButton>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 修改密码 -->
|
||
<div class="rounded-3xl bg-white border border-gray-100 shadow-sm overflow-hidden">
|
||
<div class="px-6 py-4 border-b border-gray-100 flex items-center gap-3">
|
||
<div class="w-9 h-9 rounded-xl bg-gray-100 text-gray-600 flex items-center justify-center">
|
||
<Icon name="ph:key" class="w-5 h-5" />
|
||
</div>
|
||
<div>
|
||
<h3 class="text-base font-bold text-black">{{ t('account.changePassword.title') }}</h3>
|
||
<p class="text-xs text-gray-400">定期更换密码更安全</p>
|
||
</div>
|
||
</div>
|
||
<form class="p-6 space-y-5" @submit.prevent="changePassword">
|
||
<AdminInput
|
||
v-model="pwForm.currentPassword"
|
||
:label="t('account.changePassword.currentPassword')"
|
||
type="password"
|
||
required
|
||
/>
|
||
<AdminInput
|
||
v-model="pwForm.newPassword"
|
||
:label="t('account.changePassword.newPassword')"
|
||
type="password"
|
||
required
|
||
/>
|
||
<AdminInput
|
||
v-model="pwForm.confirmPassword"
|
||
:label="t('account.changePassword.confirmPassword')"
|
||
type="password"
|
||
required
|
||
/>
|
||
<p v-if="pwError" class="text-sm text-red-600">{{ pwError }}</p>
|
||
<div class="flex justify-end pt-1">
|
||
<AdminButton type="submit" variant="secondary" :loading="pwSaving">
|
||
<Icon v-if="!pwSaving" name="ph:lock-simple" class="w-4 h-4" />
|
||
{{ pwSaving ? t('account.changePassword.saving') : t('account.changePassword.submit') }}
|
||
</AdminButton>
|
||
</div>
|
||
</form>
|
||
</div>
|
||
|
||
<!-- 删除账号(危险区) -->
|
||
<div class="rounded-3xl border-2 border-red-100 bg-red-50/50 shadow-sm overflow-hidden">
|
||
<div class="px-6 py-4 border-b border-red-100 flex items-center gap-3">
|
||
<div class="w-9 h-9 rounded-xl bg-red-100 text-red-600 flex items-center justify-center">
|
||
<Icon name="ph:warning" class="w-5 h-5" />
|
||
</div>
|
||
<div>
|
||
<h3 class="text-base font-bold text-red-600">{{ t('account.deleteAccount.title') }}</h3>
|
||
<p class="text-xs text-red-400">危险操作</p>
|
||
</div>
|
||
</div>
|
||
<div class="p-6 space-y-5">
|
||
<p class="text-sm text-gray-600 leading-relaxed">{{ t('account.deleteAccount.hint') }}</p>
|
||
<AdminInput
|
||
v-model="deletePassword"
|
||
:label="t('auth.password')"
|
||
:placeholder="t('account.deleteAccount.passwordPlaceholder')"
|
||
type="password"
|
||
/>
|
||
<p v-if="deleteError" class="text-sm text-red-600">{{ deleteError }}</p>
|
||
<div class="flex justify-end pt-1">
|
||
<AdminButton variant="danger" :loading="deleting" @click="askDeleteAccount">
|
||
<Icon v-if="!deleting" name="ph:trash" class="w-4 h-4" />
|
||
{{ t('account.deleteAccount.confirmButton') }}
|
||
</AdminButton>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 我的收藏 -->
|
||
<section v-else-if="activeTab === 'favorites'" key="favorites">
|
||
<div v-if="favLoading" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-5">
|
||
<div
|
||
v-for="i in 3"
|
||
:key="i"
|
||
class="rounded-2xl bg-white border border-gray-100 shadow-sm overflow-hidden animate-pulse"
|
||
>
|
||
<div class="aspect-[4/3] bg-gray-100"></div>
|
||
<div class="p-4 space-y-2">
|
||
<div class="h-3.5 rounded bg-gray-100 w-2/3"></div>
|
||
<div class="h-3 rounded bg-gray-100 w-1/3"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<AdminEmptyState
|
||
v-else-if="!favorites.length"
|
||
icon="ph:bookmark-simple"
|
||
:title="t('account.emptyFavorites')"
|
||
/>
|
||
|
||
<div v-else class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-5">
|
||
<div
|
||
v-for="fav in favorites"
|
||
:key="fav.slug"
|
||
class="group rounded-2xl overflow-hidden bg-white border border-gray-100 shadow-sm hover:shadow-xl transition-all duration-300 hover:-translate-y-1"
|
||
>
|
||
<div class="relative aspect-[4/3] overflow-hidden bg-gray-50">
|
||
<NuxtLink :to="`/work/${fav.slug}`" class="block w-full h-full" :aria-label="favTitle(fav)">
|
||
<img
|
||
v-if="fav.image"
|
||
:src="fav.image"
|
||
:alt="favTitle(fav)"
|
||
class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
|
||
/>
|
||
<div v-else class="w-full h-full flex items-center justify-center">
|
||
<Icon name="ph:image" class="w-8 h-8 text-gray-300" />
|
||
</div>
|
||
</NuxtLink>
|
||
<span
|
||
v-if="fav.year"
|
||
class="absolute top-3 left-3 px-2.5 py-1 rounded-full bg-black/60 backdrop-blur-sm text-white text-xs font-semibold pointer-events-none"
|
||
>
|
||
{{ fav.year }}
|
||
</span>
|
||
<button
|
||
type="button"
|
||
@click="removeFavorite(fav.slug)"
|
||
class="absolute top-3 right-3 w-9 h-9 rounded-full bg-white/90 backdrop-blur-sm text-gray-600 hover:bg-red-500 hover:text-white flex items-center justify-center shadow transition-all duration-200"
|
||
:aria-label="t('favorites.remove')"
|
||
>
|
||
<Icon name="ph:bookmark-simple-fill" class="w-4 h-4" />
|
||
</button>
|
||
</div>
|
||
<div class="p-4">
|
||
<NuxtLink
|
||
:to="`/work/${fav.slug}`"
|
||
class="block font-bold text-black group-hover:text-gray-600 transition-colors truncate"
|
||
>
|
||
{{ favTitle(fav) }}
|
||
</NuxtLink>
|
||
<p class="mt-1.5 inline-flex items-center gap-1.5">
|
||
<span class="px-2 py-0.5 rounded-full bg-gray-100 text-gray-500 text-xs font-medium">
|
||
{{ categoryLabel(fav.category) }}
|
||
</span>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 我的评论 -->
|
||
<section v-else key="comments" class="max-w-2xl mx-auto">
|
||
<div v-if="commentLoading" class="space-y-4">
|
||
<div
|
||
v-for="i in 3"
|
||
:key="i"
|
||
class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 animate-pulse space-y-3"
|
||
>
|
||
<div class="h-3.5 rounded bg-gray-100 w-1/4"></div>
|
||
<div class="h-3 rounded bg-gray-100 w-full"></div>
|
||
<div class="h-3 rounded bg-gray-100 w-2/3"></div>
|
||
</div>
|
||
</div>
|
||
|
||
<AdminEmptyState
|
||
v-else-if="!myComments.length"
|
||
icon="ph:chat-circle-text"
|
||
:title="t('account.emptyComments')"
|
||
/>
|
||
|
||
<div v-else class="space-y-4">
|
||
<div
|
||
v-for="comment in myComments"
|
||
:key="comment.id"
|
||
class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 flex gap-4"
|
||
>
|
||
<div class="w-10 h-10 rounded-full bg-gray-100 text-gray-400 flex items-center justify-center flex-shrink-0">
|
||
<Icon name="ph:chat-circle-dots" class="w-5 h-5" />
|
||
</div>
|
||
<div class="min-w-0 flex-1">
|
||
<div class="flex items-center justify-between gap-3 flex-wrap">
|
||
<NuxtLink
|
||
:to="`/news/${comment.newsSlug}`"
|
||
class="inline-flex items-center gap-1.5 text-sm font-semibold text-black hover:text-gray-600 transition-colors"
|
||
>
|
||
<Icon name="ph:article" class="w-4 h-4 text-gray-400" />
|
||
#{{ comment.newsSlug }}
|
||
</NuxtLink>
|
||
<span class="text-xs text-gray-400">{{ formatDate(comment.createdAt) }}</span>
|
||
</div>
|
||
<p class="mt-2 text-gray-700 text-sm leading-relaxed break-words">{{ comment.content }}</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
</Transition>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- 删除账号确认 -->
|
||
<AdminModal
|
||
:open="deleteConfirmOpen"
|
||
:title="t('account.deleteAccount.title')"
|
||
@update:open="deleteConfirmOpen = $event"
|
||
>
|
||
<div class="flex items-start gap-3">
|
||
<div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-red-50 text-red-600">
|
||
<Icon name="ph:warning-fill" class="w-5 h-5" />
|
||
</div>
|
||
<p class="text-sm text-gray-700 leading-relaxed">{{ t('account.deleteAccount.confirmText') }}</p>
|
||
</div>
|
||
<template #footer>
|
||
<AdminButton variant="secondary" size="sm" :disabled="deleting" @click="deleteConfirmOpen = false">
|
||
{{ t('account.deleteAccount.cancelButton') }}
|
||
</AdminButton>
|
||
<AdminButton variant="danger" size="sm" :loading="deleting" @click="doDeleteAccount">
|
||
{{ t('account.deleteAccount.confirmButton') }}
|
||
</AdminButton>
|
||
</template>
|
||
</AdminModal>
|
||
</main>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.panel-enter-active,
|
||
.panel-leave-active {
|
||
transition: opacity 0.28s ease, transform 0.28s ease;
|
||
}
|
||
.panel-enter-from {
|
||
opacity: 0;
|
||
transform: translateY(14px);
|
||
}
|
||
.panel-leave-to {
|
||
opacity: 0;
|
||
transform: translateY(-8px);
|
||
}
|
||
</style>
|