topbar.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // components/topbar.js
  2. Component({
  3. externalClasses: ['topbar-class', 'topbar-title-class'],
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. title: {
  9. type: String,
  10. value: ''
  11. }
  12. },
  13. /**
  14. * 组件的初始数据
  15. */
  16. data: {
  17. },
  18. attached: function() {
  19. var url =getCurrentPages()[getCurrentPages().length-1].route
  20. let dwObj = wx.getMenuButtonBoundingClientRect()
  21. let navHeight_ = (dwObj.top + dwObj.height)
  22. let capsuleTop_ = dwObj.top
  23. let windowHeight = wx.getSystemInfoSync().windowHeight
  24. this.setData({
  25. navHeight: navHeight_,
  26. capsuleTop:capsuleTop_,
  27. capHeight: dwObj.height,
  28. bodyHeight: windowHeight - navHeight_,
  29. });
  30. },
  31. /**
  32. * 组件的方法列表
  33. */
  34. methods: {
  35. handleBack() {
  36. let routeLen = getCurrentPages().length;
  37. if (routeLen == 1) {
  38. wx.reLaunch({
  39. url: '/pages/welfareMall/index/index',
  40. })
  41. return
  42. }
  43. const url =getCurrentPages()[getCurrentPages().length-2].route
  44. wx.switchTab({
  45. url: "/" + url,
  46. })
  47. }
  48. }
  49. })