From 03a5af3ba34e4c890c613db06738508319e553db Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Tue, 18 Nov 2025 15:54:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20antd=20mall=20diy=20=E5=88=87=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../component-container-property.vue | 2 +- .../promotion/components/diy-editor/index.vue | 2 +- .../promotion/diy/template/decorate/index.vue | 91 ++++++++----------- 3 files changed, 40 insertions(+), 55 deletions(-) diff --git a/apps/web-antd/src/views/mall/promotion/components/diy-editor/components/component-container-property.vue b/apps/web-antd/src/views/mall/promotion/components/diy-editor/components/component-container-property.vue index 37cc1ac46..97108ded9 100644 --- a/apps/web-antd/src/views/mall/promotion/components/diy-editor/components/component-container-property.vue +++ b/apps/web-antd/src/views/mall/promotion/components/diy-editor/components/component-container-property.vue @@ -189,7 +189,7 @@ function handleSliderChange(prop: string) { :max="100" :min="0" @change="handleSliderChange(dataRef.prop)" - class="mr-[16px]" + class="mr-4" /> diff --git a/apps/web-antd/src/views/mall/promotion/components/diy-editor/index.vue b/apps/web-antd/src/views/mall/promotion/components/diy-editor/index.vue index 32ec03daa..6ec29f49e 100644 --- a/apps/web-antd/src/views/mall/promotion/components/diy-editor/index.vue +++ b/apps/web-antd/src/views/mall/promotion/components/diy-editor/index.vue @@ -385,7 +385,7 @@ onMounted(() => { }" >
(); +// 当前编辑的属性 const currentFormData = ref< MallDiyPageApi.DiyPage | MallDiyTemplateApi.DiyTemplateProperty >({ property: '', -} as MallDiyPageApi.DiyPage); // 当前编辑的属性 +} as MallDiyPageApi.DiyPage); +// templateItem 对应的缓存 const currentFormDataMap = ref< Map ->(new Map()); // templateItem 对应的缓存 - -const previewUrl = ref(''); // 商城 H5 预览地址 - -const templateLibs = [] as DiyComponentLibrary[]; // 模板组件库 -const libs = ref(templateLibs); // 当前组件库 +>(new Map()); +// 商城 H5 预览地址 +const previewUrl = ref(''); +// 模板组件库 +const templateLibs = [] as DiyComponentLibrary[]; +// 当前组件库 +const libs = ref(templateLibs); /** 获取详情 */ async function getPageDetail(id: any) { @@ -58,38 +64,32 @@ async function getPageDetail(id: any) { }); try { formData.value = await getDiyTemplateProperty(id); - // 拼接手机预览链接 - const domain = import.meta.env.VITE_MALL_H5_DOMAIN; const accessStore = useAccessStore(); - previewUrl.value = `${domain}?templateId=${formData.value.id}&${accessStore.tenantId}`; + previewUrl.value = `${domain}?templateId=${formData.value.id}&tenantId=${accessStore.tenantId}`; } finally { hideLoading(); } } /** 模板选项切换 */ -// TODO @xingyu:貌似切换不对;“个人中心”切换不过去; -function handleTemplateItemChange(event: any) { - // 从事件对象中获取值 - const val = event.target?.value ?? event; - // 切换模版 - selectedTemplateItem.value = isNumber(val) - ? val - : templateItems.value.findIndex((item) => item.name === val.name); - +function handleTemplateItemChange(val: any) { + const changeValue = val.target.value; // 缓存模版编辑数据 currentFormDataMap.value.set( - templateItems.value[selectedTemplateItem.value]?.name || '', + templateItems.value[changeValue]!.name, currentFormData.value!, ); + // 切换模版 + selectedTemplateItem.value = changeValue; + // 读取模版缓存 const data = currentFormDataMap.value.get( - templateItems.value[selectedTemplateItem.value]?.name || '', + templateItems.value[changeValue]!.name, ); // 情况一:编辑模板 - if (val === 0) { + if (changeValue === 0) { libs.value = templateLibs; currentFormData.value = (isEmpty(data) ? formData.value : data) as | MallDiyPageApi.DiyPage @@ -99,22 +99,14 @@ function handleTemplateItemChange(event: any) { // 情况二:编辑页面 libs.value = PAGE_LIBS; - const pageData = isEmpty(data) - ? formData.value!.pages.find( - (page: MallDiyPageApi.DiyPage) => - page.name === templateItems.value[val]?.name, - ) - : data; - - // 如果找不到页面数据,使用默认值 - currentFormData.value = pageData - ? (pageData as - | MallDiyPageApi.DiyPage - | MallDiyTemplateApi.DiyTemplateProperty) - : ({ - property: '', - name: templateItems.value[val]?.name || '', - } as MallDiyPageApi.DiyPage); + currentFormData.value = ( + isEmpty(data) + ? formData.value!.pages.find( + (page: MallDiyPageApi.DiyPage) => + page.name === templateItems.value[changeValue]!.name, + ) + : data + ) as MallDiyPageApi.DiyPage | MallDiyTemplateApi.DiyTemplateProperty; } /** 提交表单 */ @@ -210,15 +202,8 @@ onMounted(async () => { size="large" @change="handleTemplateItemChange" > -