diff --git a/src/components/tabbar/tabbar.vue b/src/components/tabbar/tabbar.vue deleted file mode 100644 index 7159e8f..0000000 --- a/src/components/tabbar/tabbar.vue +++ /dev/null @@ -1,56 +0,0 @@ - - - - - diff --git a/src/layouts/tabbar.vue b/src/layouts/tabbar.vue new file mode 100644 index 0000000..11d1703 --- /dev/null +++ b/src/layouts/tabbar.vue @@ -0,0 +1,60 @@ + + + + diff --git a/src/pages.json b/src/pages.json index e4efccd..2718209 100644 --- a/src/pages.json +++ b/src/pages.json @@ -18,6 +18,7 @@ { "path": "pages/index/index", "type": "home", + "layout": "tabbar", "style": { "navigationStyle": "custom", "navigationBarTitleText": "首页" @@ -26,6 +27,7 @@ { "path": "pages/about/about", "type": "page", + "layout": "tabbar", "style": { "navigationBarTitleText": "关于", "navigationStyle": "custom" diff --git a/src/pages/about/about.vue b/src/pages/about/about.vue index d234b89..619d6e9 100644 --- a/src/pages/about/about.vue +++ b/src/pages/about/about.vue @@ -1,5 +1,6 @@ { + layout: 'tabbar', style: { navigationBarTitleText: '关于', navigationStyle: 'custom', // 开启自定义导航栏 diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index ab50218..88c4188 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -1,6 +1,7 @@ { + layout: 'tabbar', style: { navigationStyle: 'custom', navigationBarTitleText: '首页', diff --git a/src/store/tabbar.ts b/src/store/tabbar.ts index 4216cc5..ba858ae 100644 --- a/src/store/tabbar.ts +++ b/src/store/tabbar.ts @@ -4,13 +4,30 @@ export interface TabbarItem { name: string value: number | null active: boolean + route: string + title: string + icon: string } export const useTabbarStore = defineStore('tabbar', { state: (): { tabbarItems: TabbarItem[] } => ({ tabbarItems: [ - { name: 'index', value: null, active: true }, - { name: 'about', value: null, active: false }, + { + name: 'index', + value: null, + active: true, + route: '/pages/index/index', + title: '首页', + icon: 'home', + }, + { + name: 'about', + value: null, + active: false, + route: '/pages/about/about', + title: '关于', + icon: 'user', + }, ], }), getters: { @@ -27,6 +44,12 @@ export const useTabbarStore = defineStore('tabbar', { return item && item.value ? item.value : null } }, + getTabbarItemRoute: (state) => { + return (name: string) => { + const item = state.tabbarItems.find((item) => item.name === name) + return (item && item.route) ?? null + } + }, }, actions: { setTabbarItem(name: string, value: number) { diff --git a/src/types/components.d.ts b/src/types/components.d.ts index f30fc70..65bb6be 100644 --- a/src/types/components.d.ts +++ b/src/types/components.d.ts @@ -8,6 +8,7 @@ export {} declare module 'vue' { export interface GlobalComponents { FgNavbar: typeof import('./../components/fg-navbar/fg-navbar.vue')['default'] + FgTabbar: typeof import('./../components/fg-tabbar/fg-tabbar.vue')['default'] Tabbar: typeof import('./../components/tabbar/tabbar.vue')['default'] } }