feat: 收官补齐全部未实现功能

- 账号体系:修改密码(/account + PATCH /api/auth/password)、自助删除账号
  (DELETE /api/auth/me)、订阅退订(token + /unsubscribe 页)
- 前台/SEO:RSS 订阅 /feed.xml、作品详情分享、canonical URL、
  文章 Article JSON-LD、品牌化错误页(i18n)
- 后台增强:图片管理 /admin/uploads、操作审计日志 /admin/audit(含清空)、
  联系消息已读标记、评论列表分页
- 工程:vitest 测试(密码哈希/内容校验器/种子完整性,12 例)+ pnpm test
- DB 迁移:contacts.read、subscribers.token、audit_logs(老库 ALTER 兼容)
- 密码逻辑抽为 server/utils/password.ts 供测试
This commit is contained in:
2026-08-06 17:26:26 +08:00
parent d67849a311
commit 685c7b51d1
47 changed files with 1600 additions and 72 deletions
+36
View File
@@ -25,6 +25,7 @@
<div class="flex items-center gap-2 mb-4">
<span class="text-sm text-gray-500">共 {{ contacts.length }} 条消息</span>
<span class="text-sm text-gray-400">· 已送达 {{ deliveredCount }} 条</span>
<span class="text-sm text-gray-400">· 未读 {{ unreadCount }} 条</span>
</div>
<!-- 加载中 -->
@@ -80,6 +81,23 @@
<Icon :name="Number(c.delivered) === 1 ? 'ph:check' : 'ph:clock'" class="w-3.5 h-3.5" />
{{ Number(c.delivered) === 1 ? '已送达' : '未送达' }}
</span>
<span
class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs"
:class="Number(c.read) === 1 ? 'bg-gray-100 text-gray-500' : 'bg-black text-white font-bold'"
>
<Icon :name="Number(c.read) === 1 ? 'ph:envelope-open' : 'ph:envelope-simple'" class="w-3.5 h-3.5" />
{{ Number(c.read) === 1 ? '已读' : '未读' }}
</span>
<button
@click="toggleRead(c)"
:disabled="togglingId === c.id"
class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full border text-xs font-semibold transition-colors disabled:opacity-50"
:class="Number(c.read) === 1 ? 'border-gray-200 text-gray-500 hover:bg-gray-100' : 'border-black text-black hover:bg-black hover:text-white'"
>
<Icon v-if="togglingId === c.id" name="ph:circle-notch" class="w-3.5 h-3.5 animate-spin" />
<Icon v-else :name="Number(c.read) === 1 ? 'ph:envelope-simple-open' : 'ph:check-circle'" class="w-3.5 h-3.5" />
{{ Number(c.read) === 1 ? '标为未读' : '标为已读' }}
</button>
<button
@click="removeContact(c)"
class="w-8 h-8 rounded-full flex items-center justify-center text-gray-400 hover:bg-red-50 hover:text-red-600 transition-colors"
@@ -111,6 +129,7 @@ interface AdminContact {
subject: string
message: string
delivered: number
read: number
createdAt: string
}
@@ -119,6 +138,7 @@ const loading = ref(true)
const loadError = ref('')
const deliveredCount = computed(() => contacts.value.filter((c) => Number(c.delivered) === 1).length)
const unreadCount = computed(() => contacts.value.filter((c) => Number(c.read) !== 1).length)
const flash = ref('')
const flashKind = ref<'ok' | 'err'>('ok')
@@ -146,6 +166,22 @@ const loadContacts = async () => {
}
}
const togglingId = ref<number | null>(null)
const toggleRead = async (c: AdminContact) => {
const next = Number(c.read) === 1 ? 0 : 1
togglingId.value = c.id
try {
await $fetch(`/api/admin/contacts/${c.id}`, { method: 'PATCH', body: { read: next } })
c.read = next
showFlash(next === 1 ? '已标记为已读' : '已标记为未读')
} catch (err) {
console.error('toggle contact read error:', err)
showFlash((err as any)?.data?.message || '操作失败,请重试', 'err')
} finally {
togglingId.value = null
}
}
const removeContact = async (c: AdminContact) => {
if (!window.confirm(`确定删除「${c.name}」的这条消息吗?此操作不可恢复。`)) return
try {