uni-swipe-action-item.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <!-- 在微信小程序 app vue端 h5 使用wxs 实现-->
  3. <!-- #ifdef APP-VUE || MP-WEIXIN || H5 -->
  4. <view class="uni-swipe">
  5. <view class="uni-swipe_box" :data-threshold="threshold" :data-disabled="disabled" :change:prop="swipe.sizeReady" :prop="btn" @touchstart="swipe.touchstart" @touchmove="swipe.touchmove" @touchend="swipe.touchend" @mousedown="swipe.mousedown" @mousemove="swipe.mousemove" @mouseup="swipe.mouseup" @mouseleave="swipe.mouseleave">
  6. <!-- 在微信小程序 app vue端 h5 使用wxs 实现-->
  7. <view class="uni-swipe_button-group button-group--left">
  8. <slot name="left">
  9. <view v-for="(item,index) in leftOptions" :data-button="btn" :key="index" :style="{
  10. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  11. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  12. }" class="uni-swipe_button button-hock" @touchstart="appTouchStart" @touchend="appTouchEnd($event,index,item,'left')" @click.stop="onClickForPC(index,item,'left')"><text class="uni-swipe_button-text" :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text></view>
  13. </slot>
  14. </view>
  15. <view class="uni-swipe_text--center">
  16. <slot></slot>
  17. </view>
  18. <view class="uni-swipe_button-group button-group--right">
  19. <slot name="right">
  20. <view v-for="(item,index) in rightOptions" :data-button="btn" :key="index" :style="{
  21. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  22. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  23. }" class="uni-swipe_button button-hock" @touchstart="appTouchStart" @touchend="appTouchEnd($event,index,item,'right')" @click.stop="onClickForPC(index,item,'right')"><text class="uni-swipe_button-text" :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text></view>
  24. </slot>
  25. </view>
  26. </view>
  27. </view>
  28. <!-- #endif -->
  29. <!-- app nvue端 使用 bindingx -->
  30. <!-- #ifdef APP-NVUE -->
  31. <view ref="selector-box--hock" class="uni-swipe" @horizontalpan="touchstart" @touchend="touchend">
  32. <view ref='selector-left-button--hock' class="uni-swipe_button-group button-group--left">
  33. <slot name="left">
  34. <view v-for="(item,index) in leftOptions" :data-button="btn" :key="index" :style="{
  35. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  36. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  37. }" class="uni-swipe_button button-hock" @click.stop="onClick(index,item,'left')"><text class="uni-swipe_button-text" :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text></view>
  38. </slot>
  39. </view>
  40. <view ref='selector-right-button--hock' class="uni-swipe_button-group button-group--right">
  41. <slot name="right">
  42. <view v-for="(item,index) in rightOptions" :data-button="btn" :key="index" :style="{
  43. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  44. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  45. }" class="uni-swipe_button button-hock" @click.stop="onClick(index,item,'right')"><text class="uni-swipe_button-text" :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text></view>
  46. </slot>
  47. </view>
  48. <view ref='selector-content--hock' class="uni-swipe_box">
  49. <slot></slot>
  50. </view>
  51. </view>
  52. <!-- #endif -->
  53. <!-- 其他平台使用 js ,长列表性能可能会有影响-->
  54. <!-- #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO || MP-QQ -->
  55. <view class="uni-swipe">
  56. <view class="uni-swipe_box" @touchstart="touchstart" @touchmove="touchmove" @touchend="touchend" :style="{transform:moveLeft}" :class="{ani:ani}">
  57. <view class="uni-swipe_button-group button-group--left">
  58. <slot name="left">
  59. <view v-for="(item,index) in leftOptions" :data-button="btn" :key="index" :style="{
  60. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  61. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  62. }" class="uni-swipe_button button-hock" @touchstart="appTouchStart" @touchend="appTouchEnd($event,index,item,'left')"><text class="uni-swipe_button-text" :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text></view>
  63. </slot>
  64. </view>
  65. <slot></slot>
  66. <view class="uni-swipe_button-group button-group--right">
  67. <slot name="right">
  68. <view v-for="(item,index) in rightOptions" :data-button="btn" :key="index" :style="{
  69. backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
  70. fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px'
  71. }" @touchstart="appTouchStart" @touchend="appTouchEnd($event,index,item,'right')" class="uni-swipe_button button-hock"><text class="uni-swipe_button-text" :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text></view>
  72. </slot>
  73. </view>
  74. </view>
  75. </view>
  76. <!-- #endif -->
  77. </template>
  78. <script src="./index.wxs" module="swipe" lang="wxs"></script>
  79. <script>
  80. // #ifdef APP-VUE|| MP-WEIXIN || H5
  81. import mpwxs from './mpwxs'
  82. // #endif
  83. // #ifdef APP-NVUE
  84. import bindingx from './bindingx.js'
  85. // #endif
  86. // #ifndef APP-PLUS|| MP-WEIXIN || H5
  87. import mixins from './mpother'
  88. // #endif
  89. /**
  90. * SwipeActionItem 滑动操作子组件
  91. * @description 通过滑动触发选项的容器
  92. * @tutorial https://ext.dcloud.net.cn/plugin?id=181
  93. * @property {Boolean} show = [left|right|none] 开启关闭组件,auto-close = false 时生效
  94. * @property {Boolean} disabled = [true|false] 是否禁止滑动
  95. * @property {Boolean} autoClose = [true|false] 滑动打开当前组件,是否关闭其他组件
  96. * @property {Number} threshold 滑动缺省值
  97. * @property {Array} leftOptions 左侧选项内容及样式
  98. * @property {Array} rgihtOptions 右侧选项内容及样式
  99. * @event {Function} click 点击选项按钮时触发事件,e = {content,index} ,content(点击内容)、index(下标)
  100. * @event {Function} change 组件打开或关闭时触发,left\right\none
  101. */
  102. export default {
  103. // #ifdef APP-VUE|| MP-WEIXIN||H5
  104. mixins: [mpwxs],
  105. // #endif
  106. // #ifdef APP-NVUE
  107. mixins: [bindingx],
  108. // #endif
  109. // #ifndef APP-PLUS|| MP-WEIXIN || H5
  110. mixins: [mixins],
  111. // #endif
  112. props: {
  113. // 控制开关
  114. show: {
  115. type: String,
  116. default: 'none'
  117. },
  118. // 禁用
  119. disabled: {
  120. type: Boolean,
  121. default: false
  122. },
  123. // 是否自动关闭
  124. autoClose: {
  125. type: Boolean,
  126. default: true
  127. },
  128. // 滑动缺省距离
  129. threshold: {
  130. type: Number,
  131. default: 20
  132. },
  133. // 左侧按钮内容
  134. leftOptions: {
  135. type: Array,
  136. default () {
  137. return []
  138. }
  139. },
  140. // 右侧按钮内容
  141. rightOptions: {
  142. type: Array,
  143. default () {
  144. return []
  145. }
  146. }
  147. },
  148. inject: ['swipeaction']
  149. }
  150. </script>
  151. <style scoped>
  152. .uni-swipe {
  153. position: relative;
  154. /* #ifndef APP-NVUE */
  155. overflow: hidden;
  156. /* #endif */
  157. }
  158. .uni-swipe_box {
  159. /* #ifndef APP-NVUE */
  160. display: flex;
  161. flex-shrink: 0;
  162. /* #endif */
  163. position: relative;
  164. }
  165. .uni-swipe_text--center {
  166. width: 100%;
  167. /* #ifdef H5 */
  168. cursor: grab;
  169. /* #endif */
  170. }
  171. .uni-swipe_button-group {
  172. /* #ifndef APP-NVUE */
  173. box-sizing: border-box;
  174. display: flex;
  175. /* #endif */
  176. flex-direction: row;
  177. position: absolute;
  178. top: 0;
  179. bottom: 0;
  180. /* #ifdef H5 */
  181. cursor: pointer;
  182. /* #endif */
  183. }
  184. .button-group--left {
  185. left: 0;
  186. transform: translateX(-100%);
  187. }
  188. .button-group--right {
  189. right: 0;
  190. transform: translateX(100%);
  191. }
  192. .uni-swipe_button {
  193. /* #ifdef APP-NVUE */
  194. flex: 1;
  195. /* #endif */
  196. /* #ifndef APP-NVUE */
  197. display: flex;
  198. /* #endif */
  199. flex-direction: row;
  200. justify-content: center;
  201. align-items: center;
  202. padding: 0 20px;
  203. }
  204. .uni-swipe_button-text {
  205. /* #ifndef APP-NVUE */
  206. flex-shrink: 0;
  207. /* #endif */
  208. font-size: 14px;
  209. }
  210. .ani {
  211. transition-property: transform;
  212. transition-duration: 0.3s;
  213. transition-timing-function: cubic-bezier(0.165, 0.84, 0.44, 1);
  214. }
  215. /* #ifdef MP-ALIPAY */
  216. .movable-area {
  217. /* width: 100%; */
  218. height: 45px;
  219. }
  220. .movable-view {
  221. display: flex;
  222. /* justify-content: center; */
  223. position: relative;
  224. flex: 1;
  225. height: 45px;
  226. z-index: 2;
  227. }
  228. .movable-view-button {
  229. display: flex;
  230. flex-shrink: 0;
  231. flex-direction: row;
  232. height: 100%;
  233. background: #C0C0C0;
  234. }
  235. /* .transition {
  236. transition: all 0.3s;
  237. } */
  238. .movable-view-box {
  239. flex-shrink: 0;
  240. height: 100%;
  241. background-color: #fff;
  242. }
  243. /* #endif */
  244. </style>