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)[]` |
| 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。

