index.js 1.5 KB

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