page-header.vue 1015 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <template>
  2. <view class="page_header" :style="{ paddingTop: 80 + 'rpx' }">
  3. <text class="header_title">{{ currentSchoolName }}</text>
  4. </view>
  5. </template>
  6. <script setup>
  7. import { computed, onMounted } from 'vue';
  8. import { useStore } from 'vuex';
  9. import { useSafeArea } from '@/common/safeArea';
  10. const store = useStore();
  11. const { statusBarHeight, initSafeArea } = useSafeArea();
  12. // 使用 computed 响应式获取学校名称,当 store 中 userInfo 更新时会自动重新计算
  13. const currentSchoolName = computed(() => {
  14. const userInfo = store.state.userStore.userInfo || {};
  15. return userInfo.schoolName || '';
  16. });
  17. onMounted(() => {
  18. initSafeArea();
  19. });
  20. </script>
  21. <style lang="scss" scoped>
  22. .page_header {
  23. position: fixed;
  24. top: 0;
  25. left: 0;
  26. right: 0;
  27. background-color: #FFFFFF;
  28. padding-bottom: 26rpx;
  29. padding-left: 24rpx;
  30. padding-right: 24rpx;
  31. border-bottom: 1rpx solid #F0F0F0;
  32. z-index: 999;
  33. .header_title {
  34. font-size: 44rpx;
  35. font-weight: 600;
  36. color: #333333;
  37. }
  38. }
  39. </style>