Skip to content

Commit cfddfa0

Browse files
authored
feat: 多标签Tab页支持拖拽排序 (#426)
* feat: 多标签页Tab页支持拖拽排序 * fix: 和HomePage换序 不做处理 * fix: 右键关闭逻辑调整 * chore: 补充类型声明
1 parent 24d913d commit cfddfa0

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/layouts/components/LayoutContent.vue

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
<t-layout :class="`${prefix}-layout`">
33
<t-tabs
44
v-if="settingStore.isUseTabsRouter"
5+
drag-sort
56
theme="card"
67
:class="`${prefix}-layout-tabs-nav`"
78
:value="$route.path"
89
:style="{ position: 'sticky', top: 0, width: '100%' }"
910
@change="handleChangeCurrentTab"
1011
@remove="handleRemove"
12+
@drag-sort="handleDragend"
1113
>
1214
<t-tab-panel
1315
v-for="(routeItem, index) in tabRouters"
@@ -147,4 +149,13 @@ const handleTabMenuClick = (visible: boolean, ctx, path: string) => {
147149
if (ctx.trigger === 'document') activeTabPath.value = null;
148150
if (visible) activeTabPath.value = path;
149151
};
152+
153+
const handleDragend = (options: { currentIndex: number; targetIndex: number }) => {
154+
const { tabRouters } = tabsRouterStore;
155+
156+
[tabRouters[options.currentIndex], tabRouters[options.targetIndex]] = [
157+
tabRouters[options.targetIndex],
158+
tabRouters[options.currentIndex],
159+
];
160+
};
150161
</script>

src/store/modules/tabs-router.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,28 @@ export const useTabsRouterStore = defineStore('tabsRouter', {
4949
// 处理关闭右侧
5050
subtractTabRouterBehind(newRoute: TRouterInfo) {
5151
const { routeIdx } = newRoute;
52-
this.tabRouterList = this.tabRouterList.slice(0, routeIdx + 1);
52+
const homeIdx: number = this.tabRouters.findIndex((route) => route.isHome);
53+
let tabRouterList: Array<TRouterInfo> = this.tabRouterList.slice(0, routeIdx + 1);
54+
if (routeIdx < homeIdx) {
55+
tabRouterList = tabRouterList.concat(homeRoute);
56+
}
57+
this.tabRouterList = tabRouterList;
5358
},
5459
// 处理关闭左侧
5560
subtractTabRouterAhead(newRoute: TRouterInfo) {
5661
const { routeIdx } = newRoute;
57-
this.tabRouterList = homeRoute.concat(this.tabRouterList.slice(routeIdx));
62+
const homeIdx: number = this.tabRouters.findIndex((route) => route.isHome);
63+
let tabRouterList: Array<TRouterInfo> = this.tabRouterList.slice(routeIdx);
64+
if (routeIdx > homeIdx) {
65+
tabRouterList = homeRoute.concat(tabRouterList);
66+
}
67+
this.tabRouterList = tabRouterList;
5868
},
5969
// 处理关闭其他
6070
subtractTabRouterOther(newRoute: TRouterInfo) {
6171
const { routeIdx } = newRoute;
62-
this.tabRouterList = routeIdx === 0 ? homeRoute : homeRoute.concat([this.tabRouterList?.[routeIdx]]);
72+
const homeIdx: number = this.tabRouters.findIndex((route) => route.isHome);
73+
this.tabRouterList = routeIdx === homeIdx ? homeRoute : homeRoute.concat([this.tabRouterList?.[routeIdx]]);
6374
},
6475
removeTabRouterList() {
6576
this.tabRouterList = [];

0 commit comments

Comments
 (0)