diff --git a/frontend-vue/src/pages/jd/JdCategoryCascader.vue b/frontend-vue/src/pages/jd/JdCategoryCascader.vue index fdf63aae8..efcc72853 100644 --- a/frontend-vue/src/pages/jd/JdCategoryCascader.vue +++ b/frontend-vue/src/pages/jd/JdCategoryCascader.vue @@ -28,6 +28,10 @@ const emit = defineEmits<{ (event: 'change', value: string[]): void }>() const open = ref(false) const activeRoot = ref('') const searchText = ref('') +/** 触发框元素:打开面板瞬间按它的实际位置给浮层定位(fixed 不撑文档横向滚动)。 */ +const triggerRef = ref(null) +/** 面板浮层定位(fixed 的 top/left,px 字符串)。 */ +const panelPos = ref({ top: '0px', left: '0px' }) const roots = jdCategoryNavRoots() /** 第二栏=点亮一级的静态二级;无静态子级的一级不出第二栏。 */ @@ -55,6 +59,16 @@ function toggle(): void { } activeRoot.value = '' searchText.value = '' + // 面板是 fixed 浮层(京麦本尊形态:窄触发框 + 视口级宽面板,不撑文档横向滚动条), + // 打开瞬间按触发框实际位置定位;测试环境无真实布局时 rect 全 0,top/left 落在视口原点即可。 + const rect = triggerRef.value?.getBoundingClientRect() + if (rect) { + const width = Math.min(652, Math.max(320, window.innerWidth - 24)) + panelPos.value = { + top: `${Math.round(rect.bottom + 4)}px`, + left: `${Math.round(Math.max(8, Math.min(rect.left, window.innerWidth - width - 8)))}px`, + } + } open.value = true } @@ -88,6 +102,7 @@ function clear(): void {