mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 02:29:19 +08:00
feat: 新增拼多多草稿箱推送
This commit is contained in:
@@ -166,6 +166,13 @@ export async function deletePddPublishDeskDraftApi(id: number) {
|
||||
return requestClient.delete(`/channel/pdd/goods/publish-desk/drafts/${id}`);
|
||||
}
|
||||
|
||||
/** 将系统草稿推送到拼多多草稿箱 */
|
||||
export async function pushPddPublishDeskDraftApi(id: number) {
|
||||
return requestClient.post<PddPublishDeskVO.Draft>(
|
||||
`/channel/pdd/goods/publish-desk/drafts/${id}/push-platform`,
|
||||
);
|
||||
}
|
||||
|
||||
export async function clonePddPublishDeskDraftApi(
|
||||
data: PddPublishDeskDTO.Clone,
|
||||
) {
|
||||
|
||||
@@ -49,6 +49,9 @@ export namespace PddPublishDeskVO {
|
||||
payloadJson?: string;
|
||||
sourceDraftId?: number;
|
||||
lastError?: string;
|
||||
pddGoodsCommitId?: number;
|
||||
pddGoodsId?: number;
|
||||
pddDraftPushedAt?: string;
|
||||
createdBy?: number;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
|
||||
@@ -23,7 +23,7 @@ withDefaults(
|
||||
resizable?: boolean;
|
||||
splitHandle?: boolean;
|
||||
splitLine?: boolean;
|
||||
/** 店铺待发草稿数 */
|
||||
/** 店铺系统草稿数 */
|
||||
draftCountByShopId?: Record<number, number>;
|
||||
showUnassignedFilter?: boolean;
|
||||
unassignedCount?: number;
|
||||
|
||||
+85
-15
@@ -60,6 +60,7 @@ import {
|
||||
listPddPublishLogisticsApi,
|
||||
listPddPublishParentSpecsApi,
|
||||
publishPddGoodsApi,
|
||||
pushPddPublishDeskDraftApi,
|
||||
updatePddPublishDeskDraftApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import {
|
||||
@@ -113,6 +114,7 @@ const hasDraft = defineModel<boolean>('hasDraft', { default: false });
|
||||
/** 点击遮罩时的去向询问 */
|
||||
const dismissChoiceVisible = ref(false);
|
||||
const draftSaving = ref(false);
|
||||
const platformPushing = ref(false);
|
||||
const boundDraftId = ref<number | null>(null);
|
||||
|
||||
/** 外层 Modal / 页面壳通过 open 控制;编辑器本身不持有 vben Modal */
|
||||
@@ -2686,15 +2688,26 @@ async function hydrateFromDraft(id: number) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 保存工作台草稿;markReady=true 时写入 publishPayload 供批量发布 */
|
||||
async function saveDeskDraft(markReady: boolean) {
|
||||
/** 保存系统草稿;markReady=true 时写入 publishPayload 供批量发布 */
|
||||
async function saveDeskDraft(
|
||||
markReady: boolean,
|
||||
extras?: { includePublishPayload?: boolean; silentSuccess?: boolean },
|
||||
): Promise<{ id: number; hasPayload: boolean } | null> {
|
||||
if (!form.pddShopId) {
|
||||
message.warning('请先选择渠道店铺');
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
const title = form.goodsName.trim() || '未命名草稿';
|
||||
const includePayload = markReady || extras?.includePublishPayload === true;
|
||||
draftSaving.value = true;
|
||||
const hide = message.loading(markReady ? '生成可发布数据…' : '保存草稿…', 0);
|
||||
const hide = message.loading(
|
||||
markReady
|
||||
? '生成可发布数据…'
|
||||
: includePayload
|
||||
? '保存系统草稿…'
|
||||
: '保存系统草稿…',
|
||||
0,
|
||||
);
|
||||
try {
|
||||
// 普通保存也上传图片,否则下次打开无法回填(未上传的合并一次签名)
|
||||
const pendingThumbs = skuRows.value
|
||||
@@ -2722,19 +2735,26 @@ async function saveDeskDraft(markReady: boolean) {
|
||||
});
|
||||
|
||||
let publishPayload: PddGoodsPublishDTO.Publish | undefined;
|
||||
if (markReady) {
|
||||
if (!validateForm()) {
|
||||
return;
|
||||
if (includePayload) {
|
||||
if (markReady && !validateForm()) {
|
||||
return null;
|
||||
}
|
||||
const thumbFileIdBySkuKey = new Map<number, number>();
|
||||
for (const [k, v] of thumbBySkuKey) {
|
||||
thumbFileIdBySkuKey.set(k, v.fileId);
|
||||
}
|
||||
publishPayload = await buildPublishPayload(
|
||||
carouselFiles.map((f) => f.fileId),
|
||||
detailFiles.map((f) => f.fileId),
|
||||
thumbFileIdBySkuKey,
|
||||
);
|
||||
try {
|
||||
publishPayload = await buildPublishPayload(
|
||||
carouselFiles.map((f) => f.fileId),
|
||||
detailFiles.map((f) => f.fileId),
|
||||
thumbFileIdBySkuKey,
|
||||
);
|
||||
} catch (e: any) {
|
||||
if (markReady) {
|
||||
throw e;
|
||||
}
|
||||
// 推送场景:先落系统草稿,调用方再提示无法推送
|
||||
}
|
||||
}
|
||||
|
||||
const payloadJson = JSON.stringify({
|
||||
@@ -2801,15 +2821,58 @@ async function saveDeskDraft(markReady: boolean) {
|
||||
: await createPddPublishDeskDraftApi(body);
|
||||
boundDraftId.value = saved.id;
|
||||
emit('draft-saved', saved.id);
|
||||
message.success(markReady ? '已保存为可发布草稿' : '草稿已保存');
|
||||
if (!extras?.silentSuccess) {
|
||||
message.success(markReady ? '已保存为可发布草稿' : '系统草稿已保存');
|
||||
}
|
||||
return { id: saved.id, hasPayload: !!publishPayload };
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '保存草稿失败');
|
||||
message.error(e?.message || '保存系统草稿失败');
|
||||
return null;
|
||||
} finally {
|
||||
hide();
|
||||
draftSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 先落系统草稿(尽量带 publishPayload),再推送到拼多多草稿箱 */
|
||||
async function pushToPlatformDraft() {
|
||||
if (!form.pddShopId) {
|
||||
message.warning('请先选择渠道店铺');
|
||||
return;
|
||||
}
|
||||
if (!form.catId) {
|
||||
message.warning('请先选择叶子类目');
|
||||
return;
|
||||
}
|
||||
platformPushing.value = true;
|
||||
try {
|
||||
const saved = await saveDeskDraft(false, {
|
||||
includePublishPayload: true,
|
||||
silentSuccess: true,
|
||||
});
|
||||
if (!saved) return;
|
||||
if (!saved.hasPayload) {
|
||||
message.error('未能生成可推送数据,请补全规格、价格与图片后再试');
|
||||
return;
|
||||
}
|
||||
const hide = message.loading('推送到拼多多草稿箱…', 0);
|
||||
try {
|
||||
const vo = await pushPddPublishDeskDraftApi(saved.id);
|
||||
message.success(
|
||||
vo.pddGoodsCommitId
|
||||
? `已推送到拼多多草稿箱(ID ${vo.pddGoodsCommitId})`
|
||||
: '已推送到拼多多草稿箱',
|
||||
);
|
||||
} finally {
|
||||
hide();
|
||||
}
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '推送到拼多多草稿箱失败');
|
||||
} finally {
|
||||
platformPushing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!validateForm()) return;
|
||||
submitting.value = true;
|
||||
@@ -3718,7 +3781,7 @@ onBeforeUnmount(() => {
|
||||
{{ variant === 'page' ? '返回' : '取消' }}
|
||||
</Button>
|
||||
<Button :loading="draftSaving" @click="saveDeskDraft(false)">
|
||||
保存草稿
|
||||
保存系统草稿
|
||||
</Button>
|
||||
<Button
|
||||
type="default"
|
||||
@@ -3728,6 +3791,13 @@ onBeforeUnmount(() => {
|
||||
>
|
||||
保存并标记可发布
|
||||
</Button>
|
||||
<Button
|
||||
:loading="platformPushing || draftSaving"
|
||||
:disabled="catAuthAuthorized === false || catAuthChecking"
|
||||
@click="pushToPlatformDraft"
|
||||
>
|
||||
推送到拼多多草稿箱
|
||||
</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
:loading="submitting"
|
||||
|
||||
@@ -34,7 +34,7 @@ function goBack() {
|
||||
<template #title>
|
||||
<div class="w-full space-y-3">
|
||||
<div class="mb-0 flex items-baseline text-lg font-semibold">
|
||||
编辑发布草稿
|
||||
编辑系统草稿
|
||||
<span
|
||||
v-if="draftId"
|
||||
class="text-muted-foreground ml-2 text-sm font-normal"
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
Space,
|
||||
Table,
|
||||
Tag,
|
||||
Tooltip,
|
||||
message,
|
||||
} from 'ant-design-vue';
|
||||
|
||||
@@ -27,6 +28,7 @@ import {
|
||||
deletePddPublishDeskDraftApi,
|
||||
getPddPublishDeskJobApi,
|
||||
listPddPublishDeskDraftsApi,
|
||||
pushPddPublishDeskDraftApi,
|
||||
retryPddPublishDeskJobFailedApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
import { getPddShopPageApi } from '#/api/channel/pdd/shop';
|
||||
@@ -58,6 +60,7 @@ const cloneSubmitting = ref(false);
|
||||
const jobOpen = ref(false);
|
||||
const jobLoading = ref(false);
|
||||
const currentJob = ref<PddPublishDeskVO.Job | null>(null);
|
||||
const pushingDraftId = ref<number | null>(null);
|
||||
let jobPollTimer: ReturnType<typeof setInterval> | undefined;
|
||||
|
||||
const statusLabel: Record<string, { text: string; color: string }> = {
|
||||
@@ -91,7 +94,7 @@ const draftCountRecord = computed(() => {
|
||||
|
||||
const summaryText = computed(
|
||||
() =>
|
||||
`${shopWithDraft.value || 0} 店 · ${totalPending.value || 0} 待发`,
|
||||
`${shopWithDraft.value || 0} 店 · ${totalPending.value || 0} 条系统草稿`,
|
||||
);
|
||||
|
||||
const columns = [
|
||||
@@ -100,8 +103,9 @@ const columns = [
|
||||
{ title: '店铺', dataIndex: 'shopName', key: 'shopName', width: 140 },
|
||||
{ title: 'SKU数', dataIndex: 'skuCount', key: 'skuCount', width: 88 },
|
||||
{ title: '状态', key: 'status', width: 100 },
|
||||
{ title: '拼多多草稿', key: 'platformDraft', width: 148 },
|
||||
{ title: '更新时间', dataIndex: 'updateTime', key: 'updateTime', width: 170 },
|
||||
{ title: '操作', key: 'actions', width: 200 },
|
||||
{ title: '操作', key: 'actions', width: 280 },
|
||||
];
|
||||
|
||||
/** 列表悬停:从草稿 payloadJson.editorState.skuRows 解析 */
|
||||
@@ -202,6 +206,60 @@ function formatSkuPrice(price?: number) {
|
||||
return `¥${price.toFixed(2)}`;
|
||||
}
|
||||
|
||||
/** Table bodyCell 的 record 偏宽,只读推送判断所需字段 */
|
||||
function draftHasPublishPayload(draft: { payloadJson?: string }): boolean {
|
||||
if (!draft.payloadJson) return false;
|
||||
try {
|
||||
const root = JSON.parse(draft.payloadJson) as { publishPayload?: unknown };
|
||||
return (
|
||||
root.publishPayload != null && typeof root.publishPayload === 'object'
|
||||
);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function pushDisabledReason(draft: {
|
||||
pddShopId?: number;
|
||||
payloadJson?: string;
|
||||
}): string {
|
||||
if (!draft.pddShopId) return '请先分配渠道店铺';
|
||||
if (!draftHasPublishPayload(draft)) {
|
||||
return '请先在编辑页生成可推送数据';
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
async function pushPlatform(draft: {
|
||||
id?: number;
|
||||
pddShopId?: number;
|
||||
payloadJson?: string;
|
||||
}) {
|
||||
if (draft.id == null) return;
|
||||
const reason = pushDisabledReason(draft);
|
||||
if (reason) {
|
||||
message.warning(reason);
|
||||
return;
|
||||
}
|
||||
pushingDraftId.value = draft.id;
|
||||
const hide = message.loading('推送到拼多多草稿箱…', 0);
|
||||
try {
|
||||
const vo = await pushPddPublishDeskDraftApi(draft.id);
|
||||
message.success(
|
||||
vo.pddGoodsCommitId
|
||||
? `已推送到拼多多草稿箱(ID ${vo.pddGoodsCommitId})`
|
||||
: '已推送到拼多多草稿箱',
|
||||
);
|
||||
await loadDrafts();
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '推送失败');
|
||||
await loadDrafts();
|
||||
} finally {
|
||||
hide();
|
||||
pushingDraftId.value = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadShops() {
|
||||
try {
|
||||
const data = await getPddShopPageApi({
|
||||
@@ -263,7 +321,7 @@ async function createDraft() {
|
||||
status: 'EDITING',
|
||||
skuCount: 0,
|
||||
});
|
||||
message.success('已创建草稿');
|
||||
message.success('已创建系统草稿');
|
||||
await router.push(`/pdd/goods/publish/edit/${draft.id}`);
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '创建失败');
|
||||
@@ -442,7 +500,7 @@ onUnmounted(() => stopJobPoll());
|
||||
>
|
||||
<template #title>
|
||||
<div class="flex min-w-0 items-center gap-3">
|
||||
<span class="text-base font-semibold">发布工作台</span>
|
||||
<span class="text-base font-semibold">发布工作台(系统草稿)</span>
|
||||
<span class="text-muted-foreground truncate text-sm font-normal">
|
||||
{{ summaryText }}
|
||||
</span>
|
||||
@@ -451,7 +509,7 @@ onUnmounted(() => stopJobPoll());
|
||||
<template #extra>
|
||||
<Space wrap class="py-1">
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button type="primary" @click="createDraft">新建草稿</Button>
|
||||
<Button type="primary" @click="createDraft">新建系统草稿</Button>
|
||||
</PermissionGate>
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button
|
||||
@@ -492,7 +550,7 @@ onUnmounted(() => stopJobPoll());
|
||||
selectedRowKeys,
|
||||
onChange: onDraftSelectionChange,
|
||||
}"
|
||||
:locale="{ emptyText: '暂无待发草稿' }"
|
||||
:locale="{ emptyText: '暂无系统草稿' }"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'skuCount'">
|
||||
@@ -530,6 +588,18 @@ onUnmounted(() => stopJobPoll());
|
||||
</Popover>
|
||||
<span v-else>{{ record.skuCount ?? 0 }}</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'platformDraft'">
|
||||
<div v-if="record.pddGoodsCommitId">
|
||||
<Tag color="green">已推送</Tag>
|
||||
<div
|
||||
class="text-muted-foreground mt-1 max-w-[130px] truncate text-xs"
|
||||
:title="String(record.pddGoodsCommitId)"
|
||||
>
|
||||
{{ record.pddGoodsCommitId }}
|
||||
</div>
|
||||
</div>
|
||||
<span v-else class="text-muted-foreground text-xs">未推送</span>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'status'">
|
||||
<Tag :color="statusLabel[record.status]?.color || 'default'">
|
||||
{{ statusLabel[record.status]?.text || record.status }}
|
||||
@@ -547,6 +617,19 @@ onUnmounted(() => stopJobPoll());
|
||||
<Button type="link" size="small" @click="openEdit(record.id)">
|
||||
编辑
|
||||
</Button>
|
||||
<Tooltip :title="pushDisabledReason(record) || '推送到拼多多草稿箱'">
|
||||
<span>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
:disabled="!!pushDisabledReason(record)"
|
||||
:loading="pushingDraftId === record.id"
|
||||
@click="pushPlatform(record)"
|
||||
>
|
||||
推送平台
|
||||
</Button>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Button
|
||||
type="link"
|
||||
size="small"
|
||||
@@ -569,7 +652,7 @@ onUnmounted(() => stopJobPoll());
|
||||
<Empty
|
||||
v-if="!loading && drafts.length === 0"
|
||||
class="mt-8"
|
||||
description="暂无草稿,点击「新建草稿」开始"
|
||||
description="暂无系统草稿,点击「新建系统草稿」开始"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user