SsHeader.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <view class="ss-header" :class="{ spread: spread }" :style="{ paddingTop: navBarHeight + 'px' }">
  3. <view class="header-left" :class="{ show: showLogo }">
  4. <view class="menus" :class="{ open: switchMenu }" @tap="toggleMenus">
  5. <view class="menus-line left"></view>
  6. <image class="menus-arrow" mode="aspectFill" :src="getStaticImageUrl('/images/header-menu-arrow.png')"></image>
  7. <view class="menus-line right"></view>
  8. </view>
  9. <image class="logo" mode="aspectFill" src="/static/images/logo-round.png" @tap="goHome"></image>
  10. <view class="title">商小川</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. import { useGlobalStore } from '@/stores/global';
  16. import { MessageApi } from '@/api/message';
  17. export default {
  18. name: 'SsHeader',
  19. data() {
  20. return {
  21. globalStore: useGlobalStore(),
  22. navBarHeight: 0,
  23. showLogo: false
  24. };
  25. },
  26. computed: {
  27. spread() {
  28. return this.globalStore.spread;
  29. },
  30. switchMenu() {
  31. return this.globalStore.menuSwitch;
  32. }
  33. },
  34. mounted() {
  35. this.calculateNavBarHeight();
  36. },
  37. methods: {
  38. calculateNavBarHeight() {
  39. const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
  40. this.navBarHeight = menuButtonInfo.top + 1;
  41. setTimeout(() => {
  42. this.showLogo = true;
  43. this.globalStore.setPaddingTop(this.navBarHeight + menuButtonInfo.height);
  44. }, 100);
  45. },
  46. toggleMenus() {
  47. this.globalStore.toggleMenuSwitch();
  48. },
  49. goHome() {
  50. this.globalStore.setMenuSwitch(false);
  51. this.globalStore.setSpread(false);
  52. this.globalStore.setChatLoading(false);
  53. MessageApi.stop();
  54. }
  55. }
  56. };
  57. </script>
  58. <style scoped lang="scss">
  59. .ss-header {
  60. position: fixed;
  61. top: 0;
  62. left: 0;
  63. right: 0;
  64. z-index: 1000;
  65. padding: 0 32rpx 0 32rpx;
  66. display: flex;
  67. justify-content: space-between;
  68. align-items: center;
  69. .header-left {
  70. display: none;
  71. align-items: center;
  72. transition: padding-left 0.3s linear;
  73. .menus {
  74. display: none;
  75. align-items: center;
  76. justify-content: space-between;
  77. width: 46rpx;
  78. height: 42rpx;
  79. margin-right: 32rpx;
  80. border-top: 4rpx solid #101333;
  81. border-bottom: 4rpx solid #101333;
  82. .menus-line {
  83. height: 12rpx;
  84. border-top: 4rpx solid #101333;
  85. border-bottom: 4rpx solid #101333;
  86. transition: width 0.3s linear;
  87. &.left {
  88. width: 0;
  89. margin-left: 2rpx;
  90. }
  91. &.right {
  92. margin-right: 2rpx;
  93. width: calc(100% - 22rpx);
  94. }
  95. }
  96. .menus-arrow {
  97. width: 16rpx;
  98. height: 14rpx;
  99. margin-left: 0;
  100. margin-right: 4rpx;
  101. transition: transform 0.3s linear;
  102. }
  103. &.open {
  104. .menus-line {
  105. &.left {
  106. width: calc(100% - 20rpx);
  107. }
  108. &.right {
  109. width: 0;
  110. }
  111. }
  112. .menus-arrow {
  113. margin-left: 4rpx;
  114. margin-right: 0;
  115. transform: rotateY(180deg);
  116. }
  117. }
  118. }
  119. .logo {
  120. width: 60rpx;
  121. height: 60rpx;
  122. border-radius: 12rpx;
  123. margin-right: 16rpx;
  124. }
  125. .title {
  126. color: #101333;
  127. font-size: 32rpx;
  128. line-height: 32rpx;
  129. font-weight: bold;
  130. }
  131. &.show {
  132. display: flex;
  133. }
  134. }
  135. &.spread {
  136. .header-left {
  137. .menus {
  138. display: flex;
  139. }
  140. }
  141. }
  142. }
  143. </style>