index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <template>
  2. <view>
  3. <view class="custom-bar custom-bar-animation":style="{ 'padding-top': statusBarHeight + 'px' }" v-if="show">
  4. <!-- #ifdef MP-ALIPAY-->
  5. <view
  6. class="custom-status-bar"
  7. :style="{ 'height': navabarHeight + 'px', 'margin-left': '40rpx' }"
  8. >
  9. <image v-if="imgUrl" :src="imgUrl" style="width: 298rpx;height: 36rpx;" />
  10. <view v-else class="img-name">Hi 你好 <text>{{app_name}}</text></view>
  11. <view class="tag-wrap">放心租</view>
  12. </view>
  13. <!-- #endif -->
  14. <!-- #ifdef MP-WEIXIN -->
  15. <view
  16. class="custom-status-bar"
  17. :style="{ 'height': navabarHeight + 'px' }"
  18. >
  19. <image v-if="imgUrl" :src="imgUrl" style="width: 298rpx;height: 36rpx;" />
  20. <view v-else class="img-name">Hi 你好 <text>{{app_name}}</text></view>
  21. <view class="tag-wrap">放心租</view>
  22. </view>
  23. <!-- #endif -->
  24. </view>
  25. <view class="custom-bar":style="{ 'padding-top': statusBarHeight + 'px' }" v-else>
  26. <view
  27. class="custom-status-bar"
  28. :style="{ 'height': navabarHeight + 'px' }"
  29. >
  30. </view>
  31. </view>
  32. </view>
  33. </template>
  34. <script>
  35. const config = require('../../../../common/config.js');
  36. var storage = require('../../../../common/storage.js');
  37. import { APP_ID_NAME } from '@/common/constant.js'
  38. export default {
  39. props: {
  40. show: {
  41. type: Boolean,
  42. default: false
  43. }
  44. },
  45. data () {
  46. return {
  47. statusBarHeight: 0,
  48. navabarHeight: 0,
  49. imgUrl: '',
  50. app_name:''
  51. }
  52. },
  53. mounted() {
  54. this.setShopName()
  55. this._getCustomBar()
  56. },
  57. methods: {
  58. // 获取顶部状态栏高度(各机型不同)
  59. _getCustomBar() {
  60. const clientRect = uni.getMenuButtonBoundingClientRect()
  61. const sysinfo = uni.getSystemInfoSync()
  62. let GAP = 8
  63. // #ifdef MP-ALIPAY
  64. GAP = 0
  65. // #endif
  66. const navabarHeight = (clientRect.bottom - sysinfo.statusBarHeight) + (clientRect.top - sysinfo.statusBarHeight) + GAP
  67. this.navabarHeight = navabarHeight
  68. this.statusBarHeight = sysinfo.statusBarHeight
  69. this.$emit('customBarInfo', {
  70. navabarHeight,
  71. statusBarHeight: sysinfo.statusBarHeight
  72. })
  73. },
  74. setShopName(){
  75. const appId = uni.getAccountInfoSync().miniProgram.appId;
  76. const app_name=storage.getAppConfig().app_name
  77. var img_url='https://qiniu.bms16.com/FgUti3mvD9L4U-LzTNF70PP1BI5E' //默认小众出行 防止支付宝未配置
  78. // #ifdef MP-WEIXIN
  79. img_url=APP_ID_NAME.find(v => v.wx_id === appId)?.img_url ||''
  80. // #endif
  81. this.setData({
  82. imgUrl: img_url,
  83. app_name:app_name
  84. })
  85. }
  86. }
  87. }
  88. </script>
  89. <style scoped>
  90. .img-name {
  91. font-size: 32rpx;
  92. color: #FFFFFF;
  93. font-weight: bold;
  94. font-family: DIN;
  95. }
  96. .img-name text {
  97. font-size: 36rpx;
  98. margin-left: 20rpx;
  99. }
  100. .custom-bar {
  101. background: #0074FF;
  102. position: fixed;
  103. z-index: 999;
  104. left: 0;
  105. right: 0;
  106. top: 0;
  107. }
  108. .custom-bar-animation {
  109. /* animation: opacityAnimation 0.2s ease-in-out 0s 1; */
  110. }
  111. @keyframes opacityAnimation {
  112. 0% {
  113. transform: translateY(-60px);
  114. opacity: 0;
  115. }
  116. 100% {
  117. transform: translateY(0);
  118. opacity: 1;
  119. }
  120. }
  121. .custom-status-bar {
  122. display: flex;
  123. align-items: center;
  124. padding-left: 32rpx;
  125. }
  126. .tag-wrap {
  127. margin-left: 10rpx;
  128. background: #FFFFFF;
  129. padding: 8rpx 14rpx;
  130. border-radius: 24rpx;
  131. font-family: PingFangSC, PingFang SC;
  132. font-weight: 500;
  133. font-size: 22rpx;
  134. color: #0074FF;
  135. line-height: 20rpx;
  136. text-align: center;
  137. font-style: normal;
  138. }
  139. </style>