commonTabbar.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <view v-if="currentType === 'notice'" class="common_tabbar">
  3. <view v-for="(item, idx) in noticeTabs" :key="idx" class="tabbar_item" :class="{ active: currentPath === item.path }" @click="switchTab(item.path)">
  4. <image :src="currentPath === item.path ? item.selectedIconPath : item.iconPath" class="tabbar_icon" mode="aspectFit"></image>
  5. <text class="tabbar_text">{{ item.text }}</text>
  6. </view>
  7. </view>
  8. </template>
  9. <script setup>
  10. import { ref, computed, onMounted } from 'vue';
  11. const currentPath = ref('');
  12. const noticeTabs = [
  13. {
  14. path: '/pages/notice/overview/index',
  15. iconPath: '/static/image/overview/zonglan.png',
  16. selectedIconPath: '/static/image/overview/zonglanIcon.png',
  17. text: '通知总览'
  18. },
  19. {
  20. path: '/pages/notice/publish/index',
  21. iconPath: '/static/image/overview/tongzhi.png',
  22. selectedIconPath: '/static/image/overview/tongzhiIcon.png',
  23. text: '发布通知'
  24. },
  25. {
  26. path: '/pages/notice/mine/index',
  27. iconPath: '/static/image/overview/my.png',
  28. selectedIconPath: '/static/image/overview/myIcon.png',
  29. text: '我的通知'
  30. }
  31. ];
  32. const currentType = computed(() => {
  33. if (currentPath.value.startsWith('/pages/notice/')) {
  34. return 'notice';
  35. }
  36. return 'home';
  37. });
  38. const updateCurrentPath = () => {
  39. const pages = getCurrentPages();
  40. if (pages.length > 0) {
  41. const currentPage = pages[pages.length - 1];
  42. currentPath.value = '/' + currentPage.route;
  43. }
  44. };
  45. const switchTab = (path) => {
  46. if (currentPath.value === path) return;
  47. uni.redirectTo({ url: path });
  48. };
  49. onMounted(() => {
  50. updateCurrentPath();
  51. if (currentType.value === 'notice') {
  52. uni.hideTabBar({
  53. fail: () => {}
  54. });
  55. }
  56. });
  57. </script>
  58. <style lang="scss" scoped>
  59. .common_tabbar {
  60. position: fixed;
  61. bottom: 0;
  62. left: 0;
  63. right: 0;
  64. display: flex;
  65. justify-content: space-around;
  66. background-color: #FFFFFF;
  67. padding: 16rpx 0;
  68. padding-bottom: calc(16rpx + env(safe-area-inset-bottom));
  69. border-top: 1rpx solid #F0F0F0;
  70. height: 84px;
  71. box-sizing: border-box;
  72. z-index: 999;
  73. .tabbar_item {
  74. display: flex;
  75. flex-direction: column;
  76. align-items: center;
  77. justify-content: center;
  78. .tabbar_icon {
  79. width: 48rpx;
  80. height: 48rpx;
  81. }
  82. .tabbar_text {
  83. font-size: 22rpx;
  84. color: #7A7E83;
  85. margin-top: 4rpx;
  86. }
  87. &.active {
  88. .tabbar_text {
  89. color: #2E64FA;
  90. }
  91. }
  92. }
  93. }
  94. </style>