index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { VantComponent } from '../common/component';
  2. import { getRect, 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. height: 46,
  34. },
  35. created() {
  36. const { statusBarHeight } = getSystemInfoSync();
  37. this.setData({
  38. statusBarHeight,
  39. height: 46 + statusBarHeight,
  40. });
  41. },
  42. mounted() {
  43. this.setHeight();
  44. },
  45. methods: {
  46. onClickLeft() {
  47. this.$emit('click-left');
  48. },
  49. onClickRight() {
  50. this.$emit('click-right');
  51. },
  52. setHeight() {
  53. if (!this.data.fixed || !this.data.placeholder) {
  54. return;
  55. }
  56. wx.nextTick(() => {
  57. getRect(this, '.van-nav-bar').then((res) => {
  58. if (res && 'height' in res) {
  59. this.setData({ height: res.height });
  60. }
  61. });
  62. });
  63. },
  64. },
  65. });