mp.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. export default {
  2. data() {
  3. return {
  4. position: [],
  5. }
  6. },
  7. computed: {
  8. pos() {
  9. return JSON.stringify(this.position)
  10. }
  11. },
  12. watch: {
  13. show(newVal) {
  14. let valueObj = this.position[0]
  15. if (!valueObj) return
  16. valueObj.show = newVal
  17. valueObj.once_change = true;
  18. // console.log("show newVal:",newVal);
  19. this.$set(this.position, 0, valueObj)
  20. }
  21. },
  22. mounted() {
  23. this.init()
  24. setTimeout(()=>{
  25. this.getSize()
  26. },50)
  27. },
  28. methods: {
  29. init() {
  30. //多个页面监听到这个方法时候,需要 判断是不是this
  31. uni.$on('__uni__swipe__event', (res) => {
  32. if (res !== this) {
  33. let valueObj = this.position[0]
  34. valueObj.show = false
  35. this.$set(this.position, 0, valueObj)
  36. }else{
  37. //如果是自己,设置bshow
  38. this.bshow = true;
  39. // console.log("__uni__swipe__event",this.show);
  40. }
  41. // this.bshow = true;
  42. })
  43. //开始设置隐藏
  44. this.show = false
  45. },
  46. openSwipe() {
  47. uni.$emit('__uni__swipe__event', this)
  48. },
  49. change(e) {
  50. // this.$emit('change', e.close)
  51. let valueObj = this.position[0]
  52. valueObj.show = !e.close
  53. valueObj.once_change = false;
  54. // console.log("e.close:",e.close);
  55. this.$set(this.position, 0, valueObj)
  56. // console.log('改变', e);
  57. },
  58. onClick(index, item) {
  59. this.$emit('click', {
  60. content: item,
  61. index
  62. })
  63. },
  64. getSize() {
  65. const views = uni.createSelectorQuery().in(this)
  66. views
  67. .selectAll('.selector-query-hock')
  68. .boundingClientRect(data => {
  69. data[0].show = false
  70. data[0].once_change = false;
  71. data[0].bInit = true;
  72. this.position = data
  73. })
  74. .exec()
  75. }
  76. }
  77. }