Swipeout 滑动菜单

概述

与 iOS 原生的滑动操作交互类似,可通过滑动显示操作菜单。

使用指南

在 .json 中引入组件

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

示例

  1. <view class="i-swipeout-demo">
  2. <view class="i-swipeout-demo-title">基础用法</view>
  3. <view class="i-swipeout-demo-des">
  4. 注: 1、设置uncloseable为true时点击按钮不能关闭,必须联合toggle2来实现
  5. 2、如果传递action的话必须传递width来设置每个按钮的宽度
  6. </view>
  7. <i-swipeout i-class="i-swipeout-demo-item" actions="{{actions}}">
  8. <view slot="content">
  9. <i-cell
  10. i-class="i-cell-padding"
  11. title="猛虫过江"
  12. label="侏罗纪世界主题公园及豪华度假村被失控的恐龙们摧毁已有四年">
  13. </i-cell>
  14. </view>
  15. </i-swipeout>
  16. <i-swipeout i-class="i-swipeout-demo-item" actions="{{actions}}" toggle="{{toggle2}}" unclosable="{{true}}">
  17. <view slot="content">
  18. <i-cell
  19. i-class="i-cell-padding"
  20. title="点击按钮不可关闭"
  21. label="侏罗纪世界主题公园及豪华度假村被失控的恐龙们摧毁已有四年">
  22. </i-cell>
  23. </view>
  24. </i-swipeout>
  25. <i-swipeout i-class="i-swipeout-demo-item" actions="{{actions}}" toggle="{{toggle2}}" unclosable="{{true}}" bindchange="handlerCloseButton">
  26. <view slot="content">
  27. <i-cell
  28. i-class="i-cell-padding"
  29. title="可点击按钮关闭"
  30. label="侏罗纪世界主题公园及豪华度假村被失控的恐龙们摧毁已有四年">
  31. </i-cell>
  32. </view>
  33. </i-swipeout>
  34. <view class="i-swipeout-demo-title">自定义右侧Button</view>
  35. <view class="i-swipeout-demo-des">注: 右侧必须设置固定宽度。默认宽度160px</view>
  36. <i-swipeout i-class="i-swipeout-demo-item" operateWidth="{{210}}">
  37. <view slot="content">
  38. <i-cell
  39. i-class="i-cell-padding"
  40. title="猛虫过江"
  41. label="侏罗纪世界主题公园及豪华度假村被失控的恐龙们摧毁已有四年">
  42. </i-cell>
  43. </view>
  44. <view slot="button" class="i-swipeout-demo-button-group">
  45. <view class="i-swipeout-demo-button">点赞</view>
  46. <view class="i-swipeout-demo-button">分享</view>
  47. <view class="i-swipeout-demo-button">删除</view>
  48. </view>
  49. </i-swipeout>
  50. <i-swipeout i-class="i-swipeout-demo-item" operateWidth="{{180}}">
  51. <view slot="content">
  52. <i-cell
  53. i-class="i-cell-padding"
  54. title="猛虫过江"
  55. label="侏罗纪世界主题公园及豪华度假村被失控的恐龙们摧毁已有四年">
  56. </i-cell>
  57. </view>
  58. <view slot="button" class="i-swipeout-demo-button-group" style="background:#2db7f5;">
  59. <view class="i-swipeout-demo-button" style="width:60px"> <i-icon size="32" type="like_fill"></i-icon></view>
  60. <view class="i-swipeout-demo-button" style="width:60px"><i-icon size="32" type="share_fill"></i-icon></view>
  61. <view class="i-swipeout-demo-button" style="width:60px"><i-icon size="32" type="delete_fill"></i-icon></view>
  62. </view>
  63. </i-swipeout>
  64. <view class="i-swipeout-demo-title">和actionsheet联合使用</view>
  65. <i-action-sheet visible="{{ visible2 }}" actions="{{ actions2 }}" show-cancel bind:cancel="handleCancel2" bind:click="handleClickItem2" mask-closable="{{ false }}">
  66. <view slot="header" style="padding: 16px">
  67. <view style="color: #444;font-size: 16px">确定吗?</view>
  68. <text>删除后无法恢复哦</text>
  69. </view>
  70. </i-action-sheet>
  71. <i-swipeout i-class="i-swipeout-demo-item" operateWidth="{{180}}" unclosable="{{true}}" toggle="{{toggle}}">
  72. <view slot="content">
  73. <view class="i-swipeout-image">
  74. <i-icon size="20" color="#FFFFFF" type="feedback_fill"></i-icon>
  75. </view>
  76. <view class="i-swipeout-des">
  77. <view class="i-swipeout-des-h2">第七个小矮人</view>
  78. <view class="i-swipeout-des-detail">乐观善良的7个小矮人原本过着简单快乐的生活,不料诅咒公主的巫婆利用小矮人进入.</view>
  79. </view>
  80. </view>
  81. <view slot="button" class="i-swipeout-demo-button-group" style="background:#2db7f5;">
  82. <view class="i-swipeout-demo-button" style="width:60px" bindtap="actionsTap"> <i-icon size="32" type="like_fill"></i-icon></view>
  83. <view class="i-swipeout-demo-button" style="width:60px" bindtap="actionsTap"><i-icon size="32" type="share_fill"></i-icon></view>
  84. <view class="i-swipeout-demo-button" style="width:60px" bindtap="actionsTap"><i-icon size="32" type="delete_fill"></i-icon></view>
  85. </view>
  86. </i-swipeout>
  87. <view class="i-swipeout-demo-title">自定义样式</view>
  88. <i-swipeout i-class="i-swipeout-demo-item" actions="{{actions}}">
  89. <view slot="content">
  90. <view class="i-swipeout-image" style="background:#ff9900;">
  91. <i-icon size="20" color="#FFFFFF" type="coupons_fill" />
  92. </view>
  93. <view class="i-swipeout-des">
  94. <view class="i-swipeout-des-h2">第七个小矮人</view>
  95. <view class="i-swipeout-des-detail">乐观善良的7个小矮人原本过着简单快乐的生活,不料诅咒公主的巫婆利用小矮人进入.</view>
  96. </view>
  97. </view>
  98. </i-swipeout>
  99. </view>
  1. const { $Message } = require('../../dist/base/index');
  2. Page({
  3. data : {
  4. visible2: false,
  5. //小程序没有refs,所以只能用动态布尔值控制关闭
  6. toggle : false,
  7. toggle2 : false,
  8. actions2: [
  9. {
  10. name: '删除',
  11. color: '#ed3f14'
  12. }
  13. ],
  14. actions : [
  15. {
  16. name : '喜欢',
  17. color : '#fff',
  18. fontsize : '20',
  19. width : 100,
  20. icon : 'like',
  21. background : '#ed3f14'
  22. },
  23. {
  24. name : '返回',
  25. width : 100,
  26. color : '#80848f',
  27. fontsize : '20',
  28. icon : 'undo'
  29. }
  30. ]
  31. },
  32. handleCancel2 () {
  33. this.setData({
  34. visible2: false,
  35. toggle : this.data.toggle ? false : true
  36. });
  37. console.log( this.data.toggle,111111111 )
  38. },
  39. handleClickItem2 () {
  40. const action = [...this.data.actions2];
  41. action[0].loading = true;
  42. this.setData({
  43. actions2: action
  44. });
  45. setTimeout(() => {
  46. action[0].loading = false;
  47. this.setData({
  48. visible2: false,
  49. actions2: action,
  50. toggle: this.data.toggle ? false : true
  51. });
  52. }, 2000);
  53. },
  54. handlerCloseButton(){
  55. this.setData({
  56. toggle2: this.data.toggle2 ? false : true
  57. });
  58. },
  59. actionsTap(){
  60. this.setData({
  61. visible2: true
  62. });
  63. }
  64. });

API

Swipeout properties

属性说明类型默认值
i-class自定义 class 类名String-
actions按钮组,具体项参照后面的表格Array[]
unclosable点击菜单时,是否收起Booleanfalse
toggle当此值由 false 转为 true 时,收起菜单Booleanfalse
operate-width菜单项的总宽度Number160

Swipeout events

事件名说明返回值
bind:change点击菜单项时触发index

Swipeout slot

名称说明
content菜单内容
button自定义按钮组

Swipeout actions

属性说明类型默认值
name按钮文案String-
icon按钮图标String-
color按钮文字的颜色String-
fontsize字号String-
width宽度String-
background背景色String-