dt_custom_bar.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <template>
  2. <view>
  3. <view :style="{ background: background }" class="custom-header-container">
  4. <view :style="{height:getStausBarHeight + 'px'}" class="custom-header-status-bar"></view>
  5. <view :class="{'ios-center': isIos }" class="custom-header-top-container">
  6. <view :style="{color: color}" :class="{isIos: isIos}" class="custom-back-btn iconfont" v-if="showBack"
  7. @tap="backTap">
  8. <image v-if="color!='#ffffff'"
  9. src="https://szsq.nxzhsq.cn/community/miniofile/image/ic_back_black.png" mode="widthFix"
  10. style="width: 20px;"></image>
  11. <image v-if="color=='#ffffff'"
  12. src="https://szsq.nxzhsq.cn/community/miniofile/image/ic_back_white.png" mode="widthFix"
  13. style="width: 20px;"></image>
  14. </view>
  15. <view :style="{color: color}"
  16. :class="[{'ios-center': isIos },{'android-left-30':!isIos&&!showBack},{'android-left-80':!isIos&&showBack}]"
  17. class="custom-header-title">{{ title }}
  18. </view>
  19. </view>
  20. </view>
  21. <view :style="{ height: getStausBarHeight + (isIos ? 45 : 48) + 'px' }" class="custom-header-height"></view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. props: {
  27. title: {
  28. type: String,
  29. default: ''
  30. },
  31. background: {
  32. type: String,
  33. default: 'transparent'
  34. },
  35. color: {
  36. type: String,
  37. default: '#ffffff'
  38. },
  39. showBack: {
  40. type: Boolean,
  41. default: false
  42. },
  43. },
  44. computed: {
  45. getStausBarHeight() {
  46. try {
  47. const res = uni.getSystemInfoSync();
  48. return res.statusBarHeight;
  49. } catch (e) {
  50. }
  51. },
  52. isIos() {
  53. return uni.getSystemInfoSync().system.indexOf('iOS') > -1
  54. }
  55. },
  56. methods: {
  57. backTap() {
  58. uni.navigateBack({
  59. delta: 1
  60. })
  61. }
  62. }
  63. }
  64. </script>
  65. <style scoped lang="scss">
  66. .custom-header-top-container {
  67. display: flex;
  68. flex-flow: row nowrap;
  69. justify-content: flex-start;
  70. width: 100%;
  71. align-items: center;
  72. &.ios-center {
  73. justify-content: center;
  74. }
  75. }
  76. .custom-header-container {
  77. z-index: 9;
  78. width: 750 upx;
  79. display: flex;
  80. flex-direction: column;
  81. align-items: center;
  82. position: fixed;
  83. top: 0;
  84. }
  85. .custom-back-btn {
  86. height: 48px;
  87. line-height: 48px;
  88. width: 40px;
  89. margin: 0;
  90. padding: 0;
  91. border-radius: 0 !important;
  92. display: flex;
  93. align-items: center;
  94. justify-content: center;
  95. position: absolute;
  96. left: 0 upx;
  97. font-size: 18px;
  98. border-radius: 5px;
  99. font-weight: 500;
  100. color: #FFFFFF;
  101. &:active {
  102. background: #0D72DF;
  103. }
  104. &.isIos {
  105. line-height: 45px;
  106. height: 45px;
  107. }
  108. }
  109. .custom-header-status-bar {
  110. width: 100%;
  111. top: 0;
  112. position: sticky;
  113. z-index: 100;
  114. }
  115. .custom-header-title {
  116. height: 48px;
  117. line-height: 48px;
  118. font-size: 16px;
  119. color: #FFFFFF;
  120. &.ios-center {
  121. margin-left: 0;
  122. line-height: 45px;
  123. height: 45px;
  124. }
  125. &.android-left-30 {
  126. margin-left: 30 upx;
  127. }
  128. &.android-left-80 {
  129. margin-left: 80 upx;
  130. }
  131. }
  132. </style>