From 26e0c85aa431283b46b97c75ac2b96ba087c0436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9F=91=E8=9E=82?= Date: Sat, 18 Apr 2026 14:17:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(ecom-dmb):=20=E4=BF=AE=E5=A4=8D=E6=8E=A8?= =?UTF-8?q?=E5=B9=BF=E7=AE=A1=E7=90=86=E5=92=8C=E5=88=B7=E5=8D=95=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E8=A1=A8=E5=8D=95=E6=A8=A1=E6=80=81=E6=A1=86=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/BrushOrderFormModal.vue | 75 ++++++++++--------- .../components/PromotionFeeFormModal.vue | 73 +++++++++--------- 2 files changed, 78 insertions(+), 70 deletions(-) diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/brush-order/components/BrushOrderFormModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/brush-order/components/BrushOrderFormModal.vue index 696c81c6..0a81b6ad 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/brush-order/components/BrushOrderFormModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/brush-order/components/BrushOrderFormModal.vue @@ -8,7 +8,7 @@ import type { ProductDTO, ProductVO } from '#/api/ecommerce/product/types'; import type { ShopVO } from '#/api/ecommerce/shop/types'; import type { PageQueryDTO } from '#/types/common'; -import { computed, onMounted, ref, watch } from 'vue'; +import { computed, nextTick, onMounted, ref, watch } from 'vue'; import { useVbenModal } from '@vben/common-ui'; @@ -50,16 +50,23 @@ interface Emits { (e: 'cancel'): void; } -// 创建 vben modal +// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开 const [Modal, modalApi] = useVbenModal({ draggable: true, class: 'w-[800px]', + destroyOnClose: false, onCancel() { handleCancel(); }, onConfirm() { handleOk(); }, + onOpenChange(isOpen: boolean) { + if (!isOpen) { + emit('update:open', false); + resetFormData(); + } + }, }); // 响应式数据 @@ -120,41 +127,42 @@ const brushTimeValue = computed({ }, }); -// 监听props变化 +// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi watch( () => props.open, - (newVal) => { - if (newVal) { - modalApi.open(); - isEdit.value = !!props.brushOrderData; - if (props.brushOrderData) { - // 编辑模式,填充表单数据 - formData.value = { - shopId: props.brushOrderData.shopId, - productId: props.brushOrderData.productId, - productSpecId: props.brushOrderData.productSpecId, - brushAmount: props.brushOrderData.brushAmount, - brushTime: props.brushOrderData.brushTime - ? dayjs(props.brushOrderData.brushTime).format('YYYY-MM-DD HH:mm:ss') - : dayjs().format('YYYY-MM-DD HH:mm:ss'), - platformOrderNo: props.brushOrderData.platformOrderNo, - quantity: props.brushOrderData.quantity || 1, - remark: props.brushOrderData.remark, - }; - // 如果有商品ID,加载商品和规格选项 - if (props.brushOrderData.productId) { - searchProducts(''); - if (props.brushOrderData.productSpecId) { - searchProductSpecs(''); - } + async (newVal) => { + if (!newVal) { + modalApi.close(); + return; + } + isEdit.value = !!props.brushOrderData; + if (props.brushOrderData) { + // 编辑模式,填充表单数据 + formData.value = { + shopId: props.brushOrderData.shopId, + productId: props.brushOrderData.productId, + productSpecId: props.brushOrderData.productSpecId, + brushAmount: props.brushOrderData.brushAmount, + brushTime: props.brushOrderData.brushTime + ? dayjs(props.brushOrderData.brushTime).format('YYYY-MM-DD HH:mm:ss') + : dayjs().format('YYYY-MM-DD HH:mm:ss'), + platformOrderNo: props.brushOrderData.platformOrderNo, + quantity: props.brushOrderData.quantity || 1, + remark: props.brushOrderData.remark, + }; + if (props.brushOrderData.productId) { + searchProducts(''); + if (props.brushOrderData.productSpecId) { + searchProductSpecs(''); } - } else { - // 新增模式,重置表单数据 - resetFormData(); } } else { - modalApi.close(); + resetFormData(); } + await nextTick(); + modalApi.open(); + await nextTick(); + formRef.value?.clearValidate?.(); }, { immediate: true }, ); @@ -290,7 +298,6 @@ const handleOk = async () => { emit('success'); modalApi.close(); - emit('update:open', false); } catch (error) { if ((error as any)?.errorFields) { // 表单验证错误 @@ -301,12 +308,10 @@ const handleOk = async () => { } }; -// 取消操作 +// 取消:关闭与重置由 onOpenChange 统一处理 const handleCancel = () => { emit('cancel'); modalApi.close(); - emit('update:open', false); - resetFormData(); }; // 组件挂载时加载数据 diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue index d93d5d39..d69f0a14 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/promotion-fee/components/PromotionFeeFormModal.vue @@ -47,16 +47,23 @@ interface Emits { (e: 'cancel'): void; } -// 创建 vben modal +// 与父组件 v-model:open 同步:遮罩/右上角关闭时也要 emit false,否则父级一直为 true 无法二次打开 const [Modal, modalApi] = useVbenModal({ draggable: true, class: 'w-[800px]', + destroyOnClose: false, onCancel() { handleCancel(); }, onConfirm() { handleOk(); }, + onOpenChange(isOpen: boolean) { + if (!isOpen) { + emit('update:open', false); + resetFormData(); + } + }, }); // 响应式数据 @@ -110,41 +117,40 @@ const shopListLoading = ref(false); const feeTypeList = ref([]); const feeTypeListLoading = ref(false); -// 监听props变化 +// 监听 props.open:先准备好表单再 open,关闭时同步 modalApi watch( () => props.open, async (newVal) => { - if (newVal) { - // 等渲染周期完成后再 open,避免 Slot 依赖追踪失效 - await nextTick(); - modalApi.open(); - isEdit.value = !!props.promotionFeeData; - if (props.promotionFeeData) { - // 编辑模式,填充表单数据 - formData.value = { - shopId: props.promotionFeeData.shopId, - feeTypeId: props.promotionFeeData.feeTypeId, - feeName: props.promotionFeeData.feeName, - platform: props.promotionFeeData.platform, - campaignName: props.promotionFeeData.campaignName || '', - feeAmount: props.promotionFeeData.feeAmount, - baseAmount: props.promotionFeeData.baseAmount, - feeRate: props.promotionFeeData.feeRate, - clickCount: props.promotionFeeData.clickCount, - impressionCount: props.promotionFeeData.impressionCount, - conversionCount: props.promotionFeeData.conversionCount, - feeDate: props.promotionFeeData.feeDate - ? dayjs(props.promotionFeeData.feeDate) - : undefined, - remark: props.promotionFeeData.remark || '', - }; - } else { - // 新增模式,重置表单数据 - resetFormData(); - } - } else { + if (!newVal) { modalApi.close(); + return; } + isEdit.value = !!props.promotionFeeData; + if (props.promotionFeeData) { + formData.value = { + shopId: props.promotionFeeData.shopId, + feeTypeId: props.promotionFeeData.feeTypeId, + feeName: props.promotionFeeData.feeName, + platform: props.promotionFeeData.platform, + campaignName: props.promotionFeeData.campaignName || '', + feeAmount: props.promotionFeeData.feeAmount, + baseAmount: props.promotionFeeData.baseAmount, + feeRate: props.promotionFeeData.feeRate, + clickCount: props.promotionFeeData.clickCount, + impressionCount: props.promotionFeeData.impressionCount, + conversionCount: props.promotionFeeData.conversionCount, + feeDate: props.promotionFeeData.feeDate + ? dayjs(props.promotionFeeData.feeDate) + : undefined, + remark: props.promotionFeeData.remark || '', + }; + } else { + resetFormData(); + } + await nextTick(); + modalApi.open(); + await nextTick(); + formRef.value?.clearValidate?.(); }, ); @@ -218,19 +224,16 @@ const handleOk = async () => { emit('success'); modalApi.close(); - emit('update:open', false); } catch (error) { console.error('操作失败:', error); message.error(isEdit.value ? '更新失败' : '创建失败'); } }; -// 取消操作 +// 取消:关闭与重置由 onOpenChange 统一处理 const handleCancel = () => { emit('cancel'); modalApi.close(); - emit('update:open', false); - resetFormData(); }; // 组件挂载时加载数据