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.

270 lines
8.2 KiB

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