数据结构优化

This commit is contained in:
李琦
2026-01-19 16:14:08 +08:00
parent 6d789c7c2a
commit 68c4c6df1c
36 changed files with 4063 additions and 760 deletions

View File

@@ -95,6 +95,16 @@
</div>
</div>
<!-- Column Field -->
<div class="space-y-2">
<label for="column" class="block text-xs font-medium text-art-muted uppercase tracking-wider">专栏 <span class="text-art-muted text-xs">(可选)</span></label>
<CustomSelect
v-model="form.columnId"
:options="columns"
placeholder="选择专栏(可选)"
/>
</div>
<!-- Tags Field -->
<div class="space-y-2">
<label class="block text-xs font-medium text-art-muted uppercase tracking-wider">标签</label>
@@ -157,7 +167,7 @@ import { MdEditor } from 'md-editor-v3'
import 'md-editor-v3/lib/style.css'
import { useToast } from '../../composables/useToast'
import { createPost, updatePost, fetchPost, fetchCategories, fetchTags, Category, Tag } from '../../services/api'
import { createPost, updatePost, fetchPost, fetchCategories, fetchColumns, fetchTags, Category, Tag } from '../../services/api'
import CustomSelect from '../../components/CustomSelect.vue'
const router = useRouter()
@@ -177,12 +187,14 @@ const errors = reactive<Record<string, string>>({})
// Data sources
const categories = ref<{value: number, label: string}[]>([])
const columns = ref<{value: number, label: string}[]>([])
const availableTags = ref<Tag[]>([])
// Form data
const form = reactive({
title: '',
categoryId: 0,
columnId: 0,
date: new Date().toISOString().split('T')[0],
excerpt: '',
content: '',
@@ -254,7 +266,7 @@ const handleSubmit = async () => {
try {
// Construct payload
const payload = {
const payload: any = {
title: form.title,
categoryId: form.categoryId,
date: form.date,
@@ -264,6 +276,13 @@ const handleSubmit = async () => {
tags: form.tagIds.map(id => ({ id } as any)) // Backend expects objects with ID
}
// Add columnId if selected
if (form.columnId > 0) {
payload.columnId = form.columnId
} else {
payload.columnId = null
}
if (isEditing.value) {
// Update existing post
await updatePost(route.params.id as string, payload)
@@ -292,9 +311,10 @@ const handleCancel = () => {
// Load initial data
const loadData = async () => {
try {
// Fetch categories and tags in parallel
const [cats, tags] = await Promise.all([
// Fetch categories, columns and tags in parallel
const [cats, cols, tagList] = await Promise.all([
fetchCategories(),
fetchColumns(),
fetchTags()
])
@@ -303,7 +323,12 @@ const loadData = async () => {
label: c.name
}))
availableTags.value = tags
columns.value = cols.map(c => ({
value: c.id,
label: c.name
}))
availableTags.value = tagList
// If editing, load post data
if (isEditing.value) {
@@ -313,6 +338,7 @@ const loadData = async () => {
// Populate form with post data
form.title = post.title
form.categoryId = post.categoryId
form.columnId = post.columnId || 0
form.date = post.date
form.excerpt = post.excerpt || ''
form.content = post.content || ''