header-nav.js 2.3 KB

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