index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var component_1 = require("../common/component");
  6. var utils_1 = require("../common/utils");
  7. (0, component_1.VantComponent)({
  8. classes: ['title-class'],
  9. props: {
  10. title: String,
  11. fixed: {
  12. type: Boolean,
  13. observer: 'setHeight',
  14. },
  15. placeholder: {
  16. type: Boolean,
  17. observer: 'setHeight',
  18. },
  19. leftText: String,
  20. rightText: String,
  21. customStyle: String,
  22. leftArrow: Boolean,
  23. border: {
  24. type: Boolean,
  25. value: true,
  26. },
  27. zIndex: {
  28. type: Number,
  29. value: 1,
  30. },
  31. safeAreaInsetTop: {
  32. type: Boolean,
  33. value: true,
  34. },
  35. // 新增参数
  36. background: {
  37. type: String,
  38. value: ''
  39. },
  40. color: {
  41. type: String,
  42. value: ''
  43. },
  44. iconColor: {
  45. type: String,
  46. value: 'rgba(0,0,0,0.9)'
  47. },
  48. borderColor: {
  49. type: String,
  50. value: '#d9d9dc'
  51. },
  52. back: {
  53. type: Boolean,
  54. value: true
  55. },
  56. tab: {
  57. type: String,
  58. value: ''
  59. },
  60. url: {
  61. type: String,
  62. value: ''
  63. },
  64. homeButton: {
  65. type: Boolean,
  66. value: false,
  67. },
  68. // back为true的时候,返回的页面深度
  69. delta: {
  70. type: Number,
  71. value: 1
  72. },
  73. },
  74. data: {
  75. height: 46,
  76. },
  77. created: function () {
  78. var statusBarHeight = (0, utils_1.getSystemInfoSync)().statusBarHeight;
  79. var menu = wx.getMenuButtonBoundingClientRect()
  80. this.setData({
  81. statusBarHeight: statusBarHeight,
  82. height: 46 + statusBarHeight,
  83. menuHeight:menu.height,
  84. menuTop:menu.top - statusBarHeight
  85. });
  86. },
  87. mounted: function () {
  88. this.setHeight();
  89. },
  90. methods: {
  91. back() {
  92. const data = this.data
  93. if (data.delta) {
  94. wx.navigateBack({
  95. delta: data.delta
  96. })
  97. }
  98. this.triggerEvent('back', { delta: data.delta }, {})
  99. },
  100. //回到首页点击事件
  101. home() {
  102. const data = this.data
  103. if (data.tab) {
  104. wx.switchTab({
  105. url: data.url,
  106. })
  107. } else {
  108. wx.navigateTo({
  109. url: data.url,
  110. })
  111. }
  112. //this.triggerEvent('home', { tab: data.tab, url: data.url }, {})
  113. },
  114. onClickLeft: function () {
  115. this.$emit('click-left');
  116. },
  117. onClickRight: function () {
  118. this.$emit('click-right');
  119. },
  120. setHeight: function () {
  121. var _this = this;
  122. if (!this.data.fixed || !this.data.placeholder) {
  123. return;
  124. }
  125. wx.nextTick(function () {
  126. (0, utils_1.getRect)(_this, '.van-nav-bar').then(function (res) {
  127. if (res && 'height' in res) {
  128. _this.setData({
  129. height: res.height
  130. });
  131. }
  132. });
  133. });
  134. },
  135. },
  136. });