导入导出记录组件

This commit is contained in:
qiuyuan 2025-10-11 14:07:16 +08:00
parent 1d4b75e6f7
commit f3a17474c7
3 changed files with 869 additions and 6 deletions

View File

@ -0,0 +1,296 @@
<template>
<a-modal
v-model:open="visible"
:title="title || '导出记录'"
width="1200px"
:footer="null"
:maskClosable="false"
@cancel="handleCancel"
:destroyOnClose="true"
>
<div class="import-records-modal">
<!-- 表格 -->
<a-table
:dataSource="tableData"
:columns="columns"
:pagination="pagination"
:loading="loading"
:scroll="{ x: 1200 }"
rowKey="taskId"
>
<!-- 状态列渲染 -->
<template #status="{ record }">
<a-tag :color="getStatusColor(record.status)">
{{ getStatusText(record.status) }}
</a-tag>
</template>
<!-- 进度列渲染 -->
<template #progress="{ record }">
<a-progress
:percent="record.progress"
size="small"
:status="getProgressStatus(record.status)"
/>
</template>
<!-- 操作列渲染 -->
<template #action="{ record }">
<a-space>
<a-button type="link" size="small" @click="viewDetails(record)" :disabled="record.status !== 'completed'">
查看详情
</a-button>
<a-button type="primary" size="small" @click="downloadResult(record)" :disabled="record.status !== 'completed'">
下载文件
</a-button>
<a-button type="link" size="small" @click="retryExport(record)" :disabled="record.status !== 'failed'">
重新导出
</a-button>
</a-space>
</template>
</a-table>
</div>
</a-modal>
</template>
<script setup>
import { ref, reactive, onMounted, watch } from 'vue';
import { message } from 'ant-design-vue';
// props
const props = defineProps({
//
title: {
type: String,
default: '导出记录'
},
//
modelValue: {
type: Boolean,
default: false
},
//
fetchData: {
type: Function,
required: true
}
});
// emit
const emit = defineEmits(['update:modelValue', 'close', 'view-details', 'download-result', 'retry-export']);
//
const visible = ref(false);
//
const tableData = ref([]);
//
const loading = ref(false);
//
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
pageSizeOptions: ['10', '20', '50', '100'],
onChange: (page, pageSize) => {
pagination.current = page;
pagination.pageSize = pageSize;
fetchTableData();
},
onShowSizeChange: (current, size) => {
pagination.current = 1;
pagination.pageSize = size;
fetchTableData();
}
});
//
const columns = [
{
title: '任务ID',
dataIndex: 'taskId',
key: 'taskId',
align: 'center',
fixed: 'left',
width: 150,
},
{
title: '任务类型',
dataIndex: 'alias',
key: 'alias',
align: 'center',
width: 150,
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
align: 'center',
width: 100,
slots: { customRender: 'status' },
},
{
title: '进度',
dataIndex: 'progress',
key: 'progress',
align: 'center',
width: 150,
slots: { customRender: 'progress' },
},
{
title: '创建时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
width: 180,
},
{
title: '操作人',
dataIndex: 'createByName',
key: 'createByName',
align: 'center',
width: 120,
},
{
title: '操作',
key: 'action',
align: 'center',
fixed: 'right',
width: 280,
slots: { customRender: 'action' },
},
];
// modelValue
watch(
() => props.modelValue,
(val) => {
visible.value = val;
if (val) {
//
fetchTableData();
}
},
{ immediate: true } //
);
//
const fetchTableData = async () => {
loading.value = true;
try {
//
const result = await props.fetchData({
page: pagination.current,
pageSize: pagination.pageSize
});
// { list: [...], total: 100 }
tableData.value = Array.isArray(result.list) ? result.list : result;
pagination.total = result.total || tableData.value.length;
} catch (error) {
console.error('获取数据失败:', error);
message.error(error.message || '获取导出记录失败');
tableData.value = [];
pagination.total = 0;
} finally {
loading.value = false;
}
};
//
const getStatusText = (status) => {
switch (status) {
case 'completed': return '已完成';
case 'failed': return '失败';
case 'processing': return '处理中';
case 'pending': return '待处理';
default: return status;
}
};
//
const getStatusColor = (status) => {
switch (status) {
case 'completed': return 'green';
case 'failed': return 'red';
case 'processing': return 'blue';
case 'pending': return '#ffcc00';
default: return 'default';
}
};
//
const getProgressStatus = (status) => {
if (status === 'completed') return 'success';
if (status === 'failed') return 'exception';
if (status === 'processing') return 'active';
return 'normal';
};
//
const handleCancel = () => {
visible.value = false;
emit('update:modelValue', false);
emit('close');
};
//
const viewDetails = (record) => {
emit('view-details', record);
};
//
const downloadResult = (record) => {
emit('download-result', record);
};
//
const retryExport = (record) => {
emit('retry-export', record);
};
</script>
<style scoped>
.import-records-modal {
padding: 10px 0;
}
/* 针对表格的样式优化 */
:deep(.ant-table) {
background: #fff;
border-radius: 6px;
}
:deep(.ant-table-thead > tr > th) {
text-align: center;
background-color: #f9f9f9;
font-weight: 600;
}
:deep(.ant-table-tbody > tr > td) {
text-align: center;
}
/* 操作按钮样式 */
:deep(.ant-btn-link) {
height: auto;
padding: 2px 4px;
color: #1890ff;
}
:deep(.ant-btn-link:hover) {
color: #40a9ff;
}
:deep(.ant-btn-primary) {
height: 24px;
padding: 0 8px;
font-size: 12px;
}
</style>

