commonTabbar.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <view v-if="currentType === 'home'" class="common_tabbar" :style="{ paddingBottom: 24 + 'rpx' }">
  3. <view v-for="(item, idx) in homeTabs" :key="idx" class="tabbar_item"
  4. :class="{ active: currentPath === item.path }" @click="switchTab(item.path)">
  5. <image :src="currentPath === item.path ? item.selectedIconPath : item.iconPath" class="tabbar_icon"
  6. mode="aspectFit"></image>
  7. <text class="tabbar_text">{{ item.text }}</text>
  8. </view>
  9. </view>
  10. <view v-else-if="currentType === 'notice'" class="common_tabbar" :style="{ paddingBottom: 24 + 'rpx' }">
  11. <view v-for="(item, idx) in noticeTabs" :key="idx" class="tabbar_item"
  12. :class="{ active: currentPath === item.path }" @click="switchTab(item.path)">
  13. <image :src="currentPath === item.path ? item.selectedIconPath : item.iconPath" class="tabbar_icon"
  14. mode="aspectFit"></image>
  15. <text class="tabbar_text">{{ item.text }}</text>
  16. </view>
  17. </view>
  18. <view v-else-if="currentType === 'materialCollection'" class="common_tabbar" :style="{ paddingBottom: 24 + 'rpx' }">
  19. <view v-for="(item, idx) in materialCollectionTabs" :key="idx" class="tabbar_item"
  20. :class="{ active: currentPath === item.path }" @click="switchTab(item.path)">
  21. <image :src="currentPath === item.path ? item.selectedIconPath : item.iconPath" class="tabbar_icon"
  22. mode="aspectFit"></image>
  23. <text class="tabbar_text">{{ item.text }}</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script setup>
  28. import { ref, computed, onMounted } from 'vue';
  29. import { useSafeArea } from '@/common/safeArea';
  30. const currentPath = ref('');
  31. const { safeAreaBottom, initSafeArea } = useSafeArea();
  32. const homeTabs = [
  33. {
  34. path: '/pages/workspace/index',
  35. iconPath: '/static/image/tabbar/workspace.png',
  36. selectedIconPath: '/static/image/tabbar/workspace_cur.png',
  37. text: '工作台'
  38. },
  39. {
  40. path: '/pages/todo/index',
  41. iconPath: '/static/image/tabbar/todo.png',
  42. selectedIconPath: '/static/image/tabbar/todo_cur.png',
  43. text: '待办'
  44. },
  45. {
  46. path: '/pages/message/index',
  47. iconPath: '/static/image/tabbar/message.png',
  48. selectedIconPath: '/static/image/tabbar/message_cur.png',
  49. text: '消息'
  50. },
  51. {
  52. path: '/pages/my/index',
  53. iconPath: '/static/image/tabbar/my.png',
  54. selectedIconPath: '/static/image/tabbar/my_cur.png',
  55. text: '我的'
  56. }
  57. ];
  58. const noticeTabs = [
  59. {
  60. path: '/pages/notice/overview/index',
  61. iconPath: '/static/image/overview/zonglan.png',
  62. selectedIconPath: '/static/image/overview/zonglanIcon.png',
  63. text: '通知总览'
  64. },
  65. {
  66. path: '/pages/notice/publish/index',
  67. iconPath: '/static/image/overview/tongzhi.png',
  68. selectedIconPath: '/static/image/overview/tongzhiIcon.png',
  69. text: '发布通知'
  70. },
  71. {
  72. path: '/pages/notice/mine/index',
  73. iconPath: '/static/image/overview/my.png',
  74. selectedIconPath: '/static/image/overview/myIcon.png',
  75. text: '我的通知'
  76. }
  77. ];
  78. const materialCollectionTabs = [
  79. {
  80. path: '/pages/materialCollection/taskOverview/index',
  81. iconPath: '/static/image/overview/zonglan.png',
  82. selectedIconPath: '/static/image/overview/zonglanIcon.png',
  83. text: '任务总览'
  84. },
  85. {
  86. path: '/pages/materialCollection/submitMaterial/index',
  87. iconPath: '/static/image/materialCollection/tijiao.png',
  88. selectedIconPath: '/static/image/materialCollection/tijiaoIcon.png',
  89. text: '提交材料'
  90. },
  91. {
  92. path: '/pages/materialCollection/reviewMaterial/index',
  93. iconPath: '/static/image/materialCollection/shenhe.png',
  94. selectedIconPath: '/static/image/materialCollection/shenheIcon.png',
  95. text: '审核材料'
  96. }
  97. ];
  98. const currentType = computed(() => {
  99. if (currentPath.value.startsWith('/pages/notice/')) {
  100. return 'notice';
  101. }
  102. if (currentPath.value.startsWith('/pages/materialCollection/taskOverview/') ||
  103. currentPath.value.startsWith('/pages/materialCollection/submitMaterial/') ||
  104. currentPath.value.startsWith('/pages/materialCollection/reviewMaterial/')) {
  105. return 'materialCollection';
  106. }
  107. if (currentPath.value.startsWith('/pages/workspace/') ||
  108. currentPath.value.startsWith('/pages/todo/') ||
  109. currentPath.value.startsWith('/pages/message/') ||
  110. currentPath.value.startsWith('/pages/my/')) {
  111. return 'home';
  112. }
  113. return '';
  114. });
  115. const updateCurrentPath = () => {
  116. const pages = getCurrentPages();
  117. if (pages.length > 0) {
  118. const currentPage = pages[pages.length - 1];
  119. currentPath.value = '/' + currentPage.route;
  120. }
  121. };
  122. const switchTab = (path) => {
  123. if (currentPath.value === path) return;
  124. if (currentType.value === 'materialCollection') {
  125. uni.redirectTo({ url: path });
  126. return;
  127. }
  128. uni.reLaunch({ url: path });
  129. };
  130. onMounted(() => {
  131. initSafeArea();
  132. updateCurrentPath();
  133. });
  134. </script>
  135. <style lang="scss" scoped>
  136. .common_tabbar {
  137. position: fixed;
  138. bottom: 0;
  139. left: 0;
  140. right: 0;
  141. display: flex;
  142. justify-content: space-around;
  143. align-items: center;
  144. background-color: #FFFFFF;
  145. padding-top: 24rpx;
  146. padding-bottom: 24rpx;
  147. border-top: 1rpx solid #F0F0F0;
  148. box-sizing: border-box;
  149. z-index: 999;
  150. .tabbar_item {
  151. display: flex;
  152. flex-direction: column;
  153. align-items: center;
  154. justify-content: center;
  155. padding: 4rpx 16rpx;
  156. .tabbar_icon {
  157. width: 44rpx;
  158. height: 44rpx;
  159. }
  160. .tabbar_text {
  161. font-size: 22rpx;
  162. color: #7A7E83;
  163. margin-top: 4rpx;
  164. }
  165. &.active {
  166. .tabbar_text {
  167. color: #2E64FA;
  168. }
  169. }
  170. }
  171. }
  172. </style>