# ActionSheet 操作菜单 - 图1 Wuss-weapp

首页

组件库

快速上手

GitHub

首页

组件库

快速上手

GitHub

基础组件

  • 布局

  • 导航

表单

  • 其他

# ActionSheet 操作菜单

# 使用指南

在 page.json 中引入组件

  1. "usingComponents": {
  2. "w-pane":"wuss-weapp/w-pane/index",
  3. "w-button":"wuss-weapp/w-button/index",
  4. "w-action-sheet":"wuss-weapp/w-action-sheet/index"
  5. }

# 视频演示

# 代码演示

  1. <w-pane title="ActionSheet" desc="操作菜单" />
  2. <w-pane desc="Default" />
  3. <w-button
  4. type="info"
  5. data-key="1"
  6. bind:onClick="handleShow"
  7. >
  8. {{ visible1 ? 'show' : 'hide' }}
  9. </w-button>
  10. <w-action-sheet
  11. data-key="1"
  12. visible="{{ visible1 }}"
  13. options="{{ items1 }}"
  14. bind:onChange="handleClick"
  15. bind:onClose="handleClose"
  16. />
  17. <w-pane desc="Icon" />
  18. <w-button
  19. type="info"
  20. data-key="2"
  21. bind:onClick="handleShow"
  22. >
  23. {{ visible2 ? 'show' : 'hide' }}
  24. </w-button>
  25. <w-action-sheet
  26. data-key="2"
  27. visible="{{ visible2 }}"
  28. options="{{ items2 }}"
  29. bind:onChange="handleClick"
  30. bind:onClose="handleClose"
  31. />
  32. <w-pane desc="MaskCancel = False" />
  33. <w-button
  34. type="info"
  35. data-key="3"
  36. bind:onClick="handleShow"
  37. >
  38. {{ visible3 ? 'show' : 'hide' }}
  39. </w-button>
  40. <w-action-sheet
  41. maskCancel="{{ false }}"
  42. data-key="3"
  43. visible="{{ visible3 }}"
  44. options="{{ items3 }}"
  45. bind:onChange="handleClick"
  46. bind:onClose="handleClose"
  47. />
  48. <w-pane desc="ShowCancel = False" />
  49. <w-button
  50. type="info"
  51. data-key="4"
  52. bind:onClick="handleShow"
  53. >
  54. {{ visible4 ? 'show' : 'hide' }}
  55. </w-button>
  56. <w-action-sheet
  57. showCancel="{{ false }}"
  58. data-key="4"
  59. visible="{{ visible4 }}"
  60. options="{{ items4 }}"
  61. bind:onChange="handleClick"
  62. bind:onClose="handleClose"
  63. />
  64. <w-pane desc="CancelText = 退出" />
  65. <w-button
  66. type="info"
  67. data-key="5"
  68. bind:onClick="handleShow"
  69. >
  70. {{ visible5 ? 'show' : 'hide' }}
  71. </w-button>
  72. <w-action-sheet
  73. cancelText="退出"
  74. data-key="5"
  75. visible="{{ visible5 }}"
  76. options="{{ items5 }}"
  77. bind:onChange="handleClick"
  78. bind:onClose="handleClose"
  79. />
  80. <w-pane desc="Loading" />
  81. <w-button
  82. type="info"
  83. data-key="6"
  84. bind:onClick="handleShow"
  85. >
  86. {{ visible6 ? 'show' : 'hide' }}
  87. </w-button>
  88. <w-action-sheet
  89. cancelText="退出"
  90. data-key="6"
  91. visible="{{ visible6 }}"
  92. options="{{ items6 }}"
  93. bind:onChange="handleClick"
  94. bind:onClose="handleClose"
  95. />
  96. <w-pane desc="插件手动调用" />
  97. <w-button type="info" bind:onClick="handleClick2">ActionSheet.show()</w-button>
  98. <w-action-sheet id="wuss-actionsheet" options="{{ items6 }}" bind:onChange="handleClick" bind:onClose="handleClose" />
data: {
  visible: false,
  items1: [
    {
      text: '分享给朋友',
      type: 'share',
      openType: 'share',
    },
    {
      text: '分享到朋友圈',
      type: 'shareTimeLine',
      openType: 'share',
    },
  ],
  items2: [
    {
      text: '分享给朋友',
      type: 'share',
      icon: 'forward-o',
      openType: 'share',
    },
    {
      text: '分享到朋友圈',
      type: 'shareTimeLine',
      icon: 'share',
      openType: 'share',
    },
  ],
  items3: [
    {
      text: '分享给朋友',
      type: 'share',
      icon: 'forward-o',
      openType: 'share',
    },
    {
      text: '分享到朋友圈',
      type: 'shareTimeLine',
      icon: 'share',
      openType: 'share',
    },
  ],
  items4: [
    {
      text: '分享给朋友',
      type: 'share',
      icon: 'forward-o',
      openType: 'share',
    },
    {
      text: '分享到朋友圈',
      type: 'shareTimeLine',
      icon: 'share',
      openType: 'share',
    },
  ],
  items5: [
    {
      text: '分享给朋友',
      type: 'share',
      icon: 'forward-o',
      openType: 'share',
    },
    {
      text: '分享到朋友圈',
      type: 'shareTimeLine',
      icon: 'share',
      openType: 'share',
    },
  ],
  items6: [
    {
      text: '分享给朋友',
      type: 'share',
      openType: 'share',
    },
    {
      text: '分享到朋友圈',
      type: 'shareTimeLine',
      openType: 'share',
    },
  ],
},
handleClick(e) {
  const key = e.currentTarget.dataset.key;
  const item = e.detail;
  if(item.type === 'hide') return ActionSheet.hide({});
  if (key == 6) {
    this.setData(
      {
        [`items${key}[${item.key}].loading`]: true,
      },
      () => {
        setTimeout(() => {
          this.setData({
            [`items${key}[${item.key}].loading`]: false,
            [`visible${key}`]: false,
          });
        }, 2000);
      }
    );
  } else {
    this.setData({
      [`visible${key}`]: false,
    });
  }
},
handleClose(e) {
  const { key } = e.currentTarget.dataset;
  this.setData({ [`visible${key}`]: false });
},
handleShow(e) {
  const { key } = e.currentTarget.dataset;
  this.setData({ [`visible${key}`]: true });
},
handleClick2() {
  ActionSheet.show({
    options: [{text: 'ActionSheet.hide()',type: 'hide'}],
  })
},
onShareAppMessage: function (res) {
  if (res.from === 'button') {
    // 来自页面内转发按钮
    console.log(res.target)
  }
  return {
    title: '自定义转发标题',
    path: '/page/user?id=123'
  }
}

# API

# Attribute 属性

属性 说明 类型 默认值
visible 是否可见 boolean false
options 当前传出的菜单列表 item属性有color,openType,loading,icon,iconSize,disabled,iconColor,text array []
maskCancel 点击遮罩是否可关闭 boolean false
showCancel 是否展示取消按钮 boolean false
cancelText 取消按钮文字 string 取消

# Event 事件

事件名 说明 参数
onClose 取消回调 ——
onChange 值被改变时触发 e.detail.value

# Slot 插槽

名称 说明
header 头部插槽

# Class 自定义类名

类名 说明
wuss-class 根节点样式类

Edit this page

SegmentedControl 分段器 Toast 提示