index.vue 2.4 KB

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