ActionSheet 动作面板

概述

从底部弹出的模态框,提供和当前场景相关的 2 个以上的操作动作,也支持提供标题和描述。内置固定的展示样式、不支持特别灵活的修改。

使用指南

在 .json 中引入组件

  1. "usingComponents": {
  2. "i-action-sheet": "../../dist/action-sheet/index"
  3. }

示例

  1. <view style="margin-top: 100px">
  2. <i-button type="ghost" bind:click="handleOpen1">一般用法</i-button>
  3. <i-button type="ghost" bind:click="handleOpen2">带有提示、异步</i-button>
  4. </view>
  5. <i-action-sheet visible="{{ visible1 }}" actions="{{ actions1 }}" show-cancel bind:cancel="handleCancel1" bind:click="handleClickItem1" />
  6. <i-action-sheet visible="{{ visible2 }}" actions="{{ actions2 }}" show-cancel bind:cancel="handleCancel2" bind:click="handleClickItem2" mask-closable="{{ false }}">
  7. <view slot="header" style="padding: 16px">
  8. <view style="color: #444;font-size: 16px">确定吗?</view>
  9. <text>删除后无法恢复哦</text>
  10. </view>
  11. </i-action-sheet>
  12. <i-message id="message" />
  1. // 关于本示例的 $Message ,可以查看 Message 组件的介绍
  2. const { $Message } = require('../../dist/base/index');
  3. Page({
  4. data: {
  5. visible1: false,
  6. actions1: [
  7. {
  8. name: '选项1',
  9. },
  10. {
  11. name: '选项2'
  12. },
  13. {
  14. name: '去分享',
  15. icon: 'share',
  16. openType: 'share'
  17. }
  18. ],
  19. actions2: [
  20. {
  21. name: '删除',
  22. color: '#ed3f14'
  23. }
  24. ]
  25. },
  26. onShareAppMessage() {
  27. return {
  28. title: 'iView Weapp',
  29. imageUrl: 'https://file.iviewui.com/iview-weapp-logo.png'
  30. };
  31. },
  32. handleOpen1 () {
  33. this.setData({
  34. visible1: true
  35. });
  36. },
  37. handleCancel1 () {
  38. this.setData({
  39. visible1: false
  40. });
  41. },
  42. handleOpen2 () {
  43. this.setData({
  44. visible2: true
  45. });
  46. },
  47. handleCancel2 () {
  48. this.setData({
  49. visible2: false
  50. });
  51. },
  52. handleClickItem1 ({ detail }) {
  53. const index = detail.index + 1;
  54. $Message({
  55. content: '点击了选项' + index
  56. });
  57. },
  58. handleClickItem2 () {
  59. const action = [...this.data.actions2];
  60. action[0].loading = true;
  61. this.setData({
  62. actions2: action
  63. });
  64. setTimeout(() => {
  65. action[0].loading = false;
  66. this.setData({
  67. visible2: false,
  68. actions2: action
  69. });
  70. $Message({
  71. content: '删除成功!',
  72. type: 'success'
  73. });
  74. }, 2000);
  75. }
  76. });

API

ActionSheet properties

属性说明类型默认值
i-class自定义 class 类名String-
i-class-mask自定义 遮罩层 类名String-
i-class-header自定义 标题栏 类名String-
visible是否显示组件Booleanfalse
mask-closable点击遮罩层是否可以关闭组件Booleantrue
show-cancel是否显示取消按钮Booleanfalse
cancel-text取消按钮的文案String取消
actions按钮组,具体项参照后面的表格Array[]

ActionSheet events

事件名说明返回值
bind:click点击某个按钮时触发,返回按钮所在 actions 中的索引{ index }
bind:cancel点击关闭或遮罩层时触发-

ActionSheet slot

名称说明
header标题栏,可以添加提示信息

ActionSheet actions

属性说明类型默认值
name按钮文案String-
icon按钮图标String-
color按钮文字的颜色String-
loading按钮是否显示为加载中Booleanfalse
openType按钮的微信开放能力String-