perf: 商品保存改为基础信息秒回与SKU后台入队
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 50s

This commit is contained in:
2026-02-25 13:29:10 +08:00
parent cd9c08fad3
commit a678ca632a

View File

@@ -18,6 +18,7 @@ import { message } from 'ant-design-vue';
import { uploadTenantFileApi } from '#/api/files'; import { uploadTenantFileApi } from '#/api/files';
import { import {
createProductSkuSaveJobApi,
deleteProductApi, deleteProductApi,
getProductAddonGroupListApi, getProductAddonGroupListApi,
getProductCategoryListApi, getProductCategoryListApi,
@@ -421,6 +422,45 @@ export function createProductDetailDataActions(
}); });
} }
async function enqueueSkuSaveJobInBackground(
storeIdValue: string,
productIdValue: string,
specTemplateIds: string[],
skus: Array<{
attributes: Array<{
optionId: string;
templateId: string;
}>;
isEnabled: boolean;
originalPrice: null | number;
price: number;
skuCode?: string;
sortOrder: number;
stock: number;
}>,
) {
try {
const createdJob = await createProductSkuSaveJobApi({
storeId: storeIdValue,
productId: productIdValue,
specTemplateIds,
skus,
});
if (!createdJob?.jobId) {
message.error('SKU 异步任务创建失败');
return;
}
void watchSkuSaveJobInBackground(
storeIdValue,
productIdValue,
createdJob.jobId,
);
} catch (error) {
console.error(error);
}
}
async function saveDetail() { async function saveDetail() {
if (!storeId.value || !form.id) return; if (!storeId.value || !form.id) return;
if (!form.name.trim()) { if (!form.name.trim()) {
@@ -540,7 +580,6 @@ export function createProductDetailDataActions(
specTemplateIds: [...form.specTemplateIds], specTemplateIds: [...form.specTemplateIds],
addonGroupIds: [...form.addonGroupIds], addonGroupIds: [...form.addonGroupIds],
labelIds: [...form.labelIds], labelIds: [...form.labelIds],
skus: normalizedSkus,
comboGroups: normalizedComboGroups, comboGroups: normalizedComboGroups,
tags: [], tags: [],
}; };
@@ -550,36 +589,15 @@ export function createProductDetailDataActions(
form.id = asyncSaved.productId; form.id = asyncSaved.productId;
} }
if ( message.success(asyncSaved.message || '商品基础信息已保存');
asyncSaved.skuJobStatus === 'queued' || if (normalizedSkus.length > 0 && (asyncSaved.productId || form.id)) {
asyncSaved.skuJobStatus === 'running' void enqueueSkuSaveJobInBackground(
) { storeId.value,
if (asyncSaved.skuJobId) { asyncSaved.productId || form.id,
message.success( [...form.specTemplateIds],
asyncSaved.message || normalizedSkus,
`商品基础信息已保存,${normalizedSkus.length} 条 SKU 正在后台处理`, );
);
void watchSkuSaveJobInBackground(
storeId.value,
asyncSaved.productId || form.id,
asyncSaved.skuJobId,
);
} else {
message.warning(
asyncSaved.message || 'SKU 任务已创建,请稍后刷新查看状态',
);
}
return;
} }
if (asyncSaved.skuJobStatus === 'not_required') {
message.success(asyncSaved.message || '商品详情已保存');
return;
}
message.error(
asyncSaved.message || '商品基础信息已保存,但 SKU 异步任务创建失败',
);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} finally { } finally {