index.vue 2.1 KB

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