mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +08:00
feat: 发布商品弹窗支持最小化并保留编辑草稿
This commit is contained in:
+140
-25
@@ -7,10 +7,10 @@ import type { ProductSkuVO } from '#/api/ec/product/sku';
|
||||
import type { ProductVO } from '#/api/ec/product/types';
|
||||
import type { CascaderProps, UploadFile, UploadProps } from 'ant-design-vue';
|
||||
|
||||
import { computed, onBeforeUnmount, reactive, ref, watch } from 'vue';
|
||||
import { computed, nextTick, onBeforeUnmount, reactive, ref, watch } from 'vue';
|
||||
|
||||
import { useVbenModal } from '@vben/common-ui';
|
||||
import { PlusOutlined } from '@ant-design/icons-vue';
|
||||
import { PlusOutlined, DeleteOutlined, MinusOutlined } from '@ant-design/icons-vue';
|
||||
|
||||
import {
|
||||
Button,
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
Image,
|
||||
Input,
|
||||
InputNumber,
|
||||
Modal as AntModal,
|
||||
Select,
|
||||
Space,
|
||||
Spin,
|
||||
@@ -58,16 +59,35 @@ const emit = defineEmits<{
|
||||
success: [];
|
||||
}>();
|
||||
|
||||
/** 是否有可恢复的编辑草稿(最小化保留,关闭清空) */
|
||||
const hasDraft = defineModel<boolean>('hasDraft', { default: false });
|
||||
|
||||
/** close=关闭并清空;minimize=仅收起,下次打开续填 */
|
||||
let dismissMode: 'close' | 'minimize' = 'close';
|
||||
/** 点击遮罩时的去向询问 */
|
||||
const dismissChoiceVisible = ref(false);
|
||||
|
||||
const [Modal, modalApi] = useVbenModal({
|
||||
draggable: true,
|
||||
class: 'w-[1100px]',
|
||||
contentClass: 'max-h-[80vh] overflow-y-auto',
|
||||
destroyOnClose: true,
|
||||
// max-h 用 vh:内容区 flex 占满剩余高度,底部操作栏固定不被滚动遮挡
|
||||
class: 'w-[1100px] max-h-[80vh]',
|
||||
contentClass: 'flex min-h-0 flex-1 flex-col overflow-hidden px-5 py-4',
|
||||
// 最小化后需保留表单 DOM/状态,避免销毁重建丢交互态
|
||||
destroyOnClose: false,
|
||||
// 点遮罩不直接关,改为询问最小化 / 关闭
|
||||
closeOnClickModal: false,
|
||||
footer: false,
|
||||
onOpenChange(isOpen: boolean) {
|
||||
if (!isOpen) {
|
||||
emit('update:open', false);
|
||||
resetAll();
|
||||
dismissChoiceVisible.value = false;
|
||||
if (dismissMode === 'close') {
|
||||
resetAll();
|
||||
hasDraft.value = false;
|
||||
} else {
|
||||
hasDraft.value = true;
|
||||
}
|
||||
dismissMode = 'close';
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -77,17 +97,47 @@ watch(
|
||||
(v) => {
|
||||
if (v) {
|
||||
modalApi.open();
|
||||
form.pddShopId = props.presetPddShopId ?? undefined;
|
||||
// 无草稿时才套用预设店铺;有草稿则续填
|
||||
if (!hasDraft.value) {
|
||||
form.pddShopId = props.presetPddShopId ?? undefined;
|
||||
}
|
||||
void loadShops();
|
||||
void loadProducts();
|
||||
void loadSkuCandidates();
|
||||
// 类目/运费由 pddShopId watch 统一加载,避免重复请求
|
||||
document.addEventListener('pointerdown', onOverlayPointerDown, true);
|
||||
} else {
|
||||
document.removeEventListener('pointerdown', onOverlayPointerDown, true);
|
||||
modalApi.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
/** 点击遮罩层:询问最小化还是关闭 */
|
||||
function onOverlayPointerDown(e: PointerEvent) {
|
||||
if (!props.open || submitting.value || dismissChoiceVisible.value) return;
|
||||
const el = e.target as HTMLElement | null;
|
||||
if (!el?.hasAttribute('data-dismissable-modal')) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
dismissChoiceVisible.value = true;
|
||||
}
|
||||
|
||||
/** 最小化:收起弹窗,不清空编辑数据 */
|
||||
function handleMinimize() {
|
||||
dismissChoiceVisible.value = false;
|
||||
dismissMode = 'minimize';
|
||||
modalApi.close();
|
||||
message.info('已最小化,再次打开可继续编辑');
|
||||
}
|
||||
|
||||
/** 关闭:收起并清空(取消按钮 / 询问框「关闭」) */
|
||||
function handleClose() {
|
||||
dismissChoiceVisible.value = false;
|
||||
dismissMode = 'close';
|
||||
modalApi.close();
|
||||
}
|
||||
|
||||
const pickInternalSkuId = ref<number | undefined>(undefined);
|
||||
const submitting = ref(false);
|
||||
let skuRowSeq = 1;
|
||||
@@ -135,6 +185,8 @@ const productOptions = ref<{ label: string; value: number; name: string }[]>(
|
||||
);
|
||||
const skuOptions = ref<ProductSkuVO.Info[]>([]);
|
||||
const skuRows = ref<SkuRow[]>([]);
|
||||
/** 规格表容器:新增后滚到表体底部 */
|
||||
const skuTableWrapRef = ref<HTMLElement | null>(null);
|
||||
|
||||
const logisticsOptions = ref<{ label: string; value: number }[]>([]);
|
||||
const costTemplateDetail = ref<PddGoodsPublishVO.CostTemplateDetail | null>(
|
||||
@@ -359,6 +411,7 @@ function emptySkuRow(): SkuRow {
|
||||
|
||||
function addBlankSkuRow() {
|
||||
skuRows.value.push(emptySkuRow());
|
||||
void scrollSkuTableToBottom();
|
||||
}
|
||||
|
||||
function addInternalSku(skuId?: number) {
|
||||
@@ -383,6 +436,18 @@ function addInternalSku(skuId?: number) {
|
||||
thumbFileList: [],
|
||||
saleValues: {},
|
||||
});
|
||||
void scrollSkuTableToBottom();
|
||||
}
|
||||
|
||||
/** 新增规格后滚到表体底部,方便继续编辑新行 */
|
||||
async function scrollSkuTableToBottom() {
|
||||
await nextTick();
|
||||
await nextTick();
|
||||
const body = skuTableWrapRef.value?.querySelector(
|
||||
'.ant-table-body',
|
||||
) as HTMLElement | null;
|
||||
if (!body) return;
|
||||
body.scrollTo({ top: body.scrollHeight, behavior: 'smooth' });
|
||||
}
|
||||
|
||||
function onPickInternalSku(skuId?: number) {
|
||||
@@ -828,13 +893,25 @@ function resetAll() {
|
||||
}
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
document.removeEventListener('pointerdown', onOverlayPointerDown, true);
|
||||
clearLocalImages();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Modal title="发布拼多多商品">
|
||||
<div class="space-y-4 px-1 pb-2">
|
||||
<template #header-actions>
|
||||
<button
|
||||
type="button"
|
||||
class="hover:bg-accent hover:text-accent-foreground text-foreground/80 flex size-6 items-center justify-center rounded-full px-1 text-lg opacity-70 transition-opacity hover:opacity-100 focus:outline-none"
|
||||
title="最小化(保留编辑内容)"
|
||||
@click="handleMinimize"
|
||||
>
|
||||
<MinusOutlined class="text-sm" />
|
||||
</button>
|
||||
</template>
|
||||
<div class="flex min-h-0 flex-1 flex-col overflow-hidden">
|
||||
<div class="min-h-0 flex-1 space-y-4 overflow-y-auto px-1 pr-1">
|
||||
<Form layout="vertical">
|
||||
<div class="grid grid-cols-2 gap-3">
|
||||
<Form.Item label="渠道店铺" required>
|
||||
@@ -1114,7 +1191,12 @@ onBeforeUnmount(() => {
|
||||
|
||||
<div>
|
||||
<div class="mb-2 flex flex-wrap items-center justify-between gap-2">
|
||||
<div class="text-sm font-medium">规格 SKU</div>
|
||||
<div class="text-sm font-medium">
|
||||
规格 SKU
|
||||
<span class="ml-1 font-normal text-slate-500">
|
||||
({{ skuRows.length }})
|
||||
</span>
|
||||
</div>
|
||||
<Space wrap>
|
||||
<Select
|
||||
v-model:value="pickInternalSkuId"
|
||||
@@ -1131,14 +1213,16 @@ onBeforeUnmount(() => {
|
||||
</Space>
|
||||
</div>
|
||||
|
||||
<Table
|
||||
<div ref="skuTableWrapRef">
|
||||
<Table
|
||||
size="small"
|
||||
:pagination="false"
|
||||
:scroll="{ x: 1100 }"
|
||||
:scroll="{ x: 1200, y: 400 }"
|
||||
:data-source="skuRows"
|
||||
row-key="key"
|
||||
:columns="[
|
||||
{ title: '来源/名称', key: 'name', width: 160 },
|
||||
{ title: '来源', key: 'source', width: 140 },
|
||||
{ title: '名称', key: 'name', width: 140 },
|
||||
{ title: '商家编码', key: 'code', width: 130 },
|
||||
{ title: '单买价', key: 'price', width: 100 },
|
||||
{ title: '团购价', key: 'multi', width: 100 },
|
||||
@@ -1150,23 +1234,31 @@ onBeforeUnmount(() => {
|
||||
key: `sale_${p.refPid ?? p.templatePid}`,
|
||||
width: 130,
|
||||
})),
|
||||
{ title: '操作', key: 'action', width: 70, fixed: 'right' },
|
||||
{ title: '操作', key: 'action', width: 56, fixed: 'right' },
|
||||
]"
|
||||
>
|
||||
<template #bodyCell="{ column, record }">
|
||||
<template v-if="column.key === 'name'">
|
||||
<template v-if="column.key === 'source'">
|
||||
<div class="space-y-1">
|
||||
<Tag v-if="record.internalSkuId" color="blue">内部</Tag>
|
||||
<div v-if="record.productName" class="text-xs text-slate-500">
|
||||
<Tag :color="record.internalSkuId ? 'blue' : 'default'">
|
||||
{{ record.internalSkuId ? '内部 SKU' : '手填' }}
|
||||
</Tag>
|
||||
<div
|
||||
v-if="record.productName"
|
||||
class="text-xs text-slate-500"
|
||||
:title="record.productName"
|
||||
>
|
||||
{{ record.productName }}
|
||||
</div>
|
||||
<Input
|
||||
v-model:value="record.skuName"
|
||||
size="small"
|
||||
placeholder="规格名称"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'name'">
|
||||
<Input
|
||||
v-model:value="record.skuName"
|
||||
size="small"
|
||||
placeholder="规格名称"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="column.key === 'code'">
|
||||
<Input
|
||||
v-model:value="record.outSkuSn"
|
||||
@@ -1261,21 +1353,26 @@ onBeforeUnmount(() => {
|
||||
</template>
|
||||
<template v-else-if="column.key === 'action'">
|
||||
<Button
|
||||
type="link"
|
||||
type="text"
|
||||
size="small"
|
||||
danger
|
||||
title="删除"
|
||||
@click="removeSkuRow(record.key)"
|
||||
>
|
||||
删除
|
||||
<DeleteOutlined />
|
||||
</Button>
|
||||
</template>
|
||||
</template>
|
||||
</Table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end">
|
||||
<div
|
||||
class="mt-3 flex shrink-0 justify-end border-t border-border bg-background pt-3"
|
||||
>
|
||||
<Space>
|
||||
<Button @click="modalApi.close()">取消</Button>
|
||||
<Button @click="handleClose">取消</Button>
|
||||
<Button type="primary" :loading="submitting" @click="handleSubmit">
|
||||
发布到拼多多
|
||||
</Button>
|
||||
@@ -1292,6 +1389,24 @@ onBeforeUnmount(() => {
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
<AntModal
|
||||
v-model:open="dismissChoiceVisible"
|
||||
title="如何处理当前编辑?"
|
||||
:footer="null"
|
||||
centered
|
||||
:z-index="2100"
|
||||
destroy-on-close
|
||||
>
|
||||
<p class="text-sm text-slate-600 dark:text-slate-300">
|
||||
最小化将保留已填内容,下次可继续编辑;关闭将清空全部内容。
|
||||
</p>
|
||||
<div class="mt-5 flex flex-wrap justify-end gap-2">
|
||||
<Button @click="dismissChoiceVisible = false">继续编辑</Button>
|
||||
<Button danger @click="handleClose">关闭</Button>
|
||||
<Button type="primary" @click="handleMinimize">最小化</Button>
|
||||
</div>
|
||||
</AntModal>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -29,6 +29,7 @@ const detailDrawerRef = ref<InstanceType<typeof PddGoodsDetailDrawer>>();
|
||||
const shopDetailModalRef = ref<InstanceType<typeof PddShopDetailModal>>();
|
||||
const productDetailDrawerRef = ref<InstanceType<typeof ProductDetailDrawer>>();
|
||||
const publishOpen = ref(false);
|
||||
const publishHasDraft = ref(false);
|
||||
/** 左侧选中的拼多多渠道店铺 ID */
|
||||
const selectedShopId = ref<number | undefined>(undefined);
|
||||
const shopNameById = ref<Record<number, string>>({});
|
||||
@@ -334,8 +335,8 @@ onMounted(async () => {
|
||||
<div class="flex items-center justify-between gap-2">
|
||||
<span class="text-base font-semibold">拼多多商品</span>
|
||||
<PermissionGate code="channel:pdd:goods:create">
|
||||
<Button type="primary" size="small" @click="publishOpen = true">
|
||||
发布商品
|
||||
<Button type="primary" @click="publishOpen = true">
|
||||
{{ publishHasDraft ? '继续发布' : '发布商品' }}
|
||||
</Button>
|
||||
</PermissionGate>
|
||||
</div>
|
||||
@@ -427,6 +428,7 @@ onMounted(async () => {
|
||||
<ProductDetailDrawer ref="productDetailDrawerRef" />
|
||||
<PddGoodsPublishModal
|
||||
v-model:open="publishOpen"
|
||||
v-model:has-draft="publishHasDraft"
|
||||
:preset-pdd-shop-id="selectedShopId"
|
||||
@success="() => gridApi.reload()"
|
||||
/>
|
||||
|
||||
@@ -303,14 +303,20 @@ function handleClosed() {
|
||||
<slot></slot>
|
||||
</div>
|
||||
<VbenLoading v-if="showLoading || submitting" spinning />
|
||||
<VbenIconButton
|
||||
v-if="fullscreenButton"
|
||||
class="hover:bg-accent hover:text-accent-foreground text-foreground/80 flex-center absolute right-10 top-3 hidden size-6 rounded-full px-1 text-lg opacity-70 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none sm:block"
|
||||
@click="handleFullscreen"
|
||||
<!-- 关闭按钮左侧:全屏 + 自定义操作;从右到左为 关闭 | 自定义 | 全屏 -->
|
||||
<div
|
||||
class="absolute right-10 top-3 hidden items-center gap-1 sm:flex"
|
||||
>
|
||||
<Shrink v-if="fullscreen" class="size-3.5" />
|
||||
<Expand v-else class="size-3.5" />
|
||||
</VbenIconButton>
|
||||
<VbenIconButton
|
||||
v-if="fullscreenButton"
|
||||
class="hover:bg-accent hover:text-accent-foreground text-foreground/80 flex-center size-6 rounded-full px-1 text-lg opacity-70 transition-opacity hover:opacity-100 focus:outline-none disabled:pointer-events-none"
|
||||
@click="handleFullscreen"
|
||||
>
|
||||
<Shrink v-if="fullscreen" class="size-3.5" />
|
||||
<Expand v-else class="size-3.5" />
|
||||
</VbenIconButton>
|
||||
<slot name="header-actions"></slot>
|
||||
</div>
|
||||
|
||||
<DialogFooter
|
||||
v-if="showFooter"
|
||||
|
||||
Reference in New Issue
Block a user