feat: 增加批量铺货发布强制间隔

This commit is contained in:
Christ committed 2026-08-18 16:19:07 +08:00
1 parent a90c9422c1
commit be080e1500
39 files changed
+362 -75

No files matched your search

+3
View File
@@ -109,6 +109,8 @@ export const previewItemPublishBatch = async (form: {
/** tbCatId 表示淘宝分类标识。 */ tbCatId?: string;
};
/** location 表示地址。 */ location?: PublishLocation;
/** publishIntervalSeconds 表示最终商品发布之间的最小间隔秒数。 */
publishIntervalSeconds?: number;
}, options?: RequestControlOptions): Promise<ItemPublishBatchPreviewResponse> => {
// 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);
}
+9 -1
View File
@@ -45,6 +45,8 @@ export const useItemPublishBatch = (options: ItemPublishBatchOptions): ItemPubli
const [batchLocations, setBatchLocations] = useState<NonNullable<ItemPublishBatchState['batchLocations']>>([]);
// batchLocation 保存批量任务当前选中的发货地。
const [batchLocation, setBatchLocation] = useState<ItemPublishBatchState['batchLocation']>(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,
+11 -2
View File
@@ -79,6 +79,8 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
setRecentBatch,
batchLocations,
batchLocation,
batchPublishIntervalSeconds,
setBatchPublishIntervalSeconds,
setBatchLocations,
setBatchLocation,
openBatchModal,
@@ -657,9 +659,16 @@ const ItemList: React.FC<ItemListProps> = ({ onConfigureDelivery }) => {
{batchLocations.length > 0 && <select className="w-full ios-input rounded-xl bg-white px-4 py-3" value={String(Math.max(0, batchLocations.indexOf(batchLocation!)))} onChange={/* 当前回调处理用户交互或异步状态变化。 */ e => setBatchLocation(batchLocations[Number(e.target.value)] || null)}>
{batchLocations.map(/* 当前回调处理集合中的单个元素。 */ (item, index) => <option key={`${item.division_id}-${item.poi_id}-${index}`} value={String(index)}>{[item.province, item.city, item.area, item.poi_name].filter(Boolean).join(' ')}</option>)}
</select>}
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="rounded-xl border border-violet-200 bg-violet-50 p-4 space-y-2">
<label className="flex items-center justify-between gap-4" htmlFor="batch-publish-interval">
<span className="min-w-0"><span className="block text-sm font-extrabold text-gray-900">商品发布强制间隔</span><span className="mt-1 block text-xs text-violet-800">图片会提前上传,只有最终发布请求之间至少等待该时间。</span></span>
<span className="flex shrink-0 items-center gap-2"><input id="batch-publish-interval" type="number" min={1} max={3600} step={1} inputMode="numeric" className="ios-input w-24 rounded-xl bg-white px-3 py-2 text-right" value={batchPublishIntervalSeconds} onChange={/* 当前回调处理用户交互或异步状态变化。 */ e => setBatchPublishIntervalSeconds(Math.min(3600, Math.max(1, Number(e.target.value) || 1)))} /><span className="text-sm font-bold text-violet-900">秒</span></span>
</label>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<label className="flex min-h-[150px] cursor-pointer flex-col items-center justify-center rounded-2xl border-2 border-dashed border-gray-200 bg-gray-50 px-4 py-6 text-center hover:border-blue-300 hover:bg-blue-50 transition-colors">
<UploadCloud className="w-9 h-9 text-blue-600 mb-3" />
<span className="text-sm font-extrabold text-gray-900">上传商品表格</span>
+6
View File
@@ -95,6 +95,8 @@ export interface PublishBatchDetail {
running: number;
// retryable 是可重试失败行数。
retryable: number;
// publish_interval_seconds 是相邻最终商品发布请求的最小间隔秒数。
publish_interval_seconds?: number;
// rows 是逐行执行结果。
rows: PublishBatchDetailRow[];
}
@@ -175,6 +177,10 @@ export interface ItemPublishBatchState {
setBatchLocations: Dispatch<SetStateAction<PublishLocation[]>>;
// setBatchLocation 更新批量当前发货地。
setBatchLocation: Dispatch<SetStateAction<PublishLocation | null>>;
// batchPublishIntervalSeconds 保存最终商品发布之间的最小间隔秒数。
batchPublishIntervalSeconds: number;
// setBatchPublishIntervalSeconds 更新用户设置的发布最小间隔。
setBatchPublishIntervalSeconds: Dispatch<SetStateAction<number>>;
// openBatchModal 打开批量铺货流程并恢复可继续任务。
openBatchModal: () => Promise<void>;
// handleRecommendBatchCategory 请求默认类目推荐。