mp.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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) return
  21. valueObj.show = newVal
  22. this.$set(this.position, 0, valueObj)
  23. }
  24. },
  25. mounted() {
  26. this.init()
  27. setTimeout(()=>{
  28. this.getSize()
  29. this.getButtonSize()
  30. },50)
  31. },
  32. methods: {
  33. init() {
  34. uni.$on('__uni__swipe__event', (res) => {
  35. if (res !== this && this.autoClose) {
  36. let valueObj = this.position[0]
  37. valueObj.show = false
  38. this.$set(this.position, 0, valueObj)
  39. }
  40. })
  41. },
  42. openSwipe() {
  43. uni.$emit('__uni__swipe__event', this)
  44. },
  45. change(e) {
  46. this.$emit('change', e.open)
  47. let valueObj = this.position[0]
  48. valueObj.show = e.open
  49. this.$set(this.position, 0, valueObj)
  50. // console.log('改变', e);
  51. },
  52. onClick(index, item) {
  53. this.$emit('click', {
  54. content: item,
  55. index
  56. })
  57. },
  58. getSize() {
  59. const views = uni.createSelectorQuery().in(this)
  60. views
  61. .selectAll('.selector-query-hock')
  62. .boundingClientRect(data => {
  63. if (this.autoClose) {
  64. data[0].show = false
  65. } else {
  66. data[0].show = this.show
  67. }
  68. this.position = data
  69. })
  70. .exec()
  71. },
  72. getButtonSize() {
  73. const views = uni.createSelectorQuery().in(this)
  74. views
  75. .selectAll('.button-hock')
  76. .boundingClientRect(data => {
  77. this.button = data
  78. })
  79. .exec()
  80. }
  81. }
  82. }