index.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <view class="zs-header" :style="{height:statusBarHeight+navBareight +'px',background:background?'#fff':''}" @click="back">
  3. <image class="back" :src="background?backIcon:whiteBack" mode=""></image>
  4. <!-- <image class="back" :src="backIcon" mode=""></image> -->
  5. <view class="title" :style="{color:background?'#222222':'#fff'}">
  6. {{title}}
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. props: {
  13. id: {
  14. type: String,
  15. default: '#zs-Header'
  16. },
  17. top: {
  18. type: String,
  19. default: ''
  20. },
  21. title: {
  22. type: String,
  23. default: ''
  24. },
  25. background: {
  26. type: Boolean,
  27. default: false
  28. },
  29. customPath: {
  30. type: String,
  31. default: ''
  32. },
  33. },
  34. data() {
  35. return {
  36. backIcon:require('@/static/back-btn.png'),
  37. whiteBack:require('@/static/back-btn-white.png'),
  38. statusBarHeight:20,
  39. navBareight: 45,
  40. }
  41. },
  42. methods: {
  43. back(){
  44. if(this.customPath){
  45. uni.navigateTo({
  46. url:this.customPath
  47. })
  48. }else{
  49. var pages = getCurrentPages();
  50. if(pages.length == 1){
  51. uni.switchTab({
  52. url:'/pages/index/index'
  53. })
  54. }else{
  55. uni.navigateBack();
  56. }
  57. }
  58. },
  59. },
  60. onReady() {
  61. },
  62. beforeDestroy() {
  63. },
  64. created() {
  65. //获取手机系统信息 -- 状态栏高度
  66. let {
  67. statusBarHeight,
  68. } = uni.getSystemInfoSync()
  69. this.statusBarHeight = statusBarHeight
  70. //去除
  71. //#ifndef H5 || MP-ALIPAY ||APP-PLUS
  72. //获取小程序胶囊的高度
  73. let {
  74. top,
  75. bottom,
  76. left
  77. } = uni.getMenuButtonBoundingClientRect()
  78. //高度 =(胶囊底部高低-状态栏高度)+(胶囊顶部高度-状态栏内的高度)
  79. this.navBareight = (bottom - statusBarHeight) + (top - statusBarHeight)
  80. //#endif
  81. }
  82. }
  83. </script>
  84. <style lang="scss" scoped>
  85. .zs-header {
  86. position: fixed;
  87. width: 100%;
  88. // height: calc(44px + env(safe-area-inset-top));
  89. top: 0;
  90. left: 0;
  91. z-index: 999;
  92. display: flex;
  93. align-items: flex-end;
  94. justify-content: center;
  95. box-sizing: border-box;
  96. padding: 6px;
  97. transition: background .3s ease-in-out;
  98. .back {
  99. width: 30rpx;
  100. height: 30rpx;
  101. position: absolute;
  102. bottom: 10px;
  103. // top: calc(16px + env(safe-area-inset-top));
  104. left: 20rpx;
  105. }
  106. .title {
  107. font-size: 36rpx;
  108. color: #222222;
  109. font-weight: bold;
  110. }
  111. }
  112. </style>