From 5795eab75c9277d76516a6c00ddf3d685c18b44c Mon Sep 17 00:00:00 2001 From: ah-max150 Date: Sun, 11 Oct 2026 01:30:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20ColPage=20=E8=A7=A3=E5=8C=85=E4=BE=A7?= =?UTF-8?q?=E6=A0=8F=20isCollapsed=20=E4=BB=A5=E4=BF=AE=E5=A4=8D=E5=85=AC?= =?UTF-8?q?=E5=8F=B8=E5=88=97=E8=A1=A8=E5=B8=83=E5=B1=80=E8=AE=B0=E5=BF=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../channel/pdd/components/PddShopColPage.vue | 2 +- .../company/components/CompanyColPage.vue | 4 +- .../src/views/ec/components/EcShopColPage.vue | 2 +- .../src/components/col-page/col-page.vue | 82 +++++++++++++++---- 4 files changed, 68 insertions(+), 22 deletions(-) diff --git a/apps/web/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue b/apps/web/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue index 4c3023bc..8a8b243f 100644 --- a/apps/web/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue +++ b/apps/web/apps/web-antd/src/views/channel/pdd/components/PddShopColPage.vue @@ -84,7 +84,7 @@ const { width: leftWidth, collapsed: leftCollapsed } = > import type { ColPageProps } from './types'; -import { computed, nextTick, onMounted, ref, useSlots, watch } from 'vue'; +import { + computed, + nextTick, + onMounted, + ref, + toValue, + useSlots, + watch, +} from 'vue'; import { ResizableHandle, @@ -61,8 +69,13 @@ type LeftPanelExpose = { const leftPanelRef = ref(null); -/** 拖拽写回时跳过,避免 resize↔emit 回环 */ +/** 拖拽/程序化同步时跳过写回,避免回环 */ let syncingFromProp = false; +/** + * Panel 首次 layout 会在 lastSize=null 时误抛 expand, + * 若立刻写回会把持久化的 collapsed=true 冲掉。就绪后再接受用户操作。 + */ +let layoutReady = false; function isLeftPanelCollapsed() { const flag = leftPanelRef.value?.isCollapsed; @@ -88,7 +101,7 @@ function isCollapsedSize(size: number) { /** 把展开宽度写回父级(忽略收起态的小宽度) */ function commitLeftWidth(size: number) { - if (syncingFromProp) return; + if (!layoutReady || syncingFromProp) return; if (!Number.isFinite(size) || isCollapsedSize(size)) return; if (Math.abs(size - props.leftWidth) < 0.05) return; emit('update:leftWidth', size); @@ -102,10 +115,14 @@ function onLayout(sizes: number[]) { } function onLeftCollapse() { + if (!layoutReady || syncingFromProp) return; + if (props.leftCollapsed) return; emit('update:leftCollapsed', true); } function onLeftExpand() { + if (!layoutReady || syncingFromProp) return; + if (!props.leftCollapsed) return; emit('update:leftCollapsed', false); } @@ -113,9 +130,23 @@ function syncCollapsedFromProp(collapsed: boolean) { if (!leftPanelRef.value) return; const current = isLeftPanelCollapsed(); if (collapsed && !current) { - collapseLeft(); + syncingFromProp = true; + try { + collapseLeft(); + } finally { + void nextTick(() => { + syncingFromProp = false; + }); + } } else if (!collapsed && current) { - expandLeft(); + syncingFromProp = true; + try { + expandLeft(); + } finally { + void nextTick(() => { + syncingFromProp = false; + }); + } } } @@ -138,19 +169,26 @@ function applyWidthFromProp() { } } +async function hydrateLayoutFromProps() { + await nextTick(); + if (props.leftCollapsed) { + syncCollapsedFromProp(true); + } else { + applyWidthFromProp(); + } + // 再等一拍,吞掉首帧误报的 expand/collapse + await nextTick(); + layoutReady = true; +} + onMounted(() => { - void nextTick(() => { - if (props.leftCollapsed) { - syncCollapsedFromProp(true); - } else { - applyWidthFromProp(); - } - }); + void hydrateLayoutFromProps(); }); watch( () => props.leftCollapsed, (collapsed) => { + if (!layoutReady) return; syncCollapsedFromProp(!!collapsed); }, ); @@ -159,6 +197,7 @@ watch( watch( () => props.leftWidth, () => { + if (!layoutReady) return; void nextTick(applyWidthFromProp); }, ); @@ -194,14 +233,21 @@ defineExpose({ @collapse="onLeftCollapse" @expand="onLeftExpand" > -