dt_custom_bar.vue 2.8 KB

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