diff --git a/frontend/app/features/apiAdapters.test.ts b/frontend/app/features/apiAdapters.test.ts index f6979eb..2640b7f 100644 --- a/frontend/app/features/apiAdapters.test.ts +++ b/frontend/app/features/apiAdapters.test.ts @@ -1243,6 +1243,7 @@ const runVersionedItemBatchAPITest = async () => { defaultCookieId: 'acc1', fallbackCategory: { catId: 'cat-1', catName: '资料', channelCatId: 'channel-1', tbCatId: 'tb-1' }, location: { area: '区域', city: '城市', division_id: '1', longitude: 120, latitude: 30, poi_id: 'poi-1', poi_name: '地点', province: '省' }, + publishIntervalSeconds: 12, }); await startItemPublishBatch('preview-1'); await getItemPublishBatches(10); @@ -1254,6 +1255,9 @@ const runVersionedItemBatchAPITest = async () => { expect(fetchMock).toHaveBeenNthCalledWith(1, '/api/v1/items/get-all-from-account', expect.objectContaining({ method: 'POST' })); expect(fetchMock).toHaveBeenNthCalledWith(2, '/api/v1/items/publish-categories/recommend', expect.objectContaining({ method: 'POST' })); expect(fetchMock).toHaveBeenNthCalledWith(3, '/api/v1/items/publish-batches/preview', expect.objectContaining({ method: 'POST', body: expect.any(FormData) })); + // previewBody 保存批量预检表单,确保用户设置的间隔进入后端持久化边界。 + const previewBody = fetchMock.mock.calls[2][1].body as FormData; + expect(previewBody.get('publish_interval_seconds')).toBe('12'); expect(fetchMock).toHaveBeenNthCalledWith(4, '/api/v1/items/publish-batches', expect.objectContaining({ method: 'POST' })); expect(fetchMock).toHaveBeenNthCalledWith(5, '/api/v1/items/publish-batches?limit=10', expect.objectContaining({ method: 'GET' })); expect(fetchMock).toHaveBeenNthCalledWith(6, '/api/v1/items/publish-batches/batch-1', expect.objectContaining({ method: 'GET' })); diff --git a/frontend/app/features/items/api.ts b/frontend/app/features/items/api.ts index cc425ff..cdb4187 100644 --- a/frontend/app/features/items/api.ts +++ b/frontend/app/features/items/api.ts @@ -109,6 +109,8 @@ export const previewItemPublishBatch = async (form: { /** tbCatId 表示淘宝分类标识。 */ tbCatId?: string; }; /** location 表示地址。 */ location?: PublishLocation; + /** publishIntervalSeconds 表示最终商品发布之间的最小间隔秒数。 */ + publishIntervalSeconds?: number; }, options?: RequestControlOptions): Promise => { // body 请求体,用于当前 API 处理流程。 const body = new FormData(); @@ -120,6 +122,7 @@ export const previewItemPublishBatch = async (form: { body.set('fallback_channel_category_id', form.fallbackCategory.channelCatId || ''); body.set('fallback_tb_category_id', form.fallbackCategory.tbCatId || ''); if (form.location) body.set('location', JSON.stringify(form.location)); + body.set('publish_interval_seconds', String(form.publishIntervalSeconds ?? 5)); return postForm('/api/v1/items/publish-batches/preview', body, options); } diff --git a/frontend/app/features/items/hooks.ts b/frontend/app/features/items/hooks.ts index 811fe3e..8c91dc6 100644 --- a/frontend/app/features/items/hooks.ts +++ b/frontend/app/features/items/hooks.ts @@ -45,6 +45,8 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli const [batchLocations, setBatchLocations] = useState>([]); // batchLocation 保存批量任务当前选中的发货地。 const [batchLocation, setBatchLocation] = useState(null); + // batchPublishIntervalSeconds 保存当前批量任务的最终发布最小间隔,默认五秒。 + const [batchPublishIntervalSeconds, setBatchPublishIntervalSeconds] = useState(5); // batchLoading 表示批量任务请求是否正在执行。 const [batchLoading, setBatchLoading] = useState(false); // batchPollInFlight 防止同一批次的轮询请求重叠。 @@ -97,6 +99,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli setBatchFallbackCategory({ catId: '', catName: '', channelCatId: '', tbCatId: '' }); setBatchLocations([]); setBatchLocation(null); + setBatchPublishIntervalSeconds(5); setShowBatchModal(true); setBatchLoading(true); try { @@ -111,6 +114,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; setRecentBatch(detail); setBatchDetail(detail); + setBatchPublishIntervalSeconds(detail.publish_interval_seconds || 5); setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done'); } } catch (error /* 恢复任务错误 */) { @@ -177,6 +181,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli const detail = await getItemPublishBatch(recentBatch.id, { signal: request.controller.signal }); if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; setBatchDetail(detail); + setBatchPublishIntervalSeconds(detail.publish_interval_seconds || 5); setBatchPhase(['running', 'canceling'].includes(detail.status) ? 'running' : 'done'); } catch (error /* 最近结果读取错误 */) { if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; @@ -211,6 +216,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli defaultCookieId: options.selectedAccount, fallbackCategory: batchFallbackCategory, location: batchLocation || undefined, + publishIntervalSeconds: batchPublishIntervalSeconds, }, { signal: request.controller.signal }); if (!isCurrentBatchOperation(request.requestGeneration, request.controller)) return; setBatchPreview(result); @@ -224,7 +230,7 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli if (isCurrentBatchOperation(request.requestGeneration, request.controller)) setBatchLoading(false); } }, - [batchFallbackCategory, batchFile, batchImagesZip, batchLocation, beginBatchRequest, isCurrentBatchOperation, options.selectedAccount], + [batchFallbackCategory, batchFile, batchImagesZip, batchLocation, batchPublishIntervalSeconds, beginBatchRequest, isCurrentBatchOperation, options.selectedAccount], ); // handleStartBatch 启动预检通过的批量任务并读取首个详情。 @@ -429,6 +435,8 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli batchLocation, setBatchLocations, setBatchLocation, + batchPublishIntervalSeconds, + setBatchPublishIntervalSeconds, openBatchModal, handleRecommendBatchCategory, openRecentBatchResult, diff --git a/frontend/app/features/items/pages/ItemList.tsx b/frontend/app/features/items/pages/ItemList.tsx index 6f9c81f..cedc5bc 100644 --- a/frontend/app/features/items/pages/ItemList.tsx +++ b/frontend/app/features/items/pages/ItemList.tsx @@ -79,6 +79,8 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { setRecentBatch, batchLocations, batchLocation, + batchPublishIntervalSeconds, + setBatchPublishIntervalSeconds, setBatchLocations, setBatchLocation, openBatchModal, @@ -657,9 +659,16 @@ const ItemList: React.FC = ({ onConfigureDelivery }) => { {batchLocations.length > 0 && } - + -
+
+ +
+ +