数据结构优化

This commit is contained in:
李琦
2026-01-19 20:21:09 +08:00
parent 68c4c6df1c
commit 7e918cedd4
39 changed files with 3703 additions and 824 deletions

View File

@@ -29,7 +29,10 @@
<form @submit.prevent="handleSubmit" class="flex-1 flex overflow-hidden gap-6 relative">
<!-- Left Column: Main Editor -->
<div class="flex-1 flex flex-col min-w-0 transition-all duration-300 ease-in-out h-full">
<div class="admin-card flex-1 flex flex-col overflow-hidden border border-white/10 focus-within:border-art-accent/50 transition-colors">
<div
class="admin-card flex-1 flex flex-col overflow-hidden border border-white/10 focus-within:border-art-accent/50 transition-colors"
@paste="handlePaste"
>
<MdEditor
v-model="form.content"
theme="dark"
@@ -308,6 +311,71 @@ const handleCancel = () => {
router.push('/admin/posts')
}
// Handle paste event for image upload
const handlePaste = async (e: ClipboardEvent) => {
const items = e.clipboardData?.items
if (!items) return
// Check if any item is an image
let hasImage = false
for (let i = 0; i < items.length; i++) {
if (items[i].type.startsWith('image/')) {
hasImage = true
break
}
}
if (!hasImage) return
// Prevent default paste behavior for images
e.preventDefault()
for (let i = 0; i < items.length; i++) {
const item = items[i]
if (item.type.startsWith('image/')) {
const file = item.getAsFile()
if (!file) continue
try {
// Upload image
const formData = new FormData()
formData.append('file', file)
formData.append('categoryId', '1') // 默认上传到分类1
formData.append('storageType', 'local')
const token = localStorage.getItem('token')
const response = await fetch('http://localhost:8081/api/admin/attachments/upload', {
method: 'POST',
headers: {
...(token ? { Authorization: `Bearer ${token}` } : {})
},
body: formData
})
if (!response.ok) {
const errorData = await response.json()
throw new Error(errorData.message || '上传失败')
}
const data = await response.json()
const imageUrl = data.result.fileUrl
// Insert markdown image syntax
const imageMarkdown = `![${file.name}](${imageUrl})`
const currentContent = form.content
// Insert at the end of content (md-editor-v3 will handle cursor position)
form.content = currentContent + (currentContent ? '\n\n' : '') + imageMarkdown + '\n'
toast.showToast('图片上传成功', 'success')
} catch (error: any) {
console.error('上传图片失败:', error)
toast.showToast(error.message || '上传图片失败', 'error')
}
break // Only handle first image
}
}
}
// Load initial data
const loadData = async () => {
try {