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:
+30
-68
@@ -26,6 +26,17 @@
|
||||
<p class="text-gray-500">{{ userStore.user?.email }}</p>
|
||||
</div>
|
||||
|
||||
<!-- 管理员入口 -->
|
||||
<div v-if="userStore.user?.role === 'admin'" class="flex justify-center mb-6">
|
||||
<NuxtLink
|
||||
to="/admin"
|
||||
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors"
|
||||
>
|
||||
<Icon name="ph:gear-six" class="w-4 h-4" />
|
||||
{{ t('account.adminEntry') }}
|
||||
</NuxtLink>
|
||||
</div>
|
||||
|
||||
<!-- 页签 -->
|
||||
<div class="flex justify-center gap-2 md:gap-3 mb-10 flex-wrap">
|
||||
<button
|
||||
@@ -83,19 +94,19 @@
|
||||
<p v-if="!favorites.length" class="text-center text-gray-500 py-12">{{ t('account.emptyFavorites') }}</p>
|
||||
<div v-else class="grid grid-cols-1 sm:grid-cols-2 gap-5">
|
||||
<div
|
||||
v-for="slug in favorites"
|
||||
:key="slug"
|
||||
v-for="fav in favorites"
|
||||
:key="fav.slug"
|
||||
class="group rounded-2xl overflow-hidden bg-white border border-gray-100 shadow-sm hover:shadow-xl transition-all duration-300"
|
||||
>
|
||||
<NuxtLink :to="`/work/${slug}`" class="block relative aspect-[4/3] overflow-hidden">
|
||||
<img :src="workBySlug[slug]?.image" :alt="t(`work.items.${slug}.title`)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
|
||||
<NuxtLink :to="`/work/${fav.slug}`" class="block relative aspect-[4/3] overflow-hidden">
|
||||
<img :src="fav.image" :alt="favTitle(fav)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
|
||||
</NuxtLink>
|
||||
<div class="p-5 flex items-center justify-between">
|
||||
<NuxtLink :to="`/work/${slug}`" class="font-bold text-black group-hover:text-gray-600 transition-colors">
|
||||
{{ t(`work.items.${slug}.title`) }}
|
||||
<NuxtLink :to="`/work/${fav.slug}`" class="font-bold text-black group-hover:text-gray-600 transition-colors">
|
||||
{{ favTitle(fav) }}
|
||||
</NuxtLink>
|
||||
<button
|
||||
@click="removeFavorite(slug)"
|
||||
@click="removeFavorite(fav.slug)"
|
||||
class="w-9 h-9 rounded-full bg-gray-50 text-gray-500 hover:bg-red-50 hover:text-red-600 flex items-center justify-center transition-colors"
|
||||
aria-label="unfavorite"
|
||||
>
|
||||
@@ -116,48 +127,13 @@
|
||||
>
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<NuxtLink :to="`/news/${comment.newsSlug}`" class="text-sm font-semibold text-black hover:text-gray-600">
|
||||
{{ t(`news.items.${comment.newsSlug}.title`) }}
|
||||
#{{ comment.newsSlug }}
|
||||
</NuxtLink>
|
||||
<span class="text-xs text-gray-400">{{ formatDate(comment.createdAt) }}</span>
|
||||
</div>
|
||||
<p class="text-gray-700 text-sm break-words">{{ comment.content }}</p>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 管理面板 -->
|
||||
<section v-if="activeTab === 'admin'" class="max-w-4xl mx-auto space-y-12">
|
||||
<div>
|
||||
<h3 class="text-xl font-bold text-black mb-5">{{ t('account.admin.contacts') }}</h3>
|
||||
<p v-if="!adminData.contacts.length" class="text-gray-500 text-center py-8">{{ t('account.admin.emptyContacts') }}</p>
|
||||
<div v-else class="space-y-4">
|
||||
<div v-for="c in adminData.contacts" :key="c.id" class="p-5 rounded-2xl bg-white border border-gray-100 shadow-sm">
|
||||
<div class="flex items-center justify-between mb-2">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="font-semibold text-black">{{ c.name }}</span>
|
||||
<span class="text-sm text-gray-500">{{ c.email }}</span>
|
||||
</div>
|
||||
<span class="text-xs px-2 py-1 rounded-full" :class="c.delivered ? 'bg-green-50 text-green-700' : 'bg-amber-50 text-amber-700'">
|
||||
{{ c.delivered ? t('account.admin.delivered') : t('account.admin.notDelivered') }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="text-sm font-semibold text-gray-700 mb-1">{{ c.subject }}</p>
|
||||
<p class="text-sm text-gray-600 whitespace-pre-line break-words mb-2">{{ c.message }}</p>
|
||||
<p class="text-xs text-gray-400">{{ formatDate(c.createdAt) }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<h3 class="text-xl font-bold text-black mb-5">{{ t('account.admin.subscribers') }}</h3>
|
||||
<p v-if="!adminData.subscribers.length" class="text-gray-500 text-center py-8">{{ t('account.admin.emptySubscribers') }}</p>
|
||||
<div v-else class="rounded-2xl overflow-hidden border border-gray-100 shadow-sm bg-white">
|
||||
<div v-for="s in adminData.subscribers" :key="s.id" class="flex items-center justify-between px-5 py-3 border-b border-gray-100 last:border-b-0">
|
||||
<span class="text-sm font-medium text-gray-700">{{ s.email }}</span>
|
||||
<span class="text-xs text-gray-400">{{ formatDate(s.createdAt) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
@@ -169,7 +145,6 @@ import { useSeoMeta } from '#imports'
|
||||
import gsap from 'gsap'
|
||||
import { useUserStore } from '~/stores/user'
|
||||
import { useAuthModalStore } from '~/stores/authModal'
|
||||
import { workBySlug } from '~/data/work'
|
||||
import { useApiError } from '~/composables/useApiError'
|
||||
|
||||
const { t, locale } = useI18n()
|
||||
@@ -187,9 +162,6 @@ const tabs = computed(() => {
|
||||
{ key: 'favorites', label: t('account.favorites') },
|
||||
{ key: 'comments', label: t('account.comments') },
|
||||
]
|
||||
if (userStore.user?.role === 'admin') {
|
||||
list.push({ key: 'admin', label: t('account.adminTitle') })
|
||||
}
|
||||
return list
|
||||
})
|
||||
|
||||
@@ -198,7 +170,6 @@ const switchTab = (key: string) => {
|
||||
activeTab.value = key
|
||||
if (key === 'favorites') loadFavorites()
|
||||
if (key === 'comments') loadComments()
|
||||
if (key === 'admin') loadAdmin()
|
||||
}
|
||||
|
||||
const formatDate = (raw?: string) => {
|
||||
@@ -241,11 +212,18 @@ const saveProfile = async () => {
|
||||
}
|
||||
|
||||
// ---- 收藏 ----
|
||||
const favorites = ref<string[]>([])
|
||||
interface FavedWork { slug: string; titleZh: string; titleEn: string; image: string | null }
|
||||
const favorites = ref<FavedWork[]>([])
|
||||
const favTitle = (w: FavedWork) => (locale.value === 'zh' ? w.titleZh : w.titleEn)
|
||||
|
||||
const loadFavorites = async () => {
|
||||
try {
|
||||
const data = await $fetch<{ slugs: string[] }>('/api/favorites')
|
||||
favorites.value = data.slugs
|
||||
const [favRes, workRes] = await Promise.all([
|
||||
$fetch<{ slugs: string[] }>('/api/favorites'),
|
||||
$fetch<{ works: FavedWork[] }>('/api/work'),
|
||||
])
|
||||
const bySlug = new Map(workRes.works.map((w) => [w.slug, w]))
|
||||
favorites.value = favRes.slugs.map((s) => bySlug.get(s)).filter(Boolean) as FavedWork[]
|
||||
} catch (err) {
|
||||
console.error('load favorites error:', err)
|
||||
}
|
||||
@@ -253,7 +231,7 @@ const loadFavorites = async () => {
|
||||
const removeFavorite = async (slug: string) => {
|
||||
try {
|
||||
await $fetch('/api/favorites', { method: 'DELETE', body: { workSlug: slug } })
|
||||
favorites.value = favorites.value.filter((s) => s !== slug)
|
||||
favorites.value = favorites.value.filter((f) => f.slug !== slug)
|
||||
} catch (err) {
|
||||
console.error('remove favorite error:', err)
|
||||
}
|
||||
@@ -270,22 +248,6 @@ const loadComments = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 管理面板 ----
|
||||
const adminData = reactive<{
|
||||
contacts: Array<{ id: number; name: string; email: string; subject: string; message: string; delivered: number; createdAt: string }>
|
||||
subscribers: Array<{ id: number; email: string; createdAt: string }>
|
||||
}>({ contacts: [], subscribers: [] })
|
||||
|
||||
const loadAdmin = async () => {
|
||||
try {
|
||||
const data = await $fetch<typeof adminData>('/api/account/admin')
|
||||
adminData.contacts = data.contacts
|
||||
adminData.subscribers = data.subscribers
|
||||
} catch (err) {
|
||||
console.error('load admin error:', err)
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 页面进场动画 ----
|
||||
const mainRef = ref<HTMLElement | null>(null)
|
||||
let ctx: gsap.Context | null = null
|
||||
|
||||
Reference in New Issue
Block a user