topbar.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. const { isEmpty } = require("../utils/util")
  2. // components/topbar.js
  3. Component({
  4. externalClasses: ['topbar-class', 'topbar-title-class', 'back-color-class'],
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. title: {
  10. type: String,
  11. value: ''
  12. },
  13. backColor: {
  14. type: String,
  15. value: ''
  16. },
  17. titleColor: {
  18. type: String,
  19. value: ''
  20. }
  21. },
  22. /**
  23. * 组件的初始数据
  24. */
  25. data: {
  26. },
  27. attached: function() {
  28. let dwObj = wx.getMenuButtonBoundingClientRect()
  29. let navHeight_ = (dwObj.top + dwObj.height)
  30. let capsuleTop_ = dwObj.top
  31. let windowHeight = wx.getSystemInfoSync().windowHeight
  32. const data = {
  33. navHeight: navHeight_,
  34. capsuleTop:capsuleTop_,
  35. capHeight: dwObj.height,
  36. bodyHeight: windowHeight - navHeight_,
  37. }
  38. if (!isEmpty(this.data.backColor)) {
  39. data.backStyle = "color:" + this.data.backColor + ";";
  40. }
  41. if (!isEmpty(this.data.titleColor)) {
  42. data.titleStyle = "color:" + this.data.titleColor + ";"
  43. }
  44. this.setData(data);
  45. },
  46. /**
  47. * 组件的方法列表
  48. */
  49. methods: {
  50. handleBack() {
  51. let routeLen = getCurrentPages().length;
  52. if (routeLen == 1) {
  53. wx.reLaunch({
  54. url: '/pages/welfareMall/index/index',
  55. })
  56. return
  57. }
  58. wx.navigateBack({
  59. delta: -1
  60. })
  61. }
  62. }
  63. })