多租户商城-商户小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
5.7 KiB

2 years ago
  1. ## SwipeAction 滑动操作
  2. > 代码块: `uSwipeAction`、`uSwipeActionItem`
  3. 通过滑动触发选项的容器
  4. > 为了避免错误使用,给大家带来不好的开发体验,请在使用组件前仔细阅读下面的注意事项,可以帮你避免一些错误。
  5. > - 如果有动态显示隐藏组件之类的操作,请使用 `v-if` 而不是 `v-show`,因为组件内需要获取节点信息,v-show 之后不能正确获取
  6. > - swipeAction的跟手联动是非常考验性能的。为了提高交互体验,本组件在 app 端 vue 页面、h5、微信小程序使用了wxs 技术,nvue 页面使用 bindingx 技术,可以达到流畅的体验。在其他小程序平台由于底层不支持优化技术,只能使用使用普通 js ,此时性能一般。
  7. > - `uni-swipe-action` 和 `uni-swipe-action-item`
  8. > - `uni-swipe-action` 不能嵌套在 `swiper` 中使用
  9. > - 长列表不建议使用 autoClose属性,会影响组件性能,造成卡顿,原因是打开之后要通知其他已经打开的组件关闭,会导致多个组件重新渲染
  10. > - 事件中传入 `$event` 获取额外参数
  11. > - 向下兼容,需要将 `options` 属性替换成 `right-options`
  12. ### 安装方式
  13. 本组件符合[easycom](https://uniapp.dcloud.io/collocation/pages?id=easycom)规范,`HBuilderX 2.5.5`起,只需将本组件导入项目,在页面`template`中即可直接使用,无需在页面中`import`和注册`components`。
  14. 如需通过`npm`方式使用`uni-ui`组件,另见文档:[https://ext.dcloud.net.cn/plugin?id=55](https://ext.dcloud.net.cn/plugin?id=55)
  15. ## 基本用法
  16. 在 ``template`` 中的使用
  17. ```html
  18. <uni-swipe-action>
  19. <!-- 基础用法 -->
  20. <uni-swipe-action-item :right-options="options" :left-options="options" @click="onClick" @change="change">
  21. <view>SwipeAction 基础使用场景</view>
  22. </uni-swipe-action-item>
  23. <!-- 使用插槽 (请自行给定插槽内容宽度)-->
  24. <uni-swipe-action-item>
  25. <template v-slot:left>
  26. <view><text>置顶</text></view>
  27. </template>
  28. <view>
  29. <text >使用插槽</text>
  30. </view>
  31. <template v-slot:right>
  32. <view><text>删除</text></view>
  33. </template>
  34. </uni-swipe-action-item>
  35. <!-- 混合用法 -->
  36. <uni-swipe-action-item :right-options="options">
  37. <template v-slot:left>
  38. <view><text>置顶</text></view>
  39. </template>
  40. <view><text>混合使用</text></view>
  41. </uni-swipe-action-item>
  42. </uni-swipe-action>
  43. <!-- 禁止滑动 -->
  44. <uni-swipe-action>
  45. <uni-swipe-action-item :disabled="true" :right-options="options">
  46. <view>SwipeAction 基础使用场景</view>
  47. </uni-swipe-action-item>
  48. </uni-swipe-action>
  49. <!-- 按组使用 -->
  50. <uni-swipe-action>
  51. <uni-swipe-action-item :right-options="options" @click="bindClick" @change="swipeChange($event, index)">
  52. <view >item1</view>
  53. </uni-swipe-action-item>
  54. <uni-swipe-action-item :right-options="options" @click="bindClick" @change="swipeChange($event, index)">
  55. <view>item2</view>
  56. </uni-swipe-action-item>
  57. <uni-swipe-action-item :right-options="options" @click="bindClick" @change="swipeChange($event, index)">
  58. <view>item3</view>
  59. </uni-swipe-action-item>
  60. </uni-swipe-action>
  61. ```
  62. ```javascript
  63. export default {
  64. data(){
  65. return {
  66. options:[
  67. {
  68. text: '取消',
  69. style: {
  70. backgroundColor: '#007aff'
  71. }
  72. }, {
  73. text: '确认',
  74. style: {
  75. backgroundColor: '#dd524d'
  76. }
  77. }
  78. ]
  79. }
  80. },
  81. methods:{
  82. onClick(e){
  83. console.log('点击了'+(e.position === 'left' ? '左侧' : '右侧') + e.content.text + '按钮')
  84. },
  85. swipeChange(e,index){
  86. console.log('当前状态:'+ open +',下标:' + index)
  87. }
  88. }
  89. }
  90. ```
  91. ## API
  92. ### SwipeAciton Props
  93. |属性名 |类型 |可选值|默认值 |是否必填 |说明 |
  94. |:-: |:-: |:-: |:-: |:-: |:-: |
  95. |show |String |left/right/none |none |否 |开启关闭组件(只能打开右侧),auto-close = false 时生效,可选值, |
  96. |threshold |Number |- |20 |否 |滑动阙值 |
  97. |disabled |Boolean |- |false|否 |是否禁止滑动 |
  98. |autoClose |Boolean |- |true |否 |其他组件开启的时候,当前组件是否自动关闭 【注意:长列表使用会有性能问题】 |
  99. |**leftOptions** |Array/Object |- |- |否 |左侧选项内容及样式 |
  100. |**rightOptions** |Array/Object |- |- |否 |右侧选项内容及样式 |
  101. #### LeftOptions & RightOptions Options
  102. |参数 |类型 |是否必填 |说明 |
  103. |:-: |:-: |:-: |:-: |
  104. |text |String |是 |按钮的文字 |
  105. |style |Object |否 |按钮样式{backgroundColor,color,fontSize},backgroundColor默认为:#C7C6CD,color默认为:#FFFFFF,fontSize默认为:14px |
  106. ### SwipeAction Events
  107. |事件称名 |说明 |返回值 |
  108. |:-: |:-: |:-: |
  109. |@click |点击选项按钮时触发事件 |e = {content,index} ,content(点击内容)、index(下标)、position (位置信息) |
  110. |@change |组件打开或关闭时触发 |left:左侧 ,right:右侧,none:关闭 |
  111. ### SwipeAction Slots
  112. |名称 |说明 |
  113. |:-: |:-: |
  114. |- |默认插槽自定义显示内容 |
  115. |left |左侧滑动内容 ,会覆盖 leftOptions 内容 |
  116. |right |右侧滑动内容 ,会覆盖 rightOptions 内容 |
  117. > - iOS 端由于存在bounce效果,滑动体验略差,建议禁止bounce效果,禁止方式如下:
  118. > ```javascript
  119. > {
  120. > "path": "swipe-action/swipe-action",
  121. > "style": {
  122. > "navigationBarTitleText": "SwipeAction 滑动操作",
  123. > "disableScroll":true,
  124. > "app-plus":{
  125. > "bounce":"none"
  126. > }
  127. > }
  128. > }
  129. > ```