mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:49:20 +08:00
优化部分模块
This commit is contained in:
+105
@@ -0,0 +1,105 @@
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
title="编辑文件信息"
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="标签" name="tags">
|
||||
<Input
|
||||
v-model:value="formData.tags"
|
||||
placeholder="请输入标签,多个标签用逗号分隔"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入文件描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</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'
|
||||
import type { FileDTO, FileVO } from '#/api/media/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>
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Table,
|
||||
Upload,
|
||||
@@ -17,6 +16,7 @@ import {
|
||||
Tooltip
|
||||
} from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import FileEditModal from './components/FileEditModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
@@ -28,55 +28,43 @@ const EyeIcon = createIconifyIcon('lucide:eye');
|
||||
import {
|
||||
uploadFileApi,
|
||||
batchUploadFilesApi,
|
||||
updateFileApi,
|
||||
deleteFileApi,
|
||||
getFilePageApi,
|
||||
type MediaFileVO,
|
||||
type MediaFileDTO
|
||||
} from '#/api/media';
|
||||
import type { FileVO, FileDTO } from '#/api/media/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
|
||||
defineOptions({ name: 'FileRepository' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const fileList = ref<MediaFileVO.MediaFileInfoVO[]>([]);
|
||||
const fileList = ref<FileVO.Info[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentFileId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
const editModalVisible = ref(false);
|
||||
const currentFileData = ref<FileVO.Info | null>(null);
|
||||
const uploadLoading = ref(false);
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
filename: '',
|
||||
fileType: undefined as string | undefined,
|
||||
fileFormat: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<MediaFileDTO.UpdateFileDTO>({
|
||||
id: 0,
|
||||
fileType: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
});
|
||||
|
||||
// 文件类型选项
|
||||
const fileTypeOptions = [
|
||||
{ label: 'PDF', value: 'PDF' },
|
||||
{ label: 'CAD', value: 'CAD' },
|
||||
{ label: 'Excel', value: 'Excel' },
|
||||
{ label: 'Word', value: 'Word' },
|
||||
{ label: 'PPT', value: 'PPT' },
|
||||
{ label: '图片', value: '图片' },
|
||||
{ label: '视频', value: '视频' },
|
||||
{ label: '音频', value: '音频' },
|
||||
{ label: '压缩包', value: '压缩包' },
|
||||
{ label: '其他', value: '其他' },
|
||||
// 文件格式选项
|
||||
const fileFormatOptions = [
|
||||
{ label: 'PDF', value: 'pdf' },
|
||||
{ label: 'CAD', value: 'cad' },
|
||||
{ label: 'Excel', value: 'xlsx' },
|
||||
{ label: 'Word', value: 'doc' },
|
||||
{ label: 'PPT', value: 'ppt' },
|
||||
{ label: '图片', value: 'jpg' },
|
||||
{ label: '视频', value: 'mp4' },
|
||||
{ label: '音频', value: 'mp3' },
|
||||
{ label: '压缩包', value: 'zip' },
|
||||
{ label: '其他', value: 'other' },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
@@ -86,20 +74,20 @@ const columns = [
|
||||
dataIndex: 'filename',
|
||||
key: 'filename',
|
||||
width: 300,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
return h('div', { style: 'display: flex; align-items: center; gap: 8px;' }, [
|
||||
h('span', { style: 'font-weight: 500;' }, record.filename),
|
||||
h(Tag, { color: 'blue', size: 'small' }, () => record.fileType || '未知'),
|
||||
h(Tag, { color: 'blue', size: 'small' }, () => record.fileFormat || '未知'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '文件类型',
|
||||
dataIndex: 'fileType',
|
||||
key: 'fileType',
|
||||
title: '文件格式',
|
||||
dataIndex: 'fileFormat',
|
||||
key: 'fileFormat',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
return h(Tag, { color: 'blue' }, () => record.fileType || '未知');
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
return h(Tag, { color: 'blue' }, () => record.fileFormat || '未知');
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -107,7 +95,7 @@ const columns = [
|
||||
dataIndex: 'tags',
|
||||
key: 'tags',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
if (!record.tags) return h('span', { style: 'color: #999;' }, '无标签');
|
||||
const tags = record.tags.split(',').filter(tag => tag.trim());
|
||||
return h('div', { style: 'display: flex; flex-wrap: wrap; gap: 4px;' },
|
||||
@@ -120,7 +108,7 @@ const columns = [
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
if (!record.remark) return h('span', { style: 'color: #999;' }, '无描述');
|
||||
return h(Tooltip, { title: record.remark }, {
|
||||
default: () => h('span', {
|
||||
@@ -140,7 +128,7 @@ const columns = [
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: MediaFileVO.MediaFileInfoVO }) => {
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Tooltip, { title: '预览' }, {
|
||||
default: () => h(Button, {
|
||||
@@ -195,12 +183,12 @@ const filteredFileList = computed(() => fileList.value);
|
||||
const loadFileList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<MediaFileDTO.MediaFileFilterDTO> = {
|
||||
const params: PageQueryDTO<FileDTO.Filters> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
fileType: searchForm.value.fileType || undefined,
|
||||
fileFormat: searchForm.value.fileFormat || undefined,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -222,7 +210,7 @@ const handleSearch = () => {
|
||||
const handleReset = () => {
|
||||
searchForm.value = {
|
||||
filename: '',
|
||||
fileType: undefined,
|
||||
fileFormat: undefined,
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
@@ -253,24 +241,16 @@ const handleBatchUpload = async (files: File[]) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = (record: MediaFileVO.MediaFileInfoVO) => {
|
||||
isEdit.value = true;
|
||||
modalTitle.value = '编辑文件信息';
|
||||
currentFileId.value = record.id;
|
||||
formData.value = {
|
||||
id: record.id,
|
||||
fileType: record.fileType,
|
||||
tags: record.tags,
|
||||
remark: record.remark,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
const handleEdit = (record: FileVO.Info) => {
|
||||
currentFileData.value = record;
|
||||
editModalVisible.value = true;
|
||||
};
|
||||
|
||||
const handlePreview = (record: MediaFileVO.MediaFileInfoVO) => {
|
||||
const handlePreview = (record: FileVO.Info) => {
|
||||
window.open(record.url, '_blank');
|
||||
};
|
||||
|
||||
const handleDownload = (record: MediaFileVO.MediaFileInfoVO) => {
|
||||
const handleDownload = (record: FileVO.Info) => {
|
||||
const link = document.createElement('a');
|
||||
link.href = record.url;
|
||||
link.download = record.filename;
|
||||
@@ -287,26 +267,8 @@ const handleDelete = async (id: number) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
await updateFileApi(formData.value);
|
||||
message.success('更新成功');
|
||||
modalVisible.value = false;
|
||||
loadFileList();
|
||||
} catch (error) {
|
||||
message.error('更新失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false;
|
||||
formData.value = {
|
||||
id: 0,
|
||||
fileType: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
};
|
||||
const handleEditSuccess = () => {
|
||||
loadFileList();
|
||||
};
|
||||
|
||||
// 上传配置
|
||||
@@ -350,15 +312,15 @@ loadFileList();
|
||||
@press-enter="handleSearch"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="文件类型">
|
||||
<Form.Item label="文件格式">
|
||||
<Select
|
||||
v-model:value="searchForm.fileType"
|
||||
placeholder="请选择文件类型"
|
||||
v-model:value="searchForm.fileFormat"
|
||||
placeholder="请选择文件格式"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in fileTypeOptions"
|
||||
v-for="option in fileFormatOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
@@ -411,44 +373,12 @@ loadFileList();
|
||||
</div>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="文件类型" name="fileType">
|
||||
<Select v-model:value="formData.fileType" placeholder="请选择文件类型">
|
||||
<Select.Option
|
||||
v-for="option in fileTypeOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="标签" name="tags">
|
||||
<Input
|
||||
v-model:value="formData.tags"
|
||||
placeholder="请输入标签,多个标签用逗号分隔"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="描述" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入文件描述"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
<FileEditModal
|
||||
v-model:open="editModalVisible"
|
||||
:file-data="currentFileData"
|
||||
@success="handleEditSuccess"
|
||||
@cancel="editModalVisible = false"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
|
||||
+20
-18
@@ -1,7 +1,7 @@
|
||||
<script lang="ts" setup>
|
||||
import { Card, Image, Tag, Button, Space, Popconfirm } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import type { MediaImageVO } from '#/api/media';
|
||||
import type { ImageVO } from '#/api/media/types';
|
||||
|
||||
// 创建图标组件
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
@@ -9,23 +9,23 @@ const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
|
||||
interface Props {
|
||||
image: MediaImageVO.MediaImageInfoVO;
|
||||
image: ImageVO.Info;
|
||||
}
|
||||
|
||||
interface Emits {
|
||||
(e: 'download', image: MediaImageVO.MediaImageInfoVO): void;
|
||||
(e: 'edit', image: MediaImageVO.MediaImageInfoVO): void;
|
||||
(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: MediaImageVO.MediaImageInfoVO) => {
|
||||
const handleDownload = (image: ImageVO.Info) => {
|
||||
emit('download', image);
|
||||
};
|
||||
|
||||
const handleEdit = (image: MediaImageVO.MediaImageInfoVO) => {
|
||||
const handleEdit = (image: ImageVO.Info) => {
|
||||
emit('edit', image);
|
||||
};
|
||||
|
||||
@@ -33,15 +33,13 @@ const handleDelete = (id: number) => {
|
||||
emit('delete', id);
|
||||
};
|
||||
|
||||
const getTagColor = (type: string | undefined) => {
|
||||
switch (type) {
|
||||
case '设计图':
|
||||
const getTagColor = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'image':
|
||||
return 'blue';
|
||||
case '实物图':
|
||||
case 'avatar':
|
||||
return 'green';
|
||||
case '细节图':
|
||||
return 'orange';
|
||||
case '工艺图':
|
||||
case 'logo':
|
||||
return 'purple';
|
||||
default:
|
||||
return '#006BE6';
|
||||
@@ -55,22 +53,26 @@ const getTagColor = (type: string | undefined) => {
|
||||
:body-style="{ padding: '8px' }"
|
||||
class="image-card"
|
||||
>
|
||||
<div class="relative">
|
||||
<div class="relative overflow-hidden">
|
||||
<Image
|
||||
:src="image.url"
|
||||
:alt="image.filename"
|
||||
class="w-full h-32 object-cover rounded"
|
||||
:preview="true"
|
||||
/>
|
||||
<div class="absolute top-2 right-2">
|
||||
<Tag :color="getTagColor(image.type)">
|
||||
{{ image.type || '未分类' }}
|
||||
<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 }}
|
||||
{{ image.filename || '未命名' }}
|
||||
</div>
|
||||
<div class="text-xs text-gray-500 mt-1">
|
||||
{{ image.uploadTime }}
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
<Modal
|
||||
v-model:open="visible"
|
||||
title="编辑图片信息"
|
||||
@ok="handleOk"
|
||||
@cancel="handleCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="标签" name="tags">
|
||||
<Input
|
||||
v-model:value="formData.tags"
|
||||
placeholder="请输入标签,多个标签用逗号分隔"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="说明" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入图片说明"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</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'
|
||||
import type { ImageDTO, ImageVO } from '#/api/media/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>
|
||||
+272
@@ -0,0 +1,272 @@
|
||||
<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'
|
||||
import type { ImageVO, ImageDTO } from '#/api/media/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,256 +1,196 @@
|
||||
<script lang="ts" setup>
|
||||
import { h, ref, computed } from 'vue';
|
||||
import { ref, computed } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
Modal,
|
||||
Select,
|
||||
Table,
|
||||
Upload,
|
||||
message,
|
||||
Tag,
|
||||
Space,
|
||||
Popconfirm,
|
||||
Tooltip,
|
||||
Image,
|
||||
Row,
|
||||
Col
|
||||
} from 'ant-design-vue';
|
||||
import { Button, message, Space, Tag, Upload, Image } from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import ImageCard from './components/ImageCard.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const EyeIcon = createIconifyIcon('lucide:eye');
|
||||
const DownloadIcon = createIconifyIcon('lucide:download');
|
||||
const EditIcon = createIconifyIcon('lucide:edit');
|
||||
const TrashIcon = createIconifyIcon('lucide:trash-2');
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
const ListIcon = createIconifyIcon('lucide:list');
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import {
|
||||
uploadImageApi,
|
||||
batchUploadImagesApi,
|
||||
updateImageApi,
|
||||
deleteImageApi,
|
||||
getImagePageApi,
|
||||
type MediaImageVO,
|
||||
type MediaImageDTO
|
||||
} from '#/api/media';
|
||||
import type { ImageVO, ImageDTO } from '#/api/media/types';
|
||||
import type { PageQueryDTO } from '#/types/common';
|
||||
import ImageEditModal from './components/ImageEditModal.vue';
|
||||
import ImageGridView from './components/ImageGridView.vue';
|
||||
|
||||
// 创建图标组件
|
||||
const UploadIcon = createIconifyIcon('lucide:upload');
|
||||
const GridIcon = createIconifyIcon('lucide:grid-3x3');
|
||||
const ListIcon = createIconifyIcon('lucide:list');
|
||||
|
||||
defineOptions({ name: 'ImageRepository' });
|
||||
|
||||
// 响应式数据
|
||||
const loading = ref(false);
|
||||
const imageList = ref<MediaImageVO.MediaImageInfoVO[]>([]);
|
||||
const total = ref(0);
|
||||
const current = ref(1);
|
||||
const pageSize = ref(20);
|
||||
const modalVisible = ref(false);
|
||||
const modalTitle = ref('');
|
||||
const isEdit = ref(false);
|
||||
const currentImageId = ref<number | null>(null);
|
||||
const formRef = ref();
|
||||
const editModalVisible = ref(false);
|
||||
const currentImageData = ref<ImageVO.Info | null>(null);
|
||||
const uploadLoading = ref(false);
|
||||
const viewMode = ref<'grid' | 'list'>('grid'); // 视图模式:网格或列表
|
||||
const viewMode = ref<'grid' | 'list'>('grid'); // 默认使用网格视图
|
||||
|
||||
// 搜索表单
|
||||
const searchForm = ref({
|
||||
filename: '',
|
||||
type: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 表单数据
|
||||
const formData = ref<MediaImageDTO.UpdateImageDTO>({
|
||||
id: 0,
|
||||
type: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
category: undefined as string | undefined,
|
||||
});
|
||||
|
||||
// 图片分类选项
|
||||
const imageTypeOptions = [
|
||||
{ label: '设计图', value: '设计图' },
|
||||
{ label: '实物图', value: '实物图' },
|
||||
{ label: '细节图', value: '细节图' },
|
||||
{ label: '工艺图', value: '工艺图' },
|
||||
{ label: '其他', value: '其他' },
|
||||
const imageCategoryOptions = [
|
||||
{ label: '普通图片', value: 'image' },
|
||||
{ label: '头像', value: 'avatar' },
|
||||
{ label: 'Logo', value: 'logo' },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '预览',
|
||||
dataIndex: 'url',
|
||||
key: 'preview',
|
||||
width: 100,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h(Image, {
|
||||
src: record.url,
|
||||
alt: record.filename,
|
||||
width: 60,
|
||||
height: 60,
|
||||
style: { objectFit: 'cover', borderRadius: '4px' },
|
||||
preview: true,
|
||||
});
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: '预览',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'preview' },
|
||||
},
|
||||
{
|
||||
field: 'filename',
|
||||
title: '文件名',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
title: '分类',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'category' },
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
minWidth: 'auto',
|
||||
slots: { default: 'tags' },
|
||||
},
|
||||
{
|
||||
field: 'remark',
|
||||
title: '说明',
|
||||
minWidth: 'auto',
|
||||
showOverflow: 'tooltip' as const,
|
||||
},
|
||||
{
|
||||
field: 'uploadTime',
|
||||
title: '上传时间',
|
||||
minWidth: 'auto',
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 'auto',
|
||||
fixed: 'right' as const,
|
||||
slots: { default: 'action' },
|
||||
},
|
||||
],
|
||||
height: 'auto',
|
||||
border: true,
|
||||
stripe: true,
|
||||
showOverflow: true,
|
||||
size: 'small',
|
||||
toolbarConfig: {
|
||||
custom: true,
|
||||
refresh: true,
|
||||
zoom: true,
|
||||
},
|
||||
data: [],
|
||||
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')[],
|
||||
},
|
||||
// 配置远程加载
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const params: PageQueryDTO<ImageDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
category: searchForm.value.category || undefined,
|
||||
},
|
||||
};
|
||||
const data = await getImagePageApi(params);
|
||||
return {
|
||||
items: data.records,
|
||||
total: data.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('获取图片列表失败:', error);
|
||||
message.error('获取图片列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '文件名',
|
||||
dataIndex: 'filename',
|
||||
key: 'filename',
|
||||
width: 250,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; align-items: center; gap: 8px;' }, [
|
||||
h('span', { style: 'font-weight: 500;' }, record.filename),
|
||||
h(Tag, { color: 'purple', size: 'small' }, () => record.type || '未分类'),
|
||||
]);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '分类',
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h(Tag, { color: 'purple' }, () => record.type || '未分类');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
dataIndex: 'tags',
|
||||
key: 'tags',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
if (!record.tags) return h('span', { style: 'color: #999;' }, '无标签');
|
||||
const tags = record.tags.split(',').filter(tag => tag.trim());
|
||||
return h('div', { style: 'display: flex; flex-wrap: wrap; gap: 4px;' },
|
||||
tags.map(tag => h(Tag, { color: 'green', size: 'small' }, () => tag.trim()))
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '说明',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
if (!record.remark) return h('span', { style: 'color: #999;' }, '无说明');
|
||||
return h(Tooltip, { title: record.remark }, {
|
||||
default: () => h('span', {
|
||||
style: 'display: block; max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;'
|
||||
}, record.remark)
|
||||
});
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '上传时间',
|
||||
dataIndex: 'uploadTime',
|
||||
key: 'uploadTime',
|
||||
width: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 200,
|
||||
fixed: 'right' as const,
|
||||
customRender: ({ record }: { record: MediaImageVO.MediaImageInfoVO }) => {
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, [
|
||||
h(Tooltip, { title: '预览' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handlePreview(record),
|
||||
}, {
|
||||
default: () => h(EyeIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '下载' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleDownload(record),
|
||||
}, {
|
||||
default: () => h(DownloadIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '编辑' }, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
onClick: () => handleEdit(record),
|
||||
}, {
|
||||
default: () => h(EditIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
}),
|
||||
h(Tooltip, { title: '删除' }, {
|
||||
default: () => h(Popconfirm, {
|
||||
title: '确定要删除这张图片吗?',
|
||||
onConfirm: () => handleDelete(record.id),
|
||||
}, {
|
||||
default: () => h(Button, {
|
||||
type: 'text',
|
||||
size: 'small',
|
||||
danger: true,
|
||||
}, {
|
||||
default: () => h(TrashIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
})
|
||||
}),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
// 计算属性 - 由于使用后端分页,不再需要前端过滤
|
||||
const filteredImageList = computed(() => imageList.value);
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入文件名',
|
||||
},
|
||||
fieldName: 'filename',
|
||||
label: '文件名',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择图片分类',
|
||||
options: imageCategoryOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'category',
|
||||
label: '图片分类',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 方法
|
||||
const loadImageList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<MediaImageDTO.MediaImageFilterDTO> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
type: searchForm.value.type || undefined,
|
||||
}
|
||||
};
|
||||
|
||||
const response = await getImagePageApi(params);
|
||||
imageList.value = response.records;
|
||||
total.value = response.total;
|
||||
} catch (error) {
|
||||
message.error('加载图片列表失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
// 刷新表格数据
|
||||
function refreshTable() {
|
||||
if (gridApi) {
|
||||
gridApi.reload();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const handleSearch = () => {
|
||||
current.value = 1;
|
||||
loadImageList();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
searchForm.value = {
|
||||
filename: '',
|
||||
type: undefined,
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '图片管理',
|
||||
});
|
||||
|
||||
// 处理上传
|
||||
const handleUpload = async (file: File) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await uploadImageApi(file);
|
||||
message.success('图片上传成功');
|
||||
loadImageList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('图片上传失败');
|
||||
} finally {
|
||||
@@ -258,12 +198,13 @@ const handleUpload = async (file: File) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 处理批量上传
|
||||
const handleBatchUpload = async (files: File[]) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await batchUploadImagesApi(files);
|
||||
message.success(`成功上传 ${files.length} 张图片`);
|
||||
loadImageList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
@@ -271,62 +212,42 @@ const handleBatchUpload = async (files: File[]) => {
|
||||
}
|
||||
};
|
||||
|
||||
const handleEdit = (record: MediaImageVO.MediaImageInfoVO) => {
|
||||
isEdit.value = true;
|
||||
modalTitle.value = '编辑图片信息';
|
||||
currentImageId.value = record.id;
|
||||
formData.value = {
|
||||
id: record.id,
|
||||
type: record.type,
|
||||
tags: record.tags,
|
||||
remark: record.remark,
|
||||
};
|
||||
modalVisible.value = true;
|
||||
// 处理编辑
|
||||
const handleEdit = (record: ImageVO.Info) => {
|
||||
currentImageData.value = record;
|
||||
editModalVisible.value = true;
|
||||
};
|
||||
|
||||
const handlePreview = (record: MediaImageVO.MediaImageInfoVO) => {
|
||||
// 处理预览
|
||||
const handlePreview = (record: ImageVO.Info) => {
|
||||
window.open(record.url, '_blank');
|
||||
};
|
||||
|
||||
const handleDownload = (record: MediaImageVO.MediaImageInfoVO) => {
|
||||
// 处理下载
|
||||
const handleDownload = (record: ImageVO.Info) => {
|
||||
const link = document.createElement('a');
|
||||
link.href = record.url;
|
||||
link.download = record.filename;
|
||||
link.download = record.filename || '未命名';
|
||||
link.click();
|
||||
};
|
||||
|
||||
// 处理删除
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await deleteImageApi(id);
|
||||
message.success('删除成功');
|
||||
loadImageList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalOk = async () => {
|
||||
try {
|
||||
await formRef.value?.validate();
|
||||
await updateImageApi(formData.value);
|
||||
message.success('更新成功');
|
||||
modalVisible.value = false;
|
||||
loadImageList();
|
||||
} catch (error) {
|
||||
message.error('更新失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleModalCancel = () => {
|
||||
modalVisible.value = false;
|
||||
formData.value = {
|
||||
id: 0,
|
||||
type: '',
|
||||
tags: '',
|
||||
remark: '',
|
||||
};
|
||||
// 处理编辑成功
|
||||
const handleEditSuccess = () => {
|
||||
refreshTable();
|
||||
};
|
||||
|
||||
// 切换视图模式
|
||||
const toggleViewMode = () => {
|
||||
viewMode.value = viewMode.value === 'grid' ? 'list' : 'grid';
|
||||
};
|
||||
@@ -359,62 +280,51 @@ const uploadProps = {
|
||||
},
|
||||
};
|
||||
|
||||
// 初始化
|
||||
loadImageList();
|
||||
// 获取分类标签颜色
|
||||
const getCategoryColor = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'image':
|
||||
return 'blue';
|
||||
case 'avatar':
|
||||
return 'green';
|
||||
case 'logo':
|
||||
return 'purple';
|
||||
default:
|
||||
return 'default';
|
||||
}
|
||||
};
|
||||
|
||||
// 获取分类显示文本
|
||||
const getCategoryText = (category: string | undefined) => {
|
||||
switch (category) {
|
||||
case 'image':
|
||||
return '普通图片';
|
||||
case 'avatar':
|
||||
return '头像';
|
||||
case 'logo':
|
||||
return 'Logo';
|
||||
default:
|
||||
return '未分类';
|
||||
}
|
||||
};
|
||||
|
||||
// 获取标签列表
|
||||
const getTagList = (tags: string | undefined) => {
|
||||
if (!tags) return [];
|
||||
return tags.split(',').map(tag => tag.trim()).filter(tag => tag);
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page>
|
||||
<template #title>图片仓库</template>
|
||||
|
||||
<!-- 搜索区域 -->
|
||||
<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.type"
|
||||
placeholder="请选择图片分类"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in imageTypeOptions"
|
||||
: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="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>
|
||||
<Page title="图片仓库" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理图片资源,支持上传、预览、编辑和分类管理
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
</template>
|
||||
|
||||
<template #extra>
|
||||
<Space>
|
||||
<Button
|
||||
:type="viewMode === 'grid' ? 'primary' : 'default'"
|
||||
@click="toggleViewMode"
|
||||
@@ -429,92 +339,95 @@ loadImageList();
|
||||
<ListIcon class="w-4 h-4 mr-2" />
|
||||
列表视图
|
||||
</Button>
|
||||
<span class="text-gray-500">
|
||||
共 {{ total }} 张图片
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 网格视图 -->
|
||||
<div v-if="viewMode === 'grid'" class="bg-white rounded-lg shadow-sm p-4">
|
||||
<Row :gutter="[16, 16]">
|
||||
<Col
|
||||
v-for="image in filteredImageList"
|
||||
:key="image.id"
|
||||
:xs="12"
|
||||
:sm="8"
|
||||
:md="6"
|
||||
:lg="4"
|
||||
:xl="3"
|
||||
>
|
||||
<ImageCard
|
||||
:image="image"
|
||||
@download="handleDownload"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</div>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 列表视图 -->
|
||||
<div v-else class="bg-white rounded-lg shadow-sm">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="filteredImageList"
|
||||
:loading="loading"
|
||||
:pagination="{
|
||||
current: current,
|
||||
pageSize: pageSize,
|
||||
total: total,
|
||||
showSizeChanger: true,
|
||||
showQuickJumper: true,
|
||||
showTotal: (total, range) => `第 ${range[0]}-${range[1]} 条,共 ${total} 条`,
|
||||
}"
|
||||
row-key="id"
|
||||
:scroll="{ x: 1200 }"
|
||||
/>
|
||||
</div>
|
||||
<Grid
|
||||
v-if="viewMode === 'list'"
|
||||
:loading="loading"
|
||||
>
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<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>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 预览列 -->
|
||||
<template #preview="{ row }: { row: any }">
|
||||
<Image
|
||||
:src="row.url"
|
||||
:alt="row.filename"
|
||||
width="60"
|
||||
height="60"
|
||||
style="object-fit: cover; border-radius: 4px;"
|
||||
:preview="true"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<!-- 分类列 -->
|
||||
<template #category="{ row }: { row: any }">
|
||||
<Tag :color="getCategoryColor(row.category)">
|
||||
{{ getCategoryText(row.category) }}
|
||||
</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 标签列 -->
|
||||
<template #tags="{ row }: { row: any }">
|
||||
<div v-if="row.tags" class="flex flex-wrap gap-1">
|
||||
<Tag
|
||||
v-for="tag in getTagList(row.tags)"
|
||||
:key="tag"
|
||||
size="small"
|
||||
color="blue"
|
||||
>
|
||||
{{ tag }}
|
||||
</Tag>
|
||||
</div>
|
||||
<span v-else class="text-gray-400">无标签</span>
|
||||
</template>
|
||||
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Button size="small" @click="handleDownload(row)">
|
||||
下载
|
||||
</Button>
|
||||
<Button size="small" @click="handleEdit(row)">
|
||||
编辑
|
||||
</Button>
|
||||
<Button size="small" danger @click="handleDelete(row.id)">
|
||||
删除
|
||||
</Button>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 网格视图 -->
|
||||
<ImageGridView
|
||||
v-else
|
||||
:search-form="searchForm"
|
||||
:category-options="imageCategoryOptions"
|
||||
@edit="handleEdit"
|
||||
@delete="handleDelete"
|
||||
@download="handleDownload"
|
||||
@preview="handlePreview"
|
||||
/>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<Modal
|
||||
v-model:open="modalVisible"
|
||||
:title="modalTitle"
|
||||
@ok="handleModalOk"
|
||||
@cancel="handleModalCancel"
|
||||
>
|
||||
<Form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="图片分类" name="type">
|
||||
<Select v-model:value="formData.type" placeholder="请选择图片分类">
|
||||
<Select.Option
|
||||
v-for="option in imageTypeOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item label="标签" name="tags">
|
||||
<Input
|
||||
v-model:value="formData.tags"
|
||||
placeholder="请输入标签,多个标签用逗号分隔"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="说明" name="remark">
|
||||
<Input.TextArea
|
||||
v-model:value="formData.remark"
|
||||
placeholder="请输入图片说明"
|
||||
:rows="3"
|
||||
/>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</Modal>
|
||||
<ImageEditModal
|
||||
v-model:open="editModalVisible"
|
||||
:image-data="currentImageData"
|
||||
@success="handleEditSuccess"
|
||||
@cancel="editModalVisible = false"
|
||||
/>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user