feat: 后台管理系统完整重构 + 前后台数据联通

- 后台全面引入 Naive UI 组件库,统一 UI 规范
- 前台 usePublicApi 切换到 API 调用(GET /api/content/[key])
- 前后台数据源统一(site_content 表)
- 产品线统一管理(tour/camp/course 三套编辑器)
- 产品数据归一化(itinerary/faq/pricing 格式统一)
- 表单提交 API 改写入 submissions 表
- 新增 submissions 标记已读 API
- site-content PUT 支持 upsert
- 修复前台 bug(stories 路由冲突、占位符警告、selector breadcrumb)
- 消除 PageHero 类型警告(useSEO reactive 修复)
- 25 个前台页面全部 HTTP 200,展示效果不变

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
这个提交包含在:
Mimingguang
2026-03-24 17:48:02 +08:00
共同撰写人 Claude Opus 4.6
当前提交 ee078b61bc
共修改 444 个文件,包含 59890 行新增和 0 行删除
+133
查看文件
@@ -0,0 +1,133 @@
<template>
<div style="max-width: 1100px">
<n-breadcrumb style="margin-bottom: 16px">
<n-breadcrumb-item @click="navigateTo('/admin/articles')">最新动态</n-breadcrumb-item>
<n-breadcrumb-item>{{ isNew ? '新增' : '编辑' }}</n-breadcrumb-item>
</n-breadcrumb>
<n-space justify="space-between" align="center" style="margin-bottom: 24px">
<h1 style="margin: 0; font-size: 20px; font-weight: 600; color: #111827">{{ isNew ? '新增动态' : '编辑动态' }}</h1>
<n-space>
<n-button secondary @click="navigateTo('/admin/articles')">取消</n-button>
<n-button type="primary" :loading="saving" @click="handleSave">保存</n-button>
</n-space>
</n-space>
<n-card v-if="loadError" style="text-align: center; color: #ef4444">{{ loadError }}</n-card>
<n-spin v-else-if="pageLoading" style="display: flex; justify-content: center; padding: 60px" />
<template v-else>
<div class="form-layout">
<div class="form-main">
<n-card title="基本信息">
<n-form label-placement="top">
<n-form-item label="标题" required>
<n-input v-model:value="form.title" placeholder="输入文章标题" />
</n-form-item>
<n-form-item label="Slug" required>
<n-input v-model:value="form.slug" placeholder="URL 标识,如 news-2026-spring" />
<template #feedback>用于生成文章链接,仅限英文、数字和短横线</template>
</n-form-item>
<n-form-item label="摘要">
<n-input v-model:value="form.summary" type="textarea" :rows="3" placeholder="简要描述文章内容(可选)" />
</n-form-item>
<n-form-item label="正文">
<n-input v-model:value="form.content" type="textarea" :rows="16" placeholder="输入文章正文,支持 HTML" />
</n-form-item>
</n-form>
</n-card>
</div>
<div class="form-sidebar">
<n-card title="发布设置">
<n-form label-placement="top">
<n-form-item label="状态">
<n-select v-model:value="form.published" :options="[{ label: '已发布', value: true }, { label: '草稿', value: false }]" />
</n-form-item>
<n-form-item label="分类">
<n-select v-model:value="form.category" :options="[{ label: '产品', value: '产品' }, { label: '公告', value: '公告' }, { label: '活动', value: '活动' }]" />
</n-form-item>
</n-form>
</n-card>
<n-card title="封面图">
<AdminImageUpload v-model="form.coverImage" />
</n-card>
<n-card v-if="!isNew" title="其他信息" size="small">
<n-descriptions :column="1" label-placement="left" size="small">
<n-descriptions-item label="创建时间">{{ form.createdAt?.slice(0, 16).replace('T', ' ') }}</n-descriptions-item>
<n-descriptions-item label="更新时间">{{ form.updatedAt?.slice(0, 16).replace('T', ' ') }}</n-descriptions-item>
<n-descriptions-item label="ID">{{ route.params.id }}</n-descriptions-item>
</n-descriptions>
</n-card>
</div>
</div>
<n-alert v-if="formError" type="error" style="margin-top: 12px">{{ formError }}</n-alert>
<div class="save-bar">
<n-button secondary @click="navigateTo('/admin/articles')">取消</n-button>
<n-button type="primary" :loading="saving" @click="handleSave">保存</n-button>
</div>
</template>
</div>
</template>
<script setup>
import { NButton, NCard, NSpace, NInput, NForm, NFormItem, NSelect, NBreadcrumb, NBreadcrumbItem, NSpin, NDescriptions, NDescriptionsItem, NAlert } from 'naive-ui'
import { useMessage } from 'naive-ui'
definePageMeta({ layout: 'admin', middleware: 'admin' })
const route = useRoute()
const { adminFetch } = useAdmin()
const message = useMessage()
const isNew = computed(() => route.params.id === 'new')
const pageLoading = ref(!isNew.value)
const loadError = ref('')
const saving = ref(false)
const formError = ref('')
const form = ref({
title: '', slug: '', category: '产品', summary: '', content: '',
coverImage: '', published: true, createdAt: '', updatedAt: '',
})
async function loadItem() {
if (isNew.value) return
pageLoading.value = true
try {
const data = await adminFetch(`/api/admin/articles/${route.params.id}`)
form.value = { ...data, published: !!data.published, coverImage: data.coverImage || '' }
} catch (e) { loadError.value = e.data?.message || '加载失败' }
finally { pageLoading.value = false }
}
async function handleSave() {
if (!form.value.title?.trim()) { formError.value = '标题不能为空'; return }
if (!form.value.slug?.trim()) { formError.value = 'Slug 不能为空'; return }
saving.value = true; formError.value = ''
try {
if (isNew.value) {
await adminFetch('/api/admin/articles', { method: 'POST', body: { ...form.value, type: 'news' } })
message.success('创建成功')
setTimeout(() => navigateTo('/admin/articles'), 800)
} else {
await adminFetch(`/api/admin/articles/${route.params.id}`, { method: 'PUT', body: form.value })
message.success('保存成功')
}
} catch (e) { formError.value = e.data?.message || '保存失败' }
finally { saving.value = false }
}
onMounted(loadItem)
</script>
<style scoped>
.form-layout { display: grid; grid-template-columns: 1fr 300px; gap: 20px; align-items: start; }
.form-main { min-width: 0; }
.form-sidebar { display: flex; flex-direction: column; gap: 16px; }
.save-bar { position: sticky; bottom: 0; display: flex; justify-content: flex-end; gap: 8px; padding: 16px 0; margin-top: 24px; background: #f0f2f5; border-top: 1px solid #e5e7eb; }
</style>
+108
查看文件
@@ -0,0 +1,108 @@
<template>
<div style="max-width: 1200px">
<n-space justify="space-between" align="center" style="margin-bottom: 20px">
<div>
<h1 style="margin: 0 0 4px; font-size: 20px; font-weight: 600; color: #111827">最新动态</h1>
<p style="margin: 0; font-size: 13px; color: #9ca3af">管理官网新闻动态 · 对应官网「最新动态」页面</p>
</div>
<n-space>
<n-button tag="a" href="/news" target="_blank" secondary>查看前台</n-button>
<n-button type="primary" @click="navigateTo('/admin/articles/new')">新增动态</n-button>
</n-space>
</n-space>
<n-card>
<n-space style="margin-bottom: 16px">
<n-input v-model:value="search" placeholder="搜索标题、分类..." clearable style="width: 260px" @keyup.enter="page = 1; loadData()">
<template #prefix><span style="color: #9ca3af">&#128269;</span></template>
</n-input>
<n-button @click="page = 1; loadData()">搜索</n-button>
</n-space>
<n-data-table :columns="columns" :data="list" :loading="loading" :row-key="(row) => row.id" :pagination="false" size="small" striped />
<n-space justify="end" style="margin-top: 16px" v-if="totalPages > 1">
<n-pagination v-model:page="page" :page-count="totalPages" @update:page="loadData" />
</n-space>
</n-card>
</div>
</template>
<script setup>
import { h } from 'vue'
import { NButton, NCard, NSpace, NInput, NDataTable, NTag, NPagination, NPopconfirm } from 'naive-ui'
import { useMessage } from 'naive-ui'
definePageMeta({ layout: 'admin', middleware: 'admin' })
const { adminFetch } = useAdmin()
const message = useMessage()
const list = ref([])
const total = ref(0)
const page = ref(1)
const totalPages = ref(1)
const loading = ref(false)
const search = ref('')
const columns = [
{ title: 'ID', key: 'id', width: 50, render: (row) => h('span', { style: 'color: #9ca3af; font-size: 12px' }, row.id) },
{
title: '标题', key: 'title',
render: (row) => h('a', {
style: 'color: #111827; text-decoration: none; font-weight: 500; cursor: pointer',
onClick: () => navigateTo(`/admin/articles/${row.id}`),
}, row.title),
},
{
title: '分类', key: 'category', width: 80,
render: (row) => row.category ? h(NTag, { size: 'small', type: 'info', bordered: false }, () => row.category) : '-',
},
{
title: '状态', key: 'published', width: 70,
render: (row) => h(NTag, {
size: 'small', type: row.published ? 'success' : 'default', bordered: false,
style: 'cursor: pointer',
onClick: () => togglePublish(row),
}, () => row.published ? '已发布' : '草稿'),
},
{
title: '创建时间', key: 'createdAt', width: 100,
render: (row) => h('span', { style: 'color: #9ca3af; font-size: 12px' }, row.createdAt?.slice(0, 10)),
},
{
title: '操作', key: 'actions', width: 120,
render: (row) => h(NSpace, { size: 'small' }, () => [
h(NButton, { size: 'tiny', text: true, type: 'primary', onClick: () => navigateTo(`/admin/articles/${row.id}`) }, () => '编辑'),
h(NPopconfirm, { onPositiveClick: () => handleDelete(row) }, {
trigger: () => h(NButton, { size: 'tiny', text: true, type: 'error' }, () => '删除'),
default: () => `确定删除「${row.title}」?`,
}),
]),
},
]
async function loadData() {
loading.value = true
try {
const d = await adminFetch(`/api/admin/articles?type=news&page=${page.value}&limit=20&search=${encodeURIComponent(search.value)}`)
list.value = d.items; total.value = d.total; totalPages.value = d.totalPages
} catch { message.error('加载失败') } finally { loading.value = false }
}
async function togglePublish(item) {
try {
await adminFetch(`/api/admin/articles/${item.id}`, { method: 'PUT', body: { published: !item.published } })
item.published = !item.published
} catch { message.error('操作失败') }
}
async function handleDelete(item) {
try {
await adminFetch(`/api/admin/articles/${item.id}`, { method: 'DELETE' })
message.success('已删除')
loadData()
} catch { message.error('删除失败') }
}
onMounted(loadData)
</script>