Skip to content

Commit 03de3b7

Browse files
committed
feat: merge multi-tab
1 parent 5f1d8a8 commit 03de3b7

File tree

11 files changed

+1142
-1054
lines changed

11 files changed

+1142
-1054
lines changed

src/components/MultiTab/MultiTab.vue

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<template>
2+
<div style="margin: -23px -24px 24px -24px">
3+
<a-tabs
4+
hideAdd
5+
v-model="activeKey"
6+
type="editable-card"
7+
:tabBarStyle="{ background: '#FFF', margin: 0, paddingLeft: '16px', paddingTop: '1px' }"
8+
@edit="onEdit"
9+
>
10+
<a-tab-pane v-for="page in pages" :style="{ height: 0 }" :tab="page.meta.title" :key="page.fullPath" :closable="pages.length > 1">
11+
</a-tab-pane>
12+
</a-tabs>
13+
</div>
14+
</template>
15+
16+
<script>
17+
export default {
18+
name: 'MultiTab',
19+
data () {
20+
return {
21+
fullPathList: [],
22+
pages: [],
23+
activeKey: '',
24+
newTabIndex: 0
25+
}
26+
},
27+
created () {
28+
this.pages.push(this.$route)
29+
this.fullPathList.push(this.$route.fullPath)
30+
},
31+
methods: {
32+
onEdit (targetKey, action) {
33+
this[action](targetKey)
34+
},
35+
remove (targetKey) {
36+
if (this.pages.length === 1) {
37+
return
38+
}
39+
this.pages = this.pages.filter(page => page.fullPath !== targetKey)
40+
this.fullPathList = this.fullPathList.filter(path => path !== targetKey)
41+
},
42+
},
43+
watch: {
44+
'$route': function (newVal) {
45+
this.activeKey = newVal.fullPath
46+
if (this.fullPathList.indexOf(newVal.fullPath) < 0) {
47+
this.fullPathList.push(newVal.fullPath)
48+
this.pages.push(newVal)
49+
}
50+
},
51+
activeKey: function (newPathKey) {
52+
this.$router.push({ path: newPathKey })
53+
}
54+
}
55+
}
56+
</script>

src/components/MultiTab/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
import MultiTab from './MultiTab'
2+
export default MultiTab
Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
1-
<template>
2-
<global-layout>
3-
<transition name="page-transition">
4-
<route-view />
5-
</transition>
6-
</global-layout>
7-
</template>
8-
9-
<script>
10-
import RouteView from '@/components/layouts/RouteView'
11-
import GlobalLayout from '@/components/page/GlobalLayout'
12-
13-
export default {
14-
name: 'BasicLayout',
15-
components: {
16-
RouteView,
17-
GlobalLayout
18-
},
19-
data () {
20-
return {}
21-
}
22-
}
23-
</script>
24-
25-
<style lang="less">
26-
27-
/*
28-
* The following styles are auto-applied to elements with
29-
* transition="page-transition" when their visibility is toggled
30-
* by Vue.js.
31-
*
32-
* You can easily play with the page transition by editing
33-
* these styles.
34-
*/
35-
36-
.page-transition-enter {
37-
opacity: 0;
38-
}
39-
40-
.page-transition-leave-active {
41-
opacity: 0;
42-
}
43-
44-
.page-transition-enter .page-transition-container,
45-
.page-transition-leave-active .page-transition-container {
46-
-webkit-transform: scale(1.1);
47-
transform: scale(1.1);
48-
}
1+
<template>
2+
<global-layout>
3+
<multi-tab v-if="$store.getters.multiTab"></multi-tab>
4+
<transition name="page-transition">
5+
<route-view />
6+
</transition>
7+
</global-layout>
8+
</template>
9+
10+
<script>
11+
import RouteView from '@/components/layouts/RouteView'
12+
import MultiTab from '@/components/MultiTab'
13+
import GlobalLayout from '@/components/page/GlobalLayout'
14+
15+
export default {
16+
name: 'BasicLayout',
17+
components: {
18+
RouteView,
19+
MultiTab,
20+
GlobalLayout
21+
},
22+
data () {
23+
return {}
24+
}
25+
}
26+
</script>
27+
28+
<style lang="less">
29+
30+
/*
31+
* The following styles are auto-applied to elements with
32+
* transition="page-transition" when their visibility is toggled
33+
* by Vue.js.
34+
*
35+
* You can easily play with the page transition by editing
36+
* these styles.
37+
*/
38+
39+
.page-transition-enter {
40+
opacity: 0;
41+
}
42+
43+
.page-transition-leave-active {
44+
opacity: 0;
45+
}
46+
47+
.page-transition-enter .page-transition-container,
48+
.page-transition-leave-active .page-transition-container {
49+
-webkit-transform: scale(1.1);
50+
transform: scale(1.1);
51+
}
4952
</style>

0 commit comments

Comments
 (0)