mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 12:29:20 +08:00
Compare commits
2
Commits
370ead39a1
...
e136084794
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e136084794 | ||
|
|
92b6026b48 |
+28
-4
@@ -35,7 +35,8 @@ const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
||||
const PanelOpenIcon = createIconifyIcon('lucide:panel-left');
|
||||
|
||||
const props = defineProps<{
|
||||
draftId: number;
|
||||
/** 系统草稿 ID;null 表示尚未落库的新建编辑 */
|
||||
draftId: number | null;
|
||||
collapsed?: boolean;
|
||||
/** 编辑器命令面(ref) */
|
||||
editorApi: PublishEditorAgentApi | null;
|
||||
@@ -48,6 +49,25 @@ const emit = defineEmits<{
|
||||
|
||||
const SCENE = 'ecom_goods_publish' as const;
|
||||
|
||||
/** 未落库时用本地 sceneRef,落库后切到草稿 ID */
|
||||
const localSceneKey = `local-${
|
||||
typeof crypto !== 'undefined' && crypto.randomUUID
|
||||
? crypto.randomUUID()
|
||||
: `${Date.now()}-${Math.random().toString(36).slice(2)}`
|
||||
}`;
|
||||
|
||||
const sceneRef = computed(() =>
|
||||
props.draftId != null && props.draftId > 0
|
||||
? String(props.draftId)
|
||||
: localSceneKey,
|
||||
);
|
||||
|
||||
const sessionTitle = computed(() =>
|
||||
props.draftId != null && props.draftId > 0
|
||||
? `发布草稿 #${props.draftId}`
|
||||
: '发布草稿(未保存)',
|
||||
);
|
||||
|
||||
const starterPrompts = [
|
||||
{
|
||||
label: '按编码生成标题',
|
||||
@@ -222,11 +242,11 @@ async function ensureSession(): Promise<string | null> {
|
||||
if (session.value?.threadId) return session.value.threadId;
|
||||
const parsed = parseModelKey(selectedModelKey.value);
|
||||
const s = await createAgentSessionApi({
|
||||
title: `发布草稿 #${props.draftId}`,
|
||||
title: sessionTitle.value,
|
||||
llmProviderId: parsed?.providerId,
|
||||
llmModel: parsed?.model,
|
||||
scene: SCENE,
|
||||
sceneRef: String(props.draftId),
|
||||
sceneRef: sceneRef.value,
|
||||
reuseBySceneRef: true,
|
||||
});
|
||||
session.value = s;
|
||||
@@ -275,7 +295,11 @@ async function bootstrap() {
|
||||
|
||||
watch(
|
||||
() => props.draftId,
|
||||
() => {
|
||||
(id, prev) => {
|
||||
// 新建落库后仅 URL 从 new→id:沿用当前会话,避免打断
|
||||
if (prev == null && id != null && id > 0 && session.value?.threadId) {
|
||||
return;
|
||||
}
|
||||
abort?.abort();
|
||||
void bootstrap();
|
||||
},
|
||||
|
||||
+26
-5
@@ -255,6 +255,24 @@ onMounted(() => {
|
||||
}
|
||||
});
|
||||
|
||||
/** 路由 draftId 变化(含 new→真实 ID):已绑定同一草稿则跳过 hydrate */
|
||||
watch(
|
||||
() => props.draftId,
|
||||
(id, prev) => {
|
||||
if (
|
||||
(prev == null || prev === undefined) &&
|
||||
id != null &&
|
||||
id > 0 &&
|
||||
draft.boundDraftId.value === id
|
||||
) {
|
||||
return;
|
||||
}
|
||||
if (id != null && id > 0 && id !== draft.boundDraftId.value) {
|
||||
void draft.hydrateFromDraft(id);
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
function resetAll() {
|
||||
draft.submitting.value = false;
|
||||
Object.assign(form, createEmptyPublishForm());
|
||||
@@ -390,7 +408,7 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
|
||||
<Teleport defer to="#pdd-publish-edit-header-fields">
|
||||
<div class="w-full min-w-0 space-y-2">
|
||||
<div class="grid grid-cols-1 gap-3 md:grid-cols-2">
|
||||
<div class="min-w-0">
|
||||
<div class="min-w-0 w-full">
|
||||
<div class="mb-1 text-sm font-medium">
|
||||
渠道店铺 <span class="text-destructive">*</span>
|
||||
</div>
|
||||
@@ -405,7 +423,7 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
|
||||
@search="(kw: string) => loadShops(kw)"
|
||||
/>
|
||||
</div>
|
||||
<div class="min-w-0">
|
||||
<div class="min-w-0 w-full">
|
||||
<div class="mb-1 flex items-center gap-1.5 text-sm font-medium">
|
||||
<span>
|
||||
叶子类目 <span class="text-destructive">*</span>
|
||||
@@ -436,10 +454,12 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
|
||||
/>
|
||||
</Tooltip>
|
||||
</div>
|
||||
<!-- Cascader 默认不吃满格子,需显式 100% 与店铺 Select 对齐 -->
|
||||
<Cascader
|
||||
v-model:value="form.catPath"
|
||||
v-model:search-value="catCascaderSearch"
|
||||
class="w-full"
|
||||
:style="{ width: '100%' }"
|
||||
:options="displayCatOptions"
|
||||
:load-data="catLoadData"
|
||||
:show-search="{
|
||||
@@ -640,9 +660,10 @@ function onSkuTableWrapRef(el: HTMLElement | null) {
|
||||
v-model:value="form.twoPiecesDiscount"
|
||||
class="w-full"
|
||||
:min="0"
|
||||
:max="100"
|
||||
:precision="0"
|
||||
placeholder="95 表示 95 折,0 取消"
|
||||
:max="10"
|
||||
:precision="1"
|
||||
:step="0.1"
|
||||
placeholder="9.5 表示 9.5 折,0 取消"
|
||||
/>
|
||||
</Form.Item>
|
||||
</div>
|
||||
|
||||
+25
-23
@@ -18,12 +18,14 @@ import {
|
||||
updatePddPublishDeskDraftApi,
|
||||
} from '#/api/channel/pdd/goods';
|
||||
|
||||
import type {
|
||||
PersistedUpload,
|
||||
PublishFormFields,
|
||||
SpecAxis,
|
||||
SpecCatalogItem,
|
||||
SkuRow,
|
||||
import {
|
||||
twoPiecesDiscountFromStored,
|
||||
twoPiecesDiscountToApi,
|
||||
type PersistedUpload,
|
||||
type PublishFormFields,
|
||||
type SpecAxis,
|
||||
type SpecCatalogItem,
|
||||
type SkuRow,
|
||||
} from '../types';
|
||||
|
||||
type EmitDraft = {
|
||||
@@ -185,9 +187,9 @@ export function usePublishDraft(options: {
|
||||
if (
|
||||
form.twoPiecesDiscount == null ||
|
||||
form.twoPiecesDiscount < 0 ||
|
||||
form.twoPiecesDiscount > 100
|
||||
form.twoPiecesDiscount > 10
|
||||
) {
|
||||
message.warning('请填写满两件折扣(0-100,95表示95折)');
|
||||
message.warning('请填写正常折扣(0-10,9.5 表示 9.5 折)');
|
||||
return false;
|
||||
}
|
||||
for (const p of nonSaleProps.value) {
|
||||
@@ -362,7 +364,7 @@ export function usePublishDraft(options: {
|
||||
isPreSale: form.isPreSale,
|
||||
isRefundable: form.isRefundable,
|
||||
secondHand: form.secondHand,
|
||||
twoPiecesDiscount: form.twoPiecesDiscount,
|
||||
twoPiecesDiscount: twoPiecesDiscountToApi(form.twoPiecesDiscount),
|
||||
carouselImages: carouselFileIds.map(String),
|
||||
detailImages: detailFileIds.map(String),
|
||||
goodsProperties,
|
||||
@@ -459,7 +461,7 @@ export function usePublishDraft(options: {
|
||||
}
|
||||
if (typeof es.secondHand === 'boolean') form.secondHand = es.secondHand;
|
||||
if (typeof es.twoPiecesDiscount === 'number') {
|
||||
form.twoPiecesDiscount = es.twoPiecesDiscount;
|
||||
form.twoPiecesDiscount = twoPiecesDiscountFromStored(es.twoPiecesDiscount);
|
||||
}
|
||||
if (
|
||||
es.goodsPropValues &&
|
||||
@@ -777,8 +779,12 @@ export function usePublishDraft(options: {
|
||||
async function handleSubmit() {
|
||||
if (!validateForm()) return;
|
||||
submitting.value = true;
|
||||
const hide = message.loading('正在上传图片并发布…', 0);
|
||||
const hide = message.loading('正在保存并发布…', 0);
|
||||
try {
|
||||
// 先落/更新系统草稿(含 publishPayload),再发布以便回写 goods_commit_id / goods_id
|
||||
const saved = await saveDeskDraft(true, { silentSuccess: true });
|
||||
if (!saved?.id) return;
|
||||
|
||||
const pendingThumbs = skuRows.value
|
||||
.map((row) => ({ rowKey: row.key, file: row.thumbFileList[0] }))
|
||||
.filter((x): x is { rowKey: number; file: UploadFile } => !!x.file);
|
||||
@@ -797,8 +803,8 @@ export function usePublishDraft(options: {
|
||||
const thumbPersisted = persistedAll.slice(p);
|
||||
const thumbFileIdBySkuKey = new Map<number, number>();
|
||||
pendingThumbs.forEach((item, i) => {
|
||||
const saved = thumbPersisted[i];
|
||||
if (saved) thumbFileIdBySkuKey.set(item.rowKey, saved.fileId);
|
||||
const savedThumb = thumbPersisted[i];
|
||||
if (savedThumb) thumbFileIdBySkuKey.set(item.rowKey, savedThumb.fileId);
|
||||
});
|
||||
|
||||
const payload = await buildPublishPayload(
|
||||
@@ -806,17 +812,13 @@ export function usePublishDraft(options: {
|
||||
detailFileIds,
|
||||
thumbFileIdBySkuKey,
|
||||
);
|
||||
// 确保有系统草稿并回传 ID,发布结果才能写入 goods_commit_id
|
||||
if (boundDraftId.value) {
|
||||
payload.systemDraftId = boundDraftId.value;
|
||||
} else if (form.pddShopId) {
|
||||
const saved = await saveDeskDraft(true, { silentSuccess: true });
|
||||
if (saved?.id) {
|
||||
payload.systemDraftId = saved.id;
|
||||
}
|
||||
}
|
||||
payload.systemDraftId = saved.id;
|
||||
const res = await publishPddGoodsApi(payload);
|
||||
message.success(`发布成功,goodsId=${res.goodsId}`);
|
||||
message.success(
|
||||
res.goodsId != null
|
||||
? `发布成功,goodsId=${res.goodsId}`
|
||||
: '发布成功',
|
||||
);
|
||||
emit('success');
|
||||
closeEditor();
|
||||
} catch (e: any) {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/**
|
||||
* 发布编辑页路由入口(editor/index):Page 布局 + 左侧表单 + 右侧 Agent。
|
||||
* 表单实现见同目录 PddPublishEditor;智能体见 ../agent。
|
||||
* draftId=new 表示尚未落库的空编辑;保存/推送/发布时再创建系统草稿。
|
||||
*/
|
||||
import { computed, ref } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
@@ -19,10 +20,20 @@ defineOptions({ name: 'PddGoodsPublishDeskEdit' });
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
/** 数字 ID;new / 非法 → null(尚未创建系统草稿) */
|
||||
const draftId = computed(() => {
|
||||
const raw = route.params.draftId;
|
||||
const n = Number(Array.isArray(raw) ? raw[0] : raw);
|
||||
return Number.isFinite(n) ? n : null;
|
||||
const s = String(Array.isArray(raw) ? raw[0] : raw ?? '');
|
||||
if (!s || s === 'new') return null;
|
||||
const n = Number(s);
|
||||
return Number.isFinite(n) && n > 0 ? n : null;
|
||||
});
|
||||
|
||||
const presetPddShopId = computed(() => {
|
||||
const raw = route.query.shopId;
|
||||
const s = String(Array.isArray(raw) ? raw[0] : raw ?? '');
|
||||
const n = Number(s);
|
||||
return Number.isFinite(n) && n > 0 ? n : null;
|
||||
});
|
||||
|
||||
const editorRef = ref<PublishEditorAgentApi | null>(null);
|
||||
@@ -47,6 +58,15 @@ const agentPaneStyle = computed(() => {
|
||||
function goBack() {
|
||||
void router.push('/pdd/goods/publish');
|
||||
}
|
||||
|
||||
/** 首次落库后把 URL 换成真实草稿 ID,便于刷新续编与 Agent 绑定 */
|
||||
function onDraftSaved(id: number) {
|
||||
if (!id || draftId.value === id) return;
|
||||
void router.replace({
|
||||
path: `/pdd/goods/publish/editor/${id}`,
|
||||
query: {},
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -60,33 +80,22 @@ 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"
|
||||
>
|
||||
#{{ draftId }}
|
||||
</span>
|
||||
</div>
|
||||
<!-- Editor Teleport:店铺 / 类目 -->
|
||||
<div id="pdd-publish-edit-header-fields" class="w-full min-w-0"></div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div
|
||||
v-if="draftId"
|
||||
class="flex min-h-0 flex-1 overflow-hidden"
|
||||
>
|
||||
<div class="flex min-h-0 flex-1 overflow-hidden">
|
||||
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||
<PddPublishEditor
|
||||
ref="editorRef"
|
||||
class="h-full min-h-0"
|
||||
:open="true"
|
||||
:draft-id="draftId"
|
||||
:preset-pdd-shop-id="presetPddShopId"
|
||||
@close="goBack"
|
||||
@success="goBack"
|
||||
@draft-saved="() => undefined"
|
||||
@draft-saved="onDraftSaved"
|
||||
/>
|
||||
</div>
|
||||
<div
|
||||
|
||||
@@ -101,10 +101,23 @@ export type PublishFormFields = {
|
||||
isPreSale: boolean;
|
||||
isRefundable: boolean;
|
||||
secondHand: boolean;
|
||||
/** 表单展示用折扣:0–10,9.5=9.5折;提交接口时 *10 */
|
||||
twoPiecesDiscount: number;
|
||||
goodsPropValues: Record<string, string>;
|
||||
};
|
||||
|
||||
/** 表单折扣 → 拼多多接口整数(9.5 → 95) */
|
||||
export function twoPiecesDiscountToApi(ui: number | null | undefined): number {
|
||||
if (ui == null || Number.isNaN(ui)) return 95;
|
||||
return Math.round(ui * 10);
|
||||
}
|
||||
|
||||
/** 接口/旧草稿整数 → 表单折扣(95 → 9.5;已是 0–10 则原样) */
|
||||
export function twoPiecesDiscountFromStored(raw: number): number {
|
||||
if (raw > 10) return Math.round((raw / 10) * 10) / 10;
|
||||
return raw;
|
||||
}
|
||||
|
||||
/** 创建空白发布表单字段 */
|
||||
export function createEmptyPublishForm(): PublishFormFields {
|
||||
return {
|
||||
@@ -117,11 +130,11 @@ export function createEmptyPublishForm(): PublishFormFields {
|
||||
costTemplateId: undefined,
|
||||
marketPriceYuan: undefined,
|
||||
shipmentLimitSecond: 172800,
|
||||
isFolt: true,
|
||||
isFolt: false,
|
||||
isPreSale: false,
|
||||
isRefundable: true,
|
||||
secondHand: false,
|
||||
twoPiecesDiscount: 95,
|
||||
twoPiecesDiscount: 9.5,
|
||||
goodsPropValues: {},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import {
|
||||
|
||||
import {
|
||||
clonePddPublishDeskDraftApi,
|
||||
createPddPublishDeskDraftApi,
|
||||
createPddPublishDeskJobApi,
|
||||
deletePddPublishDeskDraftApi,
|
||||
getPddPublishDeskJobApi,
|
||||
@@ -315,18 +314,15 @@ function selectUnassigned() {
|
||||
}
|
||||
|
||||
async function createDraft() {
|
||||
try {
|
||||
const draft = await createPddPublishDeskDraftApi({
|
||||
title: '未命名草稿',
|
||||
pddShopId: selectedShopId.value,
|
||||
status: 'EDITING',
|
||||
skuCount: 0,
|
||||
});
|
||||
message.success('已创建系统草稿');
|
||||
await router.push(`/pdd/goods/publish/editor/${draft.id}`);
|
||||
} catch (e: any) {
|
||||
message.error(e?.message || '创建失败');
|
||||
}
|
||||
const query =
|
||||
selectedShopId.value != null && selectedShopId.value > 0
|
||||
? { shopId: String(selectedShopId.value) }
|
||||
: undefined;
|
||||
// 先进空编辑页,用户保存/推送/发布时再落系统草稿
|
||||
await router.push({
|
||||
path: '/pdd/goods/publish/editor/new',
|
||||
query,
|
||||
});
|
||||
}
|
||||
|
||||
function openEdit(id: number) {
|
||||
|
||||
Reference in New Issue
Block a user