feat: 商品详情大批量SKU保存改为后台非阻塞
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 53s
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 53s
This commit is contained in:
@@ -81,6 +81,7 @@ export function createProductDetailDataActions(
|
||||
specTemplateOptions,
|
||||
storeId,
|
||||
} = options;
|
||||
let activeSkuSaveJobId = '';
|
||||
|
||||
function resetForm() {
|
||||
Object.assign(form, {
|
||||
@@ -360,6 +361,73 @@ export function createProductDetailDataActions(
|
||||
};
|
||||
}
|
||||
|
||||
async function watchSkuSaveJobInBackground(
|
||||
storeIdValue: string,
|
||||
productIdValue: string,
|
||||
jobId: string,
|
||||
) {
|
||||
if (activeSkuSaveJobId && activeSkuSaveJobId !== jobId) {
|
||||
message.destroy(`product-sku-save-job-${activeSkuSaveJobId}`);
|
||||
}
|
||||
|
||||
activeSkuSaveJobId = jobId;
|
||||
const toastKey = `product-sku-save-job-${jobId}`;
|
||||
message.loading({
|
||||
content: 'SKU 正在后台保存,可继续操作',
|
||||
duration: 0,
|
||||
key: toastKey,
|
||||
});
|
||||
|
||||
const jobResult = await waitForSkuSaveJob(storeIdValue, jobId);
|
||||
if (activeSkuSaveJobId !== jobId) {
|
||||
message.destroy(toastKey);
|
||||
return;
|
||||
}
|
||||
|
||||
if (jobResult.status === 'succeeded') {
|
||||
if (storeId.value === storeIdValue && form.id === productIdValue) {
|
||||
try {
|
||||
const latestDetail = await getProductDetailApi({
|
||||
storeId: storeIdValue,
|
||||
productId: productIdValue,
|
||||
});
|
||||
detail.value = latestDetail;
|
||||
patchForm(latestDetail);
|
||||
buildSkuRows();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
message.success({
|
||||
content: 'SKU 后台保存完成',
|
||||
key: toastKey,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (jobResult.status === 'failed' || jobResult.status === 'canceled') {
|
||||
message.error({
|
||||
content: jobResult.errorMessage || 'SKU 异步保存失败',
|
||||
key: toastKey,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (jobResult.timedOut) {
|
||||
message.warning({
|
||||
content: 'SKU 仍在后台处理中,请稍后刷新查看',
|
||||
key: toastKey,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
message.warning({
|
||||
content: 'SKU 保存状态未知,请稍后刷新查看',
|
||||
key: toastKey,
|
||||
});
|
||||
}
|
||||
|
||||
async function saveDetail() {
|
||||
if (!storeId.value || !form.id) return;
|
||||
if (!form.name.trim()) {
|
||||
@@ -485,43 +553,33 @@ export function createProductDetailDataActions(
|
||||
tags: [],
|
||||
});
|
||||
|
||||
let latestDetail = saved;
|
||||
if (shouldSaveSkuAsync) {
|
||||
const createdJob = await createProductSkuSaveJobApi({
|
||||
storeId: storeId.value,
|
||||
productId: saved.id,
|
||||
specTemplateIds: [...form.specTemplateIds],
|
||||
skus: normalizedSkus,
|
||||
});
|
||||
const jobResult = await waitForSkuSaveJob(
|
||||
storeId.value,
|
||||
createdJob.jobId,
|
||||
);
|
||||
if (jobResult.status === 'succeeded') {
|
||||
latestDetail = await getProductDetailApi({
|
||||
try {
|
||||
const createdJob = await createProductSkuSaveJobApi({
|
||||
storeId: storeId.value,
|
||||
productId: saved.id,
|
||||
specTemplateIds: [...form.specTemplateIds],
|
||||
skus: normalizedSkus,
|
||||
});
|
||||
message.success('商品详情已保存,SKU 已异步更新');
|
||||
} else if (
|
||||
jobResult.status === 'failed' ||
|
||||
jobResult.status === 'canceled'
|
||||
) {
|
||||
message.error(
|
||||
jobResult.errorMessage || '商品基础信息已保存,但 SKU 异步保存失败',
|
||||
message.success(
|
||||
`商品基础信息已保存,${normalizedSkus.length} 条 SKU 正在后台处理`,
|
||||
);
|
||||
} else if (jobResult.timedOut) {
|
||||
message.warning('商品基础信息已保存,SKU 正在后台处理');
|
||||
} else {
|
||||
message.warning('商品基础信息已保存,SKU 保存状态请稍后刷新查看');
|
||||
detail.value = saved;
|
||||
void watchSkuSaveJobInBackground(
|
||||
storeId.value,
|
||||
saved.id,
|
||||
createdJob.jobId,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
message.error('商品基础信息已保存,但 SKU 异步任务创建失败');
|
||||
}
|
||||
} else {
|
||||
message.success('商品详情已保存');
|
||||
detail.value = saved;
|
||||
patchForm(saved);
|
||||
buildSkuRows();
|
||||
}
|
||||
|
||||
detail.value = latestDetail;
|
||||
patchForm(latestDetail);
|
||||
buildSkuRows();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user