mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 09:09:20 +08:00
prettier: 代码格式化
This commit is contained in:
@@ -1,3 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import type { FileDTO, FileVO } from '#/api/media/file/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { Form, Input, message, Modal } from 'ant-design-vue';
|
||||
|
||||
import { updateFileApi } from '#/api/media/file';
|
||||
|
||||
defineOptions({ name: 'FileEditModal' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
open: boolean;
|
||||
fileData?: FileVO.Info | null;
|
||||
}
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'update:open', value: boolean): void;
|
||||
(e: 'success'): void;
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const formRef = ref();
|
||||
const formData = ref<FileDTO.Update>({
|
||||
tags: '',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 监听props变化
|
||||
watch(
|
||||
() => props.open,
|
||||
(newVal) => {
|
||||
visible.value = newVal;
|
||||
if (newVal && props.fileData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.fileData.tags,
|
||||
remark: props.fileData.remark,
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 监听visible变化,同步到父组件
|
||||
watch(visible, (newVal) => {
|
||||
emit('update:open', newVal);
|
||||
});
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
if (props.fileData?.id) {
|
||||
await updateFileApi(props.fileData.id, formData.value);
|
||||
message.success('更新成功');
|
||||
emit('success');
|
||||
visible.value = false;
|
||||
}
|
||||
} catch {
|
||||
message.error('更新失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
visible.value = false;
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
tags: '',
|
||||
remark: '',
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
@@ -27,79 +110,3 @@
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { Modal, Form, Input, message } from 'ant-design-vue'
|
||||
import { updateFileApi } from '#/api/media/file'
|
||||
import type { FileDTO, FileVO } from '#/api/media/file/types'
|
||||
|
||||
defineOptions({ name: 'FileEditModal' })
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
open: boolean
|
||||
fileData?: FileVO.Info | null
|
||||
}
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'update:open', value: boolean): void
|
||||
(e: 'success'): void
|
||||
(e: 'cancel'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false)
|
||||
const formRef = ref()
|
||||
const formData = ref<FileDTO.Update>({
|
||||
tags: '',
|
||||
remark: '',
|
||||
})
|
||||
|
||||
// 监听props变化
|
||||
watch(() => props.open, (newVal) => {
|
||||
visible.value = newVal
|
||||
if (newVal && props.fileData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.fileData.tags,
|
||||
remark: props.fileData.remark,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 监听visible变化,同步到父组件
|
||||
watch(visible, (newVal) => {
|
||||
emit('update:open', newVal)
|
||||
})
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
if (props.fileData?.id) {
|
||||
await updateFileApi(props.fileData.id, formData.value)
|
||||
message.success('更新成功')
|
||||
emit('success')
|
||||
visible.value = false
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('更新失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel')
|
||||
visible.value = false
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
tags: '',
|
||||
remark: '',
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,21 +1,34 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { FileDTO, FileVO } from '#/api/media/file/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import {
|
||||
Button,
|
||||
Upload,
|
||||
message,
|
||||
Tag,
|
||||
Space,
|
||||
Popconfirm,
|
||||
Tooltip
|
||||
} from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import {
|
||||
Button,
|
||||
message,
|
||||
Popconfirm,
|
||||
Space,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Upload,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import {
|
||||
batchUploadFilesApi,
|
||||
deleteFileApi,
|
||||
getFilePageApi,
|
||||
uploadFileApi,
|
||||
} from '#/api/media/file';
|
||||
|
||||
import FileEditModal from './components/FileEditModal.vue';
|
||||
|
||||
defineOptions({ name: 'FileRepository' });
|
||||
// 创建图标组件
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
const DeleteIcon = createIconifyIcon('lucide:trash-2');
|
||||
@@ -23,17 +36,6 @@ const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const EyeIcon = createIconifyIcon('lucide:eye');
|
||||
|
||||
import {
|
||||
uploadFileApi,
|
||||
batchUploadFilesApi,
|
||||
deleteFileApi,
|
||||
getFilePageApi,
|
||||
} from '#/api/media/file';
|
||||
import type { FileVO, FileDTO } from '#/api/media/file/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
defineOptions({ name: 'FileRepository' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const fileList = ref<FileVO.Info[]>([]);
|
||||
@@ -48,7 +50,6 @@ const searchForm = ref({
|
||||
fileFormat: undefined as string | undefined,
|
||||
});
|
||||
|
||||
|
||||
// 文件格式选项
|
||||
const fileFormatOptions = [
|
||||
{ label: 'PDF', value: 'pdf' },
|
||||
@@ -117,7 +118,25 @@ const gridOptions: VxeGridProps<any> = {
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
@@ -195,7 +214,7 @@ const handleUpload = async (file: File) => {
|
||||
await uploadFileApi(file);
|
||||
message.success('文件上传成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch {
|
||||
message.error('文件上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
@@ -208,7 +227,7 @@ const handleBatchUpload = async (files: File[]) => {
|
||||
await batchUploadFilesApi(files);
|
||||
message.success(`成功上传 ${files.length} 个文件`);
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
@@ -236,7 +255,7 @@ const handleDelete = async (id: number) => {
|
||||
await deleteFileApi(id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
@@ -300,8 +319,8 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
|
||||
<!-- 文件名列 -->
|
||||
<template #filename="{ row }: { row: any }">
|
||||
<div style="display: flex; align-items: center; gap: 8px;">
|
||||
<span style="font-weight: 500;">{{ row.filename }}</span>
|
||||
<div style="display: flex; align-items: center; gap: 8px">
|
||||
<span style="font-weight: 500">{{ row.filename }}</span>
|
||||
<Tag color="blue" size="small">{{ row.fileFormat || '未知' }}</Tag>
|
||||
</div>
|
||||
</template>
|
||||
@@ -313,12 +332,12 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
|
||||
<!-- 标签列 -->
|
||||
<template #tags="{ row }: { row: any }">
|
||||
<div v-if="!row.tags" style="color: #999;">无标签</div>
|
||||
<div v-else style="display: flex; flex-wrap: wrap; gap: 4px;">
|
||||
<Tag
|
||||
v-for="tag in row.tags.split(',').filter((t: string) => t.trim())"
|
||||
:key="tag"
|
||||
color="green"
|
||||
<div v-if="!row.tags" style="color: #999">无标签</div>
|
||||
<div v-else style="display: flex; flex-wrap: wrap; gap: 4px">
|
||||
<Tag
|
||||
v-for="tag in row.tags.split(',').filter((t: string) => t.trim())"
|
||||
:key="tag"
|
||||
color="green"
|
||||
size="small"
|
||||
>
|
||||
{{ tag.trim() }}
|
||||
@@ -329,11 +348,19 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<!-- 描述列 -->
|
||||
<template #remark="{ row }: { row: any }">
|
||||
<Tooltip v-if="row.remark" :title="row.remark">
|
||||
<span style="display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
|
||||
<span
|
||||
style="
|
||||
display: block;
|
||||
max-width: 150px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
"
|
||||
>
|
||||
{{ row.remark }}
|
||||
</span>
|
||||
</Tooltip>
|
||||
<span v-else style="color: #999;">无描述</span>
|
||||
<span v-else style="color: #999">无描述</span>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
@@ -341,23 +368,26 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
<Space>
|
||||
<Tooltip title="预览">
|
||||
<Button type="text" size="small" @click="handlePreview(row)">
|
||||
<EyeIcon class="w-4 h-4" />
|
||||
<EyeIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="下载">
|
||||
<Button type="text" size="small" @click="handleDownload(row)">
|
||||
<DownloadIcon class="w-4 h-4" />
|
||||
<DownloadIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="编辑">
|
||||
<Button type="text" size="small" @click="handleEdit(row)">
|
||||
<EditIcon class="w-4 h-4" />
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Popconfirm title="确定要删除这个文件吗?" @confirm="handleDelete(row.id)">
|
||||
<Popconfirm
|
||||
title="确定要删除这个文件吗?"
|
||||
@confirm="handleDelete(row.id)"
|
||||
>
|
||||
<Tooltip title="删除">
|
||||
<Button type="text" size="small" danger>
|
||||
<DeleteIcon class="w-4 h-4" />
|
||||
<DeleteIcon class="h-4 w-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Popconfirm>
|
||||
|
||||
@@ -1,123 +0,0 @@
|
||||
<script lang="ts" setup>
|
||||
import { Card, Image, Tag, Button, Space, Popconfirm } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import type { ImageVO } from '#/api/media/image/types';
|
||||
|
||||
// 创建图标组件
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
interface Props {
|
||||
image: ImageVO.Info;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'download', image: ImageVO.Info): void;
|
||||
(e: 'edit', image: ImageVO.Info): void;
|
||||
(e: 'delete', id: number): void;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
const handleDownload = (image: ImageVO.Info) => {
|
||||
emit('download', image);
|
||||
};
|
||||
|
||||
const handleEdit = (image: ImageVO.Info) => {
|
||||
emit('edit', image);
|
||||
};
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
emit('delete', id);
|
||||
};
|
||||
|
||||
const getTagColor = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'image':
|
||||
return 'blue';
|
||||
case 'avatar':
|
||||
return 'green';
|
||||
case 'logo':
|
||||
return 'purple';
|
||||
default:
|
||||
return '#006BE6';
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card
|
||||
hoverable
|
||||
:body-style="{ padding: '8px' }"
|
||||
class="image-card"
|
||||
>
|
||||
<div class="relative overflow-hidden">
|
||||
<Image
|
||||
:src="image.url"
|
||||
:alt="image.filename"
|
||||
class="w-full h-32 object-cover rounded"
|
||||
:preview="true"
|
||||
/>
|
||||
<div v-if="image.tags" class="absolute top-2 right-2 max-w-[calc(100%-16px)]">
|
||||
<Tag
|
||||
:color="getTagColor(image.category)"
|
||||
class="max-w-full truncate"
|
||||
:title="image.tags"
|
||||
>
|
||||
{{ image.tags }}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2">
|
||||
<div class="text-sm font-medium truncate" :title="image.filename">
|
||||
{{ image.filename || '未命名' }}
|
||||
</div>
|
||||
<div class="text-xs text-gray-500 mt-1">
|
||||
{{ image.uploadTime }}
|
||||
</div>
|
||||
<div class="flex justify-between items-center mt-2">
|
||||
<Space size="small">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleDownload(image)"
|
||||
>
|
||||
<DownloadIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(image)"
|
||||
>
|
||||
<EditIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="确定要删除这张图片吗?"
|
||||
@confirm="handleDelete(image.id)"
|
||||
>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
danger
|
||||
>
|
||||
<TrashIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.image-card {
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.image-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
</style>
|
||||
+83
-77
@@ -1,3 +1,86 @@
|
||||
<script setup lang="ts">
|
||||
import type { ImageDTO, ImageVO } from '#/api/media/image/types';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import { Form, Input, message, Modal } from 'ant-design-vue';
|
||||
|
||||
import { updateImageApi } from '#/api/media/image';
|
||||
|
||||
defineOptions({ name: 'ImageEditModal' });
|
||||
|
||||
const props = defineProps<Props>();
|
||||
|
||||
const emit = defineEmits<Emits>();
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
open: boolean;
|
||||
imageData?: ImageVO.Info | null;
|
||||
}
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'update:open', value: boolean): void;
|
||||
(e: 'success'): void;
|
||||
(e: 'cancel'): void;
|
||||
}
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false);
|
||||
const formRef = ref();
|
||||
const formData = ref<ImageDTO.Update>({
|
||||
tags: '',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 监听props变化
|
||||
watch(
|
||||
() => props.open,
|
||||
(newVal) => {
|
||||
visible.value = newVal;
|
||||
if (newVal && props.imageData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.imageData.tags,
|
||||
remark: props.imageData.remark,
|
||||
};
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
// 监听visible变化,同步到父组件
|
||||
watch(visible, (newVal) => {
|
||||
emit('update:open', newVal);
|
||||
});
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
if (props.imageData?.id) {
|
||||
await updateImageApi(props.imageData.id, formData.value);
|
||||
message.success('更新成功');
|
||||
emit('success');
|
||||
visible.value = false;
|
||||
}
|
||||
} catch {
|
||||
message.error('更新失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel');
|
||||
visible.value = false;
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
tags: '',
|
||||
remark: '',
|
||||
};
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
@@ -27,80 +110,3 @@
|
||||
</Form>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { Modal, Form, Input, message } from 'ant-design-vue'
|
||||
import { updateImageApi } from '#/api/media/image'
|
||||
import type { ImageDTO, ImageVO } from '#/api/media/image/types'
|
||||
|
||||
defineOptions({ name: 'ImageEditModal' })
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
open: boolean
|
||||
imageData?: ImageVO.Info | null
|
||||
}
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'update:open', value: boolean): void
|
||||
(e: 'success'): void
|
||||
(e: 'cancel'): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
// 响应式数据
|
||||
const visible = ref(false)
|
||||
const formRef = ref()
|
||||
const formData = ref<ImageDTO.Update>({
|
||||
tags: '',
|
||||
remark: '',
|
||||
})
|
||||
|
||||
|
||||
// 监听props变化
|
||||
watch(() => props.open, (newVal) => {
|
||||
visible.value = newVal
|
||||
if (newVal && props.imageData) {
|
||||
// 填充表单数据
|
||||
formData.value = {
|
||||
tags: props.imageData.tags,
|
||||
remark: props.imageData.remark,
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// 监听visible变化,同步到父组件
|
||||
watch(visible, (newVal) => {
|
||||
emit('update:open', newVal)
|
||||
})
|
||||
|
||||
// 确认操作
|
||||
const handleOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate()
|
||||
if (props.imageData?.id) {
|
||||
await updateImageApi(props.imageData.id, formData.value)
|
||||
message.success('更新成功')
|
||||
emit('success')
|
||||
visible.value = false
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('更新失败')
|
||||
}
|
||||
}
|
||||
|
||||
// 取消操作
|
||||
const handleCancel = () => {
|
||||
emit('cancel')
|
||||
visible.value = false
|
||||
// 重置表单数据
|
||||
formData.value = {
|
||||
tags: '',
|
||||
remark: '',
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1,272 +0,0 @@
|
||||
<template>
|
||||
<div class="image-grid-view h-full">
|
||||
<!-- 工具栏 -->
|
||||
<div class="mb-4 flex justify-between items-center">
|
||||
<div class="flex items-center gap-4">
|
||||
<Upload v-bind="uploadProps">
|
||||
<Button type="primary" :loading="uploadLoading">
|
||||
<UploadIcon class="w-4 h-4 mr-2" />
|
||||
上传图片
|
||||
</Button>
|
||||
</Upload>
|
||||
<span class="text-gray-500">支持批量上传,单个图片最大10MB</span>
|
||||
</div>
|
||||
<div class="text-gray-500">
|
||||
共 {{ total }} 张图片
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<div class="mb-4 p-4 bg-white rounded-lg shadow-sm">
|
||||
<Form :model="searchForm" layout="inline">
|
||||
<Form.Item label="文件名">
|
||||
<Input
|
||||
v-model:value="searchForm.filename"
|
||||
placeholder="请输入文件名"
|
||||
style="width: 200px"
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="图片分类">
|
||||
<Select
|
||||
v-model:value="searchForm.category"
|
||||
placeholder="请选择图片分类"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in categoryOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 网格内容 -->
|
||||
<div class="bg-white rounded-lg shadow-sm p-4">
|
||||
<Row :gutter="[16, 16]" v-loading="loading">
|
||||
<Col
|
||||
v-for="image in imageList"
|
||||
:key="image.id"
|
||||
:xs="12"
|
||||
:sm="8"
|
||||
:md="6"
|
||||
:lg="4"
|
||||
:xl="3"
|
||||
>
|
||||
<ImageCard
|
||||
:image="image"
|
||||
@download="handleDownload"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@preview="handlePreview"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div v-if="!loading && imageList.length === 0" class="text-center py-12">
|
||||
<div class="text-gray-400 text-lg">暂无图片数据</div>
|
||||
<div class="text-gray-400 text-sm mt-2">请上传图片或调整搜索条件</div>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div v-if="total > 0" class="mt-4 flex justify-center">
|
||||
<Pagination
|
||||
v-model:current="current"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:page-size-options="['12', '24', '48', '96']"
|
||||
show-size-changer
|
||||
show-quick-jumper
|
||||
:show-total="(total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`"
|
||||
@change="handlePageChange"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue'
|
||||
import { Form, Input, Select, Button, Space, Row, Col, Pagination, Upload, message } from 'ant-design-vue'
|
||||
import { createIconifyIcon } from '@vben/icons'
|
||||
import { getImagePageApi, uploadImageApi, batchUploadImagesApi } from '#/api/media/image'
|
||||
import type { ImageVO, ImageDTO } from '#/api/media/image/types'
|
||||
import type { PageQueryDTO } from '#/types/common'
|
||||
import ImageCard from './ImageCard.vue'
|
||||
|
||||
// 创建图标组件
|
||||
const UploadIcon = createIconifyIcon('lucide:upload')
|
||||
|
||||
defineOptions({ name: 'ImageGridView' })
|
||||
|
||||
// Props
|
||||
interface Props {
|
||||
searchForm: {
|
||||
filename: string
|
||||
category?: string
|
||||
}
|
||||
categoryOptions: Array<{ label: string; value: string }>
|
||||
}
|
||||
|
||||
// Emits
|
||||
interface Emits {
|
||||
(e: 'edit', image: ImageVO.Info): void
|
||||
(e: 'delete', id: number): void
|
||||
(e: 'download', image: ImageVO.Info): void
|
||||
(e: 'preview', image: ImageVO.Info): void
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const emit = defineEmits<Emits>()
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false)
|
||||
const uploadLoading = ref(false)
|
||||
const imageList = ref<ImageVO.Info[]>([])
|
||||
const total = ref(0)
|
||||
const current = ref(1)
|
||||
const pageSize = ref(24) // 网格视图默认24个
|
||||
|
||||
// 监听搜索表单变化
|
||||
watch(() => props.searchForm, () => {
|
||||
current.value = 1
|
||||
loadImageList()
|
||||
}, { deep: true })
|
||||
|
||||
// 加载图片列表
|
||||
const loadImageList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const params: PageQueryDTO<ImageDTO.Filters> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: props.searchForm.filename || undefined,
|
||||
category: props.searchForm.category || undefined,
|
||||
}
|
||||
}
|
||||
|
||||
const response = await getImagePageApi(params)
|
||||
imageList.value = response.records
|
||||
total.value = response.total
|
||||
} catch (error) {
|
||||
message.error('加载图片列表失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// 搜索
|
||||
const handleSearch = () => {
|
||||
current.value = 1
|
||||
loadImageList()
|
||||
}
|
||||
|
||||
// 重置
|
||||
const handleReset = () => {
|
||||
props.searchForm.filename = ''
|
||||
props.searchForm.category = undefined
|
||||
handleSearch()
|
||||
}
|
||||
|
||||
// 分页变化
|
||||
const handlePageChange = (page: number, size: number) => {
|
||||
current.value = page
|
||||
pageSize.value = size
|
||||
loadImageList()
|
||||
}
|
||||
|
||||
// 上传配置
|
||||
const uploadProps = {
|
||||
multiple: true,
|
||||
showUploadList: false,
|
||||
accept: 'image/*',
|
||||
beforeUpload: (file: any) => {
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (!isImage) {
|
||||
message.error('只能上传图片文件');
|
||||
return false;
|
||||
}
|
||||
const isValidSize = file.size / 1024 / 1024 < 10; // 10MB
|
||||
if (!isValidSize) {
|
||||
message.error('图片大小不能超过 10MB');
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
customRequest: (options: any) => {
|
||||
const { file } = options;
|
||||
if (Array.isArray(file)) {
|
||||
handleBatchUpload(file);
|
||||
} else {
|
||||
handleUpload(file);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
// 处理上传
|
||||
const handleUpload = async (file: File) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await uploadImageApi(file);
|
||||
message.success('图片上传成功');
|
||||
loadImageList();
|
||||
} catch (error) {
|
||||
message.error('图片上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 处理批量上传
|
||||
const handleBatchUpload = async (files: File[]) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await batchUploadImagesApi(files);
|
||||
message.success(`成功上传 ${files.length} 张图片`);
|
||||
loadImageList();
|
||||
} catch (error) {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 事件处理
|
||||
const handleEdit = (image: ImageVO.Info) => {
|
||||
emit('edit', image)
|
||||
}
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
emit('delete', id)
|
||||
}
|
||||
|
||||
const handleDownload = (image: ImageVO.Info) => {
|
||||
emit('download', image)
|
||||
}
|
||||
|
||||
const handlePreview = (image: ImageVO.Info) => {
|
||||
emit('preview', image)
|
||||
}
|
||||
|
||||
// 初始化
|
||||
loadImageList()
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.image-grid-view {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -1,30 +1,41 @@
|
||||
<script lang="ts" setup>
|
||||
import { ref, computed } from 'vue';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import type { ImageDTO, ImageVO } from '#/api/media/image/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, message, Space, Tag, Upload, Image } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
uploadImageApi,
|
||||
import {
|
||||
Button,
|
||||
Divider,
|
||||
Flex,
|
||||
Image,
|
||||
message,
|
||||
Space,
|
||||
Tag,
|
||||
Upload,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import {
|
||||
batchUploadImagesApi,
|
||||
deleteImageApi,
|
||||
getImagePageApi,
|
||||
uploadImageApi,
|
||||
} from '#/api/media/image';
|
||||
import type { ImageVO, ImageDTO } from '#/api/media/image/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import ImageEditModal from './components/ImageEditModal.vue';
|
||||
import ImageGridView from './components/ImageGridView.vue';
|
||||
|
||||
import ImageEditModal from './components/ImageEditModal.vue';
|
||||
import ImageGridView from './views/ImageGridView/index.vue';
|
||||
|
||||
defineOptions({ name: 'ImageRepository' });
|
||||
// 创建图标组件
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
const ListIcon = createIconifyIcon('lucide:list');
|
||||
|
||||
defineOptions({ name: 'ImageRepository' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const editModalVisible = ref(false);
|
||||
@@ -106,7 +117,25 @@ const gridOptions: VxeGridProps<any> = {
|
||||
pagerConfig: {
|
||||
enabled: true,
|
||||
pageSizes: [10, 20, 50, 100],
|
||||
layouts: ['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total'] as ('PrevJump' | 'PrevPage' | 'Number' | 'NextPage' | 'NextJump' | 'Sizes' | 'FullJump' | 'Total')[],
|
||||
layouts: [
|
||||
'PrevJump',
|
||||
'PrevPage',
|
||||
'Number',
|
||||
'NextPage',
|
||||
'NextJump',
|
||||
'Sizes',
|
||||
'FullJump',
|
||||
'Total',
|
||||
] as (
|
||||
| 'FullJump'
|
||||
| 'NextJump'
|
||||
| 'NextPage'
|
||||
| 'Number'
|
||||
| 'PrevJump'
|
||||
| 'PrevPage'
|
||||
| 'Sizes'
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
@@ -191,7 +220,7 @@ const handleUpload = async (file: File) => {
|
||||
await uploadImageApi(file);
|
||||
message.success('图片上传成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch {
|
||||
message.error('图片上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
@@ -205,7 +234,7 @@ const handleBatchUpload = async (files: File[]) => {
|
||||
await batchUploadImagesApi(files);
|
||||
message.success(`成功上传 ${files.length} 张图片`);
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
uploadLoading.value = false;
|
||||
@@ -237,7 +266,7 @@ const handleDelete = async (id: number) => {
|
||||
await deleteImageApi(id);
|
||||
message.success('删除成功');
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
} catch {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
@@ -283,83 +312,86 @@ const uploadProps = {
|
||||
// 获取分类标签颜色
|
||||
const getCategoryColor = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'image':
|
||||
return 'blue';
|
||||
case 'avatar':
|
||||
case 'avatar': {
|
||||
return 'green';
|
||||
case 'logo':
|
||||
}
|
||||
case 'image': {
|
||||
return 'blue';
|
||||
}
|
||||
case 'logo': {
|
||||
return 'purple';
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 获取分类显示文本
|
||||
const getCategoryText = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'image':
|
||||
return '普通图片';
|
||||
case 'avatar':
|
||||
case 'avatar': {
|
||||
return '头像';
|
||||
case 'logo':
|
||||
}
|
||||
case 'image': {
|
||||
return '普通图片';
|
||||
}
|
||||
case 'logo': {
|
||||
return 'Logo';
|
||||
default:
|
||||
}
|
||||
default: {
|
||||
return '未分类';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 获取标签列表
|
||||
const getTagList = (tags: string | undefined) => {
|
||||
if (!tags) return [];
|
||||
return tags.split(',').map(tag => tag.trim()).filter(tag => tag);
|
||||
return tags
|
||||
.split(',')
|
||||
.map((tag) => tag.trim())
|
||||
.filter(Boolean);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="图片仓库" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理图片资源,支持上传、预览、编辑和分类管理
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<Page :auto-content-height="true" content-class="flex-col">
|
||||
<!-- 工具栏区域 -->
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button
|
||||
:type="viewMode === 'grid' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<GridIcon class="w-4 h-4 mr-2" />
|
||||
网格视图
|
||||
</Button>
|
||||
<Button
|
||||
:type="viewMode === 'list' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<ListIcon class="w-4 h-4 mr-2" />
|
||||
列表视图
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 列表视图 -->
|
||||
<Grid
|
||||
v-if="viewMode === 'list'"
|
||||
:loading="loading"
|
||||
>
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Flex gap="small" align="center">
|
||||
<Space>
|
||||
<Upload v-bind="uploadProps">
|
||||
<Button type="primary" :loading="uploadLoading">
|
||||
<UploadIcon class="w-4 h-4 mr-2" />
|
||||
<UploadIcon class="mr-2 h-4 w-4" />
|
||||
上传图片
|
||||
</Button>
|
||||
</Upload>
|
||||
<span class="text-gray-500">支持批量上传,单个图片最大10MB</span>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<Divider type="vertical" />
|
||||
|
||||
<Space>
|
||||
<Button
|
||||
:type="viewMode === 'grid' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<GridIcon class="mr-2 h-4 w-4" />
|
||||
网格视图
|
||||
</Button>
|
||||
<Button
|
||||
:type="viewMode === 'list' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
>
|
||||
<ListIcon class="mr-2 h-4 w-4" />
|
||||
列表视图
|
||||
</Button>
|
||||
</Space>
|
||||
</Flex>
|
||||
</template>
|
||||
|
||||
<!-- 列表视图 -->
|
||||
<Grid v-if="viewMode === 'list'" :loading="loading">
|
||||
<!-- 预览列 -->
|
||||
<template #preview="{ row }: { row: any }">
|
||||
<Image
|
||||
@@ -367,7 +399,7 @@ const getTagList = (tags: string | undefined) => {
|
||||
:alt="row.filename"
|
||||
width="60"
|
||||
height="60"
|
||||
style="object-fit: cover; border-radius: 4px;"
|
||||
style="object-fit: cover; border-radius: 4px"
|
||||
:preview="true"
|
||||
/>
|
||||
</template>
|
||||
@@ -382,8 +414,8 @@ const getTagList = (tags: string | undefined) => {
|
||||
<!-- 标签列 -->
|
||||
<template #tags="{ row }: { row: any }">
|
||||
<div v-if="row.tags" class="flex flex-wrap gap-1">
|
||||
<Tag
|
||||
v-for="tag in getTagList(row.tags)"
|
||||
<Tag
|
||||
v-for="tag in getTagList(row.tags)"
|
||||
:key="tag"
|
||||
size="small"
|
||||
color="blue"
|
||||
@@ -397,12 +429,8 @@ const getTagList = (tags: string | undefined) => {
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleDownload(row)">
|
||||
下载
|
||||
</Button>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" @click="handleDownload(row)"> 下载 </Button>
|
||||
<Button size="small" @click="handleEdit(row)"> 编辑 </Button>
|
||||
<Button size="small" danger @click="handleDelete(row.id)">
|
||||
删除
|
||||
</Button>
|
||||
@@ -413,22 +441,22 @@ const getTagList = (tags: string | undefined) => {
|
||||
<!-- 网格视图 -->
|
||||
<ImageGridView
|
||||
v-else
|
||||
:search-form="searchForm"
|
||||
v-model:search-form="searchForm"
|
||||
:category-options="imageCategoryOptions"
|
||||
:upload-loading="uploadLoading"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@download="handleDownload"
|
||||
@preview="handlePreview"
|
||||
/>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<ImageEditModal
|
||||
v-model:open="editModalVisible"
|
||||
:image-data="currentImageData"
|
||||
@success="handleEditSuccess"
|
||||
@cancel="editModalVisible = false"
|
||||
/>
|
||||
</Page>
|
||||
<!-- 编辑弹窗 -->
|
||||
<ImageEditModal
|
||||
v-model:open="editModalVisible"
|
||||
:image-data="currentImageData"
|
||||
@success="handleEditSuccess"
|
||||
@cancel="editModalVisible = false"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
+191
@@ -0,0 +1,191 @@
|
||||
<script lang="ts" setup>
|
||||
import type { ImageVO } from '#/api/media/image/types';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Card, Image, Popconfirm, Space, Tag } from 'ant-design-vue';
|
||||
|
||||
defineProps<Props>();
|
||||
const emit = defineEmits<Emits>();
|
||||
// 创建图标组件
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
interface Props {
|
||||
image: ImageVO.Info;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'download', image: ImageVO.Info): void;
|
||||
(e: 'edit', image: ImageVO.Info): void;
|
||||
(e: 'delete', id: number): void;
|
||||
(e: 'preview', image: ImageVO.Info): void;
|
||||
}
|
||||
|
||||
const handleDownload = (image: ImageVO.Info) => {
|
||||
emit('download', image);
|
||||
};
|
||||
|
||||
const handleEdit = (image: ImageVO.Info) => {
|
||||
emit('edit', image);
|
||||
};
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
emit('delete', id);
|
||||
};
|
||||
|
||||
const getCategoryColor = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'avatar': {
|
||||
return 'green';
|
||||
}
|
||||
case 'image': {
|
||||
return 'blue';
|
||||
}
|
||||
case 'logo': {
|
||||
return 'purple';
|
||||
}
|
||||
default: {
|
||||
return 'default';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const getCategoryText = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'avatar': {
|
||||
return '头像';
|
||||
}
|
||||
case 'image': {
|
||||
return '普通图片';
|
||||
}
|
||||
case 'logo': {
|
||||
return 'Logo';
|
||||
}
|
||||
default: {
|
||||
return '未分类';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// 获取标签列表
|
||||
const getTagList = (tags: string | undefined) => {
|
||||
if (!tags) return [];
|
||||
return tags
|
||||
.split(',')
|
||||
.map((tag) => tag.trim())
|
||||
.filter(Boolean);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card hoverable :body-style="{ padding: 0 }" class="image-card group">
|
||||
<!-- 图片区域 -->
|
||||
<div
|
||||
class="relative aspect-square cursor-pointer overflow-hidden rounded-t-lg bg-gray-100 dark:bg-neutral-800"
|
||||
>
|
||||
<Image
|
||||
:src="image.url"
|
||||
:alt="image.filename"
|
||||
class="h-full w-full object-cover transition-transform duration-300 group-hover:scale-105"
|
||||
:preview="true"
|
||||
/>
|
||||
|
||||
<!-- 分类标签 -->
|
||||
<div class="absolute left-2 top-2">
|
||||
<Tag :color="getCategoryColor(image.category)" size="small">
|
||||
{{ getCategoryText(image.category) }}
|
||||
</Tag>
|
||||
</div>
|
||||
|
||||
<!-- 标签列表(如果有多个标签) -->
|
||||
<div
|
||||
v-if="getTagList(image.tags).length > 0"
|
||||
class="absolute right-2 top-2 flex max-w-[calc(100%-80px)] flex-wrap gap-1"
|
||||
>
|
||||
<Tag
|
||||
v-for="(tag, index) in getTagList(image.tags).slice(0, 2)"
|
||||
:key="index"
|
||||
size="small"
|
||||
color="blue"
|
||||
class="max-w-[80px] truncate"
|
||||
>
|
||||
{{ tag }}
|
||||
</Tag>
|
||||
<Tag v-if="getTagList(image.tags).length > 2" size="small" color="blue">
|
||||
+{{ getTagList(image.tags).length - 2 }}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 信息区域 -->
|
||||
<div class="p-3">
|
||||
<div
|
||||
class="mb-1 truncate text-sm font-medium text-gray-900 dark:text-gray-100"
|
||||
:title="image.filename"
|
||||
>
|
||||
{{ image.filename || '未命名' }}
|
||||
</div>
|
||||
<div class="mb-3 text-xs text-gray-500 dark:text-gray-400">
|
||||
{{ image.uploadTime }}
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<Space size="small" class="w-full justify-between">
|
||||
<Space size="small">
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleDownload(image)"
|
||||
title="下载"
|
||||
>
|
||||
<template #icon>
|
||||
<DownloadIcon class="h-4 w-4" />
|
||||
</template>
|
||||
下载
|
||||
</Button>
|
||||
<Button
|
||||
type="text"
|
||||
size="small"
|
||||
@click="handleEdit(image)"
|
||||
title="编辑"
|
||||
>
|
||||
<template #icon>
|
||||
<EditIcon class="h-4 w-4" />
|
||||
</template>
|
||||
编辑
|
||||
</Button>
|
||||
</Space>
|
||||
<Popconfirm
|
||||
title="确定要删除这张图片吗?"
|
||||
@confirm="handleDelete(image.id)"
|
||||
>
|
||||
<Button type="text" size="small" danger title="删除">
|
||||
<template #icon>
|
||||
<TrashIcon class="h-4 w-4" />
|
||||
</template>
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</div>
|
||||
</Card>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.image-card {
|
||||
transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
||||
border: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.image-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
||||
border-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.image-card :deep(.ant-card-body) {
|
||||
padding: 0 !important;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,247 @@
|
||||
<script setup lang="ts">
|
||||
import type { ImageDTO, ImageVO } from '#/api/media/image/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
import { ref, watch } from 'vue';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Col,
|
||||
Form,
|
||||
Input,
|
||||
message,
|
||||
Pagination,
|
||||
Row,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
import { getImagePageApi } from '#/api/media/image';
|
||||
|
||||
import ImageCard from './components/ImageCard.vue';
|
||||
|
||||
defineOptions({ name: 'ImageGridView' });
|
||||
|
||||
const props = defineProps<{
|
||||
categoryOptions: Array<{ label: string; value: string }>;
|
||||
searchForm: {
|
||||
category?: string;
|
||||
filename: string;
|
||||
};
|
||||
uploadLoading?: boolean;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'edit', image: ImageVO.Info): void;
|
||||
(e: 'delete', id: number): void;
|
||||
(e: 'download', image: ImageVO.Info): void;
|
||||
(e: 'preview', image: ImageVO.Info): void;
|
||||
(e: 'update:searchForm', value: typeof props.searchForm): void;
|
||||
}>();
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const imageList = ref<ImageVO.Info[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(24); // 网格视图默认24个
|
||||
|
||||
// 本地搜索表单副本(用于 v-model)
|
||||
const localSearchForm = ref({
|
||||
filename: props.searchForm.filename,
|
||||
category: props.searchForm.category,
|
||||
});
|
||||
|
||||
// 监听 props 变化,同步到本地
|
||||
watch(
|
||||
() => props.searchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
localSearchForm.value.filename !== newForm.filename ||
|
||||
localSearchForm.value.category !== newForm.category
|
||||
) {
|
||||
localSearchForm.value.filename = newForm.filename;
|
||||
localSearchForm.value.category = newForm.category;
|
||||
current.value = 1;
|
||||
loadImageList();
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// 监听本地表单变化,同步到父组件
|
||||
watch(
|
||||
localSearchForm,
|
||||
(newForm) => {
|
||||
if (
|
||||
props.searchForm.filename !== newForm.filename ||
|
||||
props.searchForm.category !== newForm.category
|
||||
) {
|
||||
emit('update:searchForm', { ...newForm });
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
);
|
||||
|
||||
// 加载图片列表
|
||||
const loadImageList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<ImageDTO.Filters> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: localSearchForm.value.filename || undefined,
|
||||
category: localSearchForm.value.category || undefined,
|
||||
},
|
||||
};
|
||||
|
||||
const response = await getImagePageApi(params);
|
||||
imageList.value = response.records;
|
||||
total.value = response.total;
|
||||
} catch {
|
||||
message.error('加载图片列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 搜索
|
||||
const handleSearch = () => {
|
||||
current.value = 1;
|
||||
loadImageList();
|
||||
};
|
||||
|
||||
// 重置
|
||||
const handleReset = () => {
|
||||
localSearchForm.value.filename = '';
|
||||
localSearchForm.value.category = undefined;
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
// 分页变化
|
||||
const handlePageChange = (page: number, size: number) => {
|
||||
current.value = page;
|
||||
pageSize.value = size;
|
||||
loadImageList();
|
||||
};
|
||||
|
||||
// 事件处理
|
||||
const handleEdit = (image: ImageVO.Info) => {
|
||||
emit('edit', image);
|
||||
};
|
||||
|
||||
const handleDelete = (id: number) => {
|
||||
emit('delete', id);
|
||||
};
|
||||
|
||||
const handleDownload = (image: ImageVO.Info) => {
|
||||
emit('download', image);
|
||||
};
|
||||
|
||||
const handlePreview = (image: ImageVO.Info) => {
|
||||
emit('preview', image);
|
||||
};
|
||||
|
||||
// 初始化
|
||||
loadImageList();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="flex-col">
|
||||
<!-- 搜索区域 -->
|
||||
<Card class="mb-4" :body-style="{ padding: '16px' }">
|
||||
<Form :model="localSearchForm" layout="inline" class="w-full">
|
||||
<div class="flex flex-wrap items-center gap-4">
|
||||
<Form.Item label="文件名" class="mb-0">
|
||||
<Input
|
||||
v-model:value="localSearchForm.filename"
|
||||
placeholder="请输入文件名"
|
||||
style="width: 200px"
|
||||
allow-clear
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="图片分类" class="mb-0">
|
||||
<Select
|
||||
v-model:value="localSearchForm.category"
|
||||
placeholder="请选择图片分类"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in categoryOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item class="mb-0">
|
||||
<Space>
|
||||
<Button type="primary" @click="handleSearch">搜索</Button>
|
||||
<Button @click="handleReset">重置</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
<div class="ml-auto text-sm text-gray-500 dark:text-gray-400">
|
||||
共 {{ total }} 张图片
|
||||
</div>
|
||||
</div>
|
||||
</Form>
|
||||
</Card>
|
||||
|
||||
<!-- 网格内容 -->
|
||||
<Card class="flex-1" :body-style="{ padding: '16px' }">
|
||||
<Spin :spinning="loading">
|
||||
<Row :gutter="[16, 16]">
|
||||
<Col
|
||||
v-for="image in imageList"
|
||||
:key="image.id"
|
||||
:xs="12"
|
||||
:sm="8"
|
||||
:md="6"
|
||||
:lg="4"
|
||||
:xl="3"
|
||||
>
|
||||
<ImageCard
|
||||
:image="image"
|
||||
@download="handleDownload"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@preview="handlePreview"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div
|
||||
v-if="!loading && imageList.length === 0"
|
||||
class="py-16 text-center"
|
||||
>
|
||||
<div class="mb-4 text-6xl">📷</div>
|
||||
<div class="mb-2 text-lg text-gray-400">暂无图片数据</div>
|
||||
<div class="text-sm text-gray-400">请上传图片或调整搜索条件</div>
|
||||
</div>
|
||||
|
||||
<!-- 分页 -->
|
||||
<div v-if="total > 0" class="mt-6 flex justify-center">
|
||||
<Pagination
|
||||
v-model:current="current"
|
||||
v-model:page-size="pageSize"
|
||||
:total="total"
|
||||
:page-size-options="['12', '24', '48', '96']"
|
||||
show-size-changer
|
||||
show-quick-jumper
|
||||
:show-total="
|
||||
(total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`
|
||||
"
|
||||
@change="handlePageChange"
|
||||
/>
|
||||
</div>
|
||||
</Spin>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in New Issue
Block a user