feat: 后台管理系统(Admin Backend + 全量 CMS)
- 内容迁入数据库:articles/works 表(中英双语 + 内容块), server/utils/seed.ts 灌入现有 6 动态 + 6 作品,站点初始内容不变 - 前台内容 API:/api/news、/api/work(列表/详情,仅已发布), 页面/首页组件改为 useFetch 拉取并按 locale 选 zh/en 字段 - 后台管理 /admin(admin 中间件守卫): - Dashboard 统计、动态/作品增删改(块编辑器、图片上传 /api/admin/upload) - 用户管理(角色切换/删除)、评论审核、联系/订阅管理(导出 CSV) - 预置管理员:NUXT_ADMIN_INITIAL_PASSWORD 首次初始化创建 admin 账号 - 图片自托管:上传存 PVC /data/uploads,/uploads/[...] 路由服务 - sitemap 改查 DB;i18n 移除内容键(305 键对齐);删除 app/data 冗余模块 - 角色以数据库为准(后台可切换);admin 中间件 + 客户端会话恢复插件
This commit is contained in:
@@ -0,0 +1,171 @@
|
||||
<template>
|
||||
<section class="p-4 md:p-8 lg:p-10">
|
||||
<header class="mb-8 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
|
||||
<div class="flex items-center gap-3">
|
||||
<div class="w-11 h-11 rounded-2xl bg-black text-white flex items-center justify-center flex-shrink-0">
|
||||
<Icon name="ph:envelope" class="w-6 h-6" />
|
||||
</div>
|
||||
<div>
|
||||
<h1 class="text-2xl font-bold text-black leading-tight">邮件订阅</h1>
|
||||
<p class="text-sm text-gray-500 mt-1">订阅了站内更新的邮箱列表,可导出 CSV。</p>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
:href="'/api/admin/subscribers/export'"
|
||||
class="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors flex-shrink-0"
|
||||
title="导出全部订阅邮箱"
|
||||
>
|
||||
<Icon name="ph:download-simple" class="w-4 h-4" />
|
||||
导出 CSV
|
||||
</a>
|
||||
</header>
|
||||
|
||||
<!-- 操作反馈 -->
|
||||
<div
|
||||
v-if="flash"
|
||||
class="mb-6 px-4 py-3 rounded-xl text-sm font-medium flex items-center gap-2"
|
||||
:class="flashKind === 'ok' ? 'bg-green-50 text-green-700 border border-green-200' : 'bg-red-50 text-red-700 border border-red-200'"
|
||||
>
|
||||
<Icon :name="flashKind === 'ok' ? 'ph:check-circle' : 'ph:warning-circle'" class="w-4 h-4" />
|
||||
{{ flash }}
|
||||
</div>
|
||||
|
||||
<div class="flex items-center gap-2 mb-4">
|
||||
<span class="text-sm text-gray-500">共 {{ subscribers.length }} 个订阅</span>
|
||||
</div>
|
||||
|
||||
<!-- 加载中 -->
|
||||
<div v-if="loading" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:circle-notch" class="w-8 h-8 animate-spin" />
|
||||
<p class="text-sm">加载中…</p>
|
||||
</div>
|
||||
|
||||
<!-- 加载失败 -->
|
||||
<div v-else-if="loadError" class="py-24 text-center">
|
||||
<div class="inline-flex flex-col items-center gap-3 text-gray-500">
|
||||
<Icon name="ph:warning-circle" class="w-8 h-8 text-red-500" />
|
||||
<p class="text-sm">{{ loadError }}</p>
|
||||
<button @click="loadSubscribers" class="px-5 py-2 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors">
|
||||
重试
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 空态 -->
|
||||
<div v-else-if="!subscribers.length" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:envelope" class="w-10 h-10" />
|
||||
<p class="text-sm">暂无订阅</p>
|
||||
</div>
|
||||
|
||||
<!-- 订阅表格 -->
|
||||
<div v-else class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
|
||||
<div class="overflow-x-auto">
|
||||
<table class="w-full text-sm">
|
||||
<thead>
|
||||
<tr class="text-left text-gray-500 border-b border-gray-100 bg-gray-50">
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider">邮箱</th>
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">订阅时间</th>
|
||||
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider text-right">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="s in subscribers"
|
||||
:key="s.id"
|
||||
class="border-b border-gray-100 last:border-b-0 hover:bg-gray-50/70 transition-colors"
|
||||
>
|
||||
<td class="px-6 py-4">
|
||||
<a :href="`mailto:${s.email}`" class="inline-flex items-center gap-2 font-semibold text-black hover:text-gray-600 transition-colors">
|
||||
<Icon name="ph:envelope-simple" class="w-4 h-4 text-gray-400" />
|
||||
{{ s.email }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-500 text-xs whitespace-nowrap">{{ formatDate(s.createdAt) }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center justify-end">
|
||||
<button
|
||||
@click="removeSubscriber(s)"
|
||||
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"
|
||||
title="删除订阅"
|
||||
>
|
||||
<Icon name="ph:trash" class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
|
||||
definePageMeta({ middleware: 'admin', layout: 'admin' })
|
||||
useSeoMeta({ title: '邮件订阅' })
|
||||
|
||||
interface AdminSubscriber {
|
||||
id: number
|
||||
email: string
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
const subscribers = ref<AdminSubscriber[]>([])
|
||||
const loading = ref(true)
|
||||
const loadError = ref('')
|
||||
|
||||
const flash = ref('')
|
||||
const flashKind = ref<'ok' | 'err'>('ok')
|
||||
let flashTimer: ReturnType<typeof setTimeout> | null = null
|
||||
const showFlash = (msg: string, kind: 'ok' | 'err' = 'ok') => {
|
||||
flash.value = msg
|
||||
flashKind.value = kind
|
||||
if (flashTimer) clearTimeout(flashTimer)
|
||||
flashTimer = setTimeout(() => {
|
||||
flash.value = ''
|
||||
}, 3000)
|
||||
}
|
||||
|
||||
const loadSubscribers = async () => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ subscribers: AdminSubscriber[] }>('/api/admin/subscribers')
|
||||
subscribers.value = data.subscribers
|
||||
} catch (err) {
|
||||
console.error('load subscribers error:', err)
|
||||
loadError.value = '加载失败,请重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const removeSubscriber = async (s: AdminSubscriber) => {
|
||||
if (!window.confirm(`确定取消订阅「${s.email}」吗?此操作不可恢复。`)) return
|
||||
try {
|
||||
await $fetch(`/api/admin/subscribers/${s.id}`, { method: 'DELETE' })
|
||||
subscribers.value = subscribers.value.filter((x) => x.id !== s.id)
|
||||
showFlash(`已取消订阅「${s.email}」`)
|
||||
} catch (err) {
|
||||
console.error('delete subscriber error:', err)
|
||||
showFlash((err as any)?.data?.message || '删除失败,请重试', 'err')
|
||||
}
|
||||
}
|
||||
|
||||
const formatDate = (raw?: string) => {
|
||||
if (!raw) return ''
|
||||
const d = new Date(String(raw).replace(' ', 'T') + 'Z')
|
||||
if (Number.isNaN(d.getTime())) return raw
|
||||
return new Intl.DateTimeFormat('zh-CN', {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
}).format(d)
|
||||
}
|
||||
|
||||
onMounted(loadSubscribers)
|
||||
</script>
|
||||
Reference in New Issue
Block a user