feat: improve admin workflows and open-source docs

This commit is contained in:
YGC
2026-07-02 21:38:54 +08:00
parent eb568d3786
commit 751fdddc71
22 changed files with 598 additions and 152 deletions
+3 -1
View File
@@ -63,8 +63,10 @@ function processDates(obj: any): any {
return obj
}
const apiBaseUrl = (import.meta.env.VITE_API_BASE_URL || '/api').replace(/\/+$/, '')
const request = axios.create({
baseURL: 'http://localhost:8080/api',
baseURL: apiBaseUrl,
timeout: 15000,
})
+3 -3
View File
@@ -81,7 +81,7 @@
</div>
<div class="flex items-center gap-3">
<n-upload
action="http://localhost:8080/api/blogs/upload?type=about"
action="/api/blogs/upload?type=about"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleAvatarUploadFinish"
@@ -161,7 +161,7 @@
</div>
<div class="flex items-center gap-3">
<n-upload
action="http://localhost:8080/api/blogs/upload?type=about"
action="/api/blogs/upload?type=about"
:headers="uploadHeaders"
:show-file-list="false"
@finish="(event) => handleCoordinateUploadFinish(Number(idx), event)"
@@ -255,7 +255,7 @@
</div>
<div class="flex items-center gap-3">
<n-upload
action="http://localhost:8080/api/blogs/upload?type=about"
action="/api/blogs/upload?type=about"
:headers="uploadHeaders"
:show-file-list="false"
@finish="(event) => handleFragmentUploadFinish(Number(idx), event)"
@@ -47,7 +47,7 @@
class="flex-1"
/>
<n-upload
action="http://localhost:8080/api/blogs/upload?type=achieve"
action="/api/blogs/upload?type=achieve"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleUploadFinish"
+22 -16
View File
@@ -15,25 +15,25 @@
</div>
<div class="flex items-center gap-2">
<n-button size="small" secondary type="warning" @click="triggerFileInput">
<n-button size="small" secondary type="primary" @click="triggerFileInput">
<template #icon>
<span class="i-mdi-file-import-outline"></span>
</template>
导入 Markdown (.md)
</n-button>
<input
type="file"
ref="fileInputRef"
accept=".md"
style="display: none"
@change="handleImportMarkdown"
<input
type="file"
ref="fileInputRef"
accept=".md,text/markdown"
class="hidden"
@change="handleImportMarkdown"
/>
</div>
</div>
<!-- 导言提醒 -->
<p class="m-0 text-xs tone-muted">
在这里可以享受宽广的随笔写作空间。支持直接使用 Markdown 格式输入正文,或者通过右上角按钮直接导入本地 Markdown 随笔文件。
支持直接使用 Markdown 格式输入正文,也可以通过右上角按钮导入由 Typora、PicGo 等工具处理好的 Markdown 文件。
</p>
<n-form ref="formRef" :model="formModel" :rules="formRules" label-placement="top">
@@ -77,7 +77,7 @@
<div class="flex-1 space-y-2.5 w-full">
<!-- 上传与输入组合 -->
<div class="flex items-center gap-2 w-full">
<n-input v-model:value="formModel.cover" placeholder="输入路径(如 /assets/writing-tokyo.png)或上传图片" class="flex-1" />
<n-input v-model:value="formModel.cover" placeholder="请输入封面地址,或使用右侧按钮选择图片" class="flex-1" />
<n-button type="info" secondary round @click="emit('open-gallery')" class="shrink-0">
<template #icon>
@@ -87,7 +87,7 @@
</n-button>
<n-upload
action="http://localhost:8080/api/blogs/upload?type=blog"
action="/api/blogs/upload?type=blog"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleUploadFinish"
@@ -190,13 +190,19 @@ const triggerFileInput = () => {
const handleImportMarkdown = (event: Event) => {
const input = event.target as HTMLInputElement
if (!input.files || input.files.length === 0) return
const file = input.files[0]
const file = input.files?.[0]
if (!file) return
const reader = new FileReader()
reader.onload = (e) => {
const text = e.target?.result as string
emit('import-md', text)
message.success(`本地 Markdown 文件「${file.name}」导入成功!`)
reader.onload = (loadEvent) => {
const content = String(loadEvent.target?.result || '').replace(/^\uFEFF/, '')
emit('import-md', content)
message.success(`Markdown 文件「${file.name}」导入成功`)
input.value = ''
}
reader.onerror = () => {
message.error(`无法读取 Markdown 文件「${file.name}」`)
input.value = ''
}
reader.readAsText(file)
}
+52 -18
View File
@@ -139,6 +139,7 @@ const formModel = ref({
const formRules = {
title: { required: true, message: '请输入文章标题', trigger: 'blur' },
content: { required: true, message: '请输入文章正文内容', trigger: 'blur' },
cover: { required: true, message: '请上传、选择或填写文章封面', trigger: ['blur', 'change'] },
categoryId: { required: true, type: 'number', message: '请选择文章归档分类', trigger: 'change' }
}
@@ -294,7 +295,7 @@ const openCreate = () => {
categoryId: categories.value[0]?.id || null,
mood: 'quiet',
visibility: 'public',
cover: '/assets/writing-tokyo.png'
cover: ''
}
showEditor.value = true
}
@@ -312,7 +313,7 @@ const openEdit = (blog: Blog) => {
categoryId: blog.categoryId ? Number(blog.categoryId) : null,
mood: blog.mood || 'quiet',
visibility: blog.visibility || 'public',
cover: blog.cover
cover: blog.cover || ''
}
showEditor.value = true
}
@@ -402,10 +403,32 @@ const generateAISummary = async () => {
}
}
// 导入 Markdown 文件
const handleImportMarkdownContent = (text: string) => {
// 从 Markdown 正文中提取第一个一级标题
const extractH1Title = (markdownText: string): string => {
if (!markdownText) return ''
// 1. 匹配 Atx 风格一级标题: ^# 标题 或 \n# 标题
const atxMatch = markdownText.match(/(?:^|\n)#\s+([^\n]+)/)
if (atxMatch && atxMatch[1].trim()) {
return atxMatch[1].trim().replace(/^[*_~`]+|[*_~`]+$/g, '')
}
// 2. 匹配 Setext 风格一级标题 (标题文本\n===)
const setextMatch = markdownText.match(/(?:^|\n)([^\n]+)\r?\n=+\s*(?:\n|$)/)
if (setextMatch && setextMatch[1].trim()) {
return setextMatch[1].trim()
}
return ''
}
// 导入 Markdown 文件;正文中的远程图片链接由渲染器直接解析
const handleImportMarkdownContent = (content: string) => {
const frontmatterRegex = /^---\r?\n([\s\S]*?)\r?\n---\r?\n([\s\S]*)$/
const match = frontmatterRegex.exec(text)
const match = frontmatterRegex.exec(content)
let extractedTitle = ''
let body = content.trim()
if (match) {
const yamlContent = match[1]
@@ -421,25 +444,36 @@ const handleImportMarkdownContent = (text: string) => {
}
})
formModel.value.title = meta['title'] || '导入文章'
body = bodyContent.trim()
extractedTitle = meta['title'] || extractH1Title(body)
formModel.value.title = extractedTitle || '导入文章'
formModel.value.slug = meta['slug'] || ''
formModel.value.tags = meta['tags'] ? meta['tags'].split(',').map((t) => t.trim()).filter(Boolean) : []
formModel.value.tags = meta['tags'] ? meta['tags'].split(',').map((tag) => tag.trim()).filter(Boolean) : []
formModel.value.summary = meta['description'] || meta['summary'] || ''
formModel.value.category = meta['category'] || 'Thoughts'
formModel.value.categoryId = meta['categoryid']
? Number(meta['categoryid'])
: (categories.value[0]?.id || null)
formModel.value.mood = meta['mood'] || 'quiet'
formModel.value.visibility = meta['visibility'] || 'public'
formModel.value.cover = meta['cover'] || '/assets/writing-camera.png'
formModel.value.content = bodyContent.trim()
} else {
formModel.value.title = '导入文章'
formModel.value.content = text.trim()
formModel.value.tags = []
formModel.value.summary = ''
formModel.value.category = 'Thoughts'
formModel.value.mood = 'quiet'
formModel.value.visibility = 'public'
formModel.value.cover = '/assets/writing-camera.png'
formModel.value.cover = meta['cover'] || ''
formModel.value.content = body
return
}
extractedTitle = extractH1Title(body)
formModel.value.title = extractedTitle || '导入文章'
formModel.value.slug = ''
formModel.value.content = body
formModel.value.tags = []
formModel.value.summary = ''
formModel.value.category = 'Thoughts'
formModel.value.categoryId = categories.value[0]?.id || null
formModel.value.mood = 'quiet'
formModel.value.visibility = 'public'
formModel.value.cover = ''
}
// 图册封面选择器
+3 -3
View File
@@ -51,7 +51,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
import axios from 'axios'
import request from '@/api/request'
const message = useMessage()
const saving = ref(false)
@@ -65,7 +65,7 @@ const aiConfig = ref({
const fetchConfigs = async () => {
try {
const token = localStorage.getItem('satoken')
const response = await axios.get('http://localhost:8080/api/config/list', {
const response = await request.get('/config/list', {
headers: { satoken: token }
})
@@ -96,7 +96,7 @@ const handleSave = async () => {
]
try {
const response = await axios.post('http://localhost:8080/api/config/update-batch', payload, {
const response = await request.post('/config/update-batch', payload, {
headers: { satoken: token }
})
+3 -3
View File
@@ -56,7 +56,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
import axios from 'axios'
import request from '@/api/request'
const getBlogUrl = (path: string) => {
const protocol = window.location.protocol
@@ -108,7 +108,7 @@ const encryptKey = (str: string): string => {
const fetchConfigs = async () => {
try {
const token = localStorage.getItem('satoken')
const response = await axios.get('http://localhost:8080/api/config/list', {
const response = await request.get('/config/list', {
headers: { satoken: token }
})
@@ -154,7 +154,7 @@ const handleSave = async () => {
]
try {
const response = await axios.post('http://localhost:8080/api/config/update-batch', payload, {
const response = await request.post('/config/update-batch', payload, {
headers: { satoken: token }
})
+3 -3
View File
@@ -38,7 +38,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
import axios from 'axios'
import request from '@/api/request'
const message = useMessage()
const saving = ref(false)
@@ -53,7 +53,7 @@ const beian = ref({
const fetchConfigs = async () => {
try {
const token = localStorage.getItem('satoken')
const response = await axios.get('http://localhost:8080/api/config/list', {
const response = await request.get('/config/list', {
headers: { satoken: token }
})
@@ -86,7 +86,7 @@ const handleSave = async () => {
]
try {
const response = await axios.post('http://localhost:8080/api/config/update-batch', payload, {
const response = await request.post('/config/update-batch', payload, {
headers: { satoken: token }
})
+3 -3
View File
@@ -31,7 +31,7 @@
<div class="flex items-center gap-2 shrink-0 justify-end sm:justify-start">
<n-button secondary size="small" class="shrink-0" @click="openGallerySelect('logoUrl')">相册选择</n-button>
<n-upload
action="http://localhost:8080/api/blogs/upload?type=brand"
action="/api/blogs/upload?type=brand"
:headers="uploadHeaders"
:show-file-list="false"
class="flex shrink-0"
@@ -62,7 +62,7 @@
<div class="flex items-center gap-2 shrink-0 justify-end sm:justify-start">
<n-button secondary size="small" class="shrink-0" @click="openGallerySelect('faviconUrl')">相册选择</n-button>
<n-upload
action="http://localhost:8080/api/blogs/upload?type=brand"
action="/api/blogs/upload?type=brand"
:headers="uploadHeaders"
:show-file-list="false"
class="flex shrink-0"
@@ -110,7 +110,7 @@
<div class="flex items-center gap-2 shrink-0 justify-end sm:justify-start">
<n-button secondary size="small" class="shrink-0" @click="openGallerySelect('heroBgUrl')">相册选择</n-button>
<n-upload
action="http://localhost:8080/api/blogs/upload?type=brand"
action="/api/blogs/upload?type=brand"
:headers="uploadHeaders"
:show-file-list="false"
class="flex shrink-0"
@@ -1,4 +1,4 @@
<template>
<template>
<div class="space-y-6">
<div class="archive-card p-5 sm:p-6 bg-(--archive-bg-card) border border-(--archive-border) rounded-2xl">
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-4 border-b border-(--archive-border)/40">
@@ -69,7 +69,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useMessage, NForm, NFormItem, NInput, NButton } from 'naive-ui'
import axios from 'axios'
import request from '@/api/request'
const getBlogUrl = (path: string) => {
const protocol = window.location.protocol
@@ -98,7 +98,7 @@ const dbConfig = ref({
const fetchDbConfig = async () => {
try {
const token = localStorage.getItem('satoken')
const response = await axios.get('http://localhost:8080/api/config/database', {
const response = await request.get('/config/database', {
headers: { satoken: token }
})
if (response.data && response.data.code === 200) {
@@ -113,7 +113,7 @@ const handleSave = async () => {
saving.value = true
const token = localStorage.getItem('satoken')
try {
const response = await axios.post('http://localhost:8080/api/config/database', dbConfig.value, {
const response = await request.post('/config/database', dbConfig.value, {
headers: { satoken: token }
})
if (response.data && response.data.code === 200) {
@@ -1,4 +1,4 @@
<template>
<template>
<div class="space-y-6">
<div class="archive-card p-5 sm:p-6 bg-(--archive-bg-card) border border-(--archive-border) rounded-2xl">
<div class="flex flex-col sm:flex-row sm:items-center justify-between gap-3 pb-4 border-b border-(--archive-border)/40">
@@ -99,7 +99,7 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useMessage, NForm, NFormItem, NSelect, NInput, NButton } from 'naive-ui'
import axios from 'axios'
import request from '@/api/request'
const getBlogUrl = (path: string) => {
const protocol = window.location.protocol
@@ -159,7 +159,7 @@ const activeStorageLabel = computed(() => {
const fetchConfigs = async () => {
try {
const token = localStorage.getItem('satoken')
const response = await axios.get('http://localhost:8080/api/config/list', {
const response = await request.get('/config/list', {
headers: { satoken: token }
})
@@ -203,7 +203,7 @@ const handleSave = async () => {
]
try {
const response = await axios.post('http://localhost:8080/api/config/update-batch', payload, {
const response = await request.post('/config/update-batch', payload, {
headers: { satoken: token }
})
+5 -5
View File
@@ -153,7 +153,7 @@
<div class="flex flex-wrap items-center gap-2 mb-2">
<n-upload
action="http://localhost:8080/api/blogs/upload?type=theme"
action="/api/blogs/upload?type=theme"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleBgUploadFinish"
@@ -260,7 +260,7 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue'
import { useMessage, NForm, NFormItem, NInput, NInputNumber, NSwitch, NUpload, NButton, NModal, NSpin } from 'naive-ui'
import axios from 'axios'
import request from '@/api/request'
const message = useMessage()
const saving = ref(false)
@@ -303,7 +303,7 @@ const uploadHeaders = computed(() => ({
const fetchConfigs = async () => {
try {
const token = localStorage.getItem('satoken')
const response = await axios.get('http://localhost:8080/api/config/list', {
const response = await request.get('/config/list', {
headers: { satoken: token }
})
@@ -362,7 +362,7 @@ const handleSave = async () => {
]
try {
const response = await axios.post('http://localhost:8080/api/config/update-batch', payload, {
const response = await request.post('/config/update-batch', payload, {
headers: { satoken: token }
})
@@ -412,7 +412,7 @@ const openGallerySelect = async () => {
selectedPhotoUrl.value = theme.value.bgImageUrl || ''
const token = localStorage.getItem('satoken')
try {
const response = await axios.get('http://localhost:8080/api/gallery/list', {
const response = await request.get('/gallery/list', {
headers: { satoken: token }
})
if (response.data && response.data.code === 200) {
@@ -108,7 +108,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useMessage, NForm, NSwitch, NButton, NInput, NFormItem } from 'naive-ui'
import axios from 'axios'
import request from '@/api/request'
const message = useMessage()
const saving = ref(false)
@@ -127,7 +127,7 @@ const passcode = ref('2026')
const fetchConfigs = async () => {
try {
const token = localStorage.getItem('satoken')
const response = await axios.get('http://localhost:8080/api/config/list', {
const response = await request.get('/config/list', {
headers: { satoken: token }
})
@@ -166,7 +166,7 @@ const handleSave = async () => {
]
try {
const response = await axios.post('http://localhost:8080/api/config/update-batch', payload, {
const response = await request.post('/config/update-batch', payload, {
headers: { satoken: token }
})
+284 -74
View File
@@ -33,7 +33,15 @@
class="min-w-36 lg:max-w-40"
/>
<button
<button
class="px-4 py-2 text-xs font-semibold rounded-xl bg-(--archive-bg) border border-(--archive-border) text-(--archive-text) hover:bg-(--archive-border)/40 active:scale-[0.98] transition-all flex items-center justify-center gap-1.5 cursor-pointer whitespace-nowrap"
@click="viewMode = viewMode === 'folder' ? 'flat' : 'folder'; page = 1;"
>
<span :class="viewMode === 'folder' ? 'i-mdi-format-list-bulleted' : 'i-mdi-folder-outline'"></span>
<span>{{ viewMode === 'folder' ? '平铺视图' : '文件夹视图' }}</span>
</button>
<button
class="px-4 py-2 text-xs font-semibold rounded-xl bg-(--archive-bg) border border-(--archive-border) text-(--archive-text) hover:bg-(--archive-border)/40 active:scale-[0.98] transition-all flex items-center justify-center gap-1.5 cursor-pointer whitespace-nowrap"
@click="loadData"
>
@@ -41,7 +49,7 @@
<span>刷新</span>
</button>
<button
<button
class="px-4 py-2 text-xs font-semibold rounded-xl bg-(--archive-accent) text-white hover:opacity-90 active:scale-[0.98] transition-all flex items-center justify-center gap-1.5 shadow-sm cursor-pointer whitespace-nowrap"
@click="goToConfig"
>
@@ -51,6 +59,49 @@
</div>
</div>
<!-- 路径面包屑导航 -->
<div v-if="viewMode === 'folder'" class="border border-(--archive-border) rounded-2xl bg-(--archive-bg-card) px-5 py-3 shadow-sm flex items-center justify-between gap-4 transition-all hover:shadow-md">
<div class="flex items-center gap-1.5 text-xs font-medium text-left">
<span class="tone-muted flex items-center gap-1">
<span class="i-mdi-home-outline text-sm"></span>
当前位置:
</span>
<button
class="px-2 py-0.5 rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors cursor-pointer border-none bg-transparent font-semibold"
:class="currentDir === '' ? 'text-(--archive-accent)' : 'text-(--archive-text)'"
@click="currentDir = ''; page = 1;"
>
根目录
</button>
<template v-for="(part, idx) in breadcrumbs" :key="idx">
<span class="text-(--archive-text)/40">/</span>
<button
class="px-2 py-0.5 rounded hover:bg-black/5 dark:hover:bg-white/10 transition-colors cursor-pointer border-none bg-transparent font-semibold"
:class="idx === breadcrumbs.length - 1 ? 'text-(--archive-accent)' : 'text-(--archive-text)'"
@click="navigateToBreadcrumb(idx)"
>
{{ part }}
</button>
</template>
</div>
<div class="flex items-center gap-2">
<n-button
v-if="currentDir !== ''"
size="tiny"
secondary
round
@click="goBackDir"
>
<template #icon>
<span class="i-mdi-arrow-up"></span>
</template>
返回上级
</n-button>
</div>
</div>
<!-- 统计指示面板 -->
<div class="grid grid-cols-1 md:grid-cols-3 gap-5">
<!-- 存储介质卡片 -->
@@ -118,76 +169,104 @@
<!-- 文件卡片网格列表 -->
<div v-else class="space-y-6">
<div class="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-5">
<div
v-for="item in paginatedFiles"
:key="item.fileName"
class="border border-(--archive-border) rounded-2xl bg-(--archive-bg-card) p-3 flex flex-col group transition-all duration-300 hover:shadow-md hover:-translate-y-0.5"
<div
v-for="item in paginatedItems"
:key="item.isDir ? 'dir_' + item.path : 'file_' + item.fileName"
class="border border-(--archive-border) rounded-2xl bg-(--archive-bg-card) p-3 flex flex-col group transition-all duration-300 hover:shadow-md hover:-translate-y-0.5 cursor-pointer"
@click="handleItemClick(item)"
>
<!-- 预览图/占位图 -->
<div class="relative w-full h-38 rounded-xl overflow-hidden bg-white/2 dark:bg-white/5 shrink-0">
<template v-if="isImage(item.fileName)">
<n-image
:src="item.url"
class="w-full h-full"
:img-props="{ class: 'w-full h-full object-cover transition-transform duration-500 group-hover:scale-103' }"
show-toolbar-tooltip
fallback-src="/life-assets/placeholder.jpg"
/>
</template>
<template v-else>
<div class="w-full h-full flex flex-col items-center justify-center gap-2 text-(--archive-text)/40 bg-black/5 dark:bg-white/5">
<span :class="getFileIcon(item.fileName)" class="text-4xl"></span>
<span class="text-[10px] uppercase font-bold tracking-wider opacity-60">
{{ getFileExt(item.fileName) }} 文件
<!-- 文件夹卡片 -->
<template v-if="item.isDir">
<div class="relative w-full h-38 rounded-xl overflow-hidden bg-(--archive-accent)/5 flex flex-col items-center justify-center gap-2.5 shrink-0 transition-colors group-hover:bg-(--archive-accent)/10">
<span class="i-mdi-folder text-5xl text-(--archive-accent) drop-shadow-sm transition-transform duration-300 group-hover:scale-105"></span>
<span class="text-[10px] uppercase font-bold tracking-wider text-(--archive-accent)/80">
文件夹
</span>
</div>
<div class="mt-3 flex flex-col text-left grow">
<span class="text-xs font-bold text-(--archive-text) truncate" :title="item.name">
{{ item.name }}
</span>
<div class="flex items-center justify-between mt-2.5">
<span class="text-[10px] px-1.5 py-0.5 rounded font-medium bg-(--archive-accent)/10 text-(--archive-accent)">
{{ item.childCount }} 个文件
</span>
<span class="text-[10px] tone-muted">
目录
</span>
</div>
</template>
<!-- 悬浮操作层 -->
<div class="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-center justify-center gap-3">
<n-tooltip trigger="hover">
<template #trigger>
<button
class="h-9 w-9 rounded-full bg-white text-gray-800 flex items-center justify-center hover:bg-(--archive-accent) hover:text-white active:scale-95 transition-all shadow cursor-pointer border-none"
@click="copyUrl(item.url)"
>
<span class="i-mdi-content-copy text-base"></span>
</button>
</template>
复制链接
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<button
class="h-9 w-9 rounded-full bg-white text-red-600 flex items-center justify-center hover:bg-red-600 hover:text-white active:scale-95 transition-all shadow cursor-pointer border-none"
@click="handleDelete(item)"
>
<span class="i-mdi-trash-can-outline text-base"></span>
</button>
</template>
删除文件
</n-tooltip>
</div>
</div>
</template>
<!-- 详细信息区 -->
<div class="mt-3 flex flex-col text-left grow">
<span
class="text-xs font-bold text-(--archive-text) truncate"
:title="item.fileName"
>
{{ getFileNameOnly(item.fileName) }}
</span>
<div class="flex items-center justify-between mt-2.5">
<span class="text-[10px] px-1.5 py-0.5 rounded font-medium bg-black/5 dark:bg-white/10 tone-muted">
{{ formatBytes(item.size) }}
</span>
<span class="text-[10px] tone-muted">
{{ formatTime(item.updateTime) }}
</span>
<!-- 文件卡片 -->
<template v-else>
<!-- 预览图/占位图 -->
<div class="relative w-full h-38 rounded-xl overflow-hidden bg-white/2 dark:bg-white/5 shrink-0">
<template v-if="isImage(item.fileName)">
<n-image
:src="item.url"
class="w-full h-full"
:img-props="{ class: 'w-full h-full object-cover transition-transform duration-500 group-hover:scale-103' }"
show-toolbar-tooltip
fallback-src="/life-assets/placeholder.jpg"
/>
</template>
<template v-else>
<div class="w-full h-full flex flex-col items-center justify-center gap-2 text-(--archive-text)/40 bg-black/5 dark:bg-white/5">
<span :class="getFileIcon(item.fileName)" class="text-4xl"></span>
<span class="text-[10px] uppercase font-bold tracking-wider opacity-60">
{{ getFileExt(item.fileName) }} 文件
</span>
</div>
</template>
<!-- 悬浮操作层 (阻止冒泡防误触) -->
<div class="absolute inset-0 bg-black/40 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-center justify-center gap-3" @click.stop>
<n-tooltip trigger="hover">
<template #trigger>
<button
class="h-9 w-9 rounded-full bg-white text-gray-800 flex items-center justify-center hover:bg-(--archive-accent) hover:text-white active:scale-95 transition-all shadow cursor-pointer border-none"
@click="copyUrl(item.url)"
>
<span class="i-mdi-content-copy text-base"></span>
</button>
</template>
复制链接
</n-tooltip>
<n-tooltip trigger="hover">
<template #trigger>
<button
class="h-9 w-9 rounded-full bg-white text-red-600 flex items-center justify-center hover:bg-red-600 hover:text-white active:scale-95 transition-all shadow cursor-pointer border-none"
@click="handleDelete(item)"
>
<span class="i-mdi-trash-can-outline text-base"></span>
</button>
</template>
删除文件
</n-tooltip>
</div>
</div>
</div>
<!-- 详细信息区 -->
<div class="mt-3 flex flex-col text-left grow">
<span
class="text-xs font-bold text-(--archive-text) truncate"
:title="item.fileName"
>
{{ item.name }}
</span>
<div class="flex items-center justify-between mt-2.5">
<span class="text-[10px] px-1.5 py-0.5 rounded font-medium bg-black/5 dark:bg-white/10 tone-muted">
{{ formatBytes(item.size) }}
</span>
<span class="text-[10px] tone-muted">
{{ formatTime(item.updateTime) }}
</span>
</div>
</div>
</template>
</div>
</div>
@@ -196,7 +275,7 @@
<n-pagination
v-model:page="page"
v-model:page-size="pageSize"
:item-count="filteredFiles.length"
:item-count="totalItemsCount"
:page-sizes="[10, 20, 30, 40, 50]"
show-size-picker
class="archive-pagination"
@@ -224,6 +303,10 @@ const files = ref<FileItem[]>([])
const searchQuery = ref('')
const typeFilter = ref('all')
// 视图与路径参数
const viewMode = ref<'folder' | 'flat'>('folder')
const currentDir = ref('')
// 分页状态
const page = ref(1)
const pageSize = ref(10)
@@ -239,7 +322,14 @@ watch([searchQuery, typeFilter, pageSize], () => {
page.value = 1
})
// 计算属性:当前存储介质的工作空间/桶名标题
// 当用户输入搜索内容时,自动切换为“平铺视图”,以方便全局快速检索文件
watch(searchQuery, (newVal) => {
if (newVal.trim()) {
viewMode.value = 'flat'
}
})
// 计算属性:当前工作空间/桶名标题
const getBucketTitle = computed(() => {
if (!storageInfo.value) return 'uploads'
const info = storageInfo.value
@@ -248,7 +338,13 @@ const getBucketTitle = computed(() => {
return 'uploads/ (本地文件夹)'
})
// 文件过滤列表
// 计算属性:路径面包屑片段
const breadcrumbs = computed(() => {
if (!currentDir.value) return []
return currentDir.value.split('/')
})
// 文件过滤列表 (搜索与类型)
const filteredFiles = computed(() => {
let list = files.value
@@ -268,11 +364,100 @@ const filteredFiles = computed(() => {
return list
})
// 分页计算后的展示文件列表
const paginatedFiles = computed(() => {
interface FolderItem {
isDir: true
name: string
path: string
childCount: number
}
interface FileItemWrap {
isDir: false
fileName: string
name: string
url: string
size: number
updateTime: number
storageType: string
}
type DisplayItem = FolderItem | FileItemWrap
// 计算属性:当前文件夹下的所有子文件夹与文件集合 (虚拟文件树解析)
const currentItems = computed<DisplayItem[]>(() => {
const list = filteredFiles.value
const foldersMap = new Map<string, { path: string; files: any[] }>()
const filesList: FileItemWrap[] = []
const currentPrefix = currentDir.value ? (currentDir.value.endsWith('/') ? currentDir.value : currentDir.value + '/') : ''
list.forEach(item => {
const name = item.fileName
if (currentPrefix && !name.startsWith(currentPrefix)) {
return
}
const relative = currentPrefix ? name.substring(currentPrefix.length) : name
if (relative.includes('/')) {
const dirName = relative.split('/')[0]
const fullSubDirPath = currentPrefix + dirName
if (!foldersMap.has(dirName)) {
foldersMap.set(dirName, { path: fullSubDirPath, files: [] })
}
foldersMap.get(dirName)!.files.push(item)
} else {
filesList.push({
isDir: false,
fileName: item.fileName,
name: relative,
url: item.url,
size: item.size,
updateTime: item.updateTime,
storageType: item.storageType
})
}
})
// 转换为展示用文件夹对象列表
const displayFolders: FolderItem[] = Array.from(foldersMap.entries()).map(([name, val]) => ({
isDir: true,
name,
path: val.path,
childCount: val.files.length
}))
// 文件夹按拼音/字母排序在前,文件保持更新时间倒序在后
return [
...displayFolders.sort((a, b) => a.name.localeCompare(b.name)),
...filesList
]
})
// 分页切片数据源
const paginatedItems = computed(() => {
const start = (page.value - 1) * pageSize.value
const end = start + pageSize.value
return filteredFiles.value.slice(start, end)
if (viewMode.value === 'flat') {
return filteredFiles.value.map(item => ({
isDir: false as const,
fileName: item.fileName,
name: getFileNameOnly(item.fileName),
url: item.url,
size: item.size,
updateTime: item.updateTime,
storageType: item.storageType
})).slice(start, end)
} else {
return currentItems.value.slice(start, end)
}
})
// 分页所用总项数
const totalItemsCount = computed(() => {
return viewMode.value === 'flat' ? filteredFiles.value.length : currentItems.value.length
})
// 总文件占用容量格式化
@@ -281,6 +466,32 @@ const totalSizeFormatted = computed(() => {
return formatBytes(sumBytes)
})
// 点击网格卡片的回调
const handleItemClick = (item: DisplayItem) => {
if (item.isDir) {
currentDir.value = item.path
page.value = 1
}
}
// 导航到指定面包屑层级
const navigateToBreadcrumb = (index: number) => {
const parts = currentDir.value.split('/')
currentDir.value = parts.slice(0, index + 1).join('/')
page.value = 1
}
// 返回上一级文件夹
const goBackDir = () => {
const parts = currentDir.value.split('/')
if (parts.length <= 1) {
currentDir.value = ''
} else {
currentDir.value = parts.slice(0, -1).join('/')
}
page.value = 1
}
// 加载后台数据
const loadData = async () => {
loading.value = true
@@ -318,7 +529,7 @@ const copyUrl = async (url: string) => {
}
// 删除文件操作
const handleDelete = (item: FileItem) => {
const handleDelete = (item: any) => {
dialog.warning({
title: '强物理删除确认',
content: `您确定要彻底删除文件「${getFileNameOnly(item.fileName)}」吗?该删除行为将在存储中进行物理擦除,不可撤销。已在博客内容中引用该文件的链接将会失效。`,
@@ -329,7 +540,6 @@ const handleDelete = (item: FileItem) => {
const response = await deleteFile(item.fileName)
if (response.data?.code === 200) {
message.success('文件物理删除成功 🗑️')
// 重新加载数据刷新列表
await loadData()
} else {
throw new Error(response.data?.msg || '删除失败')
+1 -1
View File
@@ -83,7 +83,7 @@
/>
<n-upload
action="http://localhost:8080/api/blogs/upload?type=gallery"
action="/api/blogs/upload?type=gallery"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleUploadFinish"
+1 -1
View File
@@ -101,7 +101,7 @@
<n-upload
v-if="letterImagesList.length < 2"
action="http://localhost:8080/api/blogs/upload?type=letter"
action="/api/blogs/upload?type=letter"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleUploadFinish"
+1 -1
View File
@@ -95,7 +95,7 @@
<div class="grid grid-cols-2 gap-2 mb-6">
<n-upload
action="http://localhost:8080/api/blogs/upload?type=love"
action="/api/blogs/upload?type=love"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleAtmosphereUploadFinish"
+3 -3
View File
@@ -252,7 +252,7 @@
<div class="flex gap-2 items-center">
<n-input v-model:value="formModel.reading.coverUrl" placeholder="输入外部路径,或点击上传" class="archive-input flex-1" />
<n-upload
action="http://localhost:8080/api/blogs/upload?type=now"
action="/api/blogs/upload?type=now"
:headers="uploadHeaders"
:show-file-list="false"
@finish="handleUploadFinish"
@@ -475,7 +475,7 @@
<div class="flex gap-2 w-full">
<n-input v-model:value="bgm.src" placeholder="例如: /assets/music/mr-lawrence.mp3" class="archive-input font-mono flex-1" />
<n-upload
action="http://localhost:8080/api/blogs/upload?type=now"
action="/api/blogs/upload?type=now"
:headers="uploadHeaders"
:show-file-list="false"
@finish="(options: any) => handleAudioUploadFinish(options, bgm)"
@@ -529,7 +529,7 @@
<div class="flex gap-2 w-full">
<n-input v-model:value="noise.src" placeholder="例如: /assets/music/rain.mp3" class="archive-input font-mono flex-1" />
<n-upload
action="http://localhost:8080/api/blogs/upload?type=now"
action="/api/blogs/upload?type=now"
:headers="uploadHeaders"
:show-file-list="false"
@finish="(options: any) => handleAudioUploadFinish(options, noise)"