uni-swipe-action-item.vue 7.8 KB

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