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:
2026-08-06 16:15:14 +08:00
parent 5c3f3bca63
commit d67849a311
67 changed files with 4909 additions and 754 deletions
+709
View File
@@ -0,0 +1,709 @@
<script setup lang="ts">
/**
* 后台作品管理:列表 + 新建/编辑表单。
* - 列表来自 /api/admin/works(含未发布)
* - 新建 POST /api/admin/works;编辑 PATCH /api/admin/works/[id];删除 DELETE /api/admin/works/[id]
* - tags 逗号分隔输入;gallery 多 URL 行(每行可上传)
*/
import { onMounted, reactive, ref } from 'vue'
definePageMeta({ middleware: 'admin', layout: 'admin' })
useHead({ title: '作品管理' })
interface Work {
id?: number
slug: string
category: 'webDesign' | 'branding' | 'development'
titleZh: string
titleEn: string
descriptionZh: string
descriptionEn: string
overviewZh: string
overviewEn: string
challengeZh: string
challengeEn: string
solutionZh: string
solutionEn: string
clientZh: string
clientEn: string
durationZh: string
durationEn: string
year: string
tags: string[]
image: string | null
gallery: string[]
url: string | null
published: number
createdAt: string
updatedAt: string
}
const CATEGORIES = [
{ value: 'webDesign', label: '网页设计' },
{ value: 'branding', label: '品牌设计' },
{ value: 'development', label: '程序开发' },
]
const catLabel = (c: string) => CATEGORIES.find((x) => x.value === c)?.label ?? c
/* ---------- 列表 ---------- */
const works = ref<Work[]>([])
const loading = ref(true)
const error = ref('')
const loadWorks = async () => {
loading.value = true
error.value = ''
try {
const res = await $fetch<{ works: Work[] }>('/api/admin/works')
works.value = res.works
} catch (err: any) {
error.value = err?.data?.message || '加载失败'
} finally {
loading.value = false
}
}
onMounted(loadWorks)
/* ---------- 提示 ---------- */
const message = ref('')
const messageType = ref<'success' | 'error'>('success')
let toastTimer: ReturnType<typeof setTimeout> | undefined
const toast = (text: string, type: 'success' | 'error' = 'success') => {
message.value = text
messageType.value = type
if (toastTimer) clearTimeout(toastTimer)
toastTimer = setTimeout(() => (message.value = ''), 3000)
}
/* ---------- 表单 ---------- */
const view = ref<'list' | 'form'>('list')
const editingId = ref<number | null>(null)
const saving = ref(false)
const formError = ref('')
const emptyForm = () => ({
slug: '',
category: 'webDesign' as Work['category'],
titleZh: '',
titleEn: '',
descriptionZh: '',
descriptionEn: '',
overviewZh: '',
overviewEn: '',
challengeZh: '',
challengeEn: '',
solutionZh: '',
solutionEn: '',
clientZh: '',
clientEn: '',
durationZh: '',
durationEn: '',
year: String(new Date().getFullYear()),
image: '',
gallery: [''] as string[],
url: '',
published: true,
})
const form = reactive(emptyForm())
const tagsText = ref('')
const openCreate = () => {
Object.assign(form, emptyForm())
tagsText.value = ''
editingId.value = null
formError.value = ''
view.value = 'form'
window.scrollTo({ top: 0, behavior: 'smooth' })
}
const openEdit = (w: Work) => {
if (w.id == null) {
toast('该条目缺少 id 字段,暂时无法编辑(后端待补)', 'error')
return
}
editingId.value = w.id
Object.assign(form, {
slug: w.slug,
category: w.category,
titleZh: w.titleZh,
titleEn: w.titleEn,
descriptionZh: w.descriptionZh,
descriptionEn: w.descriptionEn,
overviewZh: w.overviewZh,
overviewEn: w.overviewEn,
challengeZh: w.challengeZh,
challengeEn: w.challengeEn,
solutionZh: w.solutionZh,
solutionEn: w.solutionEn,
clientZh: w.clientZh,
clientEn: w.clientEn,
durationZh: w.durationZh,
durationEn: w.durationEn,
year: w.year,
image: w.image ?? '',
gallery: w.gallery.length ? [...w.gallery] : [''],
url: w.url ?? '',
published: !!w.published,
})
tagsText.value = w.tags.join(', ')
formError.value = ''
view.value = 'form'
window.scrollTo({ top: 0, behavior: 'smooth' })
}
const backToList = () => {
view.value = 'list'
window.scrollTo({ top: 0, behavior: 'smooth' })
}
const save = async () => {
formError.value = ''
if (!/^[a-z0-9-]{2,64}$/.test(form.slug)) {
formError.value = 'slug 需为 2-64 位小写字母/数字/中划线'
return
}
if (!form.titleZh.trim() || !form.titleEn.trim()) {
formError.value = '中英文标题均为必填'
return
}
saving.value = true
try {
const payload = {
slug: form.slug,
category: form.category,
titleZh: form.titleZh,
titleEn: form.titleEn,
descriptionZh: form.descriptionZh,
descriptionEn: form.descriptionEn,
overviewZh: form.overviewZh,
overviewEn: form.overviewEn,
challengeZh: form.challengeZh,
challengeEn: form.challengeEn,
solutionZh: form.solutionZh,
solutionEn: form.solutionEn,
clientZh: form.clientZh,
clientEn: form.clientEn,
durationZh: form.durationZh,
durationEn: form.durationEn,
year: form.year,
tags: tagsText.value.split(',').map((t) => t.trim()).filter(Boolean),
image: form.image || null,
gallery: form.gallery.filter((u) => u.trim()),
url: form.url.trim() || null,
published: form.published,
}
if (editingId.value != null) {
await $fetch(`/api/admin/works/${editingId.value}`, { method: 'PATCH', body: payload })
toast('作品已更新')
} else {
await $fetch('/api/admin/works', { method: 'POST', body: payload })
toast('作品已创建')
}
await loadWorks()
view.value = 'list'
} catch (err: any) {
formError.value = err?.data?.message || '保存失败'
} finally {
saving.value = false
}
}
/* ---------- 删除 ---------- */
const confirmDelete = ref<Work | null>(null)
const deleting = ref(false)
const askDelete = (w: Work) => {
if (w.id == null) {
toast('该条目缺少 id 字段,暂时无法删除(后端待补)', 'error')
return
}
confirmDelete.value = w
}
const doDelete = async () => {
const w = confirmDelete.value
if (!w || w.id == null) return
deleting.value = true
try {
await $fetch(`/api/admin/works/${w.id}`, { method: 'DELETE' })
toast(`已删除「${w.titleZh}」`)
confirmDelete.value = null
await loadWorks()
} catch (err: any) {
toast(err?.data?.message || '删除失败', 'error')
} finally {
deleting.value = false
}
}
/* ---------- 图集(gallery)上传 ---------- */
const galleryFileInput = ref<HTMLInputElement | null>(null)
const uploadingIndex = ref<number | null>(null)
const galleryUploading = ref(false)
const galleryError = ref('')
const pickGalleryFile = (i: number) => {
uploadingIndex.value = i
galleryFileInput.value?.click()
}
const onGalleryFile = async (e: Event) => {
const input = e.target as HTMLInputElement
const file = input.files?.[0]
input.value = ''
if (!file || uploadingIndex.value == null) return
galleryUploading.value = true
galleryError.value = ''
try {
const fd = new FormData()
fd.append('file', file)
const res = await $fetch<{ ok: boolean; url: string }>('/api/admin/upload', {
method: 'POST',
body: fd,
})
form.gallery[uploadingIndex.value] = res.url
} catch (err: any) {
galleryError.value = err?.data?.message || '上传失败'
} finally {
galleryUploading.value = false
}
}
const addGalleryRow = () => form.gallery.push('')
const removeGalleryRow = (i: number) => form.gallery.splice(i, 1)
</script>
<template>
<div>
<!-- 页头 -->
<div class="flex items-center justify-between gap-4 mb-8">
<div>
<h1 class="text-2xl md:text-3xl font-bold text-black tracking-tight">作品管理</h1>
<p v-if="view === 'list'" class="mt-1 text-sm text-gray-500">共 {{ works.length }} 个作品</p>
</div>
<button
v-if="view === 'list'"
type="button"
@click="openCreate"
class="inline-flex items-center gap-2 px-4 py-2 rounded-lg bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors"
>
<Icon name="ph:plus" class="w-4 h-4" /> 新建作品
</button>
<button
v-else
type="button"
@click="backToList"
class="inline-flex items-center gap-2 px-4 py-2 rounded-lg border border-gray-200 bg-white text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors"
>
<Icon name="ph:arrow-left" class="w-4 h-4" /> 返回列表
</button>
</div>
<!-- 提示 -->
<div
v-if="message"
class="mb-6 px-4 py-3 rounded-xl text-sm font-medium border"
:class="messageType === 'success' ? 'bg-green-50 border-green-200 text-green-700' : 'bg-red-50 border-red-200 text-red-700'"
>
{{ message }}
</div>
<!-- ==================== 列表视图 ==================== -->
<template v-if="view === 'list'">
<div v-if="loading" class="space-y-3">
<div
v-for="i in 6"
:key="i"
class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 h-16 animate-pulse"
></div>
</div>
<div
v-else-if="error"
class="rounded-2xl bg-white border border-gray-100 shadow-sm p-10 text-center"
>
<Icon name="ph:warning-circle" class="w-10 h-10 text-gray-300 mx-auto mb-4" />
<p class="text-gray-500 mb-4">{{ error }}</p>
<button
type="button"
@click="loadWorks"
class="px-5 py-2 rounded-lg bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors"
>
重新加载
</button>
</div>
<div
v-else-if="!works.length"
class="rounded-2xl bg-white border border-gray-100 shadow-sm p-14 text-center"
>
<Icon name="ph:image-square" class="w-10 h-10 text-gray-300 mx-auto mb-4" />
<p class="text-gray-500 mb-4">还没有作品,点击右上角「新建作品」创建第一个</p>
</div>
<div v-else class="rounded-2xl bg-white border border-gray-100 shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-gray-400 border-b border-gray-100">
<th class="px-5 py-4 font-semibold">标题</th>
<th class="px-5 py-4 font-semibold">分类</th>
<th class="px-5 py-4 font-semibold">年份</th>
<th class="px-5 py-4 font-semibold">标签</th>
<th class="px-5 py-4 font-semibold">状态</th>
<th class="px-5 py-4 font-semibold text-right">操作</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-50">
<tr
v-for="w in works"
:key="w.slug"
class="hover:bg-gray-50/60 transition-colors"
>
<td class="px-5 py-4">
<div class="flex items-center gap-3">
<img
v-if="w.image"
:src="w.image"
:alt="w.titleZh"
class="w-10 h-10 rounded-lg object-cover border border-gray-100 flex-shrink-0"
/>
<div v-else class="w-10 h-10 rounded-lg bg-gray-100 flex items-center justify-center flex-shrink-0">
<Icon name="ph:image" class="w-4 h-4 text-gray-400" />
</div>
<div class="min-w-0">
<p class="font-semibold text-black truncate">{{ w.titleZh }}</p>
<p class="text-xs text-gray-400 mt-0.5 font-mono truncate">{{ w.slug }}</p>
</div>
</div>
</td>
<td class="px-5 py-4">
<span class="px-2.5 py-1 rounded-full bg-gray-100 text-gray-700 text-xs font-medium">
{{ catLabel(w.category) }}
</span>
</td>
<td class="px-5 py-4 text-gray-600 whitespace-nowrap">{{ w.year || '-' }}</td>
<td class="px-5 py-4">
<div class="flex flex-wrap gap-1.5 max-w-[220px]">
<span
v-for="tag in w.tags.slice(0, 3)"
:key="tag"
class="px-2 py-0.5 rounded-full bg-gray-50 text-gray-500 text-xs"
>
{{ tag }}
</span>
<span v-if="w.tags.length > 3" class="text-xs text-gray-400">+{{ w.tags.length - 3 }}</span>
</div>
</td>
<td class="px-5 py-4">
<span
class="px-2.5 py-1 rounded-full text-xs font-semibold inline-flex items-center gap-1"
:class="w.published ? 'bg-green-50 text-green-700' : 'bg-amber-50 text-amber-700'"
>
<span
class="w-1.5 h-1.5 rounded-full"
:class="w.published ? 'bg-green-500' : 'bg-amber-500'"
></span>
{{ w.published ? '已发布' : '草稿' }}
</span>
</td>
<td class="px-5 py-4">
<div class="flex items-center justify-end gap-2">
<button
type="button"
@click="openEdit(w)"
class="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-gray-100 text-gray-700 text-xs font-semibold hover:bg-gray-200 transition-colors"
>
<Icon name="ph:pencil-simple" class="w-3.5 h-3.5" /> 编辑
</button>
<button
type="button"
@click="askDelete(w)"
class="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-lg bg-red-50 text-red-600 text-xs font-semibold hover:bg-red-100 transition-colors"
>
<Icon name="ph:trash" class="w-3.5 h-3.5" /> 删除
</button>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</template>
<!-- ==================== 表单视图 ==================== -->
<template v-else>
<div class="space-y-6 max-w-4xl">
<!-- 基本信息 -->
<section class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 md:p-6">
<h3 class="text-sm font-bold text-gray-900 mb-4 flex items-center gap-2">
<Icon name="ph:info" class="w-4 h-4 text-gray-400" /> 基本信息
</h3>
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">
slug<span class="text-red-500">*</span>
</label>
<input
v-model="form.slug"
type="text"
placeholder="如 forma-digital"
class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 font-mono"
/>
<p class="mt-1 text-xs text-gray-400">2-64 位小写字母 / 数字 / 中划线,用于前台链接</p>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">分类</label>
<select
v-model="form.category"
class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black"
>
<option v-for="c in CATEGORIES" :key="c.value" :value="c.value">{{ c.label }}</option>
</select>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">年份</label>
<input
v-model="form.year"
type="text"
placeholder="如 2026"
class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black"
/>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">
标签<span class="text-gray-400 font-normal">(逗号分隔)</span>
</label>
<input
v-model="tagsText"
type="text"
placeholder="Web Design, React, E-commerce"
class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black"
/>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">
外部链接<span class="text-gray-400 font-normal">(可选)</span>
</label>
<input
v-model="form.url"
type="text"
placeholder="https://… 留空则前台不显示访问按钮"
class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black"
/>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">发布状态</label>
<button
type="button"
class="inline-flex items-center gap-3 group mt-1"
@click="form.published = !form.published"
>
<span
class="relative w-11 h-6 rounded-full transition-colors duration-300"
:class="form.published ? 'bg-black' : 'bg-gray-300'"
>
<span
class="absolute top-0.5 left-0.5 w-5 h-5 rounded-full bg-white shadow transition-transform duration-300"
:class="form.published ? 'translate-x-5' : ''"
></span>
</span>
<span class="text-sm" :class="form.published ? 'text-green-700 font-semibold' : 'text-gray-500'">
{{ form.published ? '已发布(前台可见)' : '草稿(前台隐藏)' }}
</span>
</button>
</div>
</div>
</section>
<!-- 标题与简介 -->
<section class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 md:p-6">
<h3 class="text-sm font-bold text-gray-900 mb-4 flex items-center gap-2">
<Icon name="ph:text-aa" class="w-4 h-4 text-gray-400" /> 标题与简介
</h3>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
<div class="space-y-4">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">中文标题<span class="text-red-500">*</span></label>
<input v-model="form.titleZh" type="text" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5" />
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">中文简介</label>
<textarea v-model="form.descriptionZh" rows="3" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
</div>
<div class="space-y-4">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">English Title<span class="text-red-500">*</span></label>
<input v-model="form.titleEn" type="text" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5" />
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">English Description</label>
<textarea v-model="form.descriptionEn" rows="3" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
</div>
</div>
</section>
<!-- 项目详情(中英) -->
<section class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 md:p-6">
<h3 class="text-sm font-bold text-gray-900 mb-4 flex items-center gap-2">
<Icon name="ph:notebook" class="w-4 h-4 text-gray-400" /> 项目详情(中英各一组)
</h3>
<div class="space-y-6">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
<div class="space-y-4">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">中文概述(Overview)</label>
<textarea v-model="form.overviewZh" rows="4" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">中文挑战(Challenge)</label>
<textarea v-model="form.challengeZh" rows="3" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">中文方案(Solution)</label>
<textarea v-model="form.solutionZh" rows="3" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
</div>
<div class="space-y-4">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">English Overview</label>
<textarea v-model="form.overviewEn" rows="4" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">English Challenge</label>
<textarea v-model="form.challengeEn" rows="3" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">English Solution</label>
<textarea v-model="form.solutionEn" rows="3" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/5 resize-y"></textarea>
</div>
</div>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-5">
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">中文客户(Client)</label>
<input v-model="form.clientZh" type="text" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black" />
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">English Client</label>
<input v-model="form.clientEn" type="text" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black" />
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">中文周期(Duration)</label>
<input v-model="form.durationZh" type="text" placeholder="如 3 个月" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black" />
</div>
<div>
<label class="block text-sm font-semibold text-gray-800 mb-2">English Duration</label>
<input v-model="form.durationEn" type="text" placeholder="如 3 months" class="w-full px-3 py-2.5 rounded-lg border border-gray-200 bg-white text-sm outline-none focus:border-black" />
</div>
</div>
</div>
</section>
<!-- 封面图 -->
<section class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 md:p-6">
<h3 class="text-sm font-bold text-gray-900 mb-4 flex items-center gap-2">
<Icon name="ph:image" class="w-4 h-4 text-gray-400" /> 封面图
</h3>
<AdminImageUpload v-model="form.image" label="封面图" />
</section>
<!-- 作品图集 -->
<section class="rounded-2xl bg-white border border-gray-100 shadow-sm p-5 md:p-6">
<div class="flex items-center justify-between mb-4">
<h3 class="text-sm font-bold text-gray-900 flex items-center gap-2">
<Icon name="ph:images" class="w-4 h-4 text-gray-400" /> 作品图集(Gallery)
</h3>
<button
type="button"
@click="addGalleryRow"
class="flex items-center gap-1.5 px-3 py-1.5 rounded-lg border border-gray-200 text-xs font-semibold text-gray-700 hover:bg-gray-50 transition-colors"
>
<Icon name="ph:plus" class="w-3.5 h-3.5" /> 添加图片
</button>
</div>
<div class="space-y-3">
<div
v-for="(url, i) in form.gallery"
:key="i"
class="flex items-center gap-3 border border-gray-200 rounded-xl bg-white p-3"
>
<div class="flex-1 min-w-0">
<input
v-model="form.gallery[i]"
type="text"
placeholder="图片 URL(本地 /uploads/... 或 https://...)"
class="w-full px-3 py-2 rounded-lg border border-gray-200 bg-gray-50 text-sm outline-none transition-all focus:border-black focus:bg-white"
/>
<div v-if="url" class="mt-2">
<img :src="url" alt="图集预览" class="h-24 w-auto max-w-full rounded-lg border border-gray-100 object-cover" />
</div>
</div>
<button
type="button"
:disabled="galleryUploading && uploadingIndex === i"
@click="pickGalleryFile(i)"
class="flex items-center gap-1.5 px-3 py-2 rounded-lg bg-black text-white text-xs font-semibold hover:bg-gray-800 transition-colors disabled:opacity-60 flex-shrink-0"
>
<Icon
:name="galleryUploading && uploadingIndex === i ? 'ph:circle-notch' : 'ph:upload-simple'"
:class="galleryUploading && uploadingIndex === i ? 'w-3.5 h-3.5 animate-spin' : 'w-3.5 h-3.5'"
/>
{{ galleryUploading && uploadingIndex === i ? '上传中…' : '上传' }}
</button>
<button
type="button"
@click="removeGalleryRow(i)"
class="w-8 h-8 rounded-lg hover:bg-red-50 text-gray-400 hover:text-red-600 flex items-center justify-center transition-colors flex-shrink-0"
aria-label="删除该图"
>
<Icon name="ph:trash" class="w-4 h-4" />
</button>
</div>
<p v-if="galleryError" class="text-xs text-red-600">{{ galleryError }}</p>
</div>
<input ref="galleryFileInput" type="file" accept="image/*" class="hidden" @change="onGalleryFile" />
</section>
<!-- 提交 -->
<div class="flex items-center justify-end gap-3">
<p v-if="formError" class="mr-auto text-sm text-red-600">{{ formError }}</p>
<button
type="button"
@click="backToList"
class="px-5 py-2.5 rounded-lg border border-gray-200 bg-white text-sm font-semibold text-gray-700 hover:bg-gray-100 transition-colors"
>
取消
</button>
<button
type="button"
:disabled="saving"
@click="save"
class="px-6 py-2.5 rounded-lg bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors disabled:opacity-60 inline-flex items-center gap-2"
>
<Icon v-if="saving" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
{{ saving ? '保存中…' : editingId != null ? '保存修改' : '创建作品' }}
</button>
</div>
</div>
</template>
<!-- 删除确认 -->
<AdminConfirmDialog
:open="!!confirmDelete"
:loading="deleting"
title="删除作品"
:message="`确定要删除「${confirmDelete?.titleZh}」吗?该作品下的所有收藏将一并删除,此操作不可撤销。`"
confirm-text="删除"
@confirm="doDelete"
@cancel="confirmDelete = null"
/>
</div>
</template>