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,175 @@
|
||||
<template>
|
||||
<section class="p-4 md:p-8 lg:p-10">
|
||||
<header class="mb-8">
|
||||
<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-simple-open" 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">访客通过联系表单提交的留言,关注送达状态。</p>
|
||||
</div>
|
||||
</div>
|
||||
</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">共 {{ contacts.length }} 条消息</span>
|
||||
<span class="text-sm text-gray-400">· 已送达 {{ deliveredCount }} 条</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="loadContacts" 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="!contacts.length" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:envelope-simple-open" class="w-10 h-10" />
|
||||
<p class="text-sm">暂无联系消息</p>
|
||||
</div>
|
||||
|
||||
<!-- 消息卡片列表 -->
|
||||
<div v-else class="space-y-4">
|
||||
<div
|
||||
v-for="c in contacts"
|
||||
:key="c.id"
|
||||
class="bg-white rounded-2xl border border-gray-100 shadow-sm p-5 md:p-6 hover:shadow-md transition-shadow"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-4">
|
||||
<div class="flex items-center gap-3 min-w-0">
|
||||
<div class="w-10 h-10 rounded-full bg-black text-white flex items-center justify-center font-bold flex-shrink-0">
|
||||
{{ (c.name || '?').charAt(0) }}
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div class="flex items-center gap-2 flex-wrap">
|
||||
<h3 class="font-bold text-black">{{ c.name }}</h3>
|
||||
<a :href="`mailto:${c.email}`" class="text-sm text-gray-500 hover:text-black transition-colors truncate">
|
||||
{{ c.email }}
|
||||
</a>
|
||||
</div>
|
||||
<p class="text-xs text-gray-400 mt-1">{{ formatDate(c.createdAt) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2 flex-shrink-0">
|
||||
<span
|
||||
class="inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-semibold"
|
||||
:class="Number(c.delivered) === 1 ? 'bg-green-100 text-green-700' : 'bg-amber-100 text-amber-600'"
|
||||
>
|
||||
<Icon :name="Number(c.delivered) === 1 ? 'ph:check' : 'ph:clock'" class="w-3.5 h-3.5" />
|
||||
{{ Number(c.delivered) === 1 ? '已送达' : '未送达' }}
|
||||
</span>
|
||||
<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"
|
||||
title="删除消息"
|
||||
>
|
||||
<Icon name="ph:trash" class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-4 border-t border-gray-100 pt-4">
|
||||
<p class="text-sm font-semibold text-gray-800">{{ c.subject }}</p>
|
||||
<p class="mt-1.5 text-sm text-gray-600 whitespace-pre-line break-words">{{ c.message }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
|
||||
definePageMeta({ middleware: 'admin', layout: 'admin' })
|
||||
useSeoMeta({ title: '联系消息' })
|
||||
|
||||
interface AdminContact {
|
||||
id: number
|
||||
name: string
|
||||
email: string
|
||||
subject: string
|
||||
message: string
|
||||
delivered: number
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
const contacts = ref<AdminContact[]>([])
|
||||
const loading = ref(true)
|
||||
const loadError = ref('')
|
||||
|
||||
const deliveredCount = computed(() => contacts.value.filter((c) => Number(c.delivered) === 1).length)
|
||||
|
||||
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 loadContacts = async () => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
try {
|
||||
const data = await $fetch<{ contacts: AdminContact[] }>('/api/admin/contacts')
|
||||
contacts.value = data.contacts
|
||||
} catch (err) {
|
||||
console.error('load contacts error:', err)
|
||||
loadError.value = '加载失败,请重试'
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const removeContact = async (c: AdminContact) => {
|
||||
if (!window.confirm(`确定删除「${c.name}」的这条消息吗?此操作不可恢复。`)) return
|
||||
try {
|
||||
await $fetch(`/api/admin/contacts/${c.id}`, { method: 'DELETE' })
|
||||
contacts.value = contacts.value.filter((x) => x.id !== c.id)
|
||||
showFlash('消息已删除')
|
||||
} catch (err) {
|
||||
console.error('delete contact 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(loadContacts)
|
||||
</script>
|
||||
Reference in New Issue
Block a user