mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 22:29:19 +08:00
完善创建公司初始化数据相关
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
<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,
|
||||
Select,
|
||||
Table,
|
||||
Upload,
|
||||
message,
|
||||
Tag,
|
||||
@@ -16,6 +12,8 @@ import {
|
||||
Tooltip
|
||||
} from 'ant-design-vue';
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
import FileEditModal from './components/FileEditModal.vue';
|
||||
|
||||
// 创建图标组件
|
||||
@@ -67,160 +65,148 @@ const fileFormatOptions = [
|
||||
{ label: '其他', value: 'other' },
|
||||
];
|
||||
|
||||
// 表格列配置
|
||||
const columns = [
|
||||
{
|
||||
title: '文件名',
|
||||
dataIndex: 'filename',
|
||||
key: 'filename',
|
||||
width: 300,
|
||||
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.fileFormat || '未知'),
|
||||
]);
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
minWidth: 'auto',
|
||||
title: '序号',
|
||||
},
|
||||
{
|
||||
title: '文件名',
|
||||
minWidth: 300,
|
||||
slots: { default: 'filename' },
|
||||
},
|
||||
{
|
||||
title: '文件格式',
|
||||
minWidth: 120,
|
||||
slots: { default: 'fileFormat' },
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
minWidth: 200,
|
||||
slots: { default: 'tags' },
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
minWidth: 200,
|
||||
slots: { default: 'remark' },
|
||||
},
|
||||
{
|
||||
field: 'uploadTime',
|
||||
title: '上传时间',
|
||||
minWidth: 180,
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
minWidth: 200,
|
||||
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<FileDTO.Filters> = {
|
||||
page: page.currentPage,
|
||||
pageSize: page.pageSize,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
fileFormat: searchForm.value.fileFormat || undefined,
|
||||
},
|
||||
};
|
||||
const response = await getFilePageApi(params);
|
||||
fileList.value = response.records;
|
||||
total.value = response.total;
|
||||
return {
|
||||
items: response.records,
|
||||
total: response.total,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('加载文件列表失败:', error);
|
||||
message.error('加载文件列表失败');
|
||||
return {
|
||||
items: [],
|
||||
total: 0,
|
||||
};
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '文件格式',
|
||||
dataIndex: 'fileFormat',
|
||||
key: 'fileFormat',
|
||||
width: 120,
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
return h(Tag, { color: 'blue' }, () => record.fileFormat || '未知');
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '标签',
|
||||
dataIndex: 'tags',
|
||||
key: 'tags',
|
||||
width: 200,
|
||||
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;' },
|
||||
tags.map(tag => h(Tag, { color: 'green', size: 'small' }, () => tag.trim()))
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '描述',
|
||||
dataIndex: 'remark',
|
||||
key: 'remark',
|
||||
width: 200,
|
||||
customRender: ({ record }: { record: FileVO.Info }) => {
|
||||
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: FileVO.Info }) => {
|
||||
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(DeleteIcon, { class: 'w-4 h-4' })
|
||||
})
|
||||
})
|
||||
}),
|
||||
]);
|
||||
},
|
||||
},
|
||||
];
|
||||
};
|
||||
|
||||
// 计算属性 - 由于使用后端分页,不再需要前端过滤
|
||||
const filteredFileList = computed(() => fileList.value);
|
||||
// 搜索表单配置
|
||||
const formOptions = computed(() => ({
|
||||
schema: [
|
||||
{
|
||||
component: 'Input',
|
||||
componentProps: {
|
||||
placeholder: '请输入文件名',
|
||||
},
|
||||
fieldName: 'filename',
|
||||
label: '文件名',
|
||||
},
|
||||
{
|
||||
component: 'Select',
|
||||
componentProps: {
|
||||
placeholder: '请选择文件格式',
|
||||
options: fileFormatOptions,
|
||||
allowClear: true,
|
||||
},
|
||||
fieldName: 'fileFormat',
|
||||
label: '文件格式',
|
||||
},
|
||||
],
|
||||
showDefaultActions: true,
|
||||
collapsed: true,
|
||||
collapsedRows: 1,
|
||||
}));
|
||||
|
||||
// 方法
|
||||
const loadFileList = async () => {
|
||||
loading.value = true;
|
||||
try {
|
||||
const params: PageQueryDTO<FileDTO.Filters> = {
|
||||
page: current.value,
|
||||
pageSize: pageSize.value,
|
||||
filters: {
|
||||
filename: searchForm.value.filename || undefined,
|
||||
fileFormat: searchForm.value.fileFormat || undefined,
|
||||
}
|
||||
};
|
||||
|
||||
const response = await getFilePageApi(params);
|
||||
fileList.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;
|
||||
loadFileList();
|
||||
};
|
||||
|
||||
const handleReset = () => {
|
||||
// 处理重置
|
||||
function handleReset() {
|
||||
searchForm.value = {
|
||||
filename: '',
|
||||
fileFormat: undefined,
|
||||
};
|
||||
handleSearch();
|
||||
};
|
||||
current.value = 1;
|
||||
refreshTable();
|
||||
}
|
||||
|
||||
const handleUpload = async (file: File) => {
|
||||
uploadLoading.value = true;
|
||||
try {
|
||||
await uploadFileApi(file);
|
||||
message.success('文件上传成功');
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('文件上传失败');
|
||||
} finally {
|
||||
@@ -233,7 +219,7 @@ const handleBatchUpload = async (files: File[]) => {
|
||||
try {
|
||||
await batchUploadFilesApi(files);
|
||||
message.success(`成功上传 ${files.length} 个文件`);
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('批量上传失败');
|
||||
} finally {
|
||||
@@ -261,14 +247,14 @@ const handleDelete = async (id: number) => {
|
||||
try {
|
||||
await deleteFileApi(id);
|
||||
message.success('删除成功');
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
} catch (error) {
|
||||
message.error('删除失败');
|
||||
}
|
||||
};
|
||||
|
||||
const handleEditSuccess = () => {
|
||||
loadFileList();
|
||||
refreshTable();
|
||||
};
|
||||
|
||||
// 上传配置
|
||||
@@ -293,84 +279,103 @@ const uploadProps = {
|
||||
},
|
||||
};
|
||||
|
||||
// 初始化
|
||||
loadFileList();
|
||||
// 创建 VbenVxeGrid 实例
|
||||
const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
formOptions: formOptions.value,
|
||||
showSearchForm: true,
|
||||
tableTitle: '文件管理',
|
||||
});
|
||||
</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.fileFormat"
|
||||
placeholder="请选择文件格式"
|
||||
style="width: 150px"
|
||||
allow-clear
|
||||
<Page title="文件仓库" auto-content-height>
|
||||
<template #description>
|
||||
<div class="text-foreground/80 mt-2">
|
||||
管理文件资源,支持文件上传、预览、下载和编辑
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- VbenVxeGrid 表格 -->
|
||||
<Grid :loading="loading">
|
||||
<!-- 工具栏工具 -->
|
||||
<template #toolbar-tools>
|
||||
<Space>
|
||||
<Upload v-bind="uploadProps">
|
||||
<Button type="primary" :loading="uploadLoading">
|
||||
<UploadIcon />
|
||||
上传文件
|
||||
</Button>
|
||||
</Upload>
|
||||
</Space>
|
||||
</template>
|
||||
|
||||
<!-- 文件名列 -->
|
||||
<template #filename="{ row }: { row: any }">
|
||||
<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>
|
||||
|
||||
<!-- 文件格式列 -->
|
||||
<template #fileFormat="{ row }: { row: any }">
|
||||
<Tag color="blue">{{ row.fileFormat || '未知' }}</Tag>
|
||||
</template>
|
||||
|
||||
<!-- 标签列 -->
|
||||
<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"
|
||||
size="small"
|
||||
>
|
||||
<Select.Option
|
||||
v-for="option in fileFormatOptions"
|
||||
: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>
|
||||
{{ tag.trim() }}
|
||||
</Tag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 操作区域 -->
|
||||
<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">支持批量上传,单个文件最大100MB</span>
|
||||
</div>
|
||||
<div class="text-gray-500">
|
||||
共 {{ total }} 个文件
|
||||
</div>
|
||||
</div>
|
||||
<!-- 描述列 -->
|
||||
<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;">
|
||||
{{ row.remark }}
|
||||
</span>
|
||||
</Tooltip>
|
||||
<span v-else style="color: #999;">无描述</span>
|
||||
</template>
|
||||
|
||||
<!-- 文件列表 -->
|
||||
<div class="bg-white rounded-lg shadow-sm">
|
||||
<Table
|
||||
:columns="columns"
|
||||
:data-source="filteredFileList"
|
||||
: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>
|
||||
<!-- 操作列 -->
|
||||
<template #action="{ row }: { row: any }">
|
||||
<Space>
|
||||
<Tooltip title="预览">
|
||||
<Button type="text" size="small" @click="handlePreview(row)">
|
||||
<EyeIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="下载">
|
||||
<Button type="text" size="small" @click="handleDownload(row)">
|
||||
<DownloadIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Tooltip title="编辑">
|
||||
<Button type="text" size="small" @click="handleEdit(row)">
|
||||
<EditIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
<Popconfirm title="确定要删除这个文件吗?" @confirm="handleDelete(row.id)">
|
||||
<Tooltip title="删除">
|
||||
<Button type="text" size="small" danger>
|
||||
<DeleteIcon class="w-4 h-4" />
|
||||
</Button>
|
||||
</Tooltip>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
</template>
|
||||
</Grid>
|
||||
|
||||
<!-- 编辑弹窗 -->
|
||||
<FileEditModal
|
||||
|
||||
Reference in New Issue
Block a user