View File

@ -0,0 +1,310 @@
<!-- ImportRecordsModal.vue -->
<template>
<a-modal
v-model:open="visible"
:title="title || '导入记录'"
width="1200px"
:footer="null"
:maskClosable="false"
@cancel="handleCancel"
:destroyOnClose="true"
>
<div class="import-records-modal">
<!-- 表格 -->
<a-table
:dataSource="tableData"
:columns="columns"
:pagination="pagination"
:loading="loading"
:scroll="{ x: 1200 }"
rowKey="taskId"
>
<!-- 状态列渲染 -->
<template #status="{ record }">
<a-tag :color="getStatusColor(record.status)">
{{ getStatusText(record.status) }}
</a-tag>
</template>
<!-- 进度列渲染 -->
<template #progress="{ record }">
<a-progress
:percent="record.progress"
size="small"
:status="getProgressStatus(record.status)"
/>
</template>
<!-- 操作列渲染 -->
<template #action="{ record }">
<a-space>
<a-button type="link" size="small" @click="viewDetails(record)">
查看异常数据
</a-button>
</a-space>
</template>
</a-table>
</div>
</a-modal>
</template>
<script setup>
import { ref, reactive, onMounted, watch } from 'vue';
import { message } from 'ant-design-vue';
// props
const props = defineProps({
//
title: {
type: String,
default: '导入记录'
},
//
modelValue: {
type: Boolean,
default: false
},
//
fetchData: {
type: Function,
required: true
}
});
// emit
const emit = defineEmits(['update:modelValue', 'close', 'view-details', 'download-result', 'retry-import']);
//
const visible = ref(false);
//
const tableData = ref([]);
//
const loading = ref(false);
//
const pagination = reactive({
current: 1,
pageSize: 10,
total: 0,
showSizeChanger: true,
showQuickJumper: true,
pageSizeOptions: ['10', '20', '50', '100'],
onChange: (page, pageSize) => {
pagination.current = page;
pagination.pageSize = pageSize;
fetchTableData();
},
onShowSizeChange: (current, size) => {
pagination.current = 1;
pagination.pageSize = size;
fetchTableData();
}
});
//
const columns = [
{
title: '批次号',
dataIndex: 'taskId',
key: 'taskId',
align: 'center',
fixed: 'left',
width: 150,
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
align: 'center',
width: 100,
slots: { customRender: 'status' },
},
{
title: '导入任务类型',
dataIndex: 'alias',
key: 'alias',
align: 'center',
width: 150,
},
{
title: '总数量',
dataIndex: 'totalCount',
key: 'totalCount',
align: 'center',
width: 100,
},
{
title: '成功数量',
dataIndex: 'successCount',
key: 'successCount',
align: 'center',
width: 100,
},
{
title: '异常数量',
dataIndex: 'failCount',
key: 'failCount',
align: 'center',
width: 100,
},
{
title: '上传时间',
dataIndex: 'createTime',
key: 'createTime',
align: 'center',
width: 180,
},
{
title: '操作人',
dataIndex: 'createByName',
key: 'createByName',
align: 'center',
width: 120,
},
{
title: '进度',
dataIndex: 'progress',
key: 'progress',
align: 'center',
width: 150,
slots: { customRender: 'progress' },
},
{
title: '操作',
key: 'action',
align: 'center',
fixed: 'right',
width: 200,
slots: { customRender: 'action' },
},
];
// modelValue
watch(() => props.modelValue, (val) => {
visible.value = val;
if (val) {
//
fetchTableData();
}
});
//
const fetchTableData = async () => {
loading.value = true;
try {
//
const result = await props.fetchData({
page: pagination.current,
pageSize: pagination.pageSize
});
// { list: [...], total: 100 }
tableData.value = Array.isArray(result.list) ? result.list : result;
pagination.total = result.total || tableData.value.length;
} catch (error) {
console.error('获取数据失败:', error);
message.error(error.message || '获取导入记录失败');
tableData.value = [];
pagination.total = 0;
} finally {
loading.value = false;
}
};
//
const getStatusText = (status) => {
switch (status) {
case 'completed': return '已完成';
case 'failed': return '失败';
case 'processing': return '处理中';
case 'pending': return '待处理';
default: return status;
}
};
//
const getStatusColor = (status) => {
switch (status) {
case 'completed': return 'green';
case 'failed': return 'red';
case 'processing': return 'blue';
case 'pending': return '#ffcc00';
default: return 'default';
}
};
//
const getProgressStatus = (status) => {
if (status === 'completed') return 'success';
if (status === 'failed') return 'exception';
if (status === 'processing') return 'active';
return 'normal';
};
//
const handleCancel = () => {
visible.value = false;
emit('update:modelValue', false);
emit('close');
};
//
const viewDetails = (record) => {
emit('view-details', record);
};
//
const downloadResult = (record) => {
emit('download-result', record);
};
//
const retryImport = (record) => {
emit('retry-import', record);
};
//
onMounted(() => {
//
});
</script>
<style scoped>
.import-records-modal {
padding: 10px 0;
}
/* 针对表格的样式优化 */
:deep(.ant-table) {
background: #fff;
border-radius: 6px;
}
:deep(.ant-table-thead > tr > th) {
text-align: center;
background-color: #f9f9f9;
font-weight: 600;
}
:deep(.ant-table-tbody > tr > td) {
text-align: center;
}
/* 操作按钮样式 */
:deep(.ant-btn-link) {
height: auto;
padding: 2px 4px;
color: #1890ff;
}
:deep(.ant-btn-link:hover) {
color: #40a9ff;
}
</style>

View File

@ -66,18 +66,18 @@
导入
</a-button>
<a-button v-action="'add'" type="primary" @click="$refs.editDialogRef.handleCreate()">
<a-button v-action="'add'" type="primary" @click="showImportRecordModal = true">
<template #icon>
<UnorderedListOutlined />
</template>
导入记录
</a-button>
<a-button v-action="'add'" type="primary" @click="$refs.editDialogRef.handleCreate()">
<a-button v-action="'add'" type="primary" @click="handleExport">
导出
</a-button>
<a-button v-action="'add'" type="primary" @click="$refs.editDialogRef.handleCreate()">
<a-button v-action="'add'" type="primary" @click="handleShowExportRecords">
<template #icon>
<UnorderedListOutlined />
</template>
@ -145,7 +145,28 @@
<import-modal
v-model:visible="showImportModal"
@download="handleDownloadTemplate"
@upload="handleFileUpload"
@upload="handleFileUpload"/>
<!-- 导入记录弹框组件 -->
<ImportRecordsModal
v-model:visible="showImportRecordModal"
title="导入记录"
:fetchData="fetchImportRecords"
@close="handleImportRecordClose"
@view-details="handleViewImportDetails"
@download-result="handleDownloadImportResult"
@retry-import="handleRetryImport"
/>
<!-- 导出记录弹框组件 -->
<ExportRecordsModal
v-model="showExportRecordModal"
title="导出记录"
:fetchData="fetchExportRecords"
@close="handleExportRecordClose"
@view-details="handleViewExportDetails"
@download-result="handleDownloadExportResult"
@retry-export="handleRetryExport"
/>
</template>
@ -160,7 +181,10 @@ import { usePagination, useForm } from '@/hooks'
import { formatUtcDateTime } from '@/utils/util'
import EditDialog from './components/EditDialog.vue'
//
import ImportModal from '@/components/Import/index.vue' //
import ImportModal from '@/components/Import/index.vue'
//
import ImportRecordsModal from '@/components/ImportRecord/index.vue'
import ExportRecordsModal from '@/components/ExportRecord/index.vue'
import { useI18n } from 'vue-i18n'
import storage from '@/utils/storage'
@ -172,6 +196,10 @@ const { t } = useI18n() // 解构出t方法
// /
const showImportModal = ref(false)
// /
const showImportRecordModal = ref(false)
const showExportRecordModal = ref(false)
const columns = ref([
{ title: '工单号', dataIndex: 'name', key: 'name', fixed: true, width: 280 },
{ title: '服务对象', dataIndex: 'code', key: 'code', width: 240 },
@ -275,7 +303,31 @@ async function onOk() {
await getMenuList()
}
/**
* 导出数据
*/
function handleExport() {
Modal.confirm({
title: '确认导出',
content: '是否导出当前查询条件下的所有服务站点数据?',
onOk: () => {
// API
apis.exportServiceSite(searchFormData.value).then(() => {
message.success('导出任务已提交,请在导出记录中查看进度');
showExportRecordModal.value = true;
}).catch(() => {
message.error('导出任务提交失败');
});
}
});
}
/**
* 显示导出记录
*/
function handleShowExportRecords() {
showExportRecordModal.value = true;
}
/**
* 处理下载模板
@ -323,6 +375,211 @@ function handleChange() {
//
}
//
const fetchImportRecords = async (params) => {
// API - API
await new Promise(resolve => setTimeout(resolve, 800));
//
const mockData = [
{
taskId: 'BATCH_20231201_001',
status: 'completed',
alias: '服务站点数据导入',
totalCount: 1500,
successCount: 1480,
failCount: 20,
createTime: '2023-12-01 14:30:25',
createByName: '张三',
progress: 100
},
{
taskId: 'BATCH_20231201_002',
status: 'failed',
alias: '服务站点信息导入',
totalCount: 800,
successCount: 750,
failCount: 50,
createTime: '2023-12-01 15:45:10',
createByName: '李四',
progress: 93.75
},
{
taskId: 'BATCH_20231201_003',
status: 'processing',
alias: '服务站点数据导入',
totalCount: 3200,
successCount: 1200,
failCount: 0,
createTime: '2023-12-01 16:20:30',
createByName: '王五',
progress: 37.5
},
{
taskId: 'BATCH_20231201_004',
status: 'pending',
alias: '服务站点批量导入',
totalCount: 500,
successCount: 0,
failCount: 0,
createTime: '2023-12-01 17:10:15',
createByName: '赵六',
progress: 0
},
{
taskId: 'BATCH_20231201_005',
status: 'completed',
alias: '服务站点信息导入',
totalCount: 2100,
successCount: 2095,
failCount: 5,
createTime: '2023-12-01 18:05:40',
createByName: '钱七',
progress: 100
}
];
//
const start = (params.page - 1) * params.pageSize;
const end = start + params.pageSize;
const list = mockData.slice(start, end);
return {
list,
total: mockData.length
};
};
//
const fetchExportRecords = async (params) => {
// API - API
await new Promise(resolve => setTimeout(resolve, 800));
//
const mockData = [
{
taskId: 'EXPORT_20231201_001',
status: 'completed',
alias: '服务站点数据导出',
totalCount: 1500,
successCount: 1500,
failCount: 0,
createTime: '2023-12-01 14:30:25',
createByName: '张三',
progress: 100
},
{
taskId: 'EXPORT_20231201_002',
status: 'completed',
alias: '服务站点信息导出',
totalCount: 800,
successCount: 800,
failCount: 0,
createTime: '2023-12-01 15:45:10',
createByName: '李四',
progress: 100
},
{
taskId: 'EXPORT_20231201_003',
status: 'processing',
alias: '服务站点数据导出',
totalCount: 3200,
successCount: 2500,
failCount: 0,
createTime: '2023-12-01 16:20:30',
createByName: '王五',
progress: 78.125
},
{
taskId: 'EXPORT_20231201_004',
status: 'pending',
alias: '服务站点批量导出',
totalCount: 500,
successCount: 0,
failCount: 0,
createTime: '2023-12-01 17:10:15',
createByName: '赵六',
progress: 0
},
{
taskId: 'EXPORT_20231201_005',
status: 'completed',
alias: '服务站点信息导出',
totalCount: 2100,
successCount: 2100,
failCount: 0,
createTime: '2023-12-01 18:05:40',
createByName: '钱七',
progress: 100
}
];
//
const start = (params.page - 1) * params.pageSize;
const end = start + params.pageSize;
const list = mockData.slice(start, end);
return {
list,
total: mockData.length
};
};
//
const handleImportRecordClose = () => {
console.log('导入记录弹框已关闭');
};
//
const handleViewImportDetails = (record) => {
message.info(`查看批次 ${record.taskId} 的详情`);
console.log('查看详情:', record);
};
//
const handleDownloadImportResult = (record) => {
message.success(`正在下载批次 ${record.taskId} 的结果文件`);
console.log('下载结果:', record);
};
//
const handleRetryImport = (record) => {
message.info(`正在重新导入批次 ${record.taskId}`);
console.log('重新导入:', record);
};
//
const handleExportRecordClose = () => {
console.log('导出记录弹框已关闭');
};
//
const handleViewExportDetails = (record) => {
message.info(`查看导出批次 ${record.taskId} 的详情`);
console.log('查看导出详情:', record);
};
//
const handleDownloadExportResult = (record) => {
message.success(`正在下载导出批次 ${record.taskId} 的结果文件`);
// API
apis.downloadExportResult(record.taskId).then(() => {
message.success('文件下载成功');
}).catch(() => {
message.error('文件下载失败');
});
};
//
const handleRetryExport = (record) => {
message.info(`正在重新导出批次 ${record.taskId}`);
// API
apis.retryExport(record.taskId).then(() => {
message.success('重新导出任务已提交');
}).catch(() => {
message.error('重新导出失败');
});
};
</script>
<style lang="less" scoped>