Skip to content

Fab 悬浮按钮

可拖拽的悬浮操作按钮,常用于页面快捷操作入口。支持拖拽吸边、子按钮展开、毛玻璃效果等特性。

基础用法

vue
<template>
  <lk-fab icon="plus" @click="handleClick" />
</template>

<script setup>
const handleClick = () => {
  console.log('FAB clicked');
};
</script>

带子按钮

通过 actions 属性配置子按钮列表,点击主按钮展开。

vue
<template>
  <lk-fab v-model="expanded" :actions="actions" @action-click="handleActionClick" />
</template>

<script setup>
import { ref } from 'vue';

const expanded = ref(false);
const actions = [
  { key: 'scan', icon: 'qr-code-scan', label: '扫一扫' },
  { key: 'photo', icon: 'camera', label: '拍照' },
  { key: 'share', icon: 'share' },
];

const handleActionClick = action => {
  console.log('点击了', action.key);
};
</script>

展开方向

通过 direction 属性设置子按钮展开方向。

vue
<template>
  <lk-fab direction="up" :actions="actions" />
  <!-- 向上 -->
  <lk-fab direction="down" :actions="actions" />
  <!-- 向下 -->
  <lk-fab direction="left" :actions="actions" />
  <!-- 向左 -->
  <lk-fab direction="right" :actions="actions" />
  <!-- 向右 -->
</template>

毛玻璃效果

启用 blur 属性可获得 iOS 风格的毛玻璃效果。

vue
<template>
  <lk-fab blur />
</template>

禁用拖拽

设置 draggablefalse 可禁用拖拽功能。

vue
<template>
  <lk-fab :draggable="false" />
</template>

自定义位置

通过 position 属性设置初始位置。

vue
<template>
  <lk-fab position="bottom-right" />
  <lk-fab position="bottom-left" />
  <lk-fab position="top-right" />
  <lk-fab position="top-left" />
</template>

自定义颜色

支持自定义颜色值。

vue
<template>
  <lk-fab color="primary" />
  <lk-fab color="#ff6b6b" />
  <lk-fab color="#4ecdc4" />
</template>

Props

参数说明类型默认值
v-model是否展开子按钮booleanfalse
icon主按钮图标stringplus
activeIcon展开后的图标string-
position初始位置'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'bottom-right
direction子按钮展开方向'up' | 'down' | 'left' | 'right'up
actions子按钮配置FabAction[][]
draggable是否可拖拽booleantrue
magnetic拖拽后是否吸边booleantrue
size主按钮尺寸string | number112 (rpx)
actionSize子按钮尺寸string | number88 (rpx)
offset边距string | number32 (rpx)
color主题色stringprimary
blur毛玻璃效果booleantrue
zIndex层级number999
overlay展开时显示遮罩booleanfalse
closeOnOverlay点击遮罩关闭booleantrue
safeAreaInsetBottom安全区域底部偏移booleantrue
id根节点 idstring''
customClass根节点自定义类名string | object | array-
customStyle根节点自定义样式string | object-

Events

事件名说明回调参数
update:modelValue展开状态变化,用于 v-model(value: boolean)
click点击主按钮-
action-click点击可用子按钮(action: FabAction, event?: Event)
action-disabled点击禁用子按钮(action: FabAction, event?: Event)
open展开子按钮-
close收起子按钮-
overlay-click点击遮罩(event?: Event)
drag-start开始拖拽{ x, y, event }
drag-move拖拽中{ x, y, event }
drag-end结束拖拽{ x, y, event }
direction-change展开方向因空间不足自动修正(direction, preferred)

FabAction 数据结构

属性说明类型必填
key唯一标识string
icon图标名称string
label文字标签string
color自定义颜色string
disabled是否禁用boolean

样式变量

变量名说明默认值
--fab-color主按钮颜色var(--lk-color-primary)

发布验收

lk-fab 已纳入 needs-hardening showcase 回归,发布前按下面边界验收:

场景验收方式要点
展示台基线自动回归tests/visual/needs-hardening-showcase.spec.ts 校验组件路由、verified 状态与中风险标记
拖拽吸边人工验收drag-start/drag-move/drag-end 顺序稳定,吸边后不越过安全区
视觉降级人工验收blur、遮罩和展开方向在低端 App WebView 可接受

基于 MIT 协议开源 · 粤ICP备2022114240号-3

Fab 悬浮按钮

正在连接预览服务...

请先运行 pnpm run dev:h5