perf: 商品保存改为基础信息秒回与SKU后台入队
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 50s
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 50s
This commit is contained in:
@@ -18,6 +18,7 @@ import { message } from 'ant-design-vue';
|
||||
|
||||
import { uploadTenantFileApi } from '#/api/files';
|
||||
import {
|
||||
createProductSkuSaveJobApi,
|
||||
deleteProductApi,
|
||||
getProductAddonGroupListApi,
|
||||
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() {
|
||||
if (!storeId.value || !form.id) return;
|
||||
if (!form.name.trim()) {
|
||||
@@ -540,7 +580,6 @@ export function createProductDetailDataActions(
|
||||
specTemplateIds: [...form.specTemplateIds],
|
||||
addonGroupIds: [...form.addonGroupIds],
|
||||
labelIds: [...form.labelIds],
|
||||
skus: normalizedSkus,
|
||||
comboGroups: normalizedComboGroups,
|
||||
tags: [],
|
||||
};
|
||||
@@ -550,36 +589,15 @@ export function createProductDetailDataActions(
|
||||
form.id = asyncSaved.productId;
|
||||
}
|
||||
|
||||
if (
|
||||
asyncSaved.skuJobStatus === 'queued' ||
|
||||
asyncSaved.skuJobStatus === 'running'
|
||||
) {
|
||||
if (asyncSaved.skuJobId) {
|
||||
message.success(
|
||||
asyncSaved.message ||
|
||||
`商品基础信息已保存,${normalizedSkus.length} 条 SKU 正在后台处理`,
|
||||
);
|
||||
void watchSkuSaveJobInBackground(
|
||||
storeId.value,
|
||||
asyncSaved.productId || form.id,
|
||||
asyncSaved.skuJobId,
|
||||
);
|
||||
} else {
|
||||
message.warning(
|
||||
asyncSaved.message || 'SKU 任务已创建,请稍后刷新查看状态',
|
||||
);
|
||||
}
|
||||
return;
|
||||
message.success(asyncSaved.message || '商品基础信息已保存');
|
||||
if (normalizedSkus.length > 0 && (asyncSaved.productId || form.id)) {
|
||||
void enqueueSkuSaveJobInBackground(
|
||||
storeId.value,
|
||||
asyncSaved.productId || form.id,
|
||||
[...form.specTemplateIds],
|
||||
normalizedSkus,
|
||||
);
|
||||
}
|
||||
|
||||
if (asyncSaved.skuJobStatus === 'not_required') {
|
||||
message.success(asyncSaved.message || '商品详情已保存');
|
||||
return;
|
||||
}
|
||||
|
||||
message.error(
|
||||
asyncSaved.message || '商品基础信息已保存,但 SKU 异步任务创建失败',
|
||||
);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user