nav-bar.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <view class="nav-bar">
  3. <view class="nav-bar-status" :style="{ height: statusBarHeight + 'px' }">
  4. </view>
  5. <view class="nav-bar-title" :style="{ height: titleBarHeight +'px' }">
  6. <template v-if="title">
  7. <view class="btn-back" @click="goBack">
  8. <van-icon v-if="hasParent" name="arrow-left" />
  9. </view>
  10. <view class="nav-bar-title-text">{{ title }}</view>
  11. <view></view>
  12. </template>
  13. <template v-else>
  14. <view><slot></slot></view>
  15. </template>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. title: String
  23. },
  24. computed: {
  25. hasParent() {
  26. return getCurrentPages().length > 1
  27. }
  28. },
  29. data() {
  30. return {
  31. titleBarHeight: 0,
  32. statusBarHeight: 0,
  33. isNotchScreen: false
  34. }
  35. },
  36. created() {
  37. const windowInfo = uni.getWindowInfo()
  38. this.statusBarHeight = windowInfo.statusBarHeight
  39. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  40. this.titleBarHeight = (menuButtonInfo.top - this.statusBarHeight) * 2 + menuButtonInfo.height + (windowInfo.screenWidth / 750 * 16)
  41. this.$emit('init', {
  42. detail: {
  43. navbarHeight: this.statusBarHeight + this.titleBarHeight,
  44. pageHeight: windowInfo.screenHeight - (this.statusBarHeight + this.titleBarHeight)
  45. }
  46. })
  47. },
  48. methods: {
  49. goBack() {
  50. wx.navigateBack()
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .nav-bar {
  57. background: linear-gradient( 270deg, #2b2359 9%, #405491 44%, #2b2359 92%), rgba(0,0,0,0.2);
  58. }
  59. .nav-bar-title{
  60. display: flex;
  61. justify-content: space-between;
  62. align-items: center;
  63. padding: 0 32rpx;
  64. view{
  65. color: #ffffff;
  66. }
  67. }
  68. .nav-bar-title-text{
  69. flex: 1;
  70. font-weight: 500;
  71. font-size: $fontSize5;
  72. line-height: 42rpx;
  73. text-align: left;
  74. text-transform: none;
  75. padding-left: 8rpx;
  76. }
  77. .btn-back{
  78. padding: 0 6rpx;
  79. }
  80. </style>