navBar.js 2.6 KB

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