mpalipay.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. export default {
  2. data() {
  3. return {
  4. x: 0,
  5. transition: false,
  6. width: 0,
  7. viewWidth: 0,
  8. swipeShow: 0
  9. }
  10. },
  11. watch: {
  12. show(newVal) {
  13. if (this.autoClose) return
  14. if (newVal && newVal !== 'none' ) {
  15. this.transition = true
  16. this.open(newVal)
  17. } else {
  18. this.close()
  19. }
  20. }
  21. },
  22. created() {
  23. this.swipeaction = this.getSwipeAction()
  24. if (this.swipeaction.children !== undefined) {
  25. this.swipeaction.children.push(this)
  26. }
  27. },
  28. // beforeDestroy() {
  29. // this.swipeaction.children.forEach((item, index) => {
  30. // if (item === this) {
  31. // this.swipeaction.children.splice(index, 1)
  32. // }
  33. // })
  34. // },
  35. mounted() {
  36. this.isopen = false
  37. setTimeout(() => {
  38. this.getQuerySelect()
  39. }, 50)
  40. },
  41. methods: {
  42. appTouchStart(e) {
  43. const {
  44. clientX
  45. } = e.changedTouches[0]
  46. this.clientX = clientX
  47. this.timestamp = new Date().getTime()
  48. },
  49. appTouchEnd(e, index, item, position) {
  50. const {
  51. clientX
  52. } = e.changedTouches[0]
  53. // fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
  54. let diff = Math.abs(this.clientX - clientX)
  55. let time = (new Date().getTime()) - this.timestamp
  56. if (diff < 40 && time < 300) {
  57. this.$emit('click', {
  58. content: item,
  59. index,
  60. position
  61. })
  62. }
  63. },
  64. // onClick(index, item, position) {
  65. // this.$emit('click', {
  66. // content: item,
  67. // index,
  68. // position
  69. // })
  70. // },
  71. /**
  72. * 移动触发
  73. * @param {Object} e
  74. */
  75. onChange(e) {
  76. this.moveX = e.detail.x
  77. this.isclose = false
  78. },
  79. touchstart(e) {
  80. this.transition = false
  81. this.isclose = true
  82. this.autoClose && this.swipeaction.closeOther(this)
  83. },
  84. touchmove(e) {},
  85. touchend(e) {
  86. // 0的位置什么都不执行
  87. if (this.isclose && this.isopen === 'none') return
  88. if (this.isclose && this.isopen !== 'none') {
  89. this.transition = true
  90. this.close()
  91. } else {
  92. this.move(this.moveX + this.leftWidth)
  93. }
  94. },
  95. /**
  96. * 移动
  97. * @param {Object} moveX
  98. */
  99. move(moveX) {
  100. // 打开关闭的处理逻辑不太一样
  101. this.transition = true
  102. // 未打开状态
  103. if (!this.isopen || this.isopen === 'none') {
  104. if (moveX > this.threshold) {
  105. this.open('left')
  106. } else if (moveX < -this.threshold) {
  107. this.open('right')
  108. } else {
  109. this.close()
  110. }
  111. } else {
  112. if (moveX < 0 && moveX < this.rightWidth) {
  113. const rightX = this.rightWidth + moveX
  114. if (rightX < this.threshold) {
  115. this.open('right')
  116. } else {
  117. this.close()
  118. }
  119. } else if (moveX > 0 && moveX < this.leftWidth) {
  120. const leftX = this.leftWidth - moveX
  121. if (leftX < this.threshold) {
  122. this.open('left')
  123. } else {
  124. this.close()
  125. }
  126. }
  127. }
  128. },
  129. /**
  130. * 打开
  131. */
  132. open(type) {
  133. this.x = this.moveX
  134. this.animation(type)
  135. },
  136. /**
  137. * 关闭
  138. */
  139. close() {
  140. this.x = this.moveX
  141. // TODO 解决 x 值不更新的问题,所以会多触发一次 nextTick ,待优化
  142. this.$nextTick(() => {
  143. this.x = -this.leftWidth
  144. if(this.isopen!=='none'){
  145. this.$emit('change', 'none')
  146. }
  147. this.isopen = 'none'
  148. })
  149. },
  150. /**
  151. * 执行结束动画
  152. * @param {Object} type
  153. */
  154. animation(type) {
  155. this.$nextTick(() => {
  156. if (type === 'left') {
  157. this.x = 0
  158. } else {
  159. this.x = -this.rightWidth - this.leftWidth
  160. }
  161. if(this.isopen!==type){
  162. this.$emit('change', type)
  163. }
  164. this.isopen = type
  165. })
  166. },
  167. getSlide(x) {},
  168. getQuerySelect() {
  169. const query = uni.createSelectorQuery().in(this);
  170. query.selectAll('.movable-view--hock').boundingClientRect(data => {
  171. this.leftWidth = data[1].width
  172. this.rightWidth = data[2].width
  173. this.width = data[0].width
  174. this.viewWidth = this.width + this.rightWidth + this.leftWidth
  175. if (this.leftWidth === 0) {
  176. // TODO 疑似bug ,初始化的时候如果x 是0,会导致移动位置错误,所以让元素超出一点
  177. this.x = -0.1
  178. } else {
  179. this.x = -this.leftWidth
  180. }
  181. this.moveX = this.x
  182. this.$nextTick(() => {
  183. this.swipeShow = 1
  184. })
  185. if (!this.buttonWidth) {
  186. this.disabledView = true
  187. }
  188. if (this.autoClose) return
  189. if (this.show !== 'none') {
  190. this.transition = true
  191. this.open(this.shows)
  192. }
  193. }).exec();
  194. }
  195. }
  196. }