shopro-navbar.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <view>
  3. <view class="cu-custom" :style="[{ height: customBar + 'px' }]">
  4. <view class="cu-bar u-flex u-row-between" :class="{ fixed: isFixed }" :style="[style]">
  5. <view class="action u-flex" @tap="goBack" v-if="isBack">
  6. <view class="u-iconfont" :class="'uicon-' + backIconName" :style="{ color: backIconColor, fontSize: backIconSize + 'rpx' }"></view>
  7. <view class="u-back-text u-line-1 u-m-l-20" v-if="backText" :style="[backTextStyle]">{{ backText || '' }}</view>
  8. </view>
  9. <view class="content" :style="[{ top: statusBarHeight + 'px' }]"><slot name="content"></slot></view>
  10. <slot name="right"></slot>
  11. </view>
  12. </view>
  13. </view>
  14. </template>
  15. <script>
  16. /**
  17. * shopro-navbar -自定义标题栏
  18. * @property {Boolean} isBack = [true] - 是否显示返回按钮
  19. * @property {Booelan} isFixed = [true] - 是否开启定位
  20. */
  21. // 获取系统状态栏的高度
  22. let systemInfo = uni.getSystemInfoSync();
  23. let menuButtonInfo = {};
  24. // #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
  25. menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  26. // #endif
  27. export default {
  28. name: 'shopro-tabbar',
  29. data() {
  30. return {
  31. statusBarHeight: systemInfo.statusBarHeight
  32. };
  33. },
  34. computed: {
  35. // tabbar样式
  36. style() {
  37. let statusBarHeight = systemInfo.statusBarHeight;
  38. let style = {};
  39. style.height = `${this.customBar}px`;
  40. style.paddingTop = `${statusBarHeight}px`;
  41. Object.assign(style, this.background);
  42. return style;
  43. },
  44. // 高度
  45. customBar() {
  46. let statusBarHeight = systemInfo.statusBarHeight;
  47. // #ifndef MP
  48. return systemInfo.platform == 'android' ? statusBarHeight + 50 : statusBarHeight + 45;
  49. // #endif
  50. // #ifdef MP-WEIXIN
  51. return menuButtonInfo.bottom + menuButtonInfo.top - statusBarHeight;
  52. // #endif
  53. // #ifdef MP-ALIPAY
  54. return statusBarHeight + systemInfo.titleBarHeight;
  55. // #endif
  56. }
  57. },
  58. props: {
  59. isBack: {
  60. type: Boolean,
  61. default: true
  62. },
  63. isFixed: {
  64. type: Boolean,
  65. default: true
  66. },
  67. background: {
  68. type: Object,
  69. default() {
  70. return {
  71. background: '#ffffff'
  72. };
  73. }
  74. },
  75. // 返回箭头的颜色
  76. backIconColor: {
  77. type: String,
  78. default: '#606266'
  79. },
  80. // 左边返回的图标
  81. backIconName: {
  82. type: String,
  83. default: 'arrow-left'
  84. },
  85. // 左边返回图标的大小,rpx
  86. backIconSize: {
  87. type: [String, Number],
  88. default: '44'
  89. },
  90. // 返回的文字提示
  91. backText: {
  92. type: String,
  93. default: ''
  94. },
  95. // 返回的文字的 样式
  96. backTextStyle: {
  97. type: Object,
  98. default() {
  99. return {
  100. color: '#606266'
  101. };
  102. }
  103. }
  104. },
  105. methods: {
  106. goBack() {
  107. uni.navigateBack();
  108. }
  109. }
  110. };
  111. </script>
  112. <style lang="scss" scoped>
  113. .cu-custom {
  114. width: 100%;
  115. }
  116. .cu-bar {
  117. width: 100%;
  118. .content {
  119. width: 560rpx;
  120. display: flex;
  121. flex-direction: row;
  122. flex: 1;
  123. align-items: center;
  124. pointer-events: auto;
  125. }
  126. }
  127. </style>