index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <uni-shadow-root class="weapp-lib-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'] = 'weapp/lib/nav-bar/index'
  28. "use strict";
  29. Object.defineProperty(exports, "__esModule", { value: true });
  30. var component_1 = require("../common/component");
  31. var utils_1 = require("../common/utils");
  32. (0, component_1.VantComponent)({
  33. classes: ['title-class'],
  34. props: {
  35. title: String,
  36. fixed: {
  37. type: Boolean,
  38. observer: 'setHeight',
  39. },
  40. placeholder: {
  41. type: Boolean,
  42. observer: 'setHeight',
  43. },
  44. leftText: String,
  45. rightText: String,
  46. customStyle: String,
  47. leftArrow: Boolean,
  48. border: {
  49. type: Boolean,
  50. value: true,
  51. },
  52. zIndex: {
  53. type: Number,
  54. value: 1,
  55. },
  56. safeAreaInsetTop: {
  57. type: Boolean,
  58. value: true,
  59. },
  60. },
  61. data: {
  62. height: 46,
  63. },
  64. created: function () {
  65. var statusBarHeight = (0, utils_1.getSystemInfoSync)().statusBarHeight;
  66. this.setData({
  67. statusBarHeight: statusBarHeight,
  68. height: 46 + statusBarHeight,
  69. });
  70. },
  71. mounted: function () {
  72. this.setHeight();
  73. },
  74. methods: {
  75. onClickLeft: function () {
  76. this.$emit('click-left');
  77. },
  78. onClickRight: function () {
  79. this.$emit('click-right');
  80. },
  81. setHeight: function () {
  82. var _this = this;
  83. if (!this.data.fixed || !this.data.placeholder) {
  84. return;
  85. }
  86. wx.nextTick(function () {
  87. (0, utils_1.getRect)(_this, '.van-nav-bar').then(function (res) {
  88. if (res && 'height' in res) {
  89. _this.setData({ height: res.height });
  90. }
  91. });
  92. });
  93. },
  94. },
  95. });
  96. export default global['__wxComponents']['weapp/lib/nav-bar/index']
  97. </script>
  98. <style platform="mp-weixin">
  99. @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)}
  100. </style>