Skip to content

ActionSheet 操作菜单组件

本组件用于从底部弹出一个操作菜单,供用户选择并返回结果。

温馨提示

本项目参考了 uView-Plus 开源项目的组件开发方式,基于 Vue 3 和 TypeScript 实现了自定义组件。目前该组件仍处于测试阶段。
感谢 uView-Plus 开源项目及其团队成员的贡献,他们的组件开发思路为本项目提供了宝贵地参考。如果需要了解更多组件开发细节,可以参考uView-Plus的 actionSheet组件 的代码实现。

平台差异说明

APP(vue)H5微信小程序

基本使用示例

html
<!-- 全局使用 -->
<hy-action-sheet v-model="show" :actions="actions"></hy-action-sheet>
<!-- 单个组件引入 -->
<HyActionSheet v-model="show" :actions="actions"></HyActionSheet>
ts
import { HyActionSheet, IActionSheetAction } from "hy-app";
import { ref } from 'vue'
const show = ref(true);

const actions = ref<IActionSheetAction[]>([
    {
        name: '选项1'
    },
    {
        name: '选项2'
    },
    {
        name: '选项3'
    },
])

设置选项卡

  • 通过在 actions 数组的对象中添加 name 属性,来显示选项文字
  • 通过在 actions 数组的对象中添加 loading 属性,来显示加载动画
  • 通过在 actions 数组的对象中添加 disabled 属性,来禁用点击事件
  • 通过在 actions 数组的对象中添加 sub 属性,来显示小标题提示
  • 通过在 actions 数组的对象中添加 color 属性,来设置字体颜色
vue
<template>
    <hy-action-sheet v-model="show" :actions="actions"></hy-action-sheet>
</template>
ts
import { ref } from 'vue'
import type { IActionSheetAction } from "hy-app";
const show = ref(true);

const actions = ref<IActionSheetAction[]>([
    {
        name: '选项1',
        loading: true,
        color: "red"
    },
    {
        name: '选项2',
        disabled: true,
    },
    {
        name: '选项3',
        sub: '描述信息',
    },
])

自定义面板

  • 通过panels自定义分享页面

提示

panels支持一位数组和二维数组

vue
<template>
    <hy-action-sheet v-model="show" :panels="panels" title="分享给" titleAlign="left"></hy-action-sheet>
</template>
ts
import { ref } from 'vue';

const show = ref(true);
const panels = ref([
    [
        {
            iconUrl:
                '//img12.360buyimg.com/imagetools/jfs/t1/122016/33/6657/1362/5f0692a1E8708d245/e47299e5945a6956.png',
            title: '微信好友',
        },
        {
            iconUrl:
                '//img12.360buyimg.com/imagetools/jfs/t1/122016/33/6657/1362/5f0692a1E8708d245/e47299e5945a6956.png',
            title: '微信好友',
        },
    ],
    [
        {
            iconUrl:
                '//img12.360buyimg.com/imagetools/jfs/t1/122016/33/6657/1362/5f0692a1E8708d245/e47299e5945a6956.png',
            title: '微信好友',
        },
        {
            iconUrl:
                '//img12.360buyimg.com/imagetools/jfs/t1/122016/33/6657/1362/5f0692a1E8708d245/e47299e5945a6956.png',
            title: '微信好友',
        },
    ],
])

设置标题

  • 通过title,显示标题
  • 通过titleAlign设置标题位置
html
<template>
    <hy-action-sheet v-model="show" title="我是标题" titleAlign="left"></hy-action-sheet>
</template>

显示取消按钮

  • 通过cancel-text设置文字显示底部取消按钮
html
<template>
    <hy-action-sheet v-model="show" :actions="actions" cancel-text="取消"></hy-action-sheet>
</template>

<script setup lang="ts">
    import type { IActionSheetAction } from "hy-app";
    import { ref } from 'vue'
    const show = ref(true);

    const actions = ref<IActionSheetAction[]>([
        {
            name: '选项1'
        },
        {
            name: '选项2'
        },
        {
            name: '选项3'
        },
    ])
</script>

自定义内容面板

html
<template>
    <hy-action-sheet v-model="show" title="我是标题">
        我是内容
    </hy-action-sheet>
</template>

<script setup lang="ts">
    import { ref } from 'vue'
    const show = ref(true);
</script>

API

参数说明类型默认值
v-model是否展示booleanfalse
title标题string-
titleAlign标题文字位置center|left|rightcenter
description弹框动画持续时间number200
actions菜单选项IActionSheetAction[]-
panels自定义面板项,可以为字符串数组,也可以为对象数组,如果为二维数组,则为多行展示Array<IActionSheetPanel | IActionSheetPanel[]>-
cancelText取消按钮的文字,不为空时显示按钮string-
closeOnClickAction点击某个菜单项时是否关闭弹窗booleantrue
safeAreaInsetBottom是否开启底部安全区适配booleanfalse
closeOnClickOverlay点击遮罩是否允许关闭,见上方文档示例booleantrue
round圆角值string | number20px
zIndex菜单层级number100
customStyle自定义外部样式CSSProperties-
customClass自定义外部类名string-
customHeaderClass自定义标题类名string-

actions

参数说明类型默认值
name选项名称string-
sub描述信息string-
color字体颜色string-
disabled是否禁用boolean-
loading是否加载中boolean-

panels

参数说明类型默认值
name名称string-
iconUrl图片地址string-

Events

事件名说明回调参数
select点击选项时触发菜单选项或自定义面板一维数组 (item: 选项对象, index: 选项下标),自定义面板二维数组(item: 选项对象, rowIndex: 选项行下标, colIndex 选项列下标)
open弹出层打开时触发-
close弹出层关闭时触发-
cancel点击取消按钮时触发-

Slots

插槽名说明接收值
default面板默认插槽-
10:00