navbar.js 2.4 KB

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