Mimingguang ee078b61bc 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>
2026-03-24 17:48:02 +08:00

129 行
5.2 KiB
Vue

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<template>
<div>
<n-space justify="space-between" align="flex-start" style="margin-bottom: 20px;">
<div>
<div style="font-size: 22px; font-weight: 600; color: #111827; margin-bottom: 4px;">出行指南</div>
<div style="font-size: 13px; color: #9ca3af;">管理出行准备指南各章节内容对应官网出行指南页面</div>
</div>
<n-space>
<a href="/guides" target="_blank" style="text-decoration: none;">
<n-button>查看前台 </n-button>
</a>
<n-button type="primary" :loading="saving" :disabled="saving" @click="save">
{{ saving ? '保存中...' : '保存' }}
</n-button>
</n-space>
</n-space>
<n-spin v-if="!loaded" style="display:block; padding: 60px; text-align: center;" />
<template v-else>
<n-card title="页面介绍" style="margin-bottom: 12px;">
<n-input v-model:value="data.pageIntro" type="textarea" :rows="3" />
</n-card>
<n-card
v-for="(s, i) in data.sections"
:key="i"
style="margin-bottom: 12px;"
>
<template #header>
<div
style="display: flex; justify-content: space-between; align-items: center; cursor: pointer; user-select: none;"
@click="open[i] = !open[i]"
>
<span style="font-size: 15px; color: #333;">{{ s.icon || '' }} {{ s.title }}</span>
<n-space align="center">
<span style="font-size: 12px; color: #9ca3af;">{{ s.subtitle || '' }}</span>
<span style="font-size: 12px; color: #999; transition: transform 0.2s; display: inline-block;" :style="open[i] ? 'transform: rotate(90deg)' : ''">&#9656;</span>
</n-space>
</div>
</template>
<div v-show="open[i]">
<n-grid :cols="2" :x-gap="10" style="margin-bottom: 12px;">
<n-gi>
<n-form-item label="ID" :show-feedback="false">
<n-input v-model:value="s.id" size="small" />
</n-form-item>
</n-gi>
<n-gi>
<n-form-item label="标题" :show-feedback="false">
<n-input v-model:value="s.title" size="small" />
</n-form-item>
</n-gi>
<n-gi>
<n-form-item label="副标题" :show-feedback="false">
<n-input v-model:value="s.subtitle" size="small" />
</n-form-item>
</n-gi>
<n-gi>
<n-form-item label="图标" :show-feedback="false">
<n-input v-model:value="s.icon" size="small" />
</n-form-item>
</n-gi>
</n-grid>
<n-form-item label="正文内容" :show-feedback="false" style="margin-bottom: 10px;">
<n-input v-model:value="s.content" type="textarea" :rows="4" />
</n-form-item>
<n-form-item v-if="s.tips" label="Tips每行一个" :show-feedback="false" style="margin-bottom: 10px;">
<n-input
type="textarea"
:rows="3"
:value="(s.tips||[]).join('\n')"
@input="s.tips = $event.split('\n').filter(Boolean)"
/>
</n-form-item>
<div v-if="s.items && s.items.length" style="margin-top: 14px; border-top: 1px solid #f0f0f0; padding-top: 10px;">
<div style="font-size: 14px; color: #555; margin-bottom: 10px; font-weight: 500;">子项列表</div>
<n-space v-for="(item, ii) in s.items" :key="ii" align="center" style="margin-bottom: 6px;">
<template v-if="typeof item === 'string'">
<n-input
:value="item"
@input="s.items[ii] = $event"
size="small"
style="flex: 1; min-width: 200px;"
/>
</template>
<template v-else>
<n-input v-model:value="item.text" placeholder="文字" size="small" style="flex: 1; min-width: 200px;" />
<n-tag
:type="item.important ? 'warning' : 'default'"
checkable
:checked="item.important"
@update:checked="item.important = $event"
size="small"
>
重要
</n-tag>
</template>
</n-space>
</div>
</div>
</n-card>
</template>
</div>
</template>
<script setup>
import { NButton, NCard, NSpace, NInput, NFormItem, NSpin, NGrid, NGi, NTag } from 'naive-ui'
import { useMessage } from 'naive-ui'
definePageMeta({ layout: 'admin', middleware: 'admin' })
const { adminFetch } = useAdmin()
const message = useMessage()
const data = ref({ pageIntro: '', sections: [] })
const loaded = ref(false)
const saving = ref(false)
const open = reactive({})
async function load() { const res = await adminFetch('/api/admin/site-content?key=guides'); data.value = res.data; loaded.value = true }
async function save() {
saving.value = true
try {
await adminFetch('/api/admin/site-content', { method: 'PUT', body: { key: 'guides', data: data.value } })
message.success('已保存')
} catch { message.error('保存失败') } finally { saving.value = false }
}
onMounted(load)
</script>