@@ -3,38 +3,39 @@ import { TRouterInfo, TTabRouterType } from '@/interface';
33import { store } from '@/store' ;
44
55const state = {
6- tabRouterList : [ { path : '/dashboard/base' , routeIdx : 0 , title : '仪表盘' , name : 'DashboardBase' , isHome : true } ] ,
6+ homeRouter : { path : '/dashboard/base' , routeIdx : 0 , title : '仪表盘' , name : 'DashboardBase' , isHome : true } ,
7+ tabRouterList : [ ] ,
78 isRefreshing : false ,
89} ;
910
1011export const useTabsRouterStore = defineStore ( 'tabsRouter' , {
1112 state : ( ) => state ,
1213 getters : {
13- tabRouters : ( state : TTabRouterType ) => state . tabRouterList ,
14+ tabRouters : ( state : TTabRouterType ) => [ state . homeRouter ] . concat ( state . tabRouterList ) ,
1415 refreshing : ( state : TTabRouterType ) => state . isRefreshing ,
1516 } ,
1617 actions : {
1718 toggleTabRouterAlive ( routeIdx : number ) {
1819 this . isRefreshing = ! this . isRefreshing ;
19- this . tabRouters [ routeIdx ] . isAlive = ! this . tabRouterList [ routeIdx ] . isAlive ;
20+ this . tabRouters [ routeIdx ] . isAlive = ! this . tabRouters [ routeIdx ] . isAlive ;
2021 } ,
2122 appendTabRouterList ( newRoute : TRouterInfo ) {
22- if ( ! this . tabRouterList . find ( ( route : TRouterInfo ) => route . path === newRoute . path ) ) {
23+ if ( ! this . tabRouters . find ( ( route : TRouterInfo ) => route . path === newRoute . path ) ) {
2324 // eslint-disable-next-line no-param-reassign
2425 this . tabRouterList = this . tabRouterList . concat ( newRoute ) ;
2526 }
2627 } ,
2728 subtractCurrentTabRouter ( newRoute : TRouterInfo ) {
2829 const { routeIdx } = newRoute ;
29- this . tabRouterList = this . tabRouterList . slice ( 0 , routeIdx ) . concat ( this . tabRouterList . slice ( routeIdx + 1 ) ) ;
30+ this . tabRouterList = this . tabRouterList . slice ( 0 , routeIdx - 1 ) . concat ( this . tabRouterList . slice ( routeIdx ) ) ;
3031 } ,
3132 subtractTabRouterBehind ( newRoute : TRouterInfo ) {
3233 const { routeIdx } = newRoute ;
33- this . tabRouterList = this . tabRouterList . slice ( 0 , routeIdx + 1 ) ;
34+ this . tabRouterList = this . tabRouterList . slice ( 0 , routeIdx ) ;
3435 } ,
3536 subtractTabRouterAhead ( newRoute : TRouterInfo ) {
3637 const { routeIdx } = newRoute ;
37- this . tabRouterList = this . tabRouterList . slice ( routeIdx ) ;
38+ this . tabRouterList = this . tabRouterList . slice ( routeIdx - 1 ) ;
3839 } ,
3940 subtractTabRouterOther ( newRoute : TRouterInfo ) {
4041 const { routeIdx } = newRoute ;
@@ -44,7 +45,7 @@ export const useTabsRouterStore = defineStore('tabsRouter', {
4445 this . tabRouterList = [ ] ;
4546 } ,
4647 initTabRouterList ( newRoutes : TRouterInfo [ ] ) {
47- this . tabRouterList = newRoutes ;
48+ newRoutes ?. forEach ( ( route : TRouterInfo ) => this . appendTabRouterList ( route ) ) ;
4849 } ,
4950 } ,
5051} ) ;
0 commit comments