You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
1.8 KiB

3 years ago
  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(){},
  69. appTouchEnd(){},
  70. getSize() {
  71. const views = uni.createSelectorQuery().in(this)
  72. views
  73. .selectAll('.selector-query-hock')
  74. .boundingClientRect(data => {
  75. if (this.autoClose) {
  76. data[0].show = false
  77. } else {
  78. data[0].show = this.show
  79. }
  80. this.position = data
  81. })
  82. .exec()
  83. },
  84. getButtonSize() {
  85. const views = uni.createSelectorQuery().in(this)
  86. views
  87. .selectAll('.button-hock')
  88. .boundingClientRect(data => {
  89. this.button = data
  90. })
  91. .exec()
  92. }
  93. }
  94. }