feat: 商品详情保存统一走异步SKU任务
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 52s
All checks were successful
Build and Deploy TenantUI / build-and-deploy (push) Successful in 52s
This commit is contained in:
@@ -25,7 +25,6 @@ import {
|
||||
getProductLabelListApi,
|
||||
getProductSkuSaveJobApi,
|
||||
getProductSpecListApi,
|
||||
saveProductApi,
|
||||
saveProductAsyncApi,
|
||||
} from '#/api/product';
|
||||
|
||||
@@ -43,7 +42,6 @@ const ALLOWED_PRODUCT_IMAGE_MIME_SET = new Set([
|
||||
'image/webp',
|
||||
]);
|
||||
const ALLOWED_PRODUCT_IMAGE_EXT = ['.jpg', '.jpeg', '.png', '.webp'];
|
||||
const ASYNC_SKU_THRESHOLD = 10;
|
||||
const ASYNC_SKU_POLL_INTERVAL_MS = 1000;
|
||||
const ASYNC_SKU_POLL_MAX_ATTEMPTS = 180;
|
||||
|
||||
@@ -513,7 +511,6 @@ export function createProductDetailDataActions(
|
||||
}))
|
||||
: [];
|
||||
|
||||
const shouldSaveSkuAsync = normalizedSkus.length > ASYNC_SKU_THRESHOLD;
|
||||
const payload = {
|
||||
id: form.id,
|
||||
storeId: storeId.value,
|
||||
@@ -553,50 +550,40 @@ export function createProductDetailDataActions(
|
||||
tags: [],
|
||||
};
|
||||
|
||||
if (shouldSaveSkuAsync) {
|
||||
const asyncSaved = await saveProductAsyncApi(payload);
|
||||
if (asyncSaved.productId) {
|
||||
form.id = asyncSaved.productId;
|
||||
}
|
||||
const asyncSaved = await saveProductAsyncApi(payload);
|
||||
if (asyncSaved.productId) {
|
||||
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;
|
||||
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 任务已创建,请稍后刷新查看状态');
|
||||
}
|
||||
|
||||
if (asyncSaved.skuJobStatus === 'not_required') {
|
||||
message.success(asyncSaved.message || '商品详情已保存');
|
||||
return;
|
||||
}
|
||||
|
||||
message.error(
|
||||
asyncSaved.message || '商品基础信息已保存,但 SKU 异步任务创建失败',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const saved = await saveProductApi(payload);
|
||||
message.success('商品详情已保存');
|
||||
detail.value = saved;
|
||||
patchForm(saved);
|
||||
buildSkuRows();
|
||||
if (asyncSaved.skuJobStatus === 'not_required') {
|
||||
message.success(asyncSaved.message || '商品详情已保存');
|
||||
return;
|
||||
}
|
||||
|
||||
message.error(
|
||||
asyncSaved.message || '商品基础信息已保存,但 SKU 异步任务创建失败',
|
||||
);
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user