FloatingPanel 悬浮面板
悬浮面板组件:fixed 底部面板,头部拖拽跟手、松手吸附到最近锚点。 锚点几何(百分比换算 / 最近锚点 / 吸附判定 / 拖拽钳制)全部消费 @lh-ui/share/core/floating-panel 纯函数;视口高度经 @/adapter/platform 取(H5 innerHeight / 小程序 windowHeight),组件层零 uni API。 服务筛选、详情承载、底部操作等场景。
平台差异(登记):视口高度取端侧适配(
getLhWindowInfo: H5 走window.innerHeight,小程序走uni.getWindowInfo().windowHeight); 拖拽统一为 touch 事件(H5 与 MP 一致,touches[0].clientY取坐标); 面板 fixed 定位落在根节点(share styles/floating-panel 的净化产物), 高度由内联 style 承载,拖拽中叠加--dragging修饰关闭过渡实现跟手。
基础用法
默认锚点 [60, '40%'](60px 与视口高度的 40% 两档):
<template>
<lh-floating-panel>
<view>面板内容</view>
</lh-floating-panel>
</template>自定义锚点
anchors 为高度数组:数值 = px,字符串 '40%' = 视口高度百分比; 拖拽松手后吸附到最近锚点:
<lh-floating-panel :anchors="[120, 320, 560]" @change="onChange" />受控档位(v-model)
modelValue 传值即受控:外部推进档位,面板高度同步;拖拽松手派发 update:modelValue / change:
<lh-floating-panel v-model="index" :anchors="[80, 400]" />仅头部可拖拽
contentDraggable(默认 true)为 false 时只有头部把手区响应拖拽, 内容区(如滚动列表)不再接管拖拽:
<lh-floating-panel :content-draggable="false" :anchors="[100, 300]">
<scroll-view scroll-y>长内容滚动</scroll-view>
</lh-floating-panel>禁用与安全区
<lh-floating-panel disabled :anchors="[100, 300]" />
<lh-floating-panel :safe-area-inset-bottom="false" :anchors="[100, 300]" />自定义头部
header 插槽替换默认把手(插槽内容仍是拖拽区):
<lh-floating-panel :anchors="[100, 300]">
<template #header>
<view>自定义头部</view>
</template>
</lh-floating-panel>Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| anchors | 吸附高度数组(数值 px 或 '百分比' 字符串) | (number | string)[] | [60, '40%'] |
| modelValue | 当前吸附档位下标(受控) | number | — |
| contentDraggable | 内容区可拖拽 | boolean | true |
| safeAreaInsetBottom | 底部安全区留白 | boolean | true |
| disabled | 禁用拖拽 | boolean | false |
| customClass | 自定义类名(透传到根节点) | string | — |
| sx | sx 快速布局属性 | LhSxProps | — |
Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| update:modelValue | 档位变化(受控同步) | (index: number) |
| change | 松手吸附后档位变化 | (index: number) |
| heightChange | 面板高度变化(拖拽跟手 + 吸附) | (height: number) |
Slots
| 插槽 | 说明 |
|---|---|
| header | 头部拖拽区(默认渲染 __handle 把手) |
| default | 面板内容 |
无障碍
根节点携带 role="region" 语义,aria-label 由 share core 的 getFloatingPanelAria 生成(默认「悬浮面板 第 i / N 档」),禁用时落 aria-disabled。

