mpwxs.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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, data) {
  63. this.$emit('action', {
  64. content: item,
  65. index,
  66. data
  67. })
  68. },
  69. getSize() {
  70. const views = uni.createSelectorQuery().in(this)
  71. views
  72. .selectAll('.selector-query-hock')
  73. .boundingClientRect(data => {
  74. if (this.autoClose) {
  75. data[0].show = false
  76. } else {
  77. data[0].show = this.show
  78. }
  79. this.position = data
  80. })
  81. .exec()
  82. },
  83. getButtonSize() {
  84. const views = uni.createSelectorQuery().in(this)
  85. views
  86. .selectAll('.button-hock')
  87. .boundingClientRect(data => {
  88. this.button = data
  89. })
  90. .exec()
  91. }
  92. }
  93. }