Ver Fonte

fix: 修复底部导航栏点击菜单与选中菜单不一致的问题

skyline há 12 horas atrás
pai
commit
3b2aa91cdf
1 ficheiros alterados com 16 adições e 8 exclusões
  1. 16 8
      haha-admin-mp/src/components/CustomTabBar.vue

+ 16 - 8
haha-admin-mp/src/components/CustomTabBar.vue

@@ -38,7 +38,8 @@
 </template>
 
 <script setup lang="ts">
-import { ref, onMounted } from 'vue';
+import { ref } from 'vue';
+import { onShow } from '@dcloudio/uni-app';
 import { logger } from '@/utils/logger';
 import { isReplenisher } from '@/utils/auth';
 
@@ -53,22 +54,27 @@ const tabPages = [
 
 const currentIndex = ref(0);
 
-onMounted(() => {
-  visible.value = !isReplenisher();
+const updateCurrentIndex = () => {
   const pages = getCurrentPages();
+  if (!pages || pages.length === 0) return;
   const currentPage = pages[pages.length - 1];
-  const currentPath = '/' + currentPage.route;
+  if (!currentPage) return;
+  let route = currentPage.route || '';
+  if (!route.startsWith('/')) route = '/' + route;
+  const idx = tabPages.indexOf(route);
+  if (idx !== -1) currentIndex.value = idx;
+};
 
-  const index = tabPages.indexOf(currentPath);
-  if (index !== -1) {
-    currentIndex.value = index;
-  }
+onShow(() => {
+  visible.value = !isReplenisher();
+  updateCurrentIndex();
 });
 
 const switchTab = (index: number) => {
   if (currentIndex.value === index) return;
 
   currentIndex.value = index;
+  uni.setStorageSync('__tab_index__', index);
   uni.switchTab({
     url: tabPages[index]
   });
@@ -162,6 +168,8 @@ const handleScan = () => {
   font-size: 20rpx;
   font-weight: 400;
   line-height: 1.3;
+  text-align: center;
+  width: 100%;
 }
 
 .tab-item.active .tab-text {