From 7c7e271f053f561685a65f18661a0ffc8e37a4e7 Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Mon, 28 Sep 2026 11:54:54 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20SKU=20=E5=88=97=E8=A1=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=89=B9=E9=87=8F=E8=AE=BE=E7=BD=AE=E5=8D=95=E4=B9=B0?= =?UTF-8?q?=E4=BB=B7/=E6=8B=BC=E5=8D=95=E4=BB=B7/=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/publish/editor/PddPublishEditor.vue | 2 + .../editor/components/SkuTableCard.vue | 285 ++++++++++++++++++ .../editor/composables/use-publish-sku.ts | 42 +++ 3 files changed, 329 insertions(+) diff --git a/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue b/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue index c79804b4..04f2fdf1 100644 --- a/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue +++ b/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/PddPublishEditor.vue @@ -379,6 +379,7 @@ const { bindInternalSku, applyInternalSkusInOrder, clearInternalSkuBindings, + applySkuBatchFields, } = sku; const { @@ -798,6 +799,7 @@ function onSkuTableWrapRef(el: HTMLElement | null) { @out-sku-sn-blur="onOutSkuSnBlur" @bind-internal-sku="bindInternalSku" @sku-thumb-file-list-change="onSkuThumbFileListChange" + @apply-batch="applySkuBatchFields" /> diff --git a/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/components/SkuTableCard.vue b/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/components/SkuTableCard.vue index 03ed2bb7..be7d071e 100644 --- a/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/components/SkuTableCard.vue +++ b/apps/web/apps/web-antd/src/views/channel/pdd/goods/publish/editor/components/SkuTableCard.vue @@ -2,7 +2,10 @@ import type { UploadFile, UploadProps } from 'ant-design-vue'; import type { SkuRow } from '../types'; +import { nextTick, onBeforeUnmount, onMounted, ref } from 'vue'; + import { PlusOutlined } from '@ant-design/icons-vue'; +import { createIconifyIcon } from '@vben/icons'; import { Alert, @@ -14,6 +17,7 @@ import { Select, Table, Upload, + message, } from 'ant-design-vue'; defineOptions({ name: 'SkuTableCard' }); @@ -47,11 +51,144 @@ const emit = defineEmits<{ 'out-sku-sn-blur': [rowKey: number]; 'bind-internal-sku': [rowKey: number, skuId?: number]; 'sku-thumb-file-list-change': [rowKey: number, list: UploadFile[]]; + 'apply-batch': [ + patch: { + priceYuan?: number; + multiPriceYuan?: number; + quantity?: number; + }, + ]; }>(); +const BatchIcon = createIconifyIcon('lucide:layers-2'); + +/** 列头批量:Teleport 浮层,避免被 table header overflow 裁切 */ +const colBatchPrice = ref(undefined); +const colBatchMulti = ref(undefined); +const colBatchQty = ref(undefined); +const colBatchOpen = ref<'price' | 'multi' | 'qty' | null>(null); +const batchAnchorEl = ref(null); +const batchPanelStyle = ref>({ + top: '0px', + left: '0px', +}); +/** 本次打开只自动聚焦一次,避免输入时被再次 select 覆盖 */ +let batchFocusedOnce = false; + function setTableWrapRef(el: unknown) { emit('set-table-wrap-ref', (el as HTMLElement | null) ?? null); } + +function placeBatchPanel() { + const anchor = batchAnchorEl.value; + if (!anchor) return; + const rect = anchor.getBoundingClientRect(); + const panelWidth = 176; + const left = Math.min( + Math.max(8, rect.left), + window.innerWidth - panelWidth - 8, + ); + batchPanelStyle.value = { + top: `${rect.bottom + 6}px`, + left: `${left}px`, + }; +} + +function toggleColBatch(field: 'price' | 'multi' | 'qty', event: MouseEvent) { + const anchor = event.currentTarget as HTMLElement; + if (colBatchOpen.value === field) { + closeBatchPanel(); + return; + } + batchFocusedOnce = false; + batchAnchorEl.value = anchor; + colBatchOpen.value = field; + placeBatchPanel(); + void nextTick(placeBatchPanel); +} + +/** InputNumber 挂载后立刻聚焦;有旧值才全选,避免输入过程中被再次 select */ +function onBatchInputMounted(el: unknown) { + if (!el) return; + if (batchFocusedOnce) return; + batchFocusedOnce = true; + void nextTick(() => { + const inst = el as { focus?: () => void; $el?: HTMLElement }; + inst.focus?.(); + const root = inst.$el instanceof HTMLElement ? inst.$el : null; + const input = root?.querySelector( + 'input:not([type="hidden"])', + ); + if (!input) return; + input.focus(); + // 仅已有内容时全选,方便覆盖;空输入不要 select,否则易干扰后续按键 + if (input.value) input.select(); + }); +} + +function closeBatchPanel() { + colBatchOpen.value = null; + batchAnchorEl.value = null; + batchFocusedOnce = false; +} + +function onDocPointerDown(event: PointerEvent) { + if (!colBatchOpen.value) return; + const target = event.target; + if (target instanceof Node) { + const el = target as HTMLElement; + if (el.closest?.('.sku-batch-header') || el.closest?.('.sku-batch-panel')) { + return; + } + } + closeBatchPanel(); +} + +function onWinReposition() { + if (colBatchOpen.value) placeBatchPanel(); +} + +onMounted(() => { + document.addEventListener('pointerdown', onDocPointerDown, true); + window.addEventListener('resize', onWinReposition); + window.addEventListener('scroll', onWinReposition, true); +}); +onBeforeUnmount(() => { + document.removeEventListener('pointerdown', onDocPointerDown, true); + window.removeEventListener('resize', onWinReposition); + window.removeEventListener('scroll', onWinReposition, true); +}); + +function applyColumnBatch(field: 'price' | 'multi' | 'qty') { + const value = + field === 'price' + ? colBatchPrice.value + : field === 'multi' + ? colBatchMulti.value + : colBatchQty.value; + if (value == null) { + message.warning('请先填写要设置的值'); + return; + } + const patch = + field === 'price' + ? { priceYuan: value } + : field === 'multi' + ? { multiPriceYuan: value } + : { quantity: value }; + emit('apply-batch', patch); + closeBatchPanel(); +} + +function onColumnBatchEnter( + field: 'price' | 'multi' | 'qty', + event: KeyboardEvent, +) { + if (event.isComposing || event.keyCode === 229) return; + event.preventDefault(); + event.stopPropagation(); + applyColumnBatch(field); +}