1.0.3 • Published 2 months ago

@tanzhenxing/zx-fab v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

ZX-FAB 悬浮按钮组件

一个功能丰富、高度可定制的悬浮按钮组件,支持多种位置、方向和动画效果。

功能特点

  • 支持四个角落定位(左上、右上、左下、右下)
  • 支持水平和垂直方向展开
  • 多种动画效果(缩放、淡入淡出、滑动)
  • 高度可定制的样式
  • 可自定义按钮大小、图标和颜色

基本用法

<template>
  <zx-fab 
    :content="fabItems" 
    @trigger="handleTrigger" 
    @fabClick="handleFabClick"
  />
</template>

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

const fabItems = ref([
  {
    icon: 'star',
    text: '收藏',
    active: false
  },
  {
    icon: 'share',
    text: '分享',
    active: false
  },
  {
    icon: 'heart',
    text: '喜欢',
    active: false,
    selectedIcon: 'heart-fill'
  }
]);

const handleTrigger = ({ index, item }) => {
  console.log('点击了菜单项', index, item);
  // 可以在这里处理菜单项的激活状态
  fabItems.value[index].active = !fabItems.value[index].active;
};

const handleFabClick = () => {
  console.log('点击了主按钮');
};
</script>

属性说明

属性名类型默认值说明
patternObject{}样式模式对象,包含颜色等样式配置
horizontalString'left'水平位置,可选值: 'left', 'right'
verticalString'bottom'垂直位置,可选值: 'top', 'bottom'
directionString'horizontal'展开方向,可选值: 'horizontal', 'vertical'
contentArray[]菜单项数组
showBooleanfalse初始是否展开菜单
popMenuBooleantrue是否显示弹出菜单
mainButtonSizeNumber/String55主按钮尺寸
itemButtonSizeNumber/String45菜单项按钮高度
shadowBooleantrue是否显示阴影
zIndexNumber10组件z-index值
animationTypeString'scale'动画类型,可选值: 'scale', 'fade', 'slide'
animationDurationNumber300动画持续时间(毫秒)
mainIconString'plus'主按钮图标
closeOnClickOutsideBooleantrue点击外部是否关闭菜单
marginNumber/String15边距
bottomNumber/String30底部距离
borderRadiusNumber/String45圆角大小

pattern 对象属性

属性名类型默认值说明
colorString'#3c3e49'菜单项文字和图标颜色
selectedColorString'#007AFF'菜单项选中时文字和图标颜色
backgroundColorString'#fff'菜单背景色
buttonColorString'#007AFF'主按钮背景色
iconColorString'#fff'主按钮图标颜色

content 数组项属性

属性名类型必填说明
iconString菜单项图标名称
selectedIconString菜单项选中时图标名称
textString菜单项文字
activeBoolean菜单项是否激活
iconSizeString菜单项图标大小,默认为'55rpx'
autoCloseBoolean点击菜单项后是否自动关闭,默认true

事件

事件名说明回调参数
fabClick点击主按钮时触发-
trigger点击菜单项时触发{index: 索引, item: 菜单项}
open菜单打开时触发-
close菜单关闭时触发-

方法

通过ref可以获取组件实例并调用以下方法:

方法名说明参数
open打开菜单-
close关闭菜单-

示例

不同位置

<!-- 左下角 (默认) -->
<zx-fab :content="items" horizontal="left" vertical="bottom" />

<!-- 右下角 -->
<zx-fab :content="items" horizontal="right" vertical="bottom" />

<!-- 左上角 -->
<zx-fab :content="items" horizontal="left" vertical="top" />

<!-- 右上角 -->
<zx-fab :content="items" horizontal="right" vertical="top" />

不同方向

<!-- 水平方向展开 (默认) -->
<zx-fab :content="items" direction="horizontal" />

<!-- 垂直方向展开 -->
<zx-fab :content="items" direction="vertical" />

自定义样式

<zx-fab 
  :content="items"
  :pattern="{
    color: '#333',
    selectedColor: '#ff6700',
    backgroundColor: '#f5f5f5',
    buttonColor: '#ff6700',
    iconColor: '#fff'
  }"
  :mainButtonSize="60"
  :itemButtonSize="50"
  :shadow="true"
  :borderRadius="30"
/>

不同动画效果

<!-- 缩放动画 (默认) -->
<zx-fab :content="items" animationType="scale" />

<!-- 淡入淡出动画 -->
<zx-fab :content="items" animationType="fade" />

<!-- 滑动动画 -->
<zx-fab :content="items" animationType="slide" />

自定义图标

<zx-fab :content="items" mainIcon="menu" />

禁用外部点击关闭

<zx-fab :content="items" :closeOnClickOutside="false" />

程序控制打开关闭

<template>
  <view>
    <button @click="openMenu">打开菜单</button>
    <button @click="closeMenu">关闭菜单</button>
    <zx-fab ref="fabRef" :content="items" />
  </view>
</template>

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

const fabRef = ref(null);

const openMenu = () => {
  fabRef.value.open();
};

const closeMenu = () => {
  fabRef.value.close();
};
</script>
1.0.2

2 months ago

1.0.1

3 months ago

1.0.3

2 months ago

1.0.0

12 months ago