|
@@ -0,0 +1,68 @@
|
|
|
+<template>
|
|
|
+ <nut-tabbar
|
|
|
+ v-model="tabBarStore.currentIndex"
|
|
|
+ bottom
|
|
|
+ safe-area-inset-bottom
|
|
|
+ placeholder
|
|
|
+ unactive-color="#999"
|
|
|
+ active-color="#3C92FB"
|
|
|
+ @tab-switch="handleTabSwitch"
|
|
|
+ >
|
|
|
+ <nut-tabbar-item
|
|
|
+ v-for="(item, index) in tabBarStore.tabList"
|
|
|
+ :key="index"
|
|
|
+ :tab-title="item.text"
|
|
|
+ >
|
|
|
+ <template #icon>
|
|
|
+ <component
|
|
|
+ :is="getIconComponent(item.icon)"
|
|
|
+ size="24px"
|
|
|
+ />
|
|
|
+ </template>
|
|
|
+ </nut-tabbar-item>
|
|
|
+ </nut-tabbar>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script setup lang="ts">
|
|
|
+import { onMounted, onBeforeUnmount } from 'vue'
|
|
|
+import { Home, Find, Clock, My } from '@nutui/icons-vue-taro'
|
|
|
+import { useTabBarStore } from '@/stores/tabbar'
|
|
|
+
|
|
|
+// 初始化 store
|
|
|
+const tabBarStore = useTabBarStore()
|
|
|
+
|
|
|
+// 图标组件映射
|
|
|
+const iconComponents = {
|
|
|
+ Home,
|
|
|
+ Find,
|
|
|
+ Clock,
|
|
|
+ My
|
|
|
+}
|
|
|
+
|
|
|
+// 获取图标组件
|
|
|
+const getIconComponent = (iconName) => {
|
|
|
+ return iconComponents[iconName]
|
|
|
+}
|
|
|
+
|
|
|
+// 处理tab切换
|
|
|
+const handleTabSwitch = (item, index) => {
|
|
|
+ // 调用store中的切换方法
|
|
|
+ const tabItem = tabBarStore.tabList[index]
|
|
|
+ tabBarStore.switchTab(tabItem.pagePath, index)
|
|
|
+}
|
|
|
+
|
|
|
+// 生命周期钩子
|
|
|
+onMounted(() => {
|
|
|
+ // 组件挂载时初始化 TabBar 状态
|
|
|
+ tabBarStore.updateSelected()
|
|
|
+
|
|
|
+ // 设置全局监听
|
|
|
+ tabBarStore.setupListeners()
|
|
|
+})
|
|
|
+
|
|
|
+onBeforeUnmount(() => {
|
|
|
+ // 组件卸载时移除监听
|
|
|
+ tabBarStore.removeListeners()
|
|
|
+})
|
|
|
+</script>
|
|
|
+
|