Skip to content

Commit 24451f7

Browse files
authored
fix: [多标签Tab页] 关闭左侧,关闭其他可能导致主页标签被删除 (#148)
* fix: 主页和路由页独立 主页和路由页独立 fix #147 * refactor: 撤回不属于本次提交的更改 撤回不属于本次提交的更改
1 parent 15804b7 commit 24451f7

3 files changed

Lines changed: 11 additions & 9 deletions

File tree

src/interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,6 @@ export interface TRouterInfo {
5050

5151
export interface TTabRouterType {
5252
isRefreshing: boolean;
53+
homeRouter: TRouterInfo;
5354
tabRouterList: Array<TRouterInfo>;
5455
}

src/layouts/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ export default defineComponent({
196196
<t-icon name="refresh" />
197197
刷新
198198
</t-dropdown-item>
199-
{idx > 0 && (
199+
{idx > 1 && (
200200
<t-dropdown-item onClick={() => handleCloseAhead(router.path, idx)}>
201201
<t-icon name="arrow-left" />
202202
关闭左侧

src/store/modules/tabs-router.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,39 @@ import { TRouterInfo, TTabRouterType } from '@/interface';
33
import { store } from '@/store';
44

55
const 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

1011
export 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

Comments
 (0)