index.vue 2.9 KB

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