1.5.1 • Published 1 year ago

@wines/actionsheet v1.5.1

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

@wines/actionsheet

ActionSheet 上拉菜单

从底部弹出的模态框,提供和当前场景相关的操作菜单。

使用指南

在 page.json 中引入组件

{
  "navigationBarTitleText": "ActionSheet",
  "usingComponents": {
    "wux-button": "@wines/button",
    "wux-actionsheet": "@wines/actionsheet"
  }
}
import './index.less';
import { $wuxActionSheet } from '@wines/actionsheet';

Page({
  data: {},
  onLoad() {
    /** */
  },
  showActionSheet1() {
    void wx.showActionSheet({
      itemList: ['实例菜单', '实例菜单'],
    });
  },
  timeout: 0 as number,
  showActionSheet3() {
    if (this.timeout) clearTimeout(this.timeout);
    const hideSheet = $wuxActionSheet().showSheet({
      titleText: '三秒后自动关闭',
      buttons: [
        {
          text: '实例菜单',
        },
        {
          text: '实例菜单',
        },
      ],
      buttonClicked() {
        return true;
      },
    });
    this.timeout = setTimeout(() => {
      hideSheet();
    }, 3000);
  },
});

示例

该组件主要依靠 JavaScript 主动调用,所以一般只需在 wxml 中添加一个组件,并设置 id 为 #wux-actionsheet 或其他,之后在 page.js 中调用 $wuxActionSheet(this, id) 获取匹配到的第一个组件实例对象。

<wux-actionsheet id="wux-actionsheet" />
<view class="page">
	<view class="page__hd">
		<view class="page__title">ActionSheet</view>
		<view class="page__desc">上拉菜单</view>
	</view>
	<view class="page__bd page__bd_spacing">
		<wux-button block type="light" bind:click="showActionSheet1">原生 ActionSheet</wux-button>
		<wux-button block type="light" bind:click="showActionSheet3">wx ActionSheet</wux-button>
	</view>
</view>

API

参数类型描述默认值
optionsobject配置项-
options.prefixClsstring自定义类名前缀wux-actionsheet
options.titleTextstring标题-
options.buttonsarray按钮[]
options.buttons[].textstring按钮的文本-
options.buttons[].iconstring按钮的图标-
options.buttons[].disabledboolean是否禁用false
options.buttons[].openTypestring微信开放能力,可选值为 contact、share、getUserInfo、getPhoneNumber、launchApp、openSetting、feedback-
options.buttons[].hoverClassstring指定按下去的样式类。当 hover-class="none" 时,没有点击态效果wux-actionsheet__button--hover
options.buttons[].hoverStopPropagationboolean指定是否阻止本节点的祖先节点出现点击态false
options.buttons[].hoverStartTimenumber按住后多久出现点击态,单位毫秒20
options.buttons[].hoverStayTimenumber手指松开后点击态保留时间,单位毫秒70
options.buttons[].langstring指定返回用户信息的语言,zh_CN 简体中文,zh_TW 繁体中文,en 英文。en
options.buttons[].sessionFromstring会话来源-
options.buttons[].sendMessageTitlestring会话内消息卡片标题当前标题
options.buttons[].sendMessagePathstring会话内消息卡片点击跳转小程序路径当前分享路径
options.buttons[].sendMessageImgstring会话内消息卡片图片截图
options.buttons[].showMessageCardboolean显示会话内消息卡片false
options.buttons[].appParameterstring打开 APP 时,向 APP 传递的参数-
bind:getuserinfofunction用户点击该按钮时,会返回获取到的用户信息,回调的detail数据与wx.getUserInfo返回的一致-
bind:contactfunction客服消息回调-
bind:getphonenumberfunction获取用户手机号回调-
bind:errorfunction当使用开放能力时,发生错误的回调-
bind:opensettingfunction在打开授权设置页后回调-
options.buttonClickedfunction按钮点击事件,返回值为 true 时将会关闭组件-
options.cancelTextstring取消按钮的文本取消
options.cancelfunction取消按钮或蒙层点击事件-
options.destructiveTextstring删除按钮的文本-
options.destructiveButtonClickedfunction删除按钮点击事件-

更多参数说明请参考微信官方的表单组件 Button

ActionSheet.method

  • ActionSheet.showSheet
  • ActionSheet.removeSheet
  • ActionSheet.cancel

ActionSheet.showSheet 函数调用后,会返回一个引用,可以通过该引用手动关闭组件

const hide = ActionSheet.showSheet()
hide()
1.5.1

1 year ago

1.5.0

1 year ago

1.3.5

2 years ago

1.4.0

2 years ago

1.3.4

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago