diff --git a/src/interface.ts b/src/interface.ts index 4a201b8..4a117f9 100644 --- a/src/interface.ts +++ b/src/interface.ts @@ -50,5 +50,6 @@ export interface TRouterInfo { export interface TTabRouterType { isRefreshing: boolean; + homeRouter: TRouterInfo; tabRouterList: Array; } diff --git a/src/layouts/index.tsx b/src/layouts/index.tsx index b5cd456..4a0c2e9 100644 --- a/src/layouts/index.tsx +++ b/src/layouts/index.tsx @@ -196,7 +196,7 @@ export default defineComponent({ 刷新 - {idx > 0 && ( + {idx > 1 && ( handleCloseAhead(router.path, idx)}> 关闭左侧 diff --git a/src/store/modules/tabs-router.ts b/src/store/modules/tabs-router.ts index 940a968..89f7d4c 100644 --- a/src/store/modules/tabs-router.ts +++ b/src/store/modules/tabs-router.ts @@ -3,38 +3,39 @@ import { TRouterInfo, TTabRouterType } from '@/interface'; import { store } from '@/store'; const state = { - tabRouterList: [{ path: '/dashboard/base', routeIdx: 0, title: '仪表盘', name: 'DashboardBase', isHome: true }], + homeRouter: { path: '/dashboard/base', routeIdx: 0, title: '仪表盘', name: 'DashboardBase', isHome: true }, + tabRouterList: [], isRefreshing: false, }; export const useTabsRouterStore = defineStore('tabsRouter', { state: () => state, getters: { - tabRouters: (state: TTabRouterType) => state.tabRouterList, + tabRouters: (state: TTabRouterType) => [state.homeRouter].concat(state.tabRouterList), refreshing: (state: TTabRouterType) => state.isRefreshing, }, actions: { toggleTabRouterAlive(routeIdx: number) { this.isRefreshing = !this.isRefreshing; - this.tabRouters[routeIdx].isAlive = !this.tabRouterList[routeIdx].isAlive; + this.tabRouters[routeIdx].isAlive = !this.tabRouters[routeIdx].isAlive; }, appendTabRouterList(newRoute: TRouterInfo) { - if (!this.tabRouterList.find((route: TRouterInfo) => route.path === newRoute.path)) { + if (!this.tabRouters.find((route: TRouterInfo) => route.path === newRoute.path)) { // eslint-disable-next-line no-param-reassign this.tabRouterList = this.tabRouterList.concat(newRoute); } }, subtractCurrentTabRouter(newRoute: TRouterInfo) { const { routeIdx } = newRoute; - this.tabRouterList = this.tabRouterList.slice(0, routeIdx).concat(this.tabRouterList.slice(routeIdx + 1)); + this.tabRouterList = this.tabRouterList.slice(0, routeIdx - 1).concat(this.tabRouterList.slice(routeIdx)); }, subtractTabRouterBehind(newRoute: TRouterInfo) { const { routeIdx } = newRoute; - this.tabRouterList = this.tabRouterList.slice(0, routeIdx + 1); + this.tabRouterList = this.tabRouterList.slice(0, routeIdx); }, subtractTabRouterAhead(newRoute: TRouterInfo) { const { routeIdx } = newRoute; - this.tabRouterList = this.tabRouterList.slice(routeIdx); + this.tabRouterList = this.tabRouterList.slice(routeIdx - 1); }, subtractTabRouterOther(newRoute: TRouterInfo) { const { routeIdx } = newRoute; @@ -44,7 +45,7 @@ export const useTabsRouterStore = defineStore('tabsRouter', { this.tabRouterList = []; }, initTabRouterList(newRoutes: TRouterInfo[]) { - this.tabRouterList = newRoutes; + newRoutes?.forEach((route: TRouterInfo) => this.appendTabRouterList(route)); }, }, });