From a678ca632a55bf4d861f80b99665baf403c3be28 Mon Sep 17 00:00:00 2001 From: MSuMshk <2039814060@qq.com> Date: Wed, 25 Feb 2026 13:29:10 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E5=95=86=E5=93=81=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=9F=BA=E7=A1=80=E4=BF=A1=E6=81=AF=E7=A7=92?= =?UTF-8?q?=E5=9B=9E=E4=B8=8ESKU=E5=90=8E=E5=8F=B0=E5=85=A5=E9=98=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product-detail-page/data-actions.ts | 78 ++++++++++++------- 1 file changed, 48 insertions(+), 30 deletions(-) diff --git a/apps/web-antd/src/views/product/detail/composables/product-detail-page/data-actions.ts b/apps/web-antd/src/views/product/detail/composables/product-detail-page/data-actions.ts index 0b070e3..d48e8dd 100644 --- a/apps/web-antd/src/views/product/detail/composables/product-detail-page/data-actions.ts +++ b/apps/web-antd/src/views/product/detail/composables/product-detail-page/data-actions.ts @@ -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 {