Explorar o código

fix(tabbar): sync highlight on tab page onShow

xuyunhui hai 1 semana
pai
achega
6f7626c078

+ 4 - 0
src/custom-tab-bar/index.js

@@ -62,5 +62,9 @@ Component({
         this.setData({ selected: idx })
       }
     },
+
+    setSelected(index) {
+      this.setData({ selected: index })
+    },
   },
 })

+ 7 - 0
src/pages/home/home.vue

@@ -7,6 +7,7 @@
 </template>
 
 <script setup lang="ts">
+import { onShow } from '@dcloudio/uni-app'
 import { computed } from 'vue'
 import { useAuthStore } from '@/stores/auth'
 import SalesHome from '@/components/home/SalesHome.vue'
@@ -15,4 +16,10 @@ import ConstructionHome from '@/components/home/ConstructionHome.vue'
 
 const authStore = useAuthStore()
 const role = computed(() => authStore.userRole || 'sales')
+
+onShow(() => {
+  const pages = getCurrentPages()
+  const page = pages[pages.length - 1] as any
+  page?.getTabBar?.()?.setSelected?.(0)
+})
 </script>

+ 12 - 0
src/pages/my/my.vue

@@ -5,5 +5,17 @@
 </template>
 
 <script setup lang="ts">
+import { onShow } from '@dcloudio/uni-app'
+import { useAuthStore } from '@/stores/auth'
 import ProfileView from '@/components/my/ProfileView.vue'
+
+const authStore = useAuthStore()
+
+onShow(() => {
+  const pages = getCurrentPages()
+  const page = pages[pages.length - 1] as any
+  const role = authStore.userRole
+  const index = role === 'dispatch' ? 3 : 2
+  page?.getTabBar?.()?.setSelected?.(index)
+})
 </script>

+ 7 - 0
src/pages/schedule/schedule.vue

@@ -3,5 +3,12 @@
 </template>
 
 <script setup lang="ts">
+import { onShow } from '@dcloudio/uni-app'
 import ScheduleView from '@/components/dispatch/ScheduleView.vue'
+
+onShow(() => {
+  const pages = getCurrentPages()
+  const page = pages[pages.length - 1] as any
+  page?.getTabBar?.()?.setSelected?.(1)
+})
 </script>

+ 5 - 0
src/pages/task/task.vue

@@ -23,6 +23,11 @@ onLoad(() => {
 
 onShow(() => {
   taskStore.fetchTasks()
+  const pages = getCurrentPages()
+  const page = pages[pages.length - 1] as any
+  const role = authStore.userRole
+  const index = role === 'dispatch' ? 2 : 1
+  page?.getTabBar?.()?.setSelected?.(index)
 })
 
 onPullDownRefresh(async () => {