navBar.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // pages/navBar/navBar.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. background: {
  8. type: String,
  9. value: 'rgba(255, 255, 255, 1)'
  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: ''
  26. },
  27. homeIcon: {
  28. type: String,
  29. value: ''
  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. this.triggerEvent('back', {back: 1})
  97. },
  98. home: function() {
  99. this.triggerEvent('home', {});
  100. },
  101. search: function() {
  102. wx.navigateTo({
  103. url: '../search/search'
  104. })
  105. },
  106. }
  107. })