Files
arcticnewone/app/components/admin/AdminBlockEditor.vue
T
virtheart d67849a311 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 中间件 + 客户端会话恢复插件
2026-08-06 16:27:19 +08:00

131 lines
4.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
/**
* 后台正文内容块编辑器(动态/作品共用)。
* v-model 绑定块数组 `{ type, text }[]`,支持添加/删除/上移/下移。
* 图片块以 URL 文本承载。
*/
import { computed } from 'vue'
interface Block {
type: string
text: string
}
const props = withDefaults(defineProps<{ modelValue?: Block[]; label?: string; placeholder?: string }>(), {
modelValue: () => [],
label: '正文内容',
placeholder: '输入内容…',
})
const emit = defineEmits<{ 'update:modelValue': [value: Block[]] }>()
const blocks = computed({
get: () => props.modelValue,
set: (v) => emit('update:modelValue', v),
})
const BLOCK_TYPES = [
{ value: 'paragraph', label: '段落' },
{ value: 'heading', label: '标题' },
{ value: 'quote', label: '引用' },
{ value: 'image', label: '图片' },
]
const addBlock = () => {
blocks.value = [...blocks.value, { type: 'paragraph', text: '' }]
}
const removeBlock = (i: number) => {
blocks.value = blocks.value.filter((_, idx) => idx !== i)
}
const moveUp = (i: number) => {
if (i === 0) return
const arr = [...blocks.value]
const tmp = arr[i - 1]
arr[i - 1] = arr[i]
arr[i] = tmp
blocks.value = arr
}
const moveDown = (i: number) => {
if (i >= blocks.value.length - 1) return
const arr = [...blocks.value]
const tmp = arr[i + 1]
arr[i + 1] = arr[i]
arr[i] = tmp
blocks.value = arr
}
</script>
<template>
<div>
<div class="flex items-center justify-between mb-2">
<label class="text-sm font-semibold text-gray-800">{{ label }}</label>
<button
type="button"
@click="addBlock"
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-if="!blocks.length"
class="text-sm text-gray-400 py-6 text-center border border-dashed border-gray-200 rounded-xl"
>
暂无内容块,点击「添加块」开始
</div>
<div
v-for="(block, i) in blocks"
:key="i"
class="border border-gray-200 rounded-xl bg-white p-3"
>
<div class="flex items-center gap-2 mb-2">
<select
v-model="block.type"
class="px-2 py-1.5 rounded-lg border border-gray-200 text-xs outline-none focus:border-black bg-white"
>
<option v-for="t in BLOCK_TYPES" :key="t.value" :value="t.value">{{ t.label }}</option>
</select>
<span class="text-xs text-gray-400">
{{ block.type === 'image' ? '图片 URL' : '文本内容' }}
</span>
<div class="ml-auto flex items-center gap-1">
<button
type="button"
:disabled="i === 0"
@click="moveUp(i)"
class="w-7 h-7 rounded-lg hover:bg-gray-100 text-gray-500 disabled:opacity-30 flex items-center justify-center transition-colors"
aria-label="上移"
>
<Icon name="ph:arrow-up" class="w-3.5 h-3.5" />
</button>
<button
type="button"
:disabled="i >= blocks.length - 1"
@click="moveDown(i)"
class="w-7 h-7 rounded-lg hover:bg-gray-100 text-gray-500 disabled:opacity-30 flex items-center justify-center transition-colors"
aria-label="下移"
>
<Icon name="ph:arrow-down" class="w-3.5 h-3.5" />
</button>
<button
type="button"
@click="removeBlock(i)"
class="w-7 h-7 rounded-lg hover:bg-red-50 text-gray-400 hover:text-red-600 flex items-center justify-center transition-colors"
aria-label="删除"
>
<Icon name="ph:trash" class="w-3.5 h-3.5" />
</button>
</div>
</div>
<textarea
v-model="block.text"
:rows="block.type === 'image' ? 2 : 4"
:placeholder="block.type === 'image' ? '图片 URL(如 /uploads/xxx 或 https://…)' : placeholder"
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 resize-y"
></textarea>
</div>
</div>
</div>
</template>