index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { VantComponent } from '../common/component';
  2. VantComponent({
  3. classes: ['title-class'],
  4. props: {
  5. title: String,
  6. fixed: {
  7. type: Boolean,
  8. observer: 'setHeight',
  9. },
  10. placeholder: {
  11. type: Boolean,
  12. observer: 'setHeight',
  13. },
  14. leftText: String,
  15. rightText: String,
  16. customStyle: String,
  17. leftArrow: Boolean,
  18. border: {
  19. type: Boolean,
  20. value: true,
  21. },
  22. zIndex: {
  23. type: Number,
  24. value: 1,
  25. },
  26. safeAreaInsetTop: {
  27. type: Boolean,
  28. value: true,
  29. },
  30. },
  31. data: {
  32. statusBarHeight: 0,
  33. height: 44,
  34. baseStyle: '',
  35. },
  36. created() {
  37. const { statusBarHeight } = wx.getSystemInfoSync();
  38. const { safeAreaInsetTop, zIndex } = this.data;
  39. const paddingTop = safeAreaInsetTop ? statusBarHeight : 0;
  40. const baseStyle = `z-index: ${zIndex};padding-top: ${paddingTop}px;`;
  41. this.setData({
  42. statusBarHeight,
  43. height: 44 + statusBarHeight,
  44. baseStyle,
  45. });
  46. },
  47. mounted() {
  48. this.setHeight();
  49. },
  50. methods: {
  51. onClickLeft() {
  52. this.$emit('click-left');
  53. },
  54. onClickRight() {
  55. this.$emit('click-right');
  56. },
  57. setHeight() {
  58. if (!this.data.fixed || !this.data.placeholder) {
  59. return;
  60. }
  61. wx.nextTick(() => {
  62. this.getRect('.van-nav-bar').then((res) => {
  63. this.setData({ height: res.height });
  64. });
  65. });
  66. },
  67. },
  68. });