# FloatingPanel 悬浮面板
固定底部的悬浮面板,按锚点档位吸附(锚点几何 / 吸附换算在
@lh-ui/share/core/floating-panel),根类 lh-floating-panel,
样式来自 share styles/floating-panel。
悬浮面板(锚点吸附 / 受控档位 / 内容可拖 / 安全区)
<template>
<div class="demo-col" style="gap: 18px; max-width: 480px">
<div class="demo-row" style="gap: 8px; flex-wrap: wrap">
<LhButton size="small" @click="anchorIndex = 0">收到最低档</LhButton>
<LhButton size="small" @click="anchorIndex = 1">中档</LhButton>
<LhButton size="small" @click="anchorIndex = 2">展开最高档</LhButton>
<LhButton size="small" @click="contentDraggable = !contentDraggable">内容可拖({{ contentDraggable }})</LhButton>
</div>
<div class="demo-row" style="gap: 8px; flex-wrap: wrap">
<LhButton size="small" @click="safeArea = !safeArea">安全区留白({{ safeArea }})</LhButton>
<LhButton size="small" @click="disabled = !disabled">禁用({{ disabled }})</LhButton>
</div>
<span class="demo-note">
档位:{{ anchorIndex }} / 实时高度:{{ height }}px(anchors:60px / 40% / 80% 视口高)
</span>
<LhFloatingPanel
:anchors="anchors"
:model-value.sync="anchorIndex"
:content-draggable="contentDraggable"
:safe-area-inset-bottom="safeArea"
:disabled="disabled"
label="筛选面板"
@change="onChange"
@height-change="onHeightChange"
>
<div style="padding: 12px; display: flex; flex-direction: column; gap: 12px">
<p class="demo-note" style="margin: 0">拖动头部把手或内容区改变面板高度,松手吸附最近锚点。</p>
<p class="demo-note" style="margin: 0">头部具名插槽可自定义把手;contentDraggable=false 时仅头部可拖。</p>
</div>
</LhFloatingPanel>
</div>
</template>
<script>
export default {
data: () => ({
anchors: [60, '40%', '80%'],
anchorIndex: 1,
contentDraggable: true,
safeArea: true,
disabled: false,
height: 0,
}),
methods: {
onChange(index) {
this.anchorIndex = index
},
onHeightChange(height) {
this.height = Math.round(height)
},
},
}
</script>
# 锚点与吸附
anchors 为高度数组:数值 = px,'40%' 形式字符串 = 视口高度百分比;
内部归一为升序 px(normalizeAnchors)。拖拽头部把手时高度
computeDragHeight 跟手(--dragging 关闭高度过渡),松手按
resolveSnapIndex 吸附到最近锚点并抛 change / update:modelValue:
<LhFloatingPanel :anchors="[60, '40%', '80%']" @change="onChange" />
# 受控档位
modelValue 为当前吸附档位下标(0 起,按锚点升序);受控优先 ——
外部推进覆盖内部档位,拖拽提交仅抛事件(.sync 回流裁决):
<LhFloatingPanel :anchors="[60, '40%']" :model-value.sync="index" />
# 拖拽区域与安全区
contentDraggable(默认 true)开启内容区拖拽,false 时仅头部
把手可拖;safeAreaInsetBottom(默认 true)追加底部安全区留白
(--safe-area 修饰);disabled 禁用拖拽(--disabled 修饰)。
头部具名插槽 header 默认渲染 __handle 把手条,可自定义。
# Props
| 属性 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| anchors | 吸附高度数组(数值 px 或 '百分比' 字符串) | (number \| string)[] | [60, '40%'] |
| modelValue | 当前吸附档位下标(受控;未传默认最高档) | number | — |
| contentDraggable | 内容区可拖拽(false 时仅头部) | boolean | true |
| safeAreaInsetBottom | 底部安全区留白 | boolean | true |
| disabled | 禁用拖拽 | boolean | false |
| label | 无障碍可达名称(未传走默认「悬浮面板 第 i/N 档」) | string | — |
# Events
| 事件 | 说明 | 回调参数 |
|---|---|---|
| update:modelValue | 档位变化(受控 .sync) | anchorIndex: number |
| change | 吸附档位变化 | anchorIndex: number |
| heightChange | 面板高度变化(拖拽跟手 / 吸附落位) | height: number |
# Slots
| 插槽 | 说明 |
|---|---|
| header | 头部把手区(默认渲染 lh-floating-panel__handle 指示条) |
| default | 面板内容 |
# 无障碍
根元素 role="region" + aria-label(getFloatingPanelAria 生成
「悬浮面板 第 i/N 档」,label 可覆盖)。
Copyright © 2024-2026 风默文学 | 宁ICP备2024006574号 |
苏公网安备32040002010537