mpalipay.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. export default {
  2. data() {
  3. return {
  4. isshow: false,
  5. viewWidth: 0,
  6. buttonWidth: 0,
  7. disabledView: false,
  8. x: 0,
  9. transition: false
  10. }
  11. },
  12. watch: {
  13. show(newVal) {
  14. if (this.autoClose) return
  15. if (newVal) {
  16. this.open()
  17. } else {
  18. this.close()
  19. }
  20. }
  21. },
  22. created() {
  23. if (this.swipeaction.children !== undefined) {
  24. this.swipeaction.children.push(this)
  25. }
  26. },
  27. beforeDestroy() {
  28. this.swipeaction.children.forEach((item, index) => {
  29. if (item === this) {
  30. this.swipeaction.children.splice(index, 1)
  31. }
  32. })
  33. },
  34. mounted() {
  35. this.isopen = false
  36. this.transition = true
  37. setTimeout(() => {
  38. this.getQuerySelect()
  39. }, 50)
  40. },
  41. methods: {
  42. onClick(index, item, data) {
  43. this.$emit('action', {
  44. content: item,
  45. index,
  46. data
  47. })
  48. },
  49. touchstart(e) {
  50. let {
  51. pageX,
  52. pageY
  53. } = e.changedTouches[0]
  54. this.transition = false
  55. this.startX = pageX
  56. if (this.autoClose) {
  57. this.swipeaction.closeOther(this)
  58. }
  59. },
  60. touchmove(e) {
  61. let {
  62. pageX
  63. } = e.changedTouches[0]
  64. this.slide = this.getSlide(pageX)
  65. if (this.slide === 0) {
  66. this.disabledView = false
  67. }
  68. },
  69. touchend(e) {
  70. this.stop = false
  71. this.transition = true
  72. if (this.isopen) {
  73. if (this.moveX === -this.buttonWidth) {
  74. this.close()
  75. return
  76. }
  77. this.move()
  78. } else {
  79. if (this.moveX === 0) {
  80. this.close()
  81. return
  82. }
  83. this.move()
  84. }
  85. },
  86. open() {
  87. this.x = this.moveX
  88. this.$nextTick(() => {
  89. this.x = -this.buttonWidth
  90. this.moveX = this.x
  91. if(!this.isopen){
  92. this.isopen = true
  93. this.$emit('change', true)
  94. }
  95. })
  96. },
  97. close() {
  98. this.x = this.moveX
  99. this.$nextTick(() => {
  100. this.x = 0
  101. this.moveX = this.x
  102. if(this.isopen){
  103. this.isopen = false
  104. this.$emit('change', false)
  105. }
  106. })
  107. },
  108. move() {
  109. if (this.slide === 0) {
  110. this.open()
  111. } else {
  112. this.close()
  113. }
  114. },
  115. onChange(e) {
  116. let x = e.detail.x
  117. this.moveX = x
  118. if (x >= this.buttonWidth) {
  119. this.disabledView = true
  120. this.$nextTick(() => {
  121. this.x = this.buttonWidth
  122. })
  123. }
  124. },
  125. getSlide(x) {
  126. if (x >= this.startX) {
  127. this.startX = x
  128. return 1
  129. } else {
  130. this.startX = x
  131. return 0
  132. }
  133. },
  134. getQuerySelect() {
  135. const query = uni.createSelectorQuery().in(this);
  136. query.selectAll('.viewWidth-hook').boundingClientRect(data => {
  137. this.viewWidth = data[0].width
  138. this.buttonWidth = data[1].width
  139. this.transition = false
  140. this.$nextTick(() => {
  141. this.transition = true
  142. })
  143. if (!this.buttonWidth) {
  144. this.disabledView = true
  145. }
  146. if (this.autoClose) return
  147. if (this.show) {
  148. this.open()
  149. }
  150. }).exec();
  151. }
  152. }
  153. }