优化页面、修复BUG
This commit is contained in:
136
client/src/components/admin/AdminTableFilter.vue
Normal file
136
client/src/components/admin/AdminTableFilter.vue
Normal file
@@ -0,0 +1,136 @@
|
||||
<template>
|
||||
<div class="admin-table-filter admin-card mb-6 p-4">
|
||||
<div class="filter-row">
|
||||
<div v-if="showKeyword" class="filter-keyword">
|
||||
<div class="relative flex-1 min-w-[200px]">
|
||||
<input
|
||||
type="text"
|
||||
:value="keyword"
|
||||
class="admin-input w-full pl-10"
|
||||
:placeholder="keywordPlaceholder"
|
||||
@input="onKeywordInput"
|
||||
@keyup.enter="emit('search')"
|
||||
/>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="search-icon">
|
||||
<circle cx="11" cy="11" r="8"></circle>
|
||||
<path d="m21 21-4.35-4.35"></path>
|
||||
</svg>
|
||||
<button
|
||||
v-if="keyword"
|
||||
type="button"
|
||||
class="clear-btn"
|
||||
@click="clearKeyword"
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="filter-extra">
|
||||
<slot name="filters" />
|
||||
</div>
|
||||
|
||||
<div class="filter-actions">
|
||||
<button type="button" class="admin-btn-secondary" @click="emit('search')">查询</button>
|
||||
<button type="button" class="admin-btn-secondary opacity-70" @click="emit('reset')">重置</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
withDefaults(defineProps<{
|
||||
keyword?: string
|
||||
keywordPlaceholder?: string
|
||||
showKeyword?: boolean
|
||||
}>(), {
|
||||
keyword: '',
|
||||
keywordPlaceholder: '关键词搜索...',
|
||||
showKeyword: true,
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:keyword': [value: string]
|
||||
search: []
|
||||
reset: []
|
||||
}>()
|
||||
|
||||
const onKeywordInput = (e: Event) => {
|
||||
emit('update:keyword', (e.target as HTMLInputElement).value)
|
||||
}
|
||||
|
||||
const clearKeyword = () => {
|
||||
emit('update:keyword', '')
|
||||
emit('search')
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.filter-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.filter-keyword {
|
||||
flex: 1 1 220px;
|
||||
min-width: 200px;
|
||||
}
|
||||
|
||||
.filter-extra {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: flex-end;
|
||||
gap: 0.75rem 1rem;
|
||||
}
|
||||
|
||||
.filter-actions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.search-icon {
|
||||
position: absolute;
|
||||
left: 0.75rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
color: rgba(255, 255, 255, 0.4);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.clear-btn {
|
||||
position: absolute;
|
||||
right: 0.5rem;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
border-radius: 9999px;
|
||||
border: none;
|
||||
background: rgba(255, 255, 255, 0.1);
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
cursor: pointer;
|
||||
line-height: 1;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.clear-btn:hover {
|
||||
color: #fff;
|
||||
background: rgba(255, 255, 255, 0.15);
|
||||
}
|
||||
|
||||
:deep(.filter-field) {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.35rem;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
:deep(.filter-field label) {
|
||||
font-size: 0.75rem;
|
||||
color: rgba(255, 255, 255, 0.5);
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
189
client/src/components/admin/ImagePicker.vue
Normal file
189
client/src/components/admin/ImagePicker.vue
Normal file
@@ -0,0 +1,189 @@
|
||||
<template>
|
||||
<div class="image-picker">
|
||||
<label v-if="label" class="block text-sm text-art-muted mb-2">{{ label }}</label>
|
||||
|
||||
<div class="flex items-start gap-4">
|
||||
<!-- 预览区 -->
|
||||
<div
|
||||
class="relative shrink-0 overflow-hidden bg-white/5 border border-white/10 flex items-center justify-center"
|
||||
:class="[
|
||||
variant === 'avatar' ? 'rounded-full' : 'rounded-lg',
|
||||
previewSizeClass
|
||||
]"
|
||||
>
|
||||
<img
|
||||
v-if="imageUrl"
|
||||
:src="imageUrl"
|
||||
alt="Preview"
|
||||
class="w-full h-full object-cover"
|
||||
/>
|
||||
<span v-else class="text-art-muted/50 text-xs text-center px-2">
|
||||
{{ placeholder }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<!-- 操作区 -->
|
||||
<div class="flex-1 min-w-0 space-y-2">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="admin-btn-secondary text-xs"
|
||||
:disabled="disabled || uploading"
|
||||
@click="triggerFileInput"
|
||||
>
|
||||
{{ uploading ? '上传中...' : '上传图片' }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="admin-btn-secondary text-xs"
|
||||
:disabled="disabled"
|
||||
@click="openLibraryModal"
|
||||
>
|
||||
从素材库选择
|
||||
</button>
|
||||
<button
|
||||
v-if="imageUrl"
|
||||
type="button"
|
||||
class="text-xs text-red-400 hover:text-red-300 transition-colors"
|
||||
:disabled="disabled"
|
||||
@click="clearImage"
|
||||
>
|
||||
清除
|
||||
</button>
|
||||
</div>
|
||||
<p v-if="hint" class="text-xs text-art-muted/60">{{ hint }}</p>
|
||||
<p v-if="error" class="text-xs text-red-400">{{ error }}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
:accept="accept"
|
||||
class="hidden"
|
||||
:disabled="disabled"
|
||||
@change="handleFileSelect"
|
||||
/>
|
||||
|
||||
<AttachmentLibraryModal
|
||||
:show="showLibraryModal"
|
||||
:multiple="false"
|
||||
:selected-urls="imageUrl ? [imageUrl] : []"
|
||||
@update:show="showLibraryModal = $event"
|
||||
@confirm="handleLibrarySelect"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed } from 'vue'
|
||||
import { useToast } from '../../composables/useToast'
|
||||
import { API_BASE, authFetch, parseApiResponse } from '../../services/api'
|
||||
import AttachmentLibraryModal from './AttachmentLibraryModal.vue'
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
modelValue?: string
|
||||
label?: string
|
||||
placeholder?: string
|
||||
hint?: string
|
||||
accept?: string
|
||||
disabled?: boolean
|
||||
variant?: 'avatar' | 'default'
|
||||
size?: 'sm' | 'md' | 'lg'
|
||||
categoryId?: number
|
||||
}>(), {
|
||||
modelValue: '',
|
||||
placeholder: '暂无图片',
|
||||
accept: 'image/*',
|
||||
disabled: false,
|
||||
variant: 'default',
|
||||
size: 'md'
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
'update:modelValue': [value: string]
|
||||
}>()
|
||||
|
||||
const fileInput = ref<HTMLInputElement | null>(null)
|
||||
const uploading = ref(false)
|
||||
const error = ref('')
|
||||
const showLibraryModal = ref(false)
|
||||
const toast = useToast()
|
||||
|
||||
const imageUrl = computed({
|
||||
get: () => props.modelValue || '',
|
||||
set: (val: string) => emit('update:modelValue', val)
|
||||
})
|
||||
|
||||
const previewSizeClass = computed(() => {
|
||||
if (props.variant === 'avatar') {
|
||||
return props.size === 'sm' ? 'w-12 h-12' : props.size === 'lg' ? 'w-24 h-24' : 'w-16 h-16'
|
||||
}
|
||||
return props.size === 'sm' ? 'w-20 h-20' : props.size === 'lg' ? 'w-40 h-40' : 'w-28 h-28'
|
||||
})
|
||||
|
||||
const triggerFileInput = () => {
|
||||
if (props.disabled || uploading.value) return
|
||||
fileInput.value?.click()
|
||||
}
|
||||
|
||||
const handleFileSelect = (e: Event) => {
|
||||
const target = e.target as HTMLInputElement
|
||||
const file = target.files?.[0]
|
||||
if (file) {
|
||||
uploadFile(file)
|
||||
}
|
||||
if (target) target.value = ''
|
||||
}
|
||||
|
||||
const uploadFile = async (file: File) => {
|
||||
if (!file.type.startsWith('image/')) {
|
||||
error.value = '请选择图片文件'
|
||||
toast.showToast(error.value, 'error')
|
||||
return
|
||||
}
|
||||
|
||||
uploading.value = true
|
||||
error.value = ''
|
||||
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
if (props.categoryId) {
|
||||
formData.append('categoryId', props.categoryId.toString())
|
||||
}
|
||||
formData.append('storageType', 'local')
|
||||
|
||||
const result = await parseApiResponse<{ fileUrl: string }>(await authFetch(`${API_BASE}/admin/attachments/upload`, {
|
||||
method: 'POST',
|
||||
headers: {},
|
||||
body: formData
|
||||
}))
|
||||
imageUrl.value = result.fileUrl
|
||||
toast.showToast('图片上传成功', 'success')
|
||||
} catch (err: any) {
|
||||
error.value = err.message || '上传失败,请重试'
|
||||
toast.showToast(error.value, 'error')
|
||||
} finally {
|
||||
uploading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const clearImage = () => {
|
||||
if (props.disabled) return
|
||||
imageUrl.value = ''
|
||||
if (fileInput.value) fileInput.value.value = ''
|
||||
}
|
||||
|
||||
const openLibraryModal = () => {
|
||||
if (props.disabled) return
|
||||
showLibraryModal.value = true
|
||||
}
|
||||
|
||||
const handleLibrarySelect = (urls: string[]) => {
|
||||
if (urls.length > 0) {
|
||||
imageUrl.value = urls[0]
|
||||
toast.showToast('图片选择成功', 'success')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -43,7 +43,15 @@
|
||||
<span class="text-sm text-white font-medium">v{{ item.version }}</span>
|
||||
<span class="text-xs text-art-muted">{{ item.modifiedAt }}</span>
|
||||
</div>
|
||||
<p class="text-xs text-art-muted mt-1 truncate">{{ item.modifiedByName || `用户#${item.modifiedBy}` }}</p>
|
||||
<AuthorInfo
|
||||
class="mt-2"
|
||||
:name="item.userName || item.modifiedByName"
|
||||
:email="item.userEmail"
|
||||
:avatar="item.userAvatar"
|
||||
:user-id="item.userId || item.modifiedBy"
|
||||
variant="compact"
|
||||
size="sm"
|
||||
/>
|
||||
<p class="text-xs text-white/70 mt-0.5 truncate">{{ item.title }}</p>
|
||||
</button>
|
||||
</div>
|
||||
@@ -66,7 +74,17 @@
|
||||
<div><span class="text-art-muted">专栏:</span><span class="text-white">{{ previewData.columnName || '—' }}</span></div>
|
||||
<div><span class="text-art-muted">标签:</span><span class="text-white">{{ previewData.tagNames?.join(', ') || '—' }}</span></div>
|
||||
<div><span class="text-art-muted">状态:</span><span class="text-white">{{ previewData.isPublished === 1 ? '已发布' : '草稿' }}</span></div>
|
||||
<div><span class="text-art-muted">修改人:</span><span class="text-white">{{ previewData.modifiedByName || previewData.modifiedBy }}</span></div>
|
||||
<div class="flex items-start gap-2">
|
||||
<span class="text-art-muted shrink-0">操作人:</span>
|
||||
<AuthorInfo
|
||||
:name="previewData.userName || previewData.modifiedByName"
|
||||
:email="previewData.userEmail"
|
||||
:avatar="previewData.userAvatar"
|
||||
:user-id="previewData.userId || previewData.modifiedBy"
|
||||
variant="compact"
|
||||
size="sm"
|
||||
/>
|
||||
</div>
|
||||
<div><span class="text-art-muted">摘要:</span><span class="text-white">{{ previewData.excerpt || '—' }}</span></div>
|
||||
<div>
|
||||
<span class="text-art-muted block mb-2">正文:</span>
|
||||
@@ -133,6 +151,7 @@ import {
|
||||
type PostHistoryDiff
|
||||
} from '../../services/api'
|
||||
import { useToast } from '../../composables/useToast'
|
||||
import AuthorInfo from '../AuthorInfo.vue'
|
||||
|
||||
const FIELD_LABELS: Record<string, string> = {
|
||||
title: '标题',
|
||||
|
||||
Reference in New Issue
Block a user