Files
arcticnewone/app/pages/account.vue
T
virtheart b9ffcdb874 feat: 头像上传/修改 + 个人资料连贯设置面板
- 头像:users.avatar 列 + POST /api/auth/avatar(OSS 上传/清除)+ toPublicUser 返回 avatar;
  user store updateAvatar + avatar 计算(自定义优先,ui-avatars 兜底)
- 共享 saveImage 工具(admin 上传与头像复用,消除重复)
- 个人资料布局:单一连贯设置面板(divide-y 分区:基本信息含头像编辑 / 安全设置 / 危险区),
  去掉小卡片堆叠;i18n 头像键
2026-08-06 19:40:41 +08:00

534 lines
28 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/**
* 个人中心(重新设计)—— 对齐站点黑白编辑风:极简、大排版、充足留白。
* - 资料区:头像 + 大号姓名 + 邮箱 + 角色/加入时间 + 三项统计(细分隔线)
* - 导航:下划线页签
* - profile:资料编辑 / 修改密码 / 删除账号(克制危险区)
* - favorites:作品封面网格;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 { useApiError } from '~/composables/useApiError'
const { t, locale } = useI18n()
const userStore = useUserStore()
const authModal = useAuthModalStore()
const apiError = useApiError()
useSeoMeta({ title: () => t('account.title') })
const isAdmin = computed(() => userStore.user?.role === 'admin')
const formatDate = (raw?: string, monthOnly = false) => {
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, monthOnly ? { year: 'numeric', month: 'short' } : { year: 'numeric', month: 'short', day: 'numeric' }).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 profileMsg = ref<{ ok: boolean; text: string } | null>(null)
const initProfileForm = () => {
profileForm.username = userStore.user?.username ?? ''
profileForm.phone = userStore.user?.phone ?? ''
}
const saveProfile = async () => {
profileSaving.value = true
profileMsg.value = null
const result = await userStore.updateProfile({ username: profileForm.username, phone: profileForm.phone })
profileSaving.value = false
profileMsg.value = result.success
? { ok: true, text: t('account.saved') }
: { ok: false, text: apiError({ data: { code: result.code } }) }
}
/* ---------- 头像 ---------- */
const avatarUpdating = ref(false)
const avatarMsg = ref<{ ok: boolean; text: string } | null>(null)
const onAvatarChange = async (e: Event) => {
const input = e.target as HTMLInputElement
const file = input.files?.[0]
if (!file) return
if (!/^image\//.test(file.type) || file.size > 8 * 1024 * 1024) {
avatarMsg.value = { ok: false, text: t('account.avatar.error') }
input.value = ''
return
}
avatarUpdating.value = true
avatarMsg.value = null
const result = await userStore.updateAvatar(file)
avatarUpdating.value = false
input.value = ''
avatarMsg.value = result.success
? { ok: true, text: t('account.avatar.success') }
: { ok: false, text: t('account.avatar.error') }
}
const removeAvatar = async () => {
avatarUpdating.value = true
avatarMsg.value = null
const result = await userStore.updateAvatar(null)
avatarUpdating.value = false
avatarMsg.value = result.success
? { ok: true, text: t('account.avatar.success') }
: { ok: false, text: t('account.avatar.error') }
}
/* ---------- 修改密码 ---------- */
const pwForm = reactive({ currentPassword: '', newPassword: '', confirmPassword: '' })
const pwSaving = ref(false)
const pwError = ref('')
const pwOk = ref(false)
const changePassword = async () => {
pwError.value = ''
pwOk.value = false
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 = ''
pwOk.value = true
} 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
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 categoryLabel = (cat: string) => (['webDesign', 'branding', 'development'].includes(cat) ? t(`work.categories.${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)
} catch (err) { console.error('remove favorite error:', 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: 22 })
gsap.to(targets, { autoAlpha: 1, y: 0, duration: 0.7, ease: 'power3.out', stagger: 0.08 })
}, 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-28 md:pt-36 pb-24 px-4 md:px-8 mx-auto max-w-[1000px]">
<!-- 未登录 -->
<section v-if="!userStore.isAuthenticated" data-animate class="max-w-sm mx-auto mt-10 md:mt-20 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-3xl md:text-4xl font-bold tracking-tight text-black mb-3">{{ t('account.title') }}</h1>
<p class="text-gray-500 mb-8">{{ t('auth.loginRequired') }}</p>
<button
@click="authModal.openLogin()"
class="px-8 py-3 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors"
>
{{ t('auth.login') }}
</button>
</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"
:class="isAdmin ? 'bg-black text-white' : 'bg-gray-100 text-gray-600'"
>
<Icon :name="isAdmin ? 'ph:shield-check' : 'ph:user'" class="w-3 h-3" />
{{ isAdmin ? t('account.roleAdmin') : 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>
<NuxtLink
v-if="isAdmin"
to="/admin"
class="inline-flex items-center gap-1.5 text-sm font-semibold text-black underline underline-offset-4 hover:text-gray-500 transition-colors flex-shrink-0"
>
{{ t('account.adminEntry') }}
<Icon name="ph:arrow-right" class="w-4 h-4" />
</NuxtLink>
</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>
</div>
</header>
<!-- 页签(下划线) -->
<nav data-animate class="mt-10 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="activeTab === tab.key ? 'border-black text-black' : 'border-transparent text-gray-400 hover:text-black'"
>
{{ tab.label }}
<span v-if="tab.count != null" class="text-xs text-gray-400">{{ 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="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="mt-6 flex items-center gap-6">
<img :src="userStore.avatar" :alt="userStore.user?.username"
class="w-20 h-20 rounded-2xl object-cover ring-1 ring-black/10 flex-shrink-0" />
<div class="space-y-2.5">
<label class="inline-flex cursor-pointer">
<input type="file" accept="image/*" class="hidden" @change="onAvatarChange" />
<span
class="inline-flex items-center gap-1.5 px-4 py-2 rounded-full border border-gray-200 text-sm font-semibold text-gray-700 hover:border-black hover:text-black transition-colors"
>
<Icon v-if="avatarUpdating" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
<Icon v-else name="ph:camera" class="w-4 h-4" />
{{ t('account.avatar.change') }}
</span>
</label>
<button
v-if="userStore.user?.avatar"
@click="removeAvatar"
:disabled="avatarUpdating"
class="block text-sm text-gray-400 hover:text-red-600 transition-colors disabled:opacity-50"
>
{{ t('account.avatar.remove') }}
</button>
</div>
</div>
<p v-if="avatarMsg" class="mt-3 text-sm" :class="avatarMsg.ok ? 'text-green-600' : 'text-red-600'">{{ avatarMsg.text }}</p>
<div class="mt-7 space-y-5">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.username') }}</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.phone') }}</label>
<input v-model="profileForm.phone" type="tel"
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 :value="userStore.user?.email ?? ''" type="email" disabled
class="w-full rounded-xl border border-gray-200 bg-gray-50 px-3.5 py-2.5 text-sm text-gray-500 cursor-not-allowed" />
</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>
</div>
<!-- 安全设置 -->
<div class="px-6 md:px-8 py-7">
<h3 class="text-lg font-bold text-black">{{ t('account.changePassword.title') }}</h3>
<p class="text-sm text-gray-400 mt-0.5">定期更换密码更安全</p>
<form class="mt-6 space-y-5" @submit.prevent="changePassword">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.changePassword.currentPassword') }}</label>
<input v-model="pwForm.currentPassword" type="password" autocomplete="current-password" required
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 class="grid grid-cols-1 sm:grid-cols-2 gap-5">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.changePassword.newPassword') }}</label>
<input v-model="pwForm.newPassword" type="password" autocomplete="new-password" required
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.changePassword.confirmPassword') }}</label>
<input v-model="pwForm.confirmPassword" type="password" autocomplete="new-password" required
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>
<p v-if="pwError" class="text-sm text-red-600">{{ pwError }}</p>
<p v-if="pwOk" class="text-sm text-green-600">{{ t('account.changePassword.success') }}</p>
<div class="flex justify-end">
<button type="submit" :disabled="pwSaving"
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full border border-gray-200 text-gray-700 text-sm font-semibold hover:border-black hover:text-black transition-colors disabled:opacity-50">
<Icon v-if="pwSaving" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
{{ pwSaving ? t('account.changePassword.saving') : t('account.changePassword.submit') }}
</button>
</div>
</form>
</div>
<!-- 危险操作 -->
<div class="px-6 md:px-8 py-7 bg-red-50/40">
<h3 class="text-lg font-bold text-red-600">{{ t('account.deleteAccount.title') }}</h3>
<p class="text-sm text-red-400 mt-0.5">危险操作</p>
<div class="mt-6 space-y-5">
<p class="text-sm text-gray-600 leading-relaxed">{{ t('account.deleteAccount.hint') }}</p>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('auth.password') }}</label>
<input v-model="deletePassword" type="password" autocomplete="current-password"
:placeholder="t('account.deleteAccount.passwordPlaceholder')"
@keydown.enter.prevent="askDeleteAccount"
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-red-400 focus:ring-2 focus:ring-red-500/10" />
</div>
<p v-if="deleteError" class="text-sm text-red-600">{{ deleteError }}</p>
<div class="flex justify-end">
<button @click="askDeleteAccount" :disabled="deleting"
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full bg-red-600 text-white text-sm font-semibold hover:bg-red-700 transition-colors disabled:opacity-50">
<Icon v-if="deleting" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
{{ t('account.deleteAccount.confirmButton') }}
</button>
</div>
</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 border border-gray-100 bg-white 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>
<div v-else-if="!favorites.length" class="text-center py-20">
<Icon name="ph:bookmark-simple" class="w-12 h-12 text-gray-200 mx-auto mb-4" />
<p class="text-gray-500">{{ t('account.emptyFavorites') }}</p>
</div>
<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)" loading="lazy"
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>
<span class="mt-1.5 inline-block px-2 py-0.5 rounded-full bg-gray-100 text-gray-500 text-xs font-medium">
{{ categoryLabel(fav.category) }}
</span>
</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 border border-gray-100 bg-white 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>
</div>
<div v-else-if="!myComments.length" class="text-center py-20">
<Icon name="ph:chat-circle-text" class="w-12 h-12 text-gray-200 mx-auto mb-4" />
<p class="text-gray-500">{{ t('account.emptyComments') }}</p>
</div>
<div v-else class="divide-y divide-gray-100 border border-gray-100 bg-white rounded-2xl shadow-sm">
<div v-for="comment in myComments" :key="comment.id" class="p-5 md:p-6 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>
<!-- 删除账号确认 -->
<div v-if="deleteConfirmOpen" class="fixed inset-0 z-[150] flex items-center justify-center bg-black/40 p-4" @click.self="deleteConfirmOpen = false">
<div class="w-full max-w-sm rounded-2xl bg-white shadow-2xl overflow-hidden">
<div class="px-6 py-5 border-b border-gray-100 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 pt-1">{{ t('account.deleteAccount.confirmText') }}</p>
</div>
<div class="flex justify-end gap-2 px-6 py-4">
<button @click="deleteConfirmOpen = false" :disabled="deleting"
class="px-4 py-2 rounded-full border border-gray-200 text-sm font-semibold text-gray-600 hover:border-gray-300 transition-colors disabled:opacity-50">
{{ t('account.deleteAccount.cancelButton') }}
</button>
<button @click="doDeleteAccount" :disabled="deleting"
class="inline-flex items-center gap-2 px-5 py-2 rounded-full bg-red-600 text-white text-sm font-semibold hover:bg-red-700 transition-colors disabled:opacity-50">
<Icon v-if="deleting" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
{{ t('account.deleteAccount.confirmButton') }}
</button>
</div>
</div>
</div>
</main>
</template>
<style scoped>
.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>