diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/FixSpecCodeEditor.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/FixSpecCodeEditor.vue
deleted file mode 100644
index c32a122e..00000000
--- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/FixSpecCodeEditor.vue
+++ /dev/null
@@ -1,72 +0,0 @@
-
-
-
-
-
- 共 {{ rows.length }} 行缺少规格编码,请补全后在右侧确认应用
-
-
-
-
-
-
- | 行号 |
- 订单号 |
- 商品 |
- 规格编码 |
-
-
-
-
- | {{ row.rowIndex + 2 }} |
- {{ row.orderNo || '-' }} |
- {{ row.productName || '-' }} |
-
-
- |
-
-
-
-
-
-
-
diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/ImportTaskWizard.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/ImportTaskWizard.vue
index dd187e53..05d07516 100644
--- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/ImportTaskWizard.vue
+++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/order-import/components/ImportTaskWizard.vue
@@ -8,7 +8,7 @@ import type { ImportTaskDTO } from '#/api/ecommerce/import-task';
import type { OrderStatusVO } from '#/api/ecommerce/order-status';
import type { ShopVO } from '#/api/ecommerce/shop/types';
-import { computed, ref } from 'vue';
+import { computed, ref, watch } from 'vue';
import { useVbenModal } from '@vben/common-ui';
@@ -35,7 +35,6 @@ import { getAllOrderStatusListApi } from '#/api/ecommerce/order-status';
import { getShopPageApi } from '#/api/ecommerce/shop';
import { useImportTaskStore } from '#/store';
import { uploadFileToOss } from '#/utils/oss-upload';
-import FixSpecCodeEditor from './FixSpecCodeEditor.vue';
import { createPatchedFile } from '../utils/specCodePatch';
// 定义映射项数据结构
@@ -62,6 +61,10 @@ defineOptions({ name: 'ImportTaskWizard' });
const emit = defineEmits<{
success: [];
+ /** 规格编码列绑定到的 CSV 表头变化时,供左侧表格开启该列编辑 */
+ specCodeColumnChange: [header: string | undefined];
+ /** 规格编码空行预检结果变化(含左侧编辑后) */
+ specMissingAfterPrecheck: [payload: { count: number; indices: number[] }];
}>();
// 响应式数据
@@ -71,7 +74,10 @@ const fieldDefsLoading = ref(false);
/** 创建导入任务提交中(与 message.loading 配合,仅按钮 loading) */
const createTaskSubmitting = ref(false);
const csvHeaders = ref([]);
-const csvData = ref([]);
+/** 与左侧「数据预览」表格共用同一数组引用,便于就地编辑规格编码 */
+const previewData = defineModel('previewData', { default: () => [] });
+/** 用户上传的原始文件,生成补录文件时始终以此为基准,避免多次 _patched 链式后缀 */
+const originalImportFile = ref(null);
const selectedFile = ref(null);
// 规格编码补录(仅本次导入)
@@ -83,7 +89,6 @@ interface MissingSpecCodeRow {
}
const missingSpecCodeCount = ref(0);
const missingSpecCodeRows = ref([]);
-const editableMissingSpecCodeRows = ref([]);
const specCodePrechecked = ref(false);
const hasPatchedFile = ref(false);
@@ -223,22 +228,6 @@ const [SaveStatusTemplateModal, saveStatusTemplateModalApi] = useVbenModal({
},
});
-// 创建补录规格编码模态框
-const [FixSpecCodeModal, fixSpecCodeModalApi] = useVbenModal({
- draggable: true,
- class: 'w-[900px]',
- title: '补充规格编码',
- showCancelButton: true,
- showConfirmButton: true,
- confirmText: '应用并替换导入文件',
- cancelText: '取消',
- onConfirm: handleConfirmFixSpecCode,
- onCancel() {
- editableMissingSpecCodeRows.value = [];
- fixSpecCodeModalApi.close();
- },
-});
-
// 导入任务store
const importTaskStore = useImportTaskStore();
@@ -955,7 +944,7 @@ const parseOrderStatuses = () => {
const statusColumn = statusMapping.mappedHeader;
const statusSet = new Set();
- csvData.value.forEach((row) => {
+ previewData.value.forEach((row) => {
const statusValue = row[statusColumn];
if (
statusValue !== null &&
@@ -1030,6 +1019,7 @@ const runMissingSpecCodePrecheck = () => {
missingSpecCodeRows.value = [];
missingSpecCodeCount.value = 0;
specCodePrechecked.value = true;
+ emit('specMissingAfterPrecheck', { count: 0, indices: [] });
return;
}
@@ -1037,7 +1027,7 @@ const runMissingSpecCodePrecheck = () => {
const productNameHeader = getProductNameHeader();
const rows: MissingSpecCodeRow[] = [];
- csvData.value.forEach((row, index) => {
+ previewData.value.forEach((row, index) => {
if (isEmptyValue(row[specCodeHeader])) {
rows.push({
rowIndex: index,
@@ -1051,67 +1041,32 @@ const runMissingSpecCodePrecheck = () => {
missingSpecCodeRows.value = rows;
missingSpecCodeCount.value = rows.length;
specCodePrechecked.value = true;
+ emit('specMissingAfterPrecheck', {
+ count: missingSpecCodeCount.value,
+ indices: missingSpecCodeRows.value.map((r) => r.rowIndex),
+ });
};
-// createPatchedFile 抽到 utils
-
-const handleOpenFixSpecCodeModal = () => {
- if (missingSpecCodeCount.value === 0) {
- message.info('当前不存在需要补充规格编码的行');
- return;
- }
- editableMissingSpecCodeRows.value = missingSpecCodeRows.value.map((row) => ({
- ...row,
- }));
- fixSpecCodeModalApi.open();
-};
-
-async function handleConfirmFixSpecCode() {
- const hasEmpty = editableMissingSpecCodeRows.value.some((row) =>
- isEmptyValue(row.specCode),
+/** 用当前预览行从「原始上传文件」重新生成待上传文件(规格编码列编辑后调用) */
+function syncPreviewToUploadFile() {
+ if (!originalImportFile.value || previewData.value.length === 0) return;
+ selectedFile.value = createPatchedFile(
+ originalImportFile.value,
+ csvHeaders.value,
+ previewData.value,
);
- if (hasEmpty) {
- message.warning('请先补全所有待处理行的规格编码');
- return;
- }
- if (!selectedFile.value) {
- message.error('源文件不存在,请重新上传');
- return;
- }
+ hasPatchedFile.value = true;
+}
- try {
- fixSpecCodeModalApi.lock();
- const specCodeHeader = getMappedHeaderByFieldCandidates(
- ['spec_code', 'specCode'],
- '规格编码',
- );
- if (!specCodeHeader) {
- message.error('未找到规格编码映射列,请返回上一步检查字段映射');
- return;
- }
-
- const updatedRows = csvData.value.map((row) => ({ ...row }));
- editableMissingSpecCodeRows.value.forEach((item) => {
- updatedRows[item.rowIndex][specCodeHeader] = item.specCode.trim();
- });
-
- const patchedFile = createPatchedFile(
- selectedFile.value,
- csvHeaders.value,
- updatedRows,
- );
- csvData.value = updatedRows;
- selectedFile.value = patchedFile;
- hasPatchedFile.value = true;
- runMissingSpecCodePrecheck();
- message.success('已生成补录后的新文件,将用于本次导入');
- fixSpecCodeModalApi.close();
- } catch (error: any) {
- console.error('补录规格编码失败:', error);
- message.error(error?.message || '补录规格编码失败');
- } finally {
- fixSpecCodeModalApi.unlock();
- }
+/** 左侧表格规格编码单元格编辑结束并落盘后,由父级防抖调用 */
+function onPreviewSpecCodeCellSaved() {
+ const specHeader = getMappedHeaderByFieldCandidates(
+ ['spec_code', 'specCode'],
+ '规格编码',
+ );
+ if (!specHeader || !originalImportFile.value) return;
+ syncPreviewToUploadFile();
+ runMissingSpecCodePrecheck();
}
// 下一步(顺序:字段映射 → 订单状态映射 → 确认信息含选店铺)
@@ -1133,7 +1088,7 @@ const handleNext = async () => {
runMissingSpecCodePrecheck();
if (missingSpecCodeCount.value > 0) {
message.warning(
- `检测到 ${missingSpecCodeCount.value} 行规格编码为空,可在确认步骤补充后再创建任务`,
+ `检测到 ${missingSpecCodeCount.value} 行规格编码为空,请在左侧「数据预览」表格中,找到已映射为「规格编码」的列,直接点击单元格补全`,
);
}
@@ -1197,6 +1152,22 @@ const handleCreateTask = async () => {
return;
}
+ runMissingSpecCodePrecheck();
+ if (missingSpecCodeCount.value > 0) {
+ message.warning(
+ `仍有 ${missingSpecCodeCount.value} 行规格编码为空,请在左侧表格对应列补全后再创建任务`,
+ );
+ return;
+ }
+
+ if (hasPatchedFile.value && originalImportFile.value) {
+ selectedFile.value = createPatchedFile(
+ originalImportFile.value,
+ csvHeaders.value,
+ previewData.value,
+ );
+ }
+
try {
createTaskSubmitting.value = true;
@@ -1260,12 +1231,12 @@ const handleCreateTask = async () => {
uniqueStatusValues.value = [];
missingSpecCodeCount.value = 0;
missingSpecCodeRows.value = [];
- editableMissingSpecCodeRows.value = [];
specCodePrechecked.value = false;
hasPatchedFile.value = false;
csvHeaders.value = [];
- csvData.value = [];
+ previewData.value = [];
selectedFile.value = null;
+ originalImportFile.value = null;
selectedTemplateId.value = undefined;
selectedStatusTemplateId.value = undefined;
clearObsoleteSystemTargetRemind();
@@ -1279,17 +1250,16 @@ const handleCreateTask = async () => {
}
};
-// 暴露给父组件的方法(第一步为字段映射,需预拉字段定义与映射模板)
-async function open(headers: string[], file?: File, data?: any[]) {
+// 暴露给父组件的方法(第一步为字段映射,需预拉字段定义与映射模板;预览行数据与父级 v-model:preview-data 共用)
+async function open(headers: string[], file?: File) {
const headersChanged =
JSON.stringify(csvHeaders.value) !== JSON.stringify(headers);
csvHeaders.value = headers;
- csvData.value = data || [];
- selectedFile.value = file || null;
+ originalImportFile.value = file ?? null;
+ selectedFile.value = file ?? null;
missingSpecCodeCount.value = 0;
missingSpecCodeRows.value = [];
- editableMissingSpecCodeRows.value = [];
specCodePrechecked.value = false;
hasPatchedFile.value = false;
@@ -1300,7 +1270,6 @@ async function open(headers: string[], file?: File, data?: any[]) {
clearObsoleteSystemTargetRemind();
missingSpecCodeCount.value = 0;
missingSpecCodeRows.value = [];
- editableMissingSpecCodeRows.value = [];
specCodePrechecked.value = false;
hasPatchedFile.value = false;
currentStep.value = 0;
@@ -1343,21 +1312,33 @@ function reset() {
uniqueStatusValues.value = [];
missingSpecCodeCount.value = 0;
missingSpecCodeRows.value = [];
- editableMissingSpecCodeRows.value = [];
specCodePrechecked.value = false;
hasPatchedFile.value = false;
csvHeaders.value = [];
- csvData.value = [];
+ previewData.value = [];
selectedFile.value = null;
+ originalImportFile.value = null;
selectedTemplateId.value = undefined;
selectedStatusTemplateId.value = undefined;
clearObsoleteSystemTargetRemind();
}
+watch(
+ () =>
+ fieldDefs.value.length > 0
+ ? getMappedHeaderByFieldCandidates(['spec_code', 'specCode'], '规格编码')
+ : undefined,
+ (h) => {
+ emit('specCodeColumnChange', h);
+ },
+ { flush: 'post', immediate: true },
+);
+
// 暴露方法给父组件
defineExpose({
open,
reset,
+ onPreviewSpecCodeCellSaved,
});
// 店铺选项
@@ -1381,7 +1362,7 @@ const shopOptions = computed(() => {
v-if="selectedFile"
class="mb-0 mt-1 truncate text-xs text-slate-500 dark:text-[hsl(240deg_5%_64.9%)]"
>
- {{ selectedFile.name }} · {{ csvData.length }} 条
+ {{ selectedFile.name }} · {{ previewData.length }} 条
@@ -1803,15 +1784,10 @@ const shopOptions = computed(() => {
v-if="specCodePrechecked && missingSpecCodeCount > 0"
type="warning"
show-icon
- :message="`检测到 ${missingSpecCodeCount} 行规格编码为空`"
+ :message="`仍有 ${missingSpecCodeCount} 行规格编码为空`"
>
-
- 可先补充规格编码,再创建导入任务。
-
-
+ 请在左侧「数据预览」中点击已映射为「规格编码」的列单元格,直接填写后创建任务。
{
-
-
-