index.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <template>
  2. <uni-shadow-root class="vant-nav-bar-index"><view v-if="fixed && placeholder" :style="'height: '+(height)+'px;'"></view>
  3. <view :class="(utils.bem('nav-bar', { fixed }))+' custom-class '+(border ? 'van-hairline--bottom' : '')" :style="(computed.barStyle({ zIndex, statusBarHeight, safeAreaInsetTop }))+'; '+(customStyle)">
  4. <view class="van-nav-bar__content">
  5. <view class="van-nav-bar__left" @click="onClickLeft">
  6. <block v-if="leftArrow || leftText">
  7. <van-icon v-if="leftArrow" size="16px" name="arrow-left" custom-class="van-nav-bar__arrow"></van-icon>
  8. <view v-if="leftText" class="van-nav-bar__text" hover-class="van-nav-bar__text--hover" hover-stay-time="70">{{ leftText }}</view>
  9. </block>
  10. <slot v-else name="left"></slot>
  11. </view>
  12. <view class="van-nav-bar__title title-class van-ellipsis">
  13. <block v-if="title">{{ title }}</block>
  14. <slot v-else name="title"></slot>
  15. </view>
  16. <view class="van-nav-bar__right" @click="onClickRight">
  17. <view v-if="rightText" class="van-nav-bar__text" hover-class="van-nav-bar__text--hover" hover-stay-time="70">{{ rightText }}</view>
  18. <slot v-else name="right"></slot>
  19. </view>
  20. </view>
  21. </view></uni-shadow-root>
  22. </template>
  23. <wxs src="../wxs/utils.wxs" module="utils"></wxs><wxs src="./index.wxs" module="computed"></wxs>
  24. <script>
  25. import VanIcon from '../icon/index.vue'
  26. global['__wxVueOptions'] = {components:{'van-icon': VanIcon}}
  27. global['__wxRoute'] = 'vant/nav-bar/index'
  28. import { VantComponent } from '../common/component';
  29. import { getRect, getSystemInfoSync } from '../common/utils';
  30. VantComponent({
  31. classes: ['title-class'],
  32. props: {
  33. title: String,
  34. fixed: {
  35. type: Boolean,
  36. observer: 'setHeight',
  37. },
  38. placeholder: {
  39. type: Boolean,
  40. observer: 'setHeight',
  41. },
  42. leftText: String,
  43. rightText: String,
  44. customStyle: String,
  45. leftArrow: Boolean,
  46. border: {
  47. type: Boolean,
  48. value: true,
  49. },
  50. zIndex: {
  51. type: Number,
  52. value: 1,
  53. },
  54. safeAreaInsetTop: {
  55. type: Boolean,
  56. value: true,
  57. },
  58. },
  59. data: {
  60. height: 46,
  61. },
  62. created() {
  63. const { statusBarHeight } = getSystemInfoSync();
  64. this.setData({
  65. statusBarHeight,
  66. height: 46 + statusBarHeight,
  67. });
  68. },
  69. mounted() {
  70. this.setHeight();
  71. },
  72. methods: {
  73. onClickLeft() {
  74. this.$emit('click-left');
  75. },
  76. onClickRight() {
  77. this.$emit('click-right');
  78. },
  79. setHeight() {
  80. if (!this.data.fixed || !this.data.placeholder) {
  81. return;
  82. }
  83. wx.nextTick(() => {
  84. getRect(this, '.van-nav-bar').then((res) => {
  85. if (res && 'height' in res) {
  86. this.setData({ height: res.height });
  87. }
  88. });
  89. });
  90. },
  91. },
  92. });
  93. export default global['__wxComponents']['vant/nav-bar/index']
  94. </script>
  95. <style platform="mp-weixin">
  96. @import '../common/index.css';.van-nav-bar{background-color:var(--nav-bar-background-color,#fff);box-sizing:initial;height:var(--nav-bar-height,46px);line-height:var(--nav-bar-height,46px);position:relative;text-align:center;-webkit-user-select:none;user-select:none}.van-nav-bar__content{height:100%;position:relative}.van-nav-bar__text{color:var(--nav-bar-text-color,#1989fa);display:inline-block;margin:0 calc(var(--padding-md, 16px)*-1);padding:0 var(--padding-md,16px);vertical-align:middle}.van-nav-bar__text--hover{background-color:#f2f3f5}.van-nav-bar__arrow{color:var(--nav-bar-icon-color,#1989fa)!important;font-size:var(--nav-bar-arrow-size,16px)!important;vertical-align:middle}.van-nav-bar__arrow+.van-nav-bar__text{margin-left:-20px;padding-left:25px}.van-nav-bar--fixed{left:0;position:fixed;top:0;width:100%}.van-nav-bar__title{color:var(--nav-bar-title-text-color,#323233);font-size:var(--nav-bar-title-font-size,16px);font-weight:var(--font-weight-bold,500);margin:0 auto;max-width:60%}.van-nav-bar__left,.van-nav-bar__right{align-items:center;bottom:0;display:flex;font-size:var(--font-size-md,14px);position:absolute;top:0}.van-nav-bar__left{left:var(--padding-md,16px)}.van-nav-bar__right{right:var(--padding-md,16px)}
  97. </style>