mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 07:09:20 +08:00
wip: 开发订单导入功能
This commit is contained in:
@@ -45,7 +45,7 @@ export async function deleteImportFieldDefApi(id: number) {
|
||||
*/
|
||||
export async function getFieldDefsByTypeApi(type: string) {
|
||||
return requestClient.get<ImportFieldDefVO.ImportFieldDefInfoVO[]>(
|
||||
`/ec/import-field-def/list-by-type/all/${type}`,
|
||||
`/ec/import-field-def/all/${type}`,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ export namespace ImportFieldDefDTO {
|
||||
fieldName: string;
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 文件字段名,如 商品名称 */
|
||||
fileFieldName?: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
@@ -23,6 +25,8 @@ export namespace ImportFieldDefDTO {
|
||||
export interface UpdateImportFieldDefDTO {
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 文件字段名,如 商品名称 */
|
||||
fileFieldName?: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
|
||||
@@ -13,6 +13,8 @@ export namespace ImportFieldDefVO {
|
||||
fieldName: string;
|
||||
/** 中文字段名,如 商品名称 */
|
||||
fieldLabel: string;
|
||||
/** 文件字段名,如 商品名称 */
|
||||
fileFieldName?: string;
|
||||
/** 是否必填 */
|
||||
required: boolean;
|
||||
/** 排序 */
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
export namespace ImportTaskDTO {
|
||||
/** 创建导入任务参数 */
|
||||
export interface CreateImportTaskDTO {
|
||||
/** 所属店铺ID */
|
||||
shopId: number;
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 原始文件名 */
|
||||
@@ -17,6 +19,8 @@ export namespace ImportTaskDTO {
|
||||
|
||||
/** 导入任务过滤条件 */
|
||||
export interface ImportTaskFilterDTO {
|
||||
/** 所属店铺ID */
|
||||
shopId?: number;
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type?: string;
|
||||
/** 任务状态 */
|
||||
|
||||
@@ -9,6 +9,8 @@ export namespace ImportTaskVO {
|
||||
id: number;
|
||||
/** 所属公司ID */
|
||||
companyId?: number;
|
||||
/** 所属店铺ID */
|
||||
shopId?: number;
|
||||
/** 导入类型(product-商品 order-订单) */
|
||||
type: string;
|
||||
/** 原始文件名 */
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import type { FileDTO, FileVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { FileDTO, FileVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 文件管理API
|
||||
@@ -11,7 +12,10 @@ import type { FileDTO, FileVO } from './types';
|
||||
* 分页获取文件列表
|
||||
*/
|
||||
export async function getFilePageApi(params: PageQueryDTO<FileDTO.Filters>) {
|
||||
return requestClient.post<PageResultVO<FileVO.Info>>('/media/file/page', params);
|
||||
return requestClient.post<PageResultVO<FileVO.Info>>(
|
||||
'/media/file/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,14 +36,18 @@ export async function uploadFileApi(file: File) {
|
||||
*/
|
||||
export async function batchUploadFilesApi(files: File[]) {
|
||||
const formData = new FormData();
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
formData.append('files', file);
|
||||
});
|
||||
return requestClient.post<FileVO.Info[]>('/media/file/batch-upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
return requestClient.post<FileVO.Info[]>(
|
||||
'/media/file/batch-upload',
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +61,7 @@ export async function updateFileApi(id: number, data: FileDTO.Update) {
|
||||
* 删除文件
|
||||
*/
|
||||
export async function deleteFileApi(id: number) {
|
||||
return requestClient.delete<void>(`/media/file/delete/${id}`);
|
||||
return requestClient.delete(`/media/file/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,7 +75,9 @@ export async function getFileByIdApi(id: number) {
|
||||
* 批量删除文件
|
||||
*/
|
||||
export async function batchDeleteFilesApi(ids: number[]) {
|
||||
return requestClient.delete<void>('/media/file/batch-delete', { data: { ids } });
|
||||
return requestClient.delete('/media/file/batch-delete', {
|
||||
data: { ids },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import type { ImageDTO, ImageVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { ImageDTO, ImageVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 图片管理API
|
||||
@@ -11,7 +12,10 @@ import type { ImageDTO, ImageVO } from './types';
|
||||
* 分页获取图片列表
|
||||
*/
|
||||
export async function getImagePageApi(params: PageQueryDTO<ImageDTO.Filters>) {
|
||||
return requestClient.post<PageResultVO<ImageVO.Info>>('/media/image/page', params);
|
||||
return requestClient.post<PageResultVO<ImageVO.Info>>(
|
||||
'/media/image/page',
|
||||
params,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -32,14 +36,18 @@ export async function uploadImageApi(file: File) {
|
||||
*/
|
||||
export async function batchUploadImagesApi(files: File[]) {
|
||||
const formData = new FormData();
|
||||
files.forEach(file => {
|
||||
files.forEach((file) => {
|
||||
formData.append('files', file);
|
||||
});
|
||||
return requestClient.post<ImageVO.Info[]>('/media/image/batch-upload', formData, {
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
return requestClient.post<ImageVO.Info[]>(
|
||||
'/media/image/batch-upload',
|
||||
formData,
|
||||
{
|
||||
headers: {
|
||||
'Content-Type': 'multipart/form-data',
|
||||
},
|
||||
},
|
||||
});
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,7 +61,7 @@ export async function updateImageApi(id: number, data: ImageDTO.Update) {
|
||||
* 删除图片
|
||||
*/
|
||||
export async function deleteImageApi(id: number) {
|
||||
return requestClient.delete<void>(`/media/image/delete/${id}`);
|
||||
return requestClient.delete(`/media/image/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,18 +75,27 @@ export async function getImageByIdApi(id: number) {
|
||||
* 批量删除图片
|
||||
*/
|
||||
export async function batchDeleteImagesApi(ids: number[]) {
|
||||
return requestClient.delete<void>('/media/image/batch-delete', { data: { ids } });
|
||||
return requestClient.delete('/media/image/batch-delete', {
|
||||
data: { ids },
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片缩略图
|
||||
*/
|
||||
export async function getImageThumbnailApi(id: number, width?: number, height?: number) {
|
||||
export async function getImageThumbnailApi(
|
||||
id: number,
|
||||
width?: number,
|
||||
height?: number,
|
||||
) {
|
||||
const params = new URLSearchParams();
|
||||
if (width) params.append('width', width.toString());
|
||||
if (height) params.append('height', height.toString());
|
||||
|
||||
return requestClient.get(`/media/image/thumbnail/${id}?${params.toString()}`, {
|
||||
responseType: 'blob',
|
||||
});
|
||||
|
||||
return requestClient.get(
|
||||
`/media/image/thumbnail/${id}?${params.toString()}`,
|
||||
{
|
||||
responseType: 'blob',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { requestClient } from '#/api/request';
|
||||
import type { ShopDTO, ShopVO } from './types';
|
||||
|
||||
import type { PageQueryDTO, PageResultVO } from '#/types/common';
|
||||
import type { ShopDTO, ShopVO } from './types';
|
||||
|
||||
import { requestClient } from '#/api/request';
|
||||
|
||||
/**
|
||||
* 店铺管理API
|
||||
@@ -32,7 +33,7 @@ export async function updateShopApi(id: number, data: ShopDTO.Update) {
|
||||
* 删除店铺
|
||||
*/
|
||||
export async function deleteShopApi(id: number) {
|
||||
return requestClient.delete<void>(`/ec/shop/delete/${id}`);
|
||||
return requestClient.delete(`/ec/shop/delete/${id}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +57,9 @@ export async function uploadShopLogoApi(file: File) {
|
||||
* 根据名称精准查询店铺
|
||||
*/
|
||||
export async function getShopByNameApi(name: string) {
|
||||
return requestClient.get<ShopVO.Info>(`/ec/shop/find-by-name/${encodeURIComponent(name)}`);
|
||||
return requestClient.get<ShopVO.Info>(
|
||||
`/ec/shop/find-by-name/${encodeURIComponent(name)}`,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,7 +13,7 @@ const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
name: 'DataImport',
|
||||
path: '/data/import',
|
||||
component: () => import('#/views/ecommerce/data-import/index.vue'),
|
||||
component: () => import('#/views/ecommerce/order-import/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:upload',
|
||||
title: '数据导入',
|
||||
|
||||
+460
@@ -0,0 +1,460 @@
|
||||
<script setup lang="ts">
|
||||
import type { ImportFieldDefVO } from '#/api/ecommerce/import-field-def';
|
||||
import type { ImportTaskDTO } from '#/api/ecommerce/import-task';
|
||||
import type { ShopVO } from '#/api/shop/shop/types';
|
||||
|
||||
import { computed, ref } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
|
||||
import { Button, Form, message, Select, Spin, Steps } from 'ant-design-vue';
|
||||
|
||||
import { getFieldDefsByTypeApi } from '#/api/ecommerce/import-field-def';
|
||||
import { createImportTaskApi } from '#/api/ecommerce/import-task';
|
||||
import { uploadFileApi } from '#/api/media/file';
|
||||
import { getShopPageApi } from '#/api/shop/shop';
|
||||
|
||||
defineOptions({ name: 'CreateImportTaskModal' });
|
||||
|
||||
// 创建 vben modal
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[800px]',
|
||||
showCancelButton: false,
|
||||
showConfirmButton: false,
|
||||
onCancel() {
|
||||
handleCancel();
|
||||
},
|
||||
});
|
||||
|
||||
// 响应式数据
|
||||
const currentStep = ref(0);
|
||||
const loading = ref(false);
|
||||
const csvHeaders = ref<string[]>([]);
|
||||
const selectedFile = ref<File | null>(null);
|
||||
|
||||
// 第一步:店铺选择
|
||||
const shopList = ref<ShopVO.Info[]>([]);
|
||||
const selectedShopId = ref<number | undefined>();
|
||||
const shopLoading = ref(false);
|
||||
const shopPage = ref(1);
|
||||
const shopPageSize = ref(20);
|
||||
const shopHasMore = ref(true);
|
||||
const shopSearchValue = ref('');
|
||||
|
||||
// 第二步:字段映射
|
||||
const fieldDefs = ref<ImportFieldDefVO.ImportFieldDefInfoVO[]>([]);
|
||||
const fieldMappings = ref<
|
||||
Record<
|
||||
number,
|
||||
{
|
||||
fieldDef: ImportFieldDefVO.ImportFieldDefInfoVO;
|
||||
mappedHeader?: string;
|
||||
}
|
||||
>
|
||||
>({});
|
||||
|
||||
// 表单引用
|
||||
const formRef = ref();
|
||||
|
||||
// 计算属性:必填字段是否都已绑定
|
||||
const canGoToNextStep = computed(() => {
|
||||
if (currentStep.value === 0) {
|
||||
return selectedShopId.value !== undefined;
|
||||
}
|
||||
if (currentStep.value === 1) {
|
||||
const requiredFields = fieldDefs.value.filter((f) => f.required);
|
||||
return requiredFields.every((field) => {
|
||||
const mapping = fieldMappings.value[field.id];
|
||||
return mapping && mapping.mappedHeader;
|
||||
});
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
// 初始化字段映射
|
||||
const initFieldMappings = () => {
|
||||
const mappings: typeof fieldMappings.value = {};
|
||||
fieldDefs.value.forEach((fieldDef) => {
|
||||
let mappedHeader: string | undefined;
|
||||
// 如果字段有默认的 fileFieldName,尝试匹配 CSV 表头
|
||||
if (fieldDef.fileFieldName) {
|
||||
const matched = csvHeaders.value.find(
|
||||
(header) => header === fieldDef.fileFieldName,
|
||||
);
|
||||
if (matched) {
|
||||
mappedHeader = matched;
|
||||
}
|
||||
}
|
||||
mappings[fieldDef.id] = {
|
||||
fieldDef,
|
||||
mappedHeader,
|
||||
};
|
||||
});
|
||||
fieldMappings.value = mappings;
|
||||
};
|
||||
|
||||
// 获取店铺列表
|
||||
const fetchShopList = async (reset = false) => {
|
||||
if (shopLoading.value) return;
|
||||
|
||||
try {
|
||||
shopLoading.value = true;
|
||||
|
||||
if (reset) {
|
||||
shopList.value = [];
|
||||
shopPage.value = 1;
|
||||
shopHasMore.value = true;
|
||||
}
|
||||
|
||||
const result = await getShopPageApi({
|
||||
page: shopPage.value,
|
||||
pageSize: shopPageSize.value,
|
||||
filters: {
|
||||
name: shopSearchValue.value || undefined,
|
||||
},
|
||||
});
|
||||
|
||||
if (reset) {
|
||||
shopList.value = result.records || [];
|
||||
} else {
|
||||
shopList.value.push(...(result.records || []));
|
||||
}
|
||||
|
||||
// 判断是否还有更多数据
|
||||
shopHasMore.value = (result.records?.length || 0) === shopPageSize.value;
|
||||
if (shopHasMore.value) {
|
||||
shopPage.value++;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取店铺列表失败:', error);
|
||||
message.error('获取店铺列表失败');
|
||||
} finally {
|
||||
shopLoading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 店铺搜索
|
||||
const handleShopSearch = (value: string) => {
|
||||
shopSearchValue.value = value;
|
||||
fetchShopList(true);
|
||||
};
|
||||
|
||||
// 店铺下拉框滚动加载更多
|
||||
const handleShopScroll = (e: any) => {
|
||||
const { target } = e;
|
||||
if (
|
||||
target.scrollTop + target.offsetHeight === target.scrollHeight &&
|
||||
shopHasMore.value &&
|
||||
!shopLoading.value
|
||||
) {
|
||||
fetchShopList();
|
||||
}
|
||||
};
|
||||
|
||||
// 获取字段定义
|
||||
const fetchFieldDefs = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
const result = await getFieldDefsByTypeApi('order');
|
||||
fieldDefs.value = result || [];
|
||||
initFieldMappings();
|
||||
} catch (error) {
|
||||
console.error('获取字段定义失败:', error);
|
||||
message.error('获取字段定义失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 下一步
|
||||
const handleNext = () => {
|
||||
if (currentStep.value === 0) {
|
||||
if (!selectedShopId.value) {
|
||||
message.warning('请选择店铺');
|
||||
return;
|
||||
}
|
||||
currentStep.value = 1;
|
||||
if (fieldDefs.value.length === 0) {
|
||||
fetchFieldDefs();
|
||||
}
|
||||
} else if (currentStep.value === 1) {
|
||||
// 验证必填字段
|
||||
const requiredFields = fieldDefs.value.filter((f) => f.required);
|
||||
const unMappedFields = requiredFields.filter((field) => {
|
||||
const mapping = fieldMappings.value[field.id];
|
||||
return !mapping || !mapping.mappedHeader;
|
||||
});
|
||||
if (unMappedFields.length > 0) {
|
||||
message.warning(
|
||||
`请先绑定必填字段:${unMappedFields.map((f) => f.fieldLabel).join('、')}`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
currentStep.value = 2;
|
||||
}
|
||||
};
|
||||
|
||||
// 上一步
|
||||
const handlePrev = () => {
|
||||
if (currentStep.value > 0) {
|
||||
currentStep.value--;
|
||||
}
|
||||
};
|
||||
|
||||
// 取消
|
||||
const handleCancel = () => {
|
||||
// 保持所有状态:步骤、店铺选择、字段映射
|
||||
modalApi.close();
|
||||
};
|
||||
|
||||
// 创建导入任务
|
||||
const handleCreateTask = async () => {
|
||||
if (!selectedFile.value) {
|
||||
message.error('文件信息丢失,请重新上传');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
loading.value = true;
|
||||
|
||||
// 先上传文件
|
||||
message.loading('正在上传文件...', 0);
|
||||
const fileInfo = await uploadFileApi(selectedFile.value);
|
||||
message.destroy();
|
||||
|
||||
// 构建字段映射 JSON
|
||||
const mapping: Record<string, string> = {};
|
||||
Object.values(fieldMappings.value).forEach((m) => {
|
||||
if (m.mappedHeader) {
|
||||
mapping[m.fieldDef.fieldName] = m.mappedHeader;
|
||||
}
|
||||
});
|
||||
|
||||
const createData: ImportTaskDTO.CreateImportTaskDTO = {
|
||||
shopId: selectedShopId.value!,
|
||||
type: 'order',
|
||||
fileName: selectedFile.value.name,
|
||||
filePath: fileInfo.url,
|
||||
mapping: JSON.stringify(mapping),
|
||||
};
|
||||
|
||||
await createImportTaskApi(createData);
|
||||
message.success('创建导入任务成功');
|
||||
// 创建成功后,重置状态并关闭
|
||||
currentStep.value = 0;
|
||||
selectedShopId.value = undefined;
|
||||
fieldMappings.value = {};
|
||||
csvHeaders.value = [];
|
||||
selectedFile.value = null;
|
||||
modalApi.close();
|
||||
} catch (error: any) {
|
||||
message.destroy();
|
||||
console.error('创建导入任务失败:', error);
|
||||
message.error(error?.message || '创建导入任务失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 暴露给父组件的方法
|
||||
function open(headers: string[], file?: File) {
|
||||
const headersChanged =
|
||||
JSON.stringify(csvHeaders.value) !== JSON.stringify(headers);
|
||||
|
||||
csvHeaders.value = headers;
|
||||
selectedFile.value = file || null;
|
||||
// 步骤保持不变,不清空
|
||||
|
||||
// 如果 CSV 表头变化了,需要重新初始化字段映射
|
||||
if (headersChanged) {
|
||||
fieldMappings.value = {};
|
||||
// 如果已有字段定义,重新初始化映射
|
||||
if (fieldDefs.value.length > 0) {
|
||||
initFieldMappings();
|
||||
}
|
||||
// 表头变化时,重置到第一步
|
||||
currentStep.value = 0;
|
||||
}
|
||||
|
||||
// 店铺选择保持不变,不清空
|
||||
// 只在首次打开或列表为空时加载店铺列表
|
||||
if (shopList.value.length === 0) {
|
||||
shopSearchValue.value = '';
|
||||
shopPage.value = 1;
|
||||
shopHasMore.value = true;
|
||||
fetchShopList(true);
|
||||
}
|
||||
|
||||
modalApi.open();
|
||||
}
|
||||
|
||||
// 暴露方法给父组件
|
||||
defineExpose({
|
||||
open,
|
||||
});
|
||||
|
||||
// 店铺选项
|
||||
const shopOptions = computed(() => {
|
||||
return shopList.value.map((shop: ShopVO.Info) => ({
|
||||
label: shop.platform ? `${shop.name} (${shop.platform})` : shop.name,
|
||||
value: shop.id,
|
||||
}));
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="创建导入任务" :loading="loading">
|
||||
<div class="space-y-6">
|
||||
<!-- 步骤条 -->
|
||||
<Steps :current="currentStep">
|
||||
<Steps.Step title="选择店铺" />
|
||||
<Steps.Step title="字段映射" />
|
||||
<Steps.Step title="确认信息" />
|
||||
</Steps>
|
||||
|
||||
<!-- 第一步:选择店铺 -->
|
||||
<div v-if="currentStep === 0" class="py-4">
|
||||
<Form
|
||||
ref="formRef"
|
||||
:label-col="{ span: 6 }"
|
||||
:wrapper-col="{ span: 18 }"
|
||||
>
|
||||
<Form.Item label="选择店铺" required>
|
||||
<Select
|
||||
v-model:value="selectedShopId"
|
||||
placeholder="请选择店铺"
|
||||
show-search
|
||||
:filter-option="false"
|
||||
:loading="shopLoading"
|
||||
@search="handleShopSearch"
|
||||
@popup-scroll="handleShopScroll"
|
||||
>
|
||||
<template #notFoundContent>
|
||||
<div v-if="shopLoading" class="py-4 text-center">
|
||||
<Spin size="small" />
|
||||
<div class="mt-2">加载中...</div>
|
||||
</div>
|
||||
<div v-else class="py-4 text-center text-gray-400">
|
||||
暂无数据
|
||||
</div>
|
||||
</template>
|
||||
<Select.Option
|
||||
v-for="option in shopOptions"
|
||||
:key="option.value"
|
||||
:value="option.value"
|
||||
:label="option.label"
|
||||
>
|
||||
{{ option.label }}
|
||||
</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
<!-- 第二步:字段映射 -->
|
||||
<div v-if="currentStep === 1" class="py-4">
|
||||
<div class="mb-4 text-sm text-gray-600">
|
||||
请为每个订单字段选择对应的CSV列,必填字段必须绑定
|
||||
</div>
|
||||
<div class="max-h-[400px] space-y-4 overflow-y-auto">
|
||||
<div
|
||||
v-for="fieldDef in fieldDefs"
|
||||
:key="fieldDef.id"
|
||||
class="flex items-center space-x-4 rounded border p-3"
|
||||
:class="{
|
||||
'border-red-300 bg-red-50':
|
||||
fieldDef.required && !fieldMappings[fieldDef.id]?.mappedHeader,
|
||||
}"
|
||||
>
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center space-x-2">
|
||||
<span class="font-medium">{{ fieldDef.fieldLabel }}</span>
|
||||
<span v-if="fieldDef.required" class="text-xs text-red-500">
|
||||
(必填)
|
||||
</span>
|
||||
</div>
|
||||
<div class="mt-1 text-xs text-gray-500">
|
||||
字段名: {{ fieldDef.fieldName }}
|
||||
</div>
|
||||
</div>
|
||||
<Select
|
||||
v-if="fieldMappings[fieldDef.id]"
|
||||
v-model:value="fieldMappings[fieldDef.id]!.mappedHeader"
|
||||
placeholder="请选择CSV列"
|
||||
class="w-[200px]"
|
||||
show-search
|
||||
allow-clear
|
||||
:options="
|
||||
csvHeaders.map((h) => ({
|
||||
label: h,
|
||||
value: h,
|
||||
}))
|
||||
"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 第三步:确认信息 -->
|
||||
<div v-if="currentStep === 2" class="py-4">
|
||||
<div class="space-y-4">
|
||||
<div class="rounded bg-gray-50 p-4">
|
||||
<div class="mb-2 font-medium">店铺信息</div>
|
||||
<div class="text-gray-700">
|
||||
{{
|
||||
shopList.find((s: ShopVO.Info) => s.id === selectedShopId)
|
||||
?.name ?? '-'
|
||||
}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="rounded bg-gray-50 p-4">
|
||||
<div class="mb-2 font-medium">字段映射</div>
|
||||
<div class="space-y-2">
|
||||
<div
|
||||
v-for="mapping in Object.values(fieldMappings).filter(
|
||||
(m) => m.mappedHeader,
|
||||
)"
|
||||
:key="mapping.fieldDef.id"
|
||||
class="flex justify-between text-sm"
|
||||
>
|
||||
<span class="text-gray-600">
|
||||
{{ mapping.fieldDef.fieldLabel }}:
|
||||
</span>
|
||||
<span class="font-medium">{{ mapping.mappedHeader }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 操作按钮 -->
|
||||
<div class="flex justify-between border-t pt-4">
|
||||
<Button @click="handleCancel">取消</Button>
|
||||
<div class="space-x-2">
|
||||
<Button v-if="currentStep > 0" @click="handlePrev">上一步</Button>
|
||||
<Button
|
||||
v-if="currentStep < 2"
|
||||
type="primary"
|
||||
:disabled="!canGoToNextStep"
|
||||
@click="handleNext"
|
||||
>
|
||||
下一步
|
||||
</Button>
|
||||
<Button
|
||||
v-if="currentStep === 2"
|
||||
type="primary"
|
||||
:loading="loading"
|
||||
@click="handleCreateTask"
|
||||
>
|
||||
创建导入任务
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
/* 自定义样式 */
|
||||
</style>
|
||||
+25
-4
@@ -9,6 +9,7 @@ import { Button, message } from 'ant-design-vue';
|
||||
|
||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||
|
||||
import CreateImportTaskModal from './components/CreateImportTaskModal.vue';
|
||||
import FileUploadArea from './components/FileUploadArea.vue';
|
||||
import { parseCSVToRawData } from './utils/csvParser';
|
||||
|
||||
@@ -18,6 +19,7 @@ defineOptions({ name: 'DataImport' });
|
||||
const csvData = ref<any[]>([]);
|
||||
const csvHeaders = ref<string[]>([]);
|
||||
const importLoading = ref(false);
|
||||
const currentFile = ref<File | null>(null);
|
||||
|
||||
// 动态生成Grid列配置
|
||||
const gridColumns = computed(() => {
|
||||
@@ -112,6 +114,7 @@ const handleFileUpload = async (file: File) => {
|
||||
|
||||
csvData.value = result.data;
|
||||
csvHeaders.value = result.headers;
|
||||
currentFile.value = file;
|
||||
|
||||
// 更新表格
|
||||
updateTable();
|
||||
@@ -124,9 +127,20 @@ const handleFileUpload = async (file: File) => {
|
||||
}
|
||||
};
|
||||
|
||||
// 匹配向导按钮处理
|
||||
const handleMatchWizard = () => {
|
||||
message.info('匹配向导功能待实现');
|
||||
// 创建导入任务模态框引用
|
||||
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,
|
||||
);
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -134,7 +148,13 @@ const handleMatchWizard = () => {
|
||||
<Page auto-content-height>
|
||||
<!-- 顶部栏 -->
|
||||
<template #extra>
|
||||
<Button type="primary" @click="handleMatchWizard"> 匹配向导 </Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:disabled="csvHeaders.length === 0"
|
||||
@click="handleCreateImportTask"
|
||||
>
|
||||
创建导入任务
|
||||
</Button>
|
||||
</template>
|
||||
|
||||
<!-- 主体内容区域 -->
|
||||
@@ -149,6 +169,7 @@ const handleMatchWizard = () => {
|
||||
</div>
|
||||
|
||||
<Grid v-else />
|
||||
<CreateImportTaskModal ref="createImportTaskModalRef" />
|
||||
</Page>
|
||||
</template>
|
||||
|
||||
@@ -56,6 +56,7 @@ interface FormData {
|
||||
type: string;
|
||||
fieldName: string;
|
||||
fieldLabel: string;
|
||||
fileFieldName?: string;
|
||||
required: boolean;
|
||||
sort?: number;
|
||||
dataType?: string;
|
||||
@@ -66,6 +67,7 @@ const formData = ref<FormData>({
|
||||
type: 'product',
|
||||
fieldName: '',
|
||||
fieldLabel: '',
|
||||
fileFieldName: '',
|
||||
required: false,
|
||||
sort: 0,
|
||||
dataType: 'string',
|
||||
@@ -91,6 +93,7 @@ function resetForm() {
|
||||
type: 'product',
|
||||
fieldName: '',
|
||||
fieldLabel: '',
|
||||
fileFieldName: '',
|
||||
required: false,
|
||||
sort: 0,
|
||||
dataType: 'string',
|
||||
@@ -125,6 +128,7 @@ function open(
|
||||
type: fieldData.type,
|
||||
fieldName: fieldData.fieldName,
|
||||
fieldLabel: fieldData.fieldLabel,
|
||||
fileFieldName: fieldData.fileFieldName ?? '',
|
||||
required: fieldData.required,
|
||||
sort: fieldData.sort ?? 0,
|
||||
dataType: fieldData.dataType ?? 'string',
|
||||
@@ -146,6 +150,7 @@ async function handleSubmit() {
|
||||
// 更新字段
|
||||
const updateData: ImportFieldDefDTO.UpdateImportFieldDefDTO = {
|
||||
fieldLabel: formData.value.fieldLabel,
|
||||
fileFieldName: formData.value.fileFieldName,
|
||||
required: formData.value.required,
|
||||
sort: formData.value.sort,
|
||||
dataType: formData.value.dataType,
|
||||
@@ -158,6 +163,7 @@ async function handleSubmit() {
|
||||
type: formData.value.type,
|
||||
fieldName: formData.value.fieldName,
|
||||
fieldLabel: formData.value.fieldLabel,
|
||||
fileFieldName: formData.value.fileFieldName,
|
||||
required: formData.value.required,
|
||||
sort: formData.value.sort,
|
||||
dataType: formData.value.dataType,
|
||||
@@ -229,6 +235,13 @@ defineExpose({
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="文件字段名" name="fileFieldName">
|
||||
<Input
|
||||
v-model:value="formData.fileFieldName"
|
||||
placeholder="请输入文件字段名(如:商品名称)"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item label="数据类型" name="dataType">
|
||||
<Select
|
||||
v-model:value="formData.dataType"
|
||||
|
||||
Reference in New Issue
Block a user