header-nav.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. Component({
  2. properties: {
  3. background: {
  4. type: String,
  5. value: 'rgba(255, 255, 255, 1)'
  6. },
  7. color: {
  8. type: String,
  9. value: 'rgba(0, 0, 0, 1)'
  10. },
  11. titleText: {
  12. type: String,
  13. value: '导航栏'
  14. },
  15. titleImg: {
  16. type: String,
  17. value: ''
  18. },
  19. backIcon: {
  20. type: String,
  21. value: '/image/4Dage/icon-back.svg'
  22. },
  23. homeIcon: {
  24. type: String,
  25. value: '/image/4Dage/icon-home.svg'
  26. },
  27. fontSize: {
  28. type: Number,
  29. value: 16
  30. },
  31. iconHeight: {
  32. type: Number,
  33. value: 19
  34. },
  35. iconWidth: {
  36. type: Number,
  37. value: 58
  38. }
  39. },
  40. attached: function () {
  41. var that = this;
  42. that.setNavSize();
  43. that.setStyle();
  44. },
  45. data: {
  46. },
  47. methods: {
  48. // 通过获取系统信息计算导航栏高度
  49. setNavSize: function () {
  50. var that = this
  51. , sysinfo = wx.getSystemInfoSync()
  52. , statusHeight = sysinfo.statusBarHeight
  53. , isiOS = sysinfo.system.indexOf('iOS') > -1
  54. , navHeight;
  55. if (!isiOS) {
  56. navHeight = 48;
  57. } else {
  58. navHeight = 44;
  59. }
  60. that.setData({
  61. status: statusHeight,
  62. navHeight: navHeight
  63. })
  64. },
  65. setStyle: function () {
  66. var that = this
  67. , containerStyle
  68. , textStyle
  69. , iconStyle;
  70. containerStyle = [
  71. 'background:' + that.data.background
  72. ].join(';');
  73. textStyle = [
  74. 'color:' + that.data.color,
  75. 'font-size:' + that.data.fontSize + 'px'
  76. ].join(';');
  77. iconStyle = [
  78. 'width: ' + that.data.iconWidth + 'px',
  79. 'height: ' + that.data.iconHeight + 'px'
  80. ].join(';');
  81. that.setData({
  82. containerStyle: containerStyle,
  83. textStyle: textStyle,
  84. iconStyle: iconStyle
  85. })
  86. },
  87. // 返回事件
  88. back: function () {
  89. wx.navigateBack({
  90. delta: 1
  91. })
  92. getApp().autoSubcrebe && getApp().autoSubcrebe()
  93. this.triggerEvent('back', { back: 1 })
  94. },
  95. home: function () {
  96. getApp().autoSubcrebe && getApp().autoSubcrebe()
  97. wx.switchTab({
  98. url: '/pages/index/index'
  99. })
  100. this.triggerEvent('home', {});
  101. }
  102. }
  103. })