This commit is contained in:
ah--desktop
2026-01-12 00:14:47 +08:00
parent e1f39c1815
commit 59a649f002
65 changed files with 5097 additions and 369 deletions
@@ -163,10 +163,8 @@ const canGoToNextStep = computed(() => {
});
}
if (currentStep.value === 2) {
// 订单状态映射步骤:所有唯一的订单状态值都必须映射
return uniqueStatusValues.value.every(
(status) => statusMappings.value[status] !== undefined,
);
// 订单状态映射步骤:允许不映射,所以总是返回 true
return true;
}
return true;
});
@@ -565,13 +563,13 @@ async function handleConfirmSaveStatusTemplate() {
return;
}
// 验证所有订单状态是否都已映射
const unMappedStatuses = uniqueStatusValues.value.filter(
(status) => statusMappings.value[status] === undefined,
// 验证是否有映射数据(至少需要一个映射才能保存模板)
const mappedStatuses = uniqueStatusValues.value.filter(
(status) => statusMappings.value[status] !== undefined,
);
if (unMappedStatuses.length > 0) {
message.warning(`请先映射所有订单状态:${unMappedStatuses.join('、')}`);
if (mappedStatuses.length === 0) {
message.warning('请至少映射一个订单状态');
return;
}
@@ -579,13 +577,13 @@ async function handleConfirmSaveStatusTemplate() {
savingStatusTemplate.value = true;
saveStatusTemplateModalApi.lock();
// 构建映射数据(已验证所有状态都已映射,所以不会有 undefined)
const mappingItems: StatusMappingItem[] = uniqueStatusValues.value.map(
(status) => ({
// 构建映射数据(只包含已映射的状态)
const mappingItems: StatusMappingItem[] = uniqueStatusValues.value
.filter((status) => statusMappings.value[status] !== undefined)
.map((status) => ({
csvStatus: status,
mappedStatusId: statusMappings.value[status]!,
}),
);
}));
const mappingJson = JSON.stringify(mappingItems);
@@ -712,14 +710,7 @@ const handleNext = () => {
break;
}
case 2: {
// 验证所有订单状态是否都已映射
const unMappedStatuses = uniqueStatusValues.value.filter(
(status) => statusMappings.value[status] === undefined,
);
if (unMappedStatuses.length > 0) {
message.warning(`请先映射所有订单状态:${unMappedStatuses.join('、')}`);
return;
}
// 订单状态映射是可选的,可以直接进入下一步
currentStep.value = 3;
break;
@@ -781,9 +772,10 @@ const handleCreateTask = async () => {
required: m.fieldDef.required,
}));
// 构建订单状态映射 JSON(已验证所有状态都已映射,所以不会有 undefined)
const statusMappingItems: StatusMappingItem[] =
uniqueStatusValues.value.map((status) => ({
// 构建订单状态映射 JSON(只包含已映射的状态)
const statusMappingItems: StatusMappingItem[] = uniqueStatusValues.value
.filter((status) => statusMappings.value[status] !== undefined)
.map((status) => ({
csvStatus: status,
mappedStatusId: statusMappings.value[status]!,
}));
@@ -886,7 +878,7 @@ const shopOptions = computed(() => {
<template>
<Modal title="创建导入任务" :loading="loading">
<div class="space-y-6">
<div class="space-y-3">
<!-- 步骤条 -->
<Steps :current="currentStep">
<Steps.Step title="选择店铺" />
@@ -1014,7 +1006,7 @@ const shopOptions = computed(() => {
<div v-if="currentStep === 2" class="py-4">
<div class="mb-4 flex items-center justify-between">
<div class="text-sm text-gray-600">
请为每个订单状态值映射到对应的系统订单状态,所有状态必须映射
请为每个订单状态值映射到对应的系统订单状态(可选,可不映射)
</div>
<div class="flex items-center space-x-2">
<Select
@@ -1065,10 +1057,6 @@ const shopOptions = computed(() => {
v-for="statusValue in uniqueStatusValues"
:key="statusValue"
class="flex items-center space-x-4 rounded border p-3"
:class="{
'border-red-300 bg-red-50':
statusMappings[statusValue] === undefined,
}"
>
<div class="flex-1">
<div class="font-medium">{{ statusValue }}</div>
@@ -1076,9 +1064,10 @@ const shopOptions = computed(() => {
</div>
<Select
v-model:value="statusMappings[statusValue]"
placeholder="请选择订单状态"
placeholder="请选择订单状态(可选)"
class="w-[200px]"
show-search
allow-clear
:loading="orderStatusLoading"
:options="
orderStatusList.map((status) => ({
@@ -1143,7 +1132,7 @@ const shopOptions = computed(() => {
</div>
<!-- 操作按钮 -->
<div class="flex justify-between border-t pt-4">
<div class="flex justify-between">
<Button @click="handleCancel">取消</Button>
<div class="space-x-2">
<Button v-if="currentStep > 0" @click="handlePrev">上一步</Button>
@@ -1198,7 +1187,3 @@ const shopOptions = computed(() => {
</SaveStatusTemplateModal>
</Modal>
</template>
<style scoped>
/* 自定义样式 */
</style>
@@ -1,9 +1,7 @@
<script setup lang="ts">
import type { VxeGridProps } from '#/adapter/vxe-table';
import { computed, ref } from 'vue';
import { Page } from '@vben/common-ui';
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue';
import { Button, message } from 'ant-design-vue';
@@ -20,6 +18,8 @@ const csvData = ref<any[]>([]);
const csvHeaders = ref<string[]>([]);
const importLoading = ref(false);
const currentFile = ref<File | null>(null);
const tableContainerRef = ref<HTMLElement>();
const tableHeight = ref<number>(600);
// 动态生成Grid列配置
const gridColumns = computed(() => {
@@ -53,7 +53,7 @@ const gridColumns = computed(() => {
// VbenVxeGrid 表格配置
const gridOptions: VxeGridProps<any> = {
columns: [],
height: 'auto',
height: tableHeight.value,
border: true,
stripe: true,
highlightHoverRow: true,
@@ -122,11 +122,23 @@ const [Grid, gridApi] = useVbenVxeGrid({
const updateTable = () => {
gridApi.setGridOptions({
columns: gridColumns.value,
height: tableHeight.value,
});
// 触发重新加载数据
gridApi.reload();
};
// 监听表格高度变化,更新表格配置
watch(
tableHeight,
(newHeight) => {
gridApi.setGridOptions({
height: newHeight,
});
},
{ immediate: false },
);
// 处理文件上传
const handleFileUpload = async (file: File) => {
importLoading.value = true;
@@ -148,6 +160,10 @@ const handleFileUpload = async (file: File) => {
// 更新表格
updateTable();
// 重新计算表格高度
nextTick(() => {
calculateTableHeight();
});
message.success(`成功解析 ${result.data.length} 条数据`);
} catch (error: any) {
@@ -183,45 +199,213 @@ const handleClearData = () => {
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);
}
});
};
// 监听窗口大小变化
let resizeObserver: null | ResizeObserver = null;
onMounted(() => {
calculateTableHeight();
if (tableContainerRef.value) {
resizeObserver = new ResizeObserver(() => {
calculateTableHeight();
});
resizeObserver.observe(tableContainerRef.value);
}
});
onUnmounted(() => {
if (resizeObserver) {
resizeObserver.disconnect();
}
});
</script>
<template>
<Page auto-content-height>
<!-- 顶部栏 -->
<template #extra>
<div class="flex items-center space-x-2">
<Button
:disabled="csvData.length === 0"
@click="handleClearData"
>
清空数据
</Button>
<Button
type="primary"
:disabled="csvHeaders.length === 0"
@click="handleCreateImportTask"
>
创建导入任务
</Button>
<div
class="h-full overflow-hidden bg-gradient-to-br from-indigo-100 via-pink-100 to-slate-100 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">
订单导入中心
</h1>
<p class="text-base font-medium text-slate-500">
请上传 CSV 格式的订单原始数据进行分析
</p>
</div>
</template>
<!-- 主体内容区域 -->
<div
v-if="csvData.length === 0"
class="flex h-full items-center justify-center"
>
<FileUploadArea
:loading="importLoading"
@file-selected="handleFileUpload"
/>
<!-- 主体内容区域 -->
<div
v-if="csvData.length === 0"
class="flex min-h-0 flex-1 flex-col overflow-hidden"
>
<div
class="mb-8 grid shrink-0 grid-cols-1 gap-6 lg:grid-cols-[2fr_1fr]"
>
<!-- 左侧:导入区域 -->
<div
class="relative flex min-h-[400px] flex-col items-center justify-center overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-8 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] 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="flex flex-col gap-6">
<!-- 操作指南卡片 -->
<div
class="relative flex flex-col gap-4 overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-6 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] backdrop-blur-2xl"
>
<h3 class="m-0 text-base font-bold text-slate-800">操作指南</h3>
<div class="flex flex-col gap-4">
<div class="flex items-start gap-3">
<div
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full bg-indigo-600 text-xs font-bold text-white"
>
1
</div>
<p
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
>
从电商后台导出【订单详情】CSV文件
</p>
</div>
<div class="flex items-start gap-3">
<div
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-indigo-100 bg-white text-xs font-bold text-indigo-600"
>
2
</div>
<p
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
>
检查文件是否包含【订单号】与【金额】列
</p>
</div>
<div class="flex items-start gap-3">
<div
class="flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-indigo-100 bg-white text-xs font-bold text-indigo-600"
>
3
</div>
<p
class="m-0 text-xs font-medium leading-relaxed text-slate-500"
>
上传成功后,系统将自动解析并显示数据
</p>
</div>
</div>
</div>
</div>
</div>
<!-- 底部全局按钮 -->
<div class="flex justify-center gap-4 pt-4">
<Button :disabled="csvData.length === 0" @click="handleClearData">
清空当前选择
</Button>
<Button
type="primary"
:disabled="csvHeaders.length === 0"
@click="handleCreateImportTask"
>
创建导入任务
</Button>
</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"
>
<div class="flex-1">
<h2 class="mb-1 text-2xl font-bold text-slate-800">数据预览</h2>
<p class="m-0 text-sm text-slate-500">
共 {{ csvData.length }} 条数据,请检查数据后创建导入任务
</p>
</div>
<div class="flex gap-2">
<Button @click="handleClearData">清空数据</Button>
<Button type="primary" @click="handleCreateImportTask">
创建导入任务
</Button>
</div>
</div>
<div
ref="tableContainerRef"
class="flex min-h-0 flex-1 flex-col overflow-hidden rounded-[2rem] border border-white/50 bg-white/45 p-6 shadow-[0_25px_50px_-12px_rgba(0,0,0,0.1)] backdrop-blur-2xl"
>
<Grid />
</div>
</div>
<CreateImportTaskModal ref="createImportTaskModalRef" />
</div>
<Grid v-else />
<CreateImportTaskModal ref="createImportTaskModalRef" />
</Page>
</div>
</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;
}
/* VxeGrid 表格样式 */
:deep(.vxe-grid) {
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
}
:deep(.vxe-grid--body-wrapper) {
flex: 1;
overflow: auto;
}
</style>