index.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="navbar" :style="{height:statusBarHeight+navBareight +'px',background}"> <!-- 如若不写 高度始终为44 没有找到原因 -->
  3. <view class="narbar-flexd" :style="[{background}]">
  4. <view :style=" {height:statusBarHeight+'px'}"></view>
  5. <view class="narbar-content" :style="{height:navBareight+'px','justify-content':flex=='cen'?'center':''}">
  6. <!-- 左侧返回按钮 -->
  7. <view class="left" @click="onBack" v-if="back" :style="[{color},{paddingTop}]">
  8. <uni-icons type="arrowleft" size="25" :color='color'></uni-icons>
  9. </view>
  10. <view class="left" @click="" v-if="!back&&navImg">
  11. <image :showLoading="true" mode="heightFix" :src="navImg"
  12. style="width:40rpx;height:60rpx;margin-right: 8rpx;" @click="">
  13. </image>
  14. </view>
  15. <view class="title" :style="[{color}]" v-if="title">
  16. {{title.replace('true','')}}
  17. </view>
  18. </view>
  19. </view>
  20. <view class="navHeight" :style="{height:statusBarHeight+navBareight +'px'}"></view>
  21. </view>
  22. </template>
  23. <script>
  24. export default {
  25. data() {
  26. return {
  27. statusBarHeight: 20,
  28. navBareight: 45,
  29. windowWidth: 375,
  30. };
  31. },
  32. props: {
  33. backType: { // 标题文字(默认为空)
  34. type: String,
  35. default: ''
  36. },
  37. navImg: { // 标题文字(默认为空)
  38. type: String,
  39. default: ''
  40. },
  41. flex: { // 标题文字(默认为空)
  42. type: String,
  43. default: 'left'
  44. },
  45. title: { // 标题文字(默认为空)
  46. type: String,
  47. default: ' '
  48. },
  49. color: { // 标题和返回按钮颜色(默认白色)
  50. type: String,
  51. default: '#fff'
  52. },
  53. //建议使用background 因为使用backgroundColor,会导致不识别渐变颜色
  54. background: { // 背景颜色(不传值默认透明)
  55. type: String,
  56. default: 'transparent'
  57. },
  58. back: { // 是否显示返回按钮(不传值默认不显示)
  59. type: Boolean,
  60. default: false
  61. },
  62. backHome: { // 是否显示返回按钮(不传值默认不显示)
  63. type: Boolean,
  64. default: false
  65. },
  66. },
  67. created() {
  68. //获取手机系统信息 -- 状态栏高度
  69. let {
  70. statusBarHeight,
  71. windowWidth
  72. } = uni.getSystemInfoSync()
  73. this.statusBarHeight = statusBarHeight
  74. this.windowWidth = windowWidth
  75. //去除
  76. //#ifndef H5 || MP-ALIPAY ||APP-PLUS
  77. //获取小程序胶囊的高度
  78. let {
  79. top,
  80. bottom,
  81. left
  82. } = uni.getMenuButtonBoundingClientRect()
  83. //高度 =(胶囊底部高低-状态栏高度)+(胶囊顶部高度-状态栏内的高度)
  84. this.navBareight = (bottom - statusBarHeight) + (top - statusBarHeight)
  85. this.windowWidth = left
  86. //#endif
  87. },
  88. methods: {
  89. // 左侧返回按钮调用
  90. onBack() {
  91. if (this.backType) {
  92. uni.switchTab({
  93. url: '/pages/index'
  94. })
  95. } else {
  96. this.$emit("onBack");
  97. uni.navigateBack({
  98. delta: 1, //返回层数,2则上上页
  99. })
  100. }
  101. }
  102. }
  103. }
  104. </script>
  105. <style lang="scss" scoped>
  106. @import "./index.scss";
  107. </style>