From c11106ba1e34fc9ccb9d6542f84e42faccd5517a 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 10:25:23 +0800 Subject: [PATCH] =?UTF-8?q?fix(ecom-dmb):=20=E4=BF=AE=E5=A4=8D=E6=9C=88?= =?UTF-8?q?=E5=BA=A6=E7=9B=AE=E6=A0=87=E6=A8=A1=E6=80=81=E6=A1=86=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=9A=E6=9C=88=E4=BB=BD=E9=80=89=E6=8B=A9=E5=99=A8?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E5=BC=82=E5=B8=B8=E3=80=81=E7=AC=AC=E4=BA=8C?= =?UTF-8?q?=E6=AC=A1=E6=97=A0=E6=B3=95=E6=89=93=E5=BC=80=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E5=8F=8A=E5=95=86=E5=93=81=E5=8D=A1=E7=89=87=E5=AE=BD=E5=BA=A6?= =?UTF-8?q?=E4=BB=8E180=E8=B0=83=E6=95=B4=E4=B8=BA240?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/views/ProductGridView/index.vue | 2 +- .../components/ShopMonthlyTargetFormModal.vue | 89 ++++++++++--------- 2 files changed, 47 insertions(+), 44 deletions(-) diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue index b7b362d6..e8f6c353 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/product/views/ProductGridView/index.vue @@ -284,7 +284,7 @@ onUnmounted(() => { v-else-if="productList.length > 0" :list="productList" row-key="id" - :width="180" + :width="240" :breakpoints="{ 2000: { rowPerView: 5 }, 1700: { rowPerView: 4 }, diff --git a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue index 9a0ed85b..4c021421 100644 --- a/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue +++ b/ecom-dmb-frontend/apps/web-antd/src/views/ecommerce/shop/monthly-target/components/ShopMonthlyTargetFormModal.vue @@ -5,7 +5,7 @@ import type { } from '#/api/ecommerce/shop-monthly-target'; import type { ShopVO } from '#/api/ecommerce/shop/types'; -import { onMounted, ref, watch } from 'vue'; +import { computed, nextTick, onMounted, ref, watch } from 'vue'; import { useVbenModal } from '@vben/common-ui'; @@ -44,16 +44,23 @@ interface Emits { (e: 'cancel'): void; } -// 创建 vben modal +// 创建 vben modal(与父组件 v-model:open 同步 isOpen,避免仅点遮罩关闭时父级仍为 true 导致无法二次打开) const [Modal, modalApi] = useVbenModal({ draggable: true, class: 'w-[700px]', + destroyOnClose: false, onCancel() { handleCancel(); }, onConfirm() { handleOk(); }, + onOpenChange(isOpen: boolean) { + if (!isOpen) { + emit('update:open', false); + resetFormData(); + } + }, }); // 响应式数据 @@ -69,8 +76,21 @@ const formData = ref({ remark: '', }); -// 目标月份选择器的值(dayjs对象) -const targetMonthValue = ref(null); +// 目标月份展示值(只读 computed + @update:value 写回,避免与 Form 校验同一 tick 不同步) +const targetMonthForPicker = computed(() => { + if (!formData.value.targetMonth) return undefined; + return dayjs(formData.value.targetMonth); +}); + +function onTargetMonthChange(val: dayjs.Dayjs | string | undefined) { + if (val === undefined || val === null || val === '') { + formData.value.targetMonth = ''; + } else { + const d = dayjs.isDayjs(val) ? val : dayjs(val); + formData.value.targetMonth = d.isValid() ? d.format('YYYY-MM-01') : ''; + } + nextTick(() => formRef.value?.clearValidate?.(['targetMonth'])); +} // 表单验证规则 const rules = { @@ -93,42 +113,29 @@ const shopListLoading = ref(false); // 监听props变化 watch( () => props.open, - (newVal) => { - if (newVal) { - modalApi.open(); - isEdit.value = !!props.shopMonthlyTargetData; - if (props.shopMonthlyTargetData) { - // 编辑模式,填充表单数据 - formData.value = { - shopId: props.shopMonthlyTargetData.shopId, - targetMonth: props.shopMonthlyTargetData.targetMonth, - targetAmount: props.shopMonthlyTargetData.targetAmount, - targetOrderCount: props.shopMonthlyTargetData.targetOrderCount, - remark: props.shopMonthlyTargetData.remark || '', - }; - // 设置目标月份选择器的值 - targetMonthValue.value = dayjs(props.shopMonthlyTargetData.targetMonth); - } else { - // 新增模式,重置表单数据 - resetFormData(); - } - } else { + async (newVal) => { + if (!newVal) { modalApi.close(); + return; } - }, - { immediate: true }, -); - -// 监听目标月份选择器变化 -watch( - () => targetMonthValue.value, - (newVal) => { - if (newVal) { - // 格式化为 YYYY-MM-01 - formData.value.targetMonth = newVal.format('YYYY-MM-01'); + isEdit.value = !!props.shopMonthlyTargetData; + if (props.shopMonthlyTargetData) { + // 编辑模式,填充表单数据 + formData.value = { + shopId: props.shopMonthlyTargetData.shopId, + targetMonth: props.shopMonthlyTargetData.targetMonth, + targetAmount: props.shopMonthlyTargetData.targetAmount, + targetOrderCount: props.shopMonthlyTargetData.targetOrderCount, + remark: props.shopMonthlyTargetData.remark || '', + }; } else { - formData.value.targetMonth = ''; + // 新增模式,重置表单数据 + resetFormData(); } + await nextTick(); + modalApi.open(); + await nextTick(); + formRef.value?.clearValidate?.(); }, ); @@ -158,7 +165,6 @@ const resetFormData = () => { targetOrderCount: undefined as any, remark: '', }; - targetMonthValue.value = null; }; // 确认操作 @@ -187,19 +193,15 @@ 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(); }; // 组件挂载时加载数据 @@ -233,11 +235,12 @@ onMounted(() => {