fix(order-import): 修复模板自动选中时序问题

1. handleNext 改为 async,确保 fieldDefs 加载完成后才加载模板
2. handleSelectTemplate 添加 fieldDefs 非空检查,防止时序问题导致映射失败
3. handleSelectStatusTemplate 添加 uniqueStatusValues 非空检查
This commit is contained in:
小蟑螂
2026-03-29 20:06:44 +08:00
parent ae2d7ce903
commit 4950a072c6
@@ -425,6 +425,11 @@ const handleSelectTemplate = async (value: any) => {
return;
}
// 如果 fieldDefs 尚未加载,不应用模板(防止时序问题)
if (fieldDefs.value.length === 0) {
return;
}
const template = mappingTemplates.value.find((t) => t.id === templateId);
if (!template) {
return;
@@ -551,6 +556,11 @@ const handleSelectStatusTemplate = async (value: any) => {
return;
}
// 如果没有订单状态值,不应用模板
if (uniqueStatusValues.value.length === 0) {
return;
}
const template = statusMappingTemplates.value.find(
(t) => t.id === templateId,
);
@@ -852,7 +862,7 @@ const parseOrderStatuses = () => {
};
// 下一步
const handleNext = () => {
const handleNext = async () => {
switch (currentStep.value) {
case 0: {
if (!selectedShopId.value) {
@@ -860,12 +870,13 @@ const handleNext = () => {
return;
}
currentStep.value = 1;
// 确保字段定义加载完成后,再加载模板(模板自动选中依赖 fieldDefs)
if (fieldDefs.value.length === 0) {
fetchFieldDefs();
await fetchFieldDefs();
}
// 加载映射模板列表
if (mappingTemplates.value.length === 0) {
fetchMappingTemplates();
await fetchMappingTemplates();
}
break;