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 行删除
+154
查看文件
@@ -0,0 +1,154 @@
<template>
<div style="max-width: 800px;">
<NBreadcrumb style="margin-bottom: 16px;">
<NBreadcrumbItem>
<NuxtLink to="/admin/content/selector">产品选择器</NuxtLink>
</NBreadcrumbItem>
<NBreadcrumbItem>Q{{ idx + 1 }}: {{ form.text || '编辑' }}</NBreadcrumbItem>
</NBreadcrumb>
<NSpace justify="space-between" align="center" style="margin-bottom: 24px;">
<div style="font-size: 20px; font-weight: 600; color: #111827;">编辑问题 Q{{ idx + 1 }}</div>
<NSpace :size="8">
<NuxtLink to="/admin/content/selector">
<NButton>返回列表</NButton>
</NuxtLink>
<NButton type="primary" :loading="saving" @click="handleSave">保存</NButton>
</NSpace>
</NSpace>
<NSpin :show="pageLoading">
<template v-if="!pageLoading">
<NCard style="margin-bottom: 16px;">
<template #header>
<span style="font-size: 14px; font-weight: 600; color: #374151;">问题设置</span>
</template>
<NForm label-placement="top">
<NFormItem label="问题文本">
<NInput v-model:value="form.text" />
</NFormItem>
<NFormItem label="提示语">
<NInput v-model:value="form.hint" />
</NFormItem>
<NGrid v-if="form.condition" :cols="2" :x-gap="12">
<NGi>
<NFormItem label="条件:依赖问题">
<NInput v-model:value="form.condition.key" placeholder="如 q2" />
</NFormItem>
</NGi>
<NGi>
<NFormItem label="条件:选择值">
<NInput v-model:value="form.condition.value" />
</NFormItem>
</NGi>
</NGrid>
</NForm>
</NCard>
<NCard style="margin-bottom: 16px;">
<template #header>
<NSpace justify="space-between" align="center">
<span style="font-size: 14px; font-weight: 600; color: #374151;">选项 ({{ form.options?.length || 0 }})</span>
<NButton size="small" type="primary" @click="addOption">+ 添加选项</NButton>
</NSpace>
</template>
<NSpace vertical :size="10">
<div
v-for="(opt, i) in (form.options || [])"
:key="i"
style="display: flex; gap: 12px; align-items: flex-start; padding: 14px; background: #f9fafb; border: 1px solid #f3f4f6; border-radius: 8px;"
>
<div style="width: 28px; height: 28px; background: #e5e7eb; color: #374151; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; margin-top: 4px;">
{{ i + 1 }}
</div>
<div style="flex: 1;">
<NGrid :cols="2" :x-gap="8">
<NGi>
<NFormItem label="标签" label-style="font-size: 13px;" style="margin-bottom: 8px;">
<NInput v-model:value="opt.label" size="small" />
</NFormItem>
</NGi>
<NGi>
<NFormItem label="值" label-style="font-size: 13px;" style="margin-bottom: 8px;">
<NInput v-model:value="opt.value" size="small" />
</NFormItem>
</NGi>
<NGi :span="2">
<NFormItem label="描述" label-style="font-size: 13px;" style="margin-bottom: 0;">
<NInput v-model:value="opt.desc" size="small" />
</NFormItem>
</NGi>
</NGrid>
</div>
<NButton size="small" type="error" ghost @click="form.options.splice(i, 1)" style="flex-shrink: 0; margin-top: 4px;">删除</NButton>
</div>
</NSpace>
</NCard>
<div v-if="formError" style="color: #ef4444; font-size: 13px; margin-bottom: 12px;">{{ formError }}</div>
<div class="save-bar">
<NuxtLink to="/admin/content/selector">
<NButton>返回列表</NButton>
</NuxtLink>
<NButton type="primary" :loading="saving" @click="handleSave">保存</NButton>
</div>
</template>
</NSpin>
</div>
</template>
<script setup>
import { NButton, NCard, NSpace, NInput, NForm, NFormItem, NSpin, NGrid, NGi, NBreadcrumb, NBreadcrumbItem } from 'naive-ui'
import { useMessage } from 'naive-ui'
definePageMeta({ layout: 'admin', middleware: 'admin', name: 'admin-content-selector-edit' })
const message = useMessage()
const route = useRoute()
const { adminFetch } = useAdmin()
const idx = computed(() => Number(route.params.idx))
const form = ref({})
const pageLoading = ref(true)
const saving = ref(false)
const formError = ref('')
async function loadItem() {
try {
const res = await adminFetch('/api/admin/site-content?key=selector')
const q = res.data.questions?.[idx.value]
if (!q) { formError.value = '不存在'; return }
form.value = JSON.parse(JSON.stringify(q))
} catch (e) {
formError.value = '加载失败'
} finally {
pageLoading.value = false
}
}
function addOption() {
if (!form.value.options) form.value.options = []
form.value.options.push({ label: '', value: '', desc: '' })
}
async function handleSave() {
saving.value = true
formError.value = ''
try {
const res = await adminFetch('/api/admin/site-content?key=selector')
res.data.questions[idx.value] = form.value
await adminFetch('/api/admin/site-content', { method: 'PUT', body: { key: 'selector', data: res.data } })
message.success('保存成功')
} catch (e) {
formError.value = e.data?.message || '保存失败'
message.error(formError.value)
} finally {
saving.value = false
}
}
onMounted(loadItem)
</script>
<style scoped>
.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>
+89
查看文件
@@ -0,0 +1,89 @@
<template>
<div style="max-width: 900px;">
<NSpace justify="space-between" align="start" style="margin-bottom: 20px;">
<div>
<div style="font-size: 20px; font-weight: 600; color: #111827; margin-bottom: 4px;">产品选择器</div>
<div style="font-size: 13px; color: #9ca3af;">管理产品推荐问答和评分逻辑 · 对应官网「帮你选」功能</div>
</div>
<a href="/selector" target="_blank">
<NButton>查看前台</NButton>
</a>
</NSpace>
<NSpin :show="!loaded">
<template v-if="loaded">
<!-- 问题列表 -->
<div style="font-size: 14px; font-weight: 600; color: #374151; margin-bottom: 10px;">
问题列表 ({{ data.questions?.length || 0 }})
</div>
<NSpace vertical :size="8" style="margin-bottom: 24px;">
<NuxtLink
v-for="(q, i) in data.questions"
:key="i"
:to="`/admin/content/selector/${i}`"
style="text-decoration: none; color: inherit; display: block;"
>
<NCard
size="small"
hoverable
style="cursor: pointer;"
:content-style="{ padding: '14px 20px' }"
>
<NSpace justify="space-between" align="center">
<NSpace align="center" :size="14">
<div style="width: 36px; height: 36px; background: #3a7d44; color: #fff; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex-shrink: 0;">
Q{{ i + 1 }}
</div>
<div>
<div style="font-size: 14px; font-weight: 600; color: #111827; margin-bottom: 2px;">{{ q.text }}</div>
<div style="font-size: 12px; color: #9ca3af;">{{ q.hint }}</div>
</div>
</NSpace>
<NSpace align="center" :size="8">
<NTag type="success" size="small">{{ q.options?.length || 0 }} 个选项</NTag>
<NTag v-if="q.condition" type="warning" size="small">条件显示</NTag>
<span style="font-size: 20px; color: #d1d5db;">›</span>
</NSpace>
</NSpace>
</NCard>
</NuxtLink>
</NSpace>
<!-- 评分矩阵 -->
<div style="font-size: 14px; font-weight: 600; color: #374151; margin-bottom: 10px;">评分矩阵</div>
<NCard style="margin-bottom: 24px;" :content-style="{ padding: '20px' }">
<div style="font-size: 13px; color: #6b7280; margin-bottom: 12px;">每个问题的每个选项对应各产品的评分权重,用于计算最终推荐排名。</div>
<NuxtLink to="/admin/content/selector/scoring" style="color: #3a7d44; font-size: 14px; font-weight: 500; text-decoration: none;">
编辑评分矩阵 ›
</NuxtLink>
</NCard>
<!-- 推荐理由 -->
<div style="font-size: 14px; font-weight: 600; color: #374151; margin-bottom: 10px;">推荐理由</div>
<NCard :content-style="{ padding: '20px' }">
<div style="font-size: 13px; color: #6b7280; margin-bottom: 12px;">每个产品在不同匹配情况下的推荐文案。</div>
<NuxtLink to="/admin/content/selector/reasons" style="color: #3a7d44; font-size: 14px; font-weight: 500; text-decoration: none;">
编辑推荐理由 ›
</NuxtLink>
</NCard>
</template>
</NSpin>
</div>
</template>
<script setup>
import { NButton, NCard, NSpace, NTag, NSpin } from 'naive-ui'
definePageMeta({ layout: 'admin', middleware: 'admin' })
const { adminFetch } = useAdmin()
const data = ref({ questions: [] })
const loaded = ref(false)
onMounted(async () => {
try {
const r = await adminFetch('/api/admin/site-content?key=selector')
data.value = r.data
} catch {}
loaded.value = true
})
</script>
+94
查看文件
@@ -0,0 +1,94 @@
<template>
<div style="max-width: 900px;">
<NBreadcrumb style="margin-bottom: 16px;">
<NBreadcrumbItem>
<NuxtLink to="/admin/content/selector">产品选择器</NuxtLink>
</NBreadcrumbItem>
<NBreadcrumbItem>推荐理由</NBreadcrumbItem>
</NBreadcrumb>
<NSpace justify="space-between" align="center" style="margin-bottom: 16px;">
<div style="font-size: 20px; font-weight: 600; color: #111827;">推荐理由</div>
<NSpace :size="8">
<NuxtLink to="/admin/content/selector">
<NButton>返回</NButton>
</NuxtLink>
<NButton type="primary" :loading="saving" @click="handleSave">保存</NButton>
</NSpace>
</NSpace>
<NSpin :show="!loaded">
<template v-if="loaded">
<div style="font-size: 13px; color: #6b7280; margin-bottom: 20px;">
每个产品在不同匹配情况下展示的推荐文案。
</div>
<NCard
v-for="(reasons, pid) in matchReasons"
:key="pid"
style="margin-bottom: 16px;"
>
<template #header>
<span style="font-size: 14px; font-weight: 600; color: #374151;">{{ pid }}</span>
</template>
<NForm label-placement="top">
<NFormItem
v-for="(text, rKey) in reasons"
:key="rKey"
:label="rKey"
:label-style="{ fontFamily: 'monospace', fontSize: '12px', color: '#9ca3af' }"
>
<NInput v-model:value="matchReasons[pid][rKey]" />
</NFormItem>
</NForm>
</NCard>
<div class="save-bar">
<NuxtLink to="/admin/content/selector">
<NButton>返回</NButton>
</NuxtLink>
<NButton type="primary" :loading="saving" @click="handleSave">保存</NButton>
</div>
</template>
</NSpin>
</div>
</template>
<script setup>
import { NButton, NCard, NSpace, NInput, NForm, NFormItem, NSpin, NBreadcrumb, NBreadcrumbItem } from 'naive-ui'
import { useMessage } from 'naive-ui'
definePageMeta({ layout: 'admin', middleware: 'admin' })
const message = useMessage()
const { adminFetch } = useAdmin()
const fullData = ref({})
const matchReasons = ref({})
const loaded = ref(false)
const saving = ref(false)
async function load() {
const res = await adminFetch('/api/admin/site-content?key=selector')
fullData.value = res.data
matchReasons.value = JSON.parse(JSON.stringify(res.data.matchReasons || {}))
loaded.value = true
}
async function handleSave() {
saving.value = true
try {
fullData.value.matchReasons = matchReasons.value
await adminFetch('/api/admin/site-content', { method: 'PUT', body: { key: 'selector', data: fullData.value } })
message.success('保存成功')
} catch {
message.error('保存失败')
} finally {
saving.value = false
}
}
onMounted(load)
</script>
<style scoped>
.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>
+136
查看文件
@@ -0,0 +1,136 @@
<template>
<div style="max-width: 1100px;">
<NBreadcrumb style="margin-bottom: 16px;">
<NBreadcrumbItem>
<NuxtLink to="/admin/content/selector">产品选择器</NuxtLink>
</NBreadcrumbItem>
<NBreadcrumbItem>评分矩阵</NBreadcrumbItem>
</NBreadcrumb>
<NSpace justify="space-between" align="center" style="margin-bottom: 16px;">
<div style="font-size: 20px; font-weight: 600; color: #111827;">评分矩阵</div>
<NSpace :size="8">
<NuxtLink to="/admin/content/selector">
<NButton>返回</NButton>
</NuxtLink>
<NButton type="primary" :loading="saving" @click="handleSave">保存</NButton>
</NSpace>
</NSpace>
<NSpin :show="!loaded">
<template v-if="loaded">
<div style="font-size: 13px; color: #6b7280; margin-bottom: 20px;">
每个问题的每个选项对应各产品的评分(0-10),分数越高越推荐该产品。
</div>
<NCard
v-for="(qScores, qId) in scoring"
:key="qId"
style="margin-bottom: 16px;"
>
<template #header>
<span style="font-size: 14px; font-weight: 600; color: #374151;">
{{ qId }} — {{ questionTexts[qId] || '' }}
</span>
</template>
<div style="overflow-x: auto;">
<table style="width: 100%; border-collapse: collapse; font-size: 13px;">
<thead>
<tr>
<th style="padding: 6px 8px; border: 1px solid #e5e7eb; background: #f9fafb; font-weight: 600; color: #374151; font-size: 11px; white-space: nowrap; text-align: center;">选项</th>
<th
v-for="pid in productIds"
:key="pid"
style="padding: 6px 8px; border: 1px solid #e5e7eb; background: #f9fafb; font-weight: 600; color: #374151; font-size: 11px; white-space: nowrap; text-align: center;"
>{{ pid }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(products, optValue) in qScores" :key="optValue">
<td style="padding: 6px 8px; border: 1px solid #e5e7eb; text-align: left; font-weight: 500; color: #111827; white-space: nowrap; min-width: 100px;">{{ optValue }}</td>
<td v-for="pid in productIds" :key="pid" style="padding: 6px 8px; border: 1px solid #e5e7eb; text-align: center;">
<NInputNumber
:value="products[pid] || 0"
:min="0"
:max="10"
size="small"
style="width: 64px;"
:show-button="false"
@update:value="val => setScore(qId, optValue, pid, Number(val || 0))"
/>
</td>
</tr>
</tbody>
</table>
</div>
</NCard>
<div class="save-bar">
<NuxtLink to="/admin/content/selector">
<NButton>返回</NButton>
</NuxtLink>
<NButton type="primary" :loading="saving" @click="handleSave">保存</NButton>
</div>
</template>
</NSpin>
</div>
</template>
<script setup>
import { NButton, NCard, NSpace, NInputNumber, NSpin, NBreadcrumb, NBreadcrumbItem } from 'naive-ui'
import { useMessage } from 'naive-ui'
definePageMeta({ layout: 'admin', middleware: 'admin' })
const message = useMessage()
const { adminFetch } = useAdmin()
const fullData = ref({})
const scoring = ref({})
const questionTexts = ref({})
const productIds = ref([])
const loaded = ref(false)
const saving = ref(false)
async function load() {
const res = await adminFetch('/api/admin/site-content?key=selector')
fullData.value = res.data
scoring.value = JSON.parse(JSON.stringify(res.data.scoring || {}))
// 收集所有产品 ID
const pids = new Set()
for (const q of Object.values(scoring.value)) {
for (const opts of Object.values(q)) {
for (const pid of Object.keys(opts)) pids.add(pid)
}
}
productIds.value = [...pids].sort()
// 问题文本映射
for (const q of (res.data.questions || [])) {
questionTexts.value[q.id] = q.text
}
loaded.value = true
}
function setScore(qId, optValue, pid, val) {
if (!scoring.value[qId][optValue]) scoring.value[qId][optValue] = {}
if (val > 0) scoring.value[qId][optValue][pid] = val
else delete scoring.value[qId][optValue][pid]
}
async function handleSave() {
saving.value = true
try {
fullData.value.scoring = scoring.value
await adminFetch('/api/admin/site-content', { method: 'PUT', body: { key: 'selector', data: fullData.value } })
message.success('保存成功')
} catch {
message.error('保存失败')
} finally {
saving.value = false
}
}
onMounted(load)
</script>
<style scoped>
.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>