header.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <script lang="ts" setup>
  2. import {computed, PropType} from "vue";
  3. import FSearch from "~/components/FSearch/FSearch.vue";
  4. import type {UserInfoModel} from "~/apis/model/userInfoModel";
  5. import {useUserStore} from "~/stores/userStore";
  6. // import {useUserStore} from "~/stores/userStore";
  7. const userStore = useUserStore()
  8. const systemInfo = uni.getSystemInfoSync()
  9. const statusBarHeight = systemInfo.statusBarHeight ?? 0
  10. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  11. const navBarHeight = computed(() => {
  12. // const propsHeight = Number(props.height)
  13. let defaultHeight = 44
  14. // #ifdef MP
  15. // if (props.fixed) {
  16. const menuButtonInfo = uni.getMenuButtonBoundingClientRect()
  17. const menuHeight = menuButtonInfo.height
  18. const menuTop = menuButtonInfo.top
  19. // console.log(menuButtonInfo)
  20. defaultHeight = (menuTop - statusBarHeight) * 2 + menuHeight
  21. // }
  22. // #endif
  23. // return propsHeight || defaultHeight
  24. return defaultHeight
  25. })
  26. const navBarStyle = computed(() => {
  27. return {
  28. paddingTop: `${statusBarHeight}px`,
  29. }
  30. })
  31. const props = defineProps({
  32. exClass: {
  33. type: String
  34. },
  35. // userInfo: {
  36. // type: Object as PropType<UserInfoModel>,
  37. // required: true
  38. // },
  39. yanglaojin: {
  40. type: Number,
  41. default: NaN
  42. }
  43. })
  44. function handleClick() {
  45. if (userStore.userInfo && userStore.uid) {
  46. uni.navigateTo({
  47. url: '/pages/annuity/index'
  48. })
  49. } else {
  50. uni.navigateTo({
  51. url: '/pages/user/login/index?key=30'
  52. })
  53. }
  54. }
  55. // function handleShowSearchPage() {
  56. //
  57. // }
  58. function handleShowMessage() {
  59. uni.navigateTo({
  60. url: '/pages/message/index'
  61. })
  62. }
  63. </script>
  64. <template>
  65. <div class="home-header fixed w-screen text-white z-10"
  66. :style="navBarStyle"
  67. :class="exClass"
  68. >
  69. <div class="flex">
  70. <div
  71. @click="handleClick"
  72. class="flex gap-2 mb-2 pl-2 flex-1"
  73. >
  74. <image v-if="userStore && userStore.userInfo && userStore.userInfo.avatar"
  75. :src="userStore.userInfo.avatar"
  76. mode="widthFix"
  77. class="w-9 h-9 rounded-full"
  78. />
  79. <image
  80. v-else
  81. src="https://app.bjtdba.com/uploads/logo.jpg"
  82. mode="widthFix"
  83. class="w-9 h-9 rounded-full"
  84. />
  85. <div class="flex flex-col ">
  86. <div class="text-sm" v-if="userStore.userInfo && userStore.userInfo.nickname">{{ userStore.userInfo.nickname ? userStore.userInfo.nickname : '登录'}}</div>
  87. <div class="text-sm" v-else>登录</div>
  88. <div class="text-xs" v-if="!isNaN(yanglaojin) && userStore.userInfo">{{ yanglaojin }}元养老金</div>
  89. <div v-else class="text-xs">
  90. 领取养老金
  91. </div>
  92. </div>
  93. </div>
  94. <div class=" right-26 flex flex-col text-[10px] justify-center items-center " @tap.stop="handleShowMessage" :style="{marginRight: `${menuButtonInfo.width + 15}px`}">
  95. <image src="/static/icon/message-dark.png" mode="widthFix" class="w-4 h-4" v-if="exClass"></image>
  96. <image src="/static/icon/message.png" mode="widthFix" class="w-4 h-4" v-else></image>
  97. <div>消息</div>
  98. </div>
  99. </div>
  100. <div class="p-3">
  101. <FSearch />
  102. </div>
  103. </div>
  104. </template>