nav-bar.vue 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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>
  8. <van-icon v-if="hasParent" name="arrow-left" @click="goBack"/>
  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 systemInfo = uni.getSystemInfoSync()
  38. this.statusBarHeight = systemInfo.statusBarHeight
  39. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  40. this.titleBarHeight = (menuButtonInfo.top - this.statusBarHeight) * 2 + menuButtonInfo.height + (systemInfo.screenWidth / 750 * 16)
  41. },
  42. methods: {
  43. goBack() {
  44. uni.navigateBack()
  45. }
  46. }
  47. }
  48. </script>
  49. <style lang="scss" scoped>
  50. .nav-bar {
  51. background: linear-gradient( 270deg, #2b2359 9%, #405491 44%, #2b2359 92%), rgba(0,0,0,0.2);
  52. }
  53. .nav-bar-title{
  54. display: flex;
  55. justify-content: space-between;
  56. align-items: center;
  57. padding: 0 32rpx;
  58. view{
  59. color: #ffffff;
  60. }
  61. }
  62. .nav-bar-title-text{
  63. flex: 1;
  64. font-weight: 500;
  65. font-size: $fontSize5;
  66. line-height: 42rpx;
  67. text-align: left;
  68. text-transform: none;
  69. padding-left: 8rpx;
  70. }
  71. </style>