From 24451f7720893a916f85b5e5f67c02b63adb439b Mon Sep 17 00:00:00 2001 From: Kerwin Bryant Date: Sat, 7 May 2022 12:50:17 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20[=E5=A4=9A=E6=A0=87=E7=AD=BETab=E9=A1=B5?= =?UTF-8?q?]=20=E5=85=B3=E9=97=AD=E5=B7=A6=E4=BE=A7=EF=BC=8C=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E5=85=B6=E4=BB=96=E5=8F=AF=E8=83=BD=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E4=B8=BB=E9=A1=B5=E6=A0=87=E7=AD=BE=E8=A2=AB=E5=88=A0=E9=99=A4?= =?UTF-8?q?=20(#148)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 主页和路由页独立 主页和路由页独立 fix #147 * refactor: 撤回不属于本次提交的更改 撤回不属于本次提交的更改 --- src/interface.ts | 1 + src/layouts/index.tsx | 2 +- src/store/modules/tabs-router.ts | 17 +++++++++-------- 3 files changed, 11 insertions(+), 9 deletions(-) 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)); }, }, });