commonTabbar.vue 2.7 KB

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