更新记录

1.0.9(2023-12-13)

修复bug

1.0.8(2023-12-13)

修复bug

1.0.7(2023-06-09)

增加悬浮球的层级设置

查看更多

平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
app-vue app-nvue ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari

next-drag-fab --悬浮拖拽按钮uni-fab的加强版(同时支持vue3 vue2语法,全平台可用)

官方uni-fab的增强版,兼并uni-fab的原有功能且比其功能更加强大,可拖拽,可配置; 遇到问题或有建议可以加入QQ群(455948571)反馈
如果觉得组件不错,给五星鼓励鼓励咯!

使用

从uniapp插件市场导入

<template>
    <view class="container">
        <uni-card :is-shadow="false" is-full>
            <text class="uni-h6">uni-ui 规范颜色色板,通过内置样式快速指定元素前景和背景色。</text>

        </uni-card>

        <uni-section title="基本功能" subTitle="点击按钮,切换 fab 不同状态" type="line">
            <view class="warp">
                <button class="button" type="primary" @click="switchBtn(0)">切换菜单方向({{ directionStr }})</button>
                <button class="button" type="primary" @click="switchBtn('lb')">左下角显示</button>
                <button class="button" type="primary" @click="switchBtn('rb')">右下角显示</button>
                <button class="button" type="primary" @click="switchBtn('lt')">左上角显示</button>
                <button class="button" type="primary" @click="switchBtn('rt')">右上角显示</button>
                <button class="button" type="primary" @click="switchBtn('lock')">锁定位置,不可以移动</button>
                <button class="button" type="primary" @click="switchBtn('unlock')">解除锁定位置</button>
                <button class="button" type="primary" @click="switchBtn('dock')">锁定在边界内可视区域</button>
                <button class="button" type="primary" @click="switchColor">修改颜色</button>
            </view>
        </uni-section>
        <next-drag-fab
            v-if="showNextDragFab"
            ref="nextDragFabRef"
            :isDock="isDock"
            :isLock="isLock"
            :pattern="pattern"
            :content="content"
            :horizontal="horizontal"
            :vertical="vertical"
            :direction="direction"
            :defpositon="defpositon"
            @trigger="trigger"
        />
    </view>

</template>

vue3 + ts 使用

<script lang="ts" setup>
import { ref, unref, nextTick } from 'vue'

const nextDragFabRef = ref()
const title = ref('next-drag-fab')
const directionStr = ref('垂直')
const horizontal = ref('left')
const vertical= ref('bottom')
const direction = ref('horizontal')
const defpositon = ref('rb')
const isDock = ref(false)
const isLock = ref(false)
const pattern = ref({
    color: '#3c3e49',
    backgroundColor: '#fff',
    selectedColor: '#f9ae3d',
    buttonColor: '#f9ae3d',
    iconColor: '#fff'
})
const showNextDragFab = ref(true)
const is_color_type = ref(false)
const content = ref([
            {
                text: '测试1',
                active: false,
                iconPath: 'https://www.yisuxiao.com/static/server/common/tab/tab1-0.png', 
                selectedIconPath: 'https://www.yisuxiao.com/static/server/common/tab/tab1-1.png'},
            {
                text: '测试2',
                active: false,
                iconPath: 'https://www.yisuxiao.com/static/server/common/tab/tab2-0.png', 
                selectedIconPath: 'https://www.yisuxiao.com/static/server/common/tab/tab2-1.png'},
            {
                text: '测试3',
                active: false,
                iconPath: 'https://www.yisuxiao.com/static/server/common/tab/tab3-0.png', 
                selectedIconPath: 'https://www.yisuxiao.com/static/server/common/tab/tab3-1.png'}
        ])

function trigger(e) {
    console.log(e)
    unref(content)[e.index].active = !e.item.active
    uni.showModal({
        title: '提示',
        content: `您${unref(content)[e.index].active ? '选中了' : '取消了'}${e.item.text}`,
        success: function(res) {
            if (res.confirm) {
                console.log('用户点击确定')
            } else if (res.cancel) {
                console.log('用户点击取消')
            }
        }
    })
}

function switchBtn(val) {
    showNextDragFab.value = false
    nextTick(() => {
        if (val === 0) {
            direction.value = unref(direction) === 'horizontal' ? 'vertical' : 'horizontal'
            directionStr.value = unref(direction) === 'horizontal' ? '垂直' : '水平'
        } else if (val === 'lock') {
            isLock.value = true
        } else if (val === 'unlock') {
            isLock.value = false
        } else if (val === 'dock') {
            isDock.value = true
        } else {
            defpositon.value = val
        }
        showNextDragFab.value = true
    })
}
function switchColor() {
    is_color_type.value = !unref(is_color_type)
    if (unref(is_color_type)) {
        pattern.value.iconColor = '#aaa'
        pattern.value.buttonColor = '#fff'
    } else {
        pattern.value.iconColor = '#fff'
        pattern.value.buttonColor = '#f9ae3d'
    }
}
</script>

vue2 同样支持,在这里不再写demo

预览


功能预览

参数

next-drag-fab Props

可选参数属性列表

参数名 说明 类型 是否必填 默认值 可选值
pattern 可选样式配置项 Object - -
horizontal 水平对齐方式。left:左对齐,right:右对齐 String right left
vertical 垂直对齐方式。bottom:下对齐,top:上对齐 String bottom top
direction horizontal String vertical horizontal
popMenu 是否使用弹出菜单 Boolean true false
content 展开菜单内容配置项 Array [] -
defpositon 初始化的位置 lt 左上 lb 左下 rt 右上 rb右下 String rb lt,lb,rt
edge 边界大小(单位是px) Number 10 -
fontSize 弹出菜单文字大小(单位是px) Number 12 -
size fab的大小 (单位是px) Number 40 -
isLock 是否锁定 Boolean false true
isDock 显示在边界内 Boolean true false
zIndex 层级 Number 999 -

pattern配置项:

可选参数属性列表

参数名 说明 类型 是否必填 默认值 可选值
color 文字默认颜色 String #3c3e49 -
selectedColor 文字选中时的颜色 String #f9ae3d -
backgroundColor 背景色 String #ffffff -
buttonColor 按钮背景色 String #f9ae3d -
icon 自定义图标,图标来自 uni-icons String plusempty -

content配置项:

可选参数属性列表

参数名 说明 类型 是否必填 默认值 可选值
iconPath 图片路径 String - -
selectedIconPath 选中后图片路径 String - -
text 文字 String - -
active 是否选中当前 String - -

本插件使用的iconfont是uni-icons可以参考如下(uni-iocns使用说明

Event 事件

事件名 说明 类型 回调参数
trigger 菜单收起时返回的筛选结果 emit array
fabClick 悬浮按钮点击事件 emit array

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问