mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 04:29:20 +08:00
feat: 发布工作台改为保存/推送/发布时再创建系统草稿
This commit is contained in:
+28
-4
@@ -35,7 +35,8 @@ const PanelCloseIcon = createIconifyIcon('lucide:panel-left-close');
|
|||||||
const PanelOpenIcon = createIconifyIcon('lucide:panel-left');
|
const PanelOpenIcon = createIconifyIcon('lucide:panel-left');
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
draftId: number;
|
/** 系统草稿 ID;null 表示尚未落库的新建编辑 */
|
||||||
|
draftId: number | null;
|
||||||
collapsed?: boolean;
|
collapsed?: boolean;
|
||||||
/** 编辑器命令面(ref) */
|
/** 编辑器命令面(ref) */
|
||||||
editorApi: PublishEditorAgentApi | null;
|
editorApi: PublishEditorAgentApi | null;
|
||||||
@@ -48,6 +49,25 @@ const emit = defineEmits<{
|
|||||||
|
|
||||||
const SCENE = 'ecom_goods_publish' as const;
|
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 = [
|
const starterPrompts = [
|
||||||
{
|
{
|
||||||
label: '按编码生成标题',
|
label: '按编码生成标题',
|
||||||
@@ -222,11 +242,11 @@ async function ensureSession(): Promise<string | null> {
|
|||||||
if (session.value?.threadId) return session.value.threadId;
|
if (session.value?.threadId) return session.value.threadId;
|
||||||
const parsed = parseModelKey(selectedModelKey.value);
|
const parsed = parseModelKey(selectedModelKey.value);
|
||||||
const s = await createAgentSessionApi({
|
const s = await createAgentSessionApi({
|
||||||
title: `发布草稿 #${props.draftId}`,
|
title: sessionTitle.value,
|
||||||
llmProviderId: parsed?.providerId,
|
llmProviderId: parsed?.providerId,
|
||||||
llmModel: parsed?.model,
|
llmModel: parsed?.model,
|
||||||
scene: SCENE,
|
scene: SCENE,
|
||||||
sceneRef: String(props.draftId),
|
sceneRef: sceneRef.value,
|
||||||
reuseBySceneRef: true,
|
reuseBySceneRef: true,
|
||||||
});
|
});
|
||||||
session.value = s;
|
session.value = s;
|
||||||
@@ -275,7 +295,11 @@ async function bootstrap() {
|
|||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => props.draftId,
|
() => props.draftId,
|
||||||
() => {
|
(id, prev) => {
|
||||||
|
// 新建落库后仅 URL 从 new→id:沿用当前会话,避免打断
|
||||||
|
if (prev == null && id != null && id > 0 && session.value?.threadId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
abort?.abort();
|
abort?.abort();
|
||||||
void bootstrap();
|
void bootstrap();
|
||||||
},
|
},
|
||||||
|
|||||||
+18
@@ -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() {
|
function resetAll() {
|
||||||
draft.submitting.value = false;
|
draft.submitting.value = false;
|
||||||
Object.assign(form, createEmptyPublishForm());
|
Object.assign(form, createEmptyPublishForm());
|
||||||
|
|||||||
+13
-13
@@ -779,8 +779,12 @@ export function usePublishDraft(options: {
|
|||||||
async function handleSubmit() {
|
async function handleSubmit() {
|
||||||
if (!validateForm()) return;
|
if (!validateForm()) return;
|
||||||
submitting.value = true;
|
submitting.value = true;
|
||||||
const hide = message.loading('正在上传图片并发布…', 0);
|
const hide = message.loading('正在保存并发布…', 0);
|
||||||
try {
|
try {
|
||||||
|
// 先落/更新系统草稿(含 publishPayload),再发布以便回写 goods_commit_id / goods_id
|
||||||
|
const saved = await saveDeskDraft(true, { silentSuccess: true });
|
||||||
|
if (!saved?.id) return;
|
||||||
|
|
||||||
const pendingThumbs = skuRows.value
|
const pendingThumbs = skuRows.value
|
||||||
.map((row) => ({ rowKey: row.key, file: row.thumbFileList[0] }))
|
.map((row) => ({ rowKey: row.key, file: row.thumbFileList[0] }))
|
||||||
.filter((x): x is { rowKey: number; file: UploadFile } => !!x.file);
|
.filter((x): x is { rowKey: number; file: UploadFile } => !!x.file);
|
||||||
@@ -799,8 +803,8 @@ export function usePublishDraft(options: {
|
|||||||
const thumbPersisted = persistedAll.slice(p);
|
const thumbPersisted = persistedAll.slice(p);
|
||||||
const thumbFileIdBySkuKey = new Map<number, number>();
|
const thumbFileIdBySkuKey = new Map<number, number>();
|
||||||
pendingThumbs.forEach((item, i) => {
|
pendingThumbs.forEach((item, i) => {
|
||||||
const saved = thumbPersisted[i];
|
const savedThumb = thumbPersisted[i];
|
||||||
if (saved) thumbFileIdBySkuKey.set(item.rowKey, saved.fileId);
|
if (savedThumb) thumbFileIdBySkuKey.set(item.rowKey, savedThumb.fileId);
|
||||||
});
|
});
|
||||||
|
|
||||||
const payload = await buildPublishPayload(
|
const payload = await buildPublishPayload(
|
||||||
@@ -808,17 +812,13 @@ export function usePublishDraft(options: {
|
|||||||
detailFileIds,
|
detailFileIds,
|
||||||
thumbFileIdBySkuKey,
|
thumbFileIdBySkuKey,
|
||||||
);
|
);
|
||||||
// 确保有系统草稿并回传 ID,发布结果才能写入 goods_commit_id
|
payload.systemDraftId = saved.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const res = await publishPddGoodsApi(payload);
|
const res = await publishPddGoodsApi(payload);
|
||||||
message.success(`发布成功,goodsId=${res.goodsId}`);
|
message.success(
|
||||||
|
res.goodsId != null
|
||||||
|
? `发布成功,goodsId=${res.goodsId}`
|
||||||
|
: '发布成功',
|
||||||
|
);
|
||||||
emit('success');
|
emit('success');
|
||||||
closeEditor();
|
closeEditor();
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
/**
|
/**
|
||||||
* 发布编辑页路由入口(editor/index):Page 布局 + 左侧表单 + 右侧 Agent。
|
* 发布编辑页路由入口(editor/index):Page 布局 + 左侧表单 + 右侧 Agent。
|
||||||
* 表单实现见同目录 PddPublishEditor;智能体见 ../agent。
|
* 表单实现见同目录 PddPublishEditor;智能体见 ../agent。
|
||||||
|
* draftId=new 表示尚未落库的空编辑;保存/推送/发布时再创建系统草稿。
|
||||||
*/
|
*/
|
||||||
import { computed, ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
import { useRoute, useRouter } from 'vue-router';
|
import { useRoute, useRouter } from 'vue-router';
|
||||||
@@ -19,10 +20,20 @@ defineOptions({ name: 'PddGoodsPublishDeskEdit' });
|
|||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
/** 数字 ID;new / 非法 → null(尚未创建系统草稿) */
|
||||||
const draftId = computed(() => {
|
const draftId = computed(() => {
|
||||||
const raw = route.params.draftId;
|
const raw = route.params.draftId;
|
||||||
const n = Number(Array.isArray(raw) ? raw[0] : raw);
|
const s = String(Array.isArray(raw) ? raw[0] : raw ?? '');
|
||||||
return Number.isFinite(n) ? n : null;
|
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);
|
const editorRef = ref<PublishEditorAgentApi | null>(null);
|
||||||
@@ -47,6 +58,15 @@ const agentPaneStyle = computed(() => {
|
|||||||
function goBack() {
|
function goBack() {
|
||||||
void router.push('/pdd/goods/publish');
|
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>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -65,19 +85,17 @@ function goBack() {
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<div
|
<div class="flex min-h-0 flex-1 overflow-hidden">
|
||||||
v-if="draftId"
|
|
||||||
class="flex min-h-0 flex-1 overflow-hidden"
|
|
||||||
>
|
|
||||||
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
<div class="flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden">
|
||||||
<PddPublishEditor
|
<PddPublishEditor
|
||||||
ref="editorRef"
|
ref="editorRef"
|
||||||
class="h-full min-h-0"
|
class="h-full min-h-0"
|
||||||
:open="true"
|
:open="true"
|
||||||
:draft-id="draftId"
|
:draft-id="draftId"
|
||||||
|
:preset-pdd-shop-id="presetPddShopId"
|
||||||
@close="goBack"
|
@close="goBack"
|
||||||
@success="goBack"
|
@success="goBack"
|
||||||
@draft-saved="() => undefined"
|
@draft-saved="onDraftSaved"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
clonePddPublishDeskDraftApi,
|
clonePddPublishDeskDraftApi,
|
||||||
createPddPublishDeskDraftApi,
|
|
||||||
createPddPublishDeskJobApi,
|
createPddPublishDeskJobApi,
|
||||||
deletePddPublishDeskDraftApi,
|
deletePddPublishDeskDraftApi,
|
||||||
getPddPublishDeskJobApi,
|
getPddPublishDeskJobApi,
|
||||||
@@ -315,18 +314,15 @@ function selectUnassigned() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function createDraft() {
|
async function createDraft() {
|
||||||
try {
|
const query =
|
||||||
const draft = await createPddPublishDeskDraftApi({
|
selectedShopId.value != null && selectedShopId.value > 0
|
||||||
title: '未命名草稿',
|
? { shopId: String(selectedShopId.value) }
|
||||||
pddShopId: selectedShopId.value,
|
: undefined;
|
||||||
status: 'EDITING',
|
// 先进空编辑页,用户保存/推送/发布时再落系统草稿
|
||||||
skuCount: 0,
|
await router.push({
|
||||||
});
|
path: '/pdd/goods/publish/editor/new',
|
||||||
message.success('已创建系统草稿');
|
query,
|
||||||
await router.push(`/pdd/goods/publish/editor/${draft.id}`);
|
});
|
||||||
} catch (e: any) {
|
|
||||||
message.error(e?.message || '创建失败');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function openEdit(id: number) {
|
function openEdit(id: number) {
|
||||||
|
|||||||
Reference in New Issue
Block a user