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,
|
getProductLabelListApi,
|
||||||
getProductSkuSaveJobApi,
|
getProductSkuSaveJobApi,
|
||||||
getProductSpecListApi,
|
getProductSpecListApi,
|
||||||
saveProductApi,
|
|
||||||
saveProductAsyncApi,
|
saveProductAsyncApi,
|
||||||
} from '#/api/product';
|
} from '#/api/product';
|
||||||
|
|
||||||
@@ -43,7 +42,6 @@ const ALLOWED_PRODUCT_IMAGE_MIME_SET = new Set([
|
|||||||
'image/webp',
|
'image/webp',
|
||||||
]);
|
]);
|
||||||
const ALLOWED_PRODUCT_IMAGE_EXT = ['.jpg', '.jpeg', '.png', '.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_INTERVAL_MS = 1000;
|
||||||
const ASYNC_SKU_POLL_MAX_ATTEMPTS = 180;
|
const ASYNC_SKU_POLL_MAX_ATTEMPTS = 180;
|
||||||
|
|
||||||
@@ -513,7 +511,6 @@ export function createProductDetailDataActions(
|
|||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
const shouldSaveSkuAsync = normalizedSkus.length > ASYNC_SKU_THRESHOLD;
|
|
||||||
const payload = {
|
const payload = {
|
||||||
id: form.id,
|
id: form.id,
|
||||||
storeId: storeId.value,
|
storeId: storeId.value,
|
||||||
@@ -553,50 +550,40 @@ export function createProductDetailDataActions(
|
|||||||
tags: [],
|
tags: [],
|
||||||
};
|
};
|
||||||
|
|
||||||
if (shouldSaveSkuAsync) {
|
const asyncSaved = await saveProductAsyncApi(payload);
|
||||||
const asyncSaved = await saveProductAsyncApi(payload);
|
if (asyncSaved.productId) {
|
||||||
if (asyncSaved.productId) {
|
form.id = asyncSaved.productId;
|
||||||
form.id = asyncSaved.productId;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
asyncSaved.skuJobStatus === 'queued' ||
|
asyncSaved.skuJobStatus === 'queued' ||
|
||||||
asyncSaved.skuJobStatus === 'running'
|
asyncSaved.skuJobStatus === 'running'
|
||||||
) {
|
) {
|
||||||
if (asyncSaved.skuJobId) {
|
if (asyncSaved.skuJobId) {
|
||||||
message.success(
|
message.success(
|
||||||
asyncSaved.message ||
|
asyncSaved.message ||
|
||||||
`商品基础信息已保存,${normalizedSkus.length} 条 SKU 正在后台处理`,
|
`商品基础信息已保存,${normalizedSkus.length} 条 SKU 正在后台处理`,
|
||||||
);
|
);
|
||||||
void watchSkuSaveJobInBackground(
|
void watchSkuSaveJobInBackground(
|
||||||
storeId.value,
|
storeId.value,
|
||||||
asyncSaved.productId || form.id,
|
asyncSaved.productId || form.id,
|
||||||
asyncSaved.skuJobId,
|
asyncSaved.skuJobId,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
message.warning(
|
message.warning(asyncSaved.message || 'SKU 任务已创建,请稍后刷新查看状态');
|
||||||
asyncSaved.message || 'SKU 任务已创建,请稍后刷新查看状态',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (asyncSaved.skuJobStatus === 'not_required') {
|
|
||||||
message.success(asyncSaved.message || '商品详情已保存');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
message.error(
|
|
||||||
asyncSaved.message || '商品基础信息已保存,但 SKU 异步任务创建失败',
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const saved = await saveProductApi(payload);
|
if (asyncSaved.skuJobStatus === 'not_required') {
|
||||||
message.success('商品详情已保存');
|
message.success(asyncSaved.message || '商品详情已保存');
|
||||||
detail.value = saved;
|
return;
|
||||||
patchForm(saved);
|
}
|
||||||
buildSkuRows();
|
|
||||||
|
message.error(
|
||||||
|
asyncSaved.message || '商品基础信息已保存,但 SKU 异步任务创建失败',
|
||||||
|
);
|
||||||
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
Reference in New Issue
Block a user