mpwxs.js 2.2 KB

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