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" />
  1. data: {
  2. visible: false,
  3. items1: [
  4. {
  5. text: '分享给朋友',
  6. type: 'share',
  7. openType: 'share',
  8. },
  9. {
  10. text: '分享到朋友圈',
  11. type: 'shareTimeLine',
  12. openType: 'share',
  13. },
  14. ],
  15. items2: [
  16. {
  17. text: '分享给朋友',
  18. type: 'share',
  19. icon: 'forward-o',
  20. openType: 'share',
  21. },
  22. {
  23. text: '分享到朋友圈',
  24. type: 'shareTimeLine',
  25. icon: 'share',
  26. openType: 'share',
  27. },
  28. ],
  29. items3: [
  30. {
  31. text: '分享给朋友',
  32. type: 'share',
  33. icon: 'forward-o',
  34. openType: 'share',
  35. },
  36. {
  37. text: '分享到朋友圈',
  38. type: 'shareTimeLine',
  39. icon: 'share',
  40. openType: 'share',
  41. },
  42. ],
  43. items4: [
  44. {
  45. text: '分享给朋友',
  46. type: 'share',
  47. icon: 'forward-o',
  48. openType: 'share',
  49. },
  50. {
  51. text: '分享到朋友圈',
  52. type: 'shareTimeLine',
  53. icon: 'share',
  54. openType: 'share',
  55. },
  56. ],
  57. items5: [
  58. {
  59. text: '分享给朋友',
  60. type: 'share',
  61. icon: 'forward-o',
  62. openType: 'share',
  63. },
  64. {
  65. text: '分享到朋友圈',
  66. type: 'shareTimeLine',
  67. icon: 'share',
  68. openType: 'share',
  69. },
  70. ],
  71. items6: [
  72. {
  73. text: '分享给朋友',
  74. type: 'share',
  75. openType: 'share',
  76. },
  77. {
  78. text: '分享到朋友圈',
  79. type: 'shareTimeLine',
  80. openType: 'share',
  81. },
  82. ],
  83. },
  84. handleClick(e) {
  85. const key = e.currentTarget.dataset.key;
  86. const item = e.detail;
  87. if(item.type === 'hide') return ActionSheet.hide({});
  88. if (key == 6) {
  89. this.setData(
  90. {
  91. [`items${key}[${item.key}].loading`]: true,
  92. },
  93. () => {
  94. setTimeout(() => {
  95. this.setData({
  96. [`items${key}[${item.key}].loading`]: false,
  97. [`visible${key}`]: false,
  98. });
  99. }, 2000);
  100. }
  101. );
  102. } else {
  103. this.setData({
  104. [`visible${key}`]: false,
  105. });
  106. }
  107. },
  108. handleClose(e) {
  109. const { key } = e.currentTarget.dataset;
  110. this.setData({ [`visible${key}`]: false });
  111. },
  112. handleShow(e) {
  113. const { key } = e.currentTarget.dataset;
  114. this.setData({ [`visible${key}`]: true });
  115. },
  116. handleClick2() {
  117. ActionSheet.show({
  118. options: [{text: 'ActionSheet.hide()',type: 'hide'}],
  119. })
  120. },
  121. onShareAppMessage: function (res) {
  122. if (res.from === 'button') {
  123. // 来自页面内转发按钮
  124. console.log(res.target)
  125. }
  126. return {
  127. title: '自定义转发标题',
  128. path: '/page/user?id=123'
  129. }
  130. }

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 根节点样式类