From 79eb7a7f166131c072e923c2197748fb22b60a85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Mon, 16 Nov 2026 14:02:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(jd):=20=E7=B1=BB=E7=9B=AE=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E8=B6=85=E8=A7=86=E7=AA=97=E5=AE=9A=E4=BD=8D=E9=92=B3=E5=88=B6?= =?UTF-8?q?=EF=BC=88B114=20=E5=B0=BE=E4=BB=B6=E5=85=A5=E5=BA=93=EF=BC=89?= =?UTF-8?q?=E2=80=94=E2=80=94=E9=9D=A2=E6=9D=BF=E6=89=93=E5=BC=80/?= =?UTF-8?q?=E6=A0=8F=E6=95=B0=E4=B8=8E=E6=90=9C=E7=B4=A2=E6=80=81=E5=8F=98?= =?UTF-8?q?=E5=8C=96=E5=90=8E=E6=8C=89=E7=9C=9F=E5=AE=9E=20rect=20?= =?UTF-8?q?=E9=87=8D=E7=AE=97=20left=20=E5=81=8F=E7=A7=BB=EF=BC=8C?= =?UTF-8?q?=E5=8F=B3=E7=BC=98=E8=B4=B4=E9=BD=90=E8=A7=86=E5=8F=A3=E5=90=8E?= =?UTF-8?q?=E4=B8=8B=E9=92=BB=E5=90=91=E5=B7=A6=E7=94=9F=E9=95=BF=EF=BC=8C?= =?UTF-8?q?=E6=9C=AB=E6=A0=8F=E4=B8=8D=E5=86=8D=E8=A2=AB=E7=AA=97=E7=BC=98?= =?UTF-8?q?=E8=A3=81=E6=8E=89=EF=BC=9B=E9=92=B3=E5=88=B6=E6=95=B0=E5=AD=A6?= =?UTF-8?q?=E6=8A=BD=E7=BA=AF=E5=87=BD=E6=95=B0=20jd-category-cascader-pos?= =?UTF-8?q?ition.ts=EF=BC=8B4=20=E4=BE=8B=E7=BA=AF=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/pages/jd/JdCategoryCascader.vue | 35 ++++++++++++++++-- .../pages/jd/jd-category-cascader-position.ts | 29 +++++++++++++++ .../jd-category-cascader-position.test.ts | 37 +++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 admin-frontend-vue/src/pages/jd/jd-category-cascader-position.ts create mode 100644 admin-frontend-vue/tests/jd-category-cascader-position.test.ts diff --git a/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue b/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue index 49384ee18..037c1e3bf 100644 --- a/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue +++ b/admin-frontend-vue/src/pages/jd/JdCategoryCascader.vue @@ -10,13 +10,14 @@ * 全路径);树外命中(已落库但京麦类目体系变更后的历史名)从 options 兜底段选,语义 * 同旧版第三栏。「全部类目」行=清选;触发框已选时出 × 清除;面板外点透明遮罩关闭。 * 零依赖自绘(radio 圆点/箭头都是 CSS),无 element 依赖。 */ -import { computed, ref } from 'vue' +import { computed, nextTick, ref, watch } from 'vue' import { jdCategoryChildren, jdCategoryRoots, jdCategorySearchLeaves, type JdCategoryNode, } from './jd-category-tree.ts' +import { clampPanelLeftX } from './jd-category-cascader-position.ts' const props = defineProps<{ /** 已落库末级类目全集(/categories 现算,页面传入)——只作**树外兜底**(搜索无树内 @@ -33,6 +34,25 @@ const open = ref(false) const activePath = ref([]) const searchText = ref('') +/** 面板水平定位钳制(2026-11-16「超出视窗了」):触发框在筛选行中部偏右时,锚 left:0 + * 的多栏面板会伸出视窗右缘。打开与栏数/搜索态变化后用真实 rect 重算 left 偏移—— + * 右缘贴齐视口后继续下钻即向左生长,不再截掉末栏。钳制数学在 + * ./jd-category-cascader-position.ts(纯函数,tests/jd-category-cascader-position.test.ts)。 */ +const hostRef = ref(null) +const panelRef = ref(null) +const panelOffsetX = ref(0) + +function reposition(): void { + const host = hostRef.value + const panel = panelRef.value + if (!host || !panel) return + panelOffsetX.value = clampPanelLeftX({ + hostLeft: host.getBoundingClientRect().left, + panelWidth: panel.offsetWidth, + viewportWidth: window.innerWidth, + }) +} + const roots = jdCategoryRoots() /** 树内全部末级名集合(判定 options 哪些是「树外历史」)。 */ const treeLeafNames = new Set( @@ -68,6 +88,14 @@ const fallbackOptions = computed(() => { .filter((option) => option.name.toLowerCase().includes(keyword)) }) +/** 栏数随下钻动态 1~4、搜索态切单栏 ⇒ 面板宽度变,开着就要重算偏移(下钻向左生长)。 */ +watch( + () => [columns.value.length, searching.value] as const, + () => { + if (open.value) nextTick(reposition) + }, +) + function toggle(): void { if (open.value) { close() @@ -76,6 +104,7 @@ function toggle(): void { activePath.value = [] searchText.value = '' open.value = true + nextTick(reposition) } function close(): void { @@ -110,7 +139,7 @@ function clear(): void {