fix(jd-collect): 建单页类目级联改 fixed 浮层——2026-11-16 形态核对实录(vite 5173 真页验收):建单页侧栏仅 ~370px,原 absolute+left:0/right:0 把三栏压到每栏 ~120px(一级名截成「服饰…」);首改容器溢出展开虽舒展,却把文档撑出横向滚动条(absolute 溢出必然进 scrollWidth)。终版按京麦本尊浮层形态:面板 fixed + toggle() 打开瞬间按触发框 getBoundingClientRect 定位(top=bottom+4、left 钳进视口,宽 min(652px, 100vw-16px),三栏 200+200+250 刚好舒展),fixed 不撑文档横向滚动——真页实测 docHScroll=false、面板 20/219/652、勾选 2 类目触发框「已选 2 个类目」+按钮「获取选中类目数据」、清空/搜索/空态文案全过。测试环境(happy-dom)rect 全 0,panelPos 落视口原点不影响 mount 断言。判据:npx vue-tsc --noEmit rc=0;catch-silence/endpoints/jd-collect-tab/jd-category-tree 22 绿;mount 9 绿

This commit is contained in:
2026-11-16 02:38:31 +08:00
parent d680a0beca
commit 301e3c5ecb
@@ -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<HTMLElement | null>(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 {
<template>
<div class="cat-cascader">
<button
ref="triggerRef"
class="cat-trigger"
type="button"
:class="{ open, filled: modelValue.length > 0 }"
@@ -107,7 +122,7 @@ function clear(): void {
<!-- 面板外点透明遮罩关闭(零 document 监听器,无泄漏面)。 -->
<div v-if="open" class="cat-mask" @click="close"></div>
<div v-if="open" class="cat-panel">
<div v-if="open" class="cat-panel" :style="panelPos">
<!-- 第一栏:静态一级导航(radio 形状照京麦,点选只展开不落值)。 -->
<div class="cat-col">
<div
@@ -249,14 +264,14 @@ function clear(): void {
z-index: 2550;
}
.cat-panel {
position: absolute;
top: calc(100% + 4px);
left: 0;
right: 0;
/* fixed 浮层:位置由 toggle() 按触发框实际位置写 :style(top/left)。
* 建单页侧栏只有 ~370px,贴容器宽会把三栏压到每栏 ~120px(一级名截成「服饰…」);
* 三栏内容 200+200+250=650,宽度固定 652 向右展开,fixed 不撑文档横向滚动条。 */
position: fixed;
width: min(652px, calc(100vw - 16px));
z-index: 2560;
display: flex;
align-items: stretch;
max-width: min(720px, 90vw);
border: 1px solid #d8e3ee;
border-radius: 10px;
background: #ffffff;