From abbe81a225fc2b213400f429a73213d93e332ba9 Mon Sep 17 00:00:00 2001
From: zhengyiming <540361168@qq.com>
Date: 星期四, 14 八月 2025 13:52:26 +0800
Subject: [PATCH] fix: 灵工管理

---
 apps/bMiniApp/src/custom-tab-bar/index.tsx |   14 ++++++++++----
 apps/cMiniApp/src/custom-tab-bar/index.tsx |   14 ++++++++++----
 2 files changed, 20 insertions(+), 8 deletions(-)

diff --git a/apps/bMiniApp/src/custom-tab-bar/index.tsx b/apps/bMiniApp/src/custom-tab-bar/index.tsx
index 083f636..72aab82 100644
--- a/apps/bMiniApp/src/custom-tab-bar/index.tsx
+++ b/apps/bMiniApp/src/custom-tab-bar/index.tsx
@@ -15,6 +15,7 @@
   icon: string;
   activeIcon: string;
   pagePath: string;
+  currentPath: string;
   active: boolean;
   className: string;
   onClick?: (url: string, index: number) => any;
@@ -28,14 +29,15 @@
 
 const TarBarItem = function (props: TarBarItemProps, context: SetupContext<TarBarItemEvents>) {
   const _badge = props.badge > 99 ? '99+' : props.badge;
+  const isActive = props.currentPath.toLowerCase().includes(props.pagePath.toLowerCase());
   return (
     <div
-      class={['bottom-tab-item', { active: props.active }, props.className]}
+      class={['bottom-tab-item', { active: isActive }, props.className]}
       onClick={() => context.emit('click', props.pagePath, props.index)}
     >
       <div class="bottom-tab-item-icon-wrapper">
         {props.badge > 0 && <div class="bottom-tab-item-badge">{_badge}</div>}
-        <img class="bottom-tab-item-icon" src={props.active ? props.activeIcon : props.icon} />
+        <img class="bottom-tab-item-icon" src={isActive ? props.activeIcon : props.icon} />
       </div>
       <div class="bottom-tab-item-text">{props.text}</div>
     </div>
@@ -82,8 +84,9 @@
         }
         return;
       }
-      system.setTabIndex(index);
-      Taro.switchTab({ url });
+      Taro.switchTab({ url }).then(() => {
+        system.setTabIndex(index);
+      });
     };
 
     function goPublish() {
@@ -121,6 +124,7 @@
             icon="../assets/tabbar/icon-home.png"
             activeIcon="../assets/tabbar/icon-home-active.png"
             pagePath={TabBarPageRouter.Home}
+            currentPath={router.path}
             index={0}
             active={system.activeTab === 0}
             className="home"
@@ -131,6 +135,7 @@
             icon="../assets/tabbar/icon-task.png"
             activeIcon="../assets/tabbar/icon-task-active.png"
             pagePath={TabBarPageRouter.Workbenches}
+            currentPath={router.path}
             active={system.activeTab === 1}
             className="task"
             onClick={switchTab}
@@ -141,6 +146,7 @@
             icon="../assets/tabbar/icon-mine.png"
             activeIcon="../assets/tabbar/icon-mine-active.png"
             pagePath={TabBarPageRouter.Mine}
+            currentPath={router.path}
             active={system.activeTab === 2}
             className="mine"
             onClick={switchTab}
diff --git a/apps/cMiniApp/src/custom-tab-bar/index.tsx b/apps/cMiniApp/src/custom-tab-bar/index.tsx
index 1645110..5626e58 100644
--- a/apps/cMiniApp/src/custom-tab-bar/index.tsx
+++ b/apps/cMiniApp/src/custom-tab-bar/index.tsx
@@ -15,6 +15,7 @@
   icon: string;
   activeIcon: string;
   pagePath: string;
+  currentPath: string;
   active: boolean;
   className: string;
   onClick?: (url: string, index: number) => any;
@@ -28,14 +29,15 @@
 
 const TarBarItem = function (props: TarBarItemProps, context: SetupContext<TarBarItemEvents>) {
   const _badge = props.badge > 99 ? '99+' : props.badge;
+  const isActive = props.currentPath.toLowerCase().includes(props.pagePath.toLowerCase());
   return (
     <div
-      class={['bottom-tab-item', { active: props.active }, props.className]}
+      class={['bottom-tab-item', { active: isActive }, props.className]}
       onClick={() => context.emit('click', props.pagePath, props.index)}
     >
       <div class="bottom-tab-item-icon-wrapper">
         {props.badge > 0 && <div class="bottom-tab-item-badge">{_badge}</div>}
-        <img class="bottom-tab-item-icon" src={props.active ? props.activeIcon : props.icon} />
+        <img class="bottom-tab-item-icon" src={isActive ? props.activeIcon : props.icon} />
       </div>
       <div class="bottom-tab-item-text">{props.text}</div>
     </div>
@@ -82,8 +84,9 @@
         }
         return;
       }
-      system.setTabIndex(index);
-      Taro.switchTab({ url });
+      Taro.switchTab({ url }).then(() => {
+        system.setTabIndex(index);
+      });
     };
 
     function goPublish() {
@@ -121,6 +124,7 @@
             icon="../assets/tabbar/icon-home.png"
             activeIcon="../assets/tabbar/icon-home-active.png"
             pagePath={TabBarPageRouter.Home}
+            currentPath={router.path}
             index={0}
             active={system.activeTab === 0}
             className="home"
@@ -132,6 +136,7 @@
             icon="../assets/tabbar/icon-task.png"
             activeIcon="../assets/tabbar/icon-task-active.png"
             pagePath={TabBarPageRouter.Task}
+            currentPath={router.path}
             active={system.activeTab === 1}
             className="task"
             onClick={switchTab}
@@ -142,6 +147,7 @@
             icon="../assets/tabbar/icon-mine.png"
             activeIcon="../assets/tabbar/icon-mine-active.png"
             pagePath={TabBarPageRouter.Mine}
+            currentPath={router.path}
             active={system.activeTab === 2}
             className="mine"
             onClick={switchTab}

--
Gitblit v1.9.1