mpwxs.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. export default {
  2. data() {
  3. return {
  4. position: [],
  5. button: {},
  6. btn: "[]"
  7. }
  8. },
  9. // computed: {
  10. // pos() {
  11. // return JSON.stringify(this.position)
  12. // },
  13. // btn() {
  14. // return JSON.stringify(this.button)
  15. // }
  16. // },
  17. watch: {
  18. button: {
  19. handler(newVal) {
  20. this.btn = JSON.stringify(newVal)
  21. },
  22. deep: true
  23. },
  24. show(newVal) {
  25. if (this.autoClose) return
  26. if (!this.button) {
  27. this.init()
  28. return
  29. }
  30. this.button.show = newVal
  31. },
  32. leftOptions() {
  33. this.init()
  34. },
  35. rightOptions() {
  36. this.init()
  37. }
  38. },
  39. created() {
  40. if (this.swipeaction.children !== undefined) {
  41. this.swipeaction.children.push(this)
  42. }
  43. },
  44. mounted() {
  45. this.init()
  46. },
  47. beforeDestroy() {
  48. this.swipeaction.children.forEach((item, index) => {
  49. if (item === this) {
  50. this.swipeaction.children.splice(index, 1)
  51. }
  52. })
  53. },
  54. methods: {
  55. init() {
  56. clearTimeout(this.swipetimer)
  57. this.swipetimer = setTimeout(() => {
  58. this.getButtonSize()
  59. }, 50)
  60. },
  61. closeSwipe(e) {
  62. if (!this.autoClose) return
  63. this.swipeaction.closeOther(this)
  64. },
  65. change(e) {
  66. this.$emit('change', e.open)
  67. let show = this.button.show
  68. if (show !== e.open) {
  69. this.button.show = e.open
  70. }
  71. },
  72. appTouchStart(e) {
  73. const {
  74. clientX
  75. } = e.changedTouches[0]
  76. this.clientX = clientX
  77. this.timestamp = new Date().getTime()
  78. },
  79. appTouchEnd(e, index, item, position) {
  80. const {
  81. clientX
  82. } = e.changedTouches[0]
  83. // fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
  84. let diff = Math.abs(this.clientX - clientX)
  85. let time = (new Date().getTime()) - this.timestamp
  86. if (diff < 40 && time < 300) {
  87. this.$emit('click', {
  88. content: item,
  89. index,
  90. position
  91. })
  92. }
  93. },
  94. getButtonSize() {
  95. const views = uni.createSelectorQuery().in(this)
  96. views
  97. .selectAll('.uni-swipe_button-group')
  98. .boundingClientRect(data => {
  99. let show = 'none'
  100. if (this.autoClose) {
  101. show = 'none'
  102. } else {
  103. show = this.show
  104. }
  105. this.button = {
  106. data,
  107. show
  108. }
  109. })
  110. .exec()
  111. }
  112. }
  113. }