uni-swipe-action-item.vue 7.9 KB

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