mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:59:19 +08:00
refactor(order-import): 重构订单导入为向导模式,优化页面布局
This commit is contained in:
+463
-328
File diff suppressed because it is too large
Load Diff
@@ -3,11 +3,12 @@ import type { VxeGridProps } from '#/adapter/vxe-table';
|
||||
|
||||
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
|
||||
import CreateImportTaskModal from './components/CreateImportTaskModal.vue';
|
||||
import ImportTaskWizard from './components/ImportTaskWizard.vue';
|
||||
import FileUploadArea from './components/FileUploadArea.vue';
|
||||
import { parseFileToRawData } from './utils/fileParser';
|
||||
|
||||
@@ -21,13 +22,14 @@ const currentFile = ref<File | null>(null);
|
||||
const tableContainerRef = ref<HTMLElement>();
|
||||
const tableHeight = ref<number>(600);
|
||||
|
||||
const importTaskWizardRef = ref<InstanceType<typeof ImportTaskWizard>>();
|
||||
|
||||
// 动态生成Grid列配置
|
||||
const gridColumns = computed(() => {
|
||||
if (csvHeaders.value.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// 序号列
|
||||
const columns: VxeGridProps<any>['columns'] = [
|
||||
{
|
||||
type: 'seq' as const,
|
||||
@@ -37,7 +39,6 @@ const gridColumns = computed(() => {
|
||||
},
|
||||
];
|
||||
|
||||
// 根据CSV表头动态生成列
|
||||
csvHeaders.value.forEach((header) => {
|
||||
columns.push({
|
||||
field: header,
|
||||
@@ -50,7 +51,6 @@ const gridColumns = computed(() => {
|
||||
return columns;
|
||||
});
|
||||
|
||||
// VbenVxeGrid 表格配置
|
||||
const gridOptions: VxeGridProps<any> = {
|
||||
columns: [],
|
||||
height: tableHeight.value,
|
||||
@@ -84,11 +84,9 @@ const gridOptions: VxeGridProps<any> = {
|
||||
| 'Total'
|
||||
)[],
|
||||
},
|
||||
// 配置远程加载,实现真正的分页
|
||||
proxyConfig: {
|
||||
ajax: {
|
||||
query: async ({ page }) => {
|
||||
// 如果没有数据,返回空
|
||||
if (csvData.value.length === 0) {
|
||||
return {
|
||||
items: [],
|
||||
@@ -96,13 +94,11 @@ const gridOptions: VxeGridProps<any> = {
|
||||
};
|
||||
}
|
||||
|
||||
// 计算分页参数
|
||||
const currentPage = page.currentPage || 1;
|
||||
const pageSize = page.pageSize || 50;
|
||||
const startIndex = (currentPage - 1) * pageSize;
|
||||
const endIndex = startIndex + pageSize;
|
||||
|
||||
// 从 csvData 中截取当前页的数据
|
||||
const pageData = csvData.value.slice(startIndex, endIndex);
|
||||
|
||||
return {
|
||||
@@ -118,17 +114,14 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||
gridOptions,
|
||||
});
|
||||
|
||||
// 更新表格列配置(不再更新 data,data 由 proxyConfig 管理)
|
||||
const updateTable = () => {
|
||||
gridApi.setGridOptions({
|
||||
columns: gridColumns.value,
|
||||
height: tableHeight.value,
|
||||
});
|
||||
// 触发重新加载数据
|
||||
gridApi.reload();
|
||||
};
|
||||
|
||||
// 监听表格高度变化,更新表格配置
|
||||
watch(
|
||||
tableHeight,
|
||||
(newHeight) => {
|
||||
@@ -139,7 +132,19 @@ watch(
|
||||
{ immediate: false },
|
||||
);
|
||||
|
||||
// 处理文件上传
|
||||
const syncWizardOpen = () => {
|
||||
if (csvData.value.length === 0 || csvHeaders.value.length === 0) {
|
||||
return;
|
||||
}
|
||||
nextTick(() => {
|
||||
importTaskWizardRef.value?.open(
|
||||
[...csvHeaders.value],
|
||||
currentFile.value ?? undefined,
|
||||
[...csvData.value],
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const handleFileUpload = async (file: File) => {
|
||||
importLoading.value = true;
|
||||
try {
|
||||
@@ -158,12 +163,11 @@ const handleFileUpload = async (file: File) => {
|
||||
csvHeaders.value = result.headers;
|
||||
currentFile.value = file;
|
||||
|
||||
// 更新表格
|
||||
updateTable();
|
||||
// 重新计算表格高度
|
||||
nextTick(() => {
|
||||
calculateTableHeight();
|
||||
});
|
||||
syncWizardOpen();
|
||||
|
||||
const fileExt = file.name.toLowerCase().split('.').pop() || '';
|
||||
const format = ['xlsx', 'xls'].includes(fileExt) ? 'Excel' : 'CSV';
|
||||
@@ -175,48 +179,44 @@ const handleFileUpload = async (file: File) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 创建导入任务模态框引用
|
||||
const createImportTaskModalRef =
|
||||
ref<InstanceType<typeof CreateImportTaskModal>>();
|
||||
|
||||
// 创建导入任务按钮处理
|
||||
const handleCreateImportTask = () => {
|
||||
if (csvHeaders.value.length === 0) {
|
||||
message.warning('请先上传CSV文件');
|
||||
return;
|
||||
}
|
||||
createImportTaskModalRef.value?.open(
|
||||
csvHeaders.value,
|
||||
currentFile.value ?? undefined,
|
||||
csvData.value,
|
||||
);
|
||||
};
|
||||
|
||||
// 清空数据
|
||||
const handleClearData = () => {
|
||||
csvData.value = [];
|
||||
csvHeaders.value = [];
|
||||
currentFile.value = null;
|
||||
// 更新表格
|
||||
importTaskWizardRef.value?.reset();
|
||||
updateTable();
|
||||
message.success('已清空数据');
|
||||
};
|
||||
|
||||
// 计算表格高度
|
||||
const handleWizardSuccess = () => {
|
||||
csvData.value = [];
|
||||
csvHeaders.value = [];
|
||||
currentFile.value = null;
|
||||
updateTable();
|
||||
message.success('已创建导入任务,可继续上传新文件');
|
||||
};
|
||||
|
||||
const calculateTableHeight = () => {
|
||||
nextTick(() => {
|
||||
if (tableContainerRef.value) {
|
||||
const rect = tableContainerRef.value.getBoundingClientRect();
|
||||
// 减去 padding (1.5rem * 2 = 3rem = 48px) 和其他元素的高度
|
||||
const headerHeight = 100; // 估算表头高度
|
||||
const padding = 48; // 1.5rem * 2
|
||||
const availableHeight = rect.height - padding - headerHeight;
|
||||
tableHeight.value = Math.max(400, availableHeight);
|
||||
const toolbarReserve = 56;
|
||||
const padding = 24;
|
||||
const availableHeight = rect.height - padding - toolbarReserve;
|
||||
tableHeight.value = Math.max(320, availableHeight);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// 监听窗口大小变化
|
||||
watch(
|
||||
() => csvData.value.length,
|
||||
(len) => {
|
||||
if (len > 0) {
|
||||
nextTick(() => calculateTableHeight());
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
let resizeObserver: null | ResizeObserver = null;
|
||||
|
||||
onMounted(() => {
|
||||
@@ -230,118 +230,91 @@ onMounted(() => {
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
if (resizeObserver) {
|
||||
resizeObserver.disconnect();
|
||||
}
|
||||
resizeObserver?.disconnect();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="h-full overflow-hidden bg-slate-100 dark:bg-[hsl(222.34deg_10.43%_12.27%)] p-8">
|
||||
<div class="mx-auto flex h-full w-[60%] flex-col overflow-hidden">
|
||||
<!-- 头部标题 -->
|
||||
<div class="mb-12 shrink-0 text-center">
|
||||
<h1 class="mb-2 text-4xl font-black tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
<Page
|
||||
auto-content-height
|
||||
:content-padding-class="csvData.length === 0 ? 'p-4 sm:p-6' : 'p-2 sm:p-3'"
|
||||
content-class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden bg-slate-100 dark:bg-[hsl(222.34deg_10.43%_12.27%)]"
|
||||
>
|
||||
<!-- 未上传:居中上传 -->
|
||||
<div
|
||||
v-if="csvData.length === 0"
|
||||
class="mx-auto flex min-h-0 w-full max-w-3xl flex-1 flex-col items-center justify-center py-8"
|
||||
>
|
||||
<div class="mb-10 shrink-0 text-center">
|
||||
<h1
|
||||
class="mb-2 text-3xl font-black tracking-tight text-slate-800 dark:text-[hsl(0deg_0%_95%)] sm:text-4xl"
|
||||
>
|
||||
订单导入中心
|
||||
</h1>
|
||||
<p class="text-base font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
请上传 CSV 格式的订单原始数据进行分析
|
||||
<p class="text-sm font-medium text-slate-500 dark:text-[hsl(240deg_5%_64.9%)] sm:text-base">
|
||||
请上传 CSV / Excel 格式的订单原始数据
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<!-- 主体内容区域 -->
|
||||
<div
|
||||
v-if="csvData.length === 0"
|
||||
class="flex min-h-0 flex-1 flex-col overflow-hidden"
|
||||
class="relative w-full overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-6 dark:border-[hsl(240deg_3.7%_22%/50%)] dark:bg-[hsl(222.34deg_10.43%_12.27%/80%)] shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] dark:shadow-none backdrop-blur-2xl sm:p-8"
|
||||
>
|
||||
<div class="mb-8 shrink-0">
|
||||
<!-- 导入区域 -->
|
||||
<div
|
||||
class="relative flex min-h-[400px] flex-col items-center justify-center overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 dark:border-[hsl(240deg_3.7%_22%/50%)] dark:bg-[hsl(222.34deg_10.43%_12.27%/80%)] p-8 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] dark:shadow-none backdrop-blur-2xl"
|
||||
>
|
||||
<div
|
||||
class="absolute -right-10 -top-10 h-32 w-32 rounded-full bg-indigo-400 opacity-10 blur-3xl"
|
||||
></div>
|
||||
<div
|
||||
class=":deep(.ant-spin-nested-loading) :deep(.ant-spin-container) w-full"
|
||||
>
|
||||
<FileUploadArea
|
||||
:loading="importLoading"
|
||||
@file-selected="handleFileUpload"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="absolute -right-10 -top-10 h-32 w-32 rounded-full bg-indigo-400 opacity-10 blur-3xl"
|
||||
></div>
|
||||
<div class="relative w-full">
|
||||
<FileUploadArea
|
||||
:loading="importLoading"
|
||||
@file-selected="handleFileUpload"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 数据表格区域 -->
|
||||
<div v-else class="flex min-h-0 w-full flex-1 flex-col overflow-hidden">
|
||||
<div
|
||||
class="mb-6 flex shrink-0 flex-wrap items-start justify-between gap-4"
|
||||
<!-- 已上传:左表右配置(flex-1 + min-h-0 约束在布局内容高度内,避免撑开外层滚动) -->
|
||||
<div
|
||||
v-else
|
||||
class="flex min-h-0 w-full min-w-0 flex-1 flex-row gap-3 overflow-hidden sm:gap-4"
|
||||
>
|
||||
<div class="flex-1">
|
||||
<h2 class="mb-1 text-2xl font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">数据预览</h2>
|
||||
<p class="m-0 text-sm text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]">
|
||||
共 {{ csvData.length }} 条数据,请检查数据后创建导入任务
|
||||
<section
|
||||
class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden rounded-2xl border border-slate-200/80 bg-white/90 shadow-sm dark:border-[hsl(240deg_3.7%_22%)] dark:bg-[hsl(222.34deg_10.43%_12.27%/90%)]"
|
||||
>
|
||||
<div
|
||||
class="flex shrink-0 flex-wrap items-center justify-between gap-3 border-b border-slate-100 px-4 py-3 dark:border-[hsl(240deg_3.7%_22%)]"
|
||||
>
|
||||
<div class="min-w-0">
|
||||
<h2 class="mb-0.5 text-lg font-bold text-slate-800 dark:text-[hsl(0deg_0%_95%)]">
|
||||
数据预览
|
||||
</h2>
|
||||
<p class="m-0 text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)] sm:text-sm">
|
||||
共 {{ csvData.length }} 条 · 右侧配置导入任务
|
||||
</p>
|
||||
</div>
|
||||
<div class="flex gap-2">
|
||||
<Button @click="handleClearData">清空数据</Button>
|
||||
<Button type="primary" @click="handleCreateImportTask">
|
||||
创建导入任务
|
||||
</Button>
|
||||
</div>
|
||||
<Button size="small" @click="handleClearData">清空数据</Button>
|
||||
</div>
|
||||
<div
|
||||
ref="tableContainerRef"
|
||||
class="flex min-h-0 flex-1 flex-col overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 dark:border-[hsl(240deg_3.7%_22%/50%)] dark:bg-[hsl(222.34deg_10.43%_12.27%/80%)] p-6 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] dark:shadow-none backdrop-blur-2xl"
|
||||
class="flex min-h-0 flex-1 flex-col overflow-hidden p-3 sm:p-4"
|
||||
>
|
||||
<Grid />
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<CreateImportTaskModal ref="createImportTaskModalRef" />
|
||||
<aside
|
||||
class="flex min-h-0 w-[min(100%,440px)] shrink-0 flex-col self-stretch overflow-hidden sm:w-[400px] lg:w-[440px]"
|
||||
>
|
||||
<!-- 单独一层 flex-1,避免多根子组件时侧栏被内容撑出视口 -->
|
||||
<div class="flex min-h-0 flex-1 flex-col overflow-hidden">
|
||||
<ImportTaskWizard
|
||||
ref="importTaskWizardRef"
|
||||
@success="handleWizardSuccess"
|
||||
/>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
</div>
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 上传区域深度选择器样式 */
|
||||
:deep(.ant-spin-nested-loading),
|
||||
:deep(.ant-spin-container) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.border-dashed) {
|
||||
background: transparent;
|
||||
border: 2px dashed rgba(99, 102, 241, 0.3);
|
||||
border-radius: 2rem;
|
||||
padding: 3rem;
|
||||
transition: all 0.3s ease;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.border-dashed:hover) {
|
||||
border-color: #6366f1;
|
||||
background: rgba(99, 102, 241, 0.05);
|
||||
transform: scale(1.01);
|
||||
}
|
||||
|
||||
:deep(.border-blue-500) {
|
||||
border-color: #6366f1 !important;
|
||||
background: rgba(99, 102, 241, 0.05) !important;
|
||||
}
|
||||
|
||||
html.dark :deep(.border-dashed) {
|
||||
border-color: hsl(240deg 3.7% 30%);
|
||||
}
|
||||
|
||||
html.dark :deep(.border-dashed:hover) {
|
||||
border-color: #818cf8;
|
||||
background: hsl(240deg 3.7% 15.9% / 15%);
|
||||
}
|
||||
|
||||
/* VxeGrid 表格样式 */
|
||||
:deep(.vxe-grid) {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
|
||||
Reference in New Issue
Block a user