@@ -49,8 +49,10 @@ export default {
49
49
remove (targetKey) {
50
50
this.pages = this.pages.filter(page => page.fullPath !== targetKey)
51
51
this.fullPathList = this.fullPathList.filter(path => path !== targetKey)
52
- // 跳转到最后一个还存在的标签页
53
- this.selectedLastPath()
52
+ // 判断当前标签是否关闭,若关闭则跳转到最后一个还存在的标签页
53
+ if (!this.fullPathList.includes(this.activeKey)) {
54
+ this.selectedLastPath()
55
+ }
54
56
},
55
57
selectedLastPath () {
56
58
this.activeKey = this.fullPathList[this.fullPathList.length - 1]
@@ -65,15 +67,29 @@ export default {
65
67
// TODO
66
68
console.log('close left', e)
67
69
const index = this.fullPathList.indexOf(e)
68
- if (index > -1) {
69
- this.fullPathList.splice(index, -1)
70
+ if (index > 0) {
71
+ this.remove(this.fullPathList[index - 1])
72
+ } else {
73
+ this.$message.info('左侧没有标签')
70
74
}
71
75
},
72
76
closeRight (e) {
73
77
console.log('close right', e)
78
+ const index = this.fullPathList.indexOf(e)
79
+ if (index < (this.fullPathList.length - 1)) {
80
+ this.remove(this.fullPathList[index + 1])
81
+ } else {
82
+ this.$message.info('右侧没有标签')
83
+ }
74
84
},
75
85
closeAll (e) {
76
86
console.log('close all', e)
87
+ const currentIndex = this.fullPathList.indexOf(e)
88
+ this.fullPathList.forEach((item, index) => {
89
+ if (index !== currentIndex) {
90
+ this.remove(item)
91
+ }
92
+ })
77
93
},
78
94
closeMenuClick ({ key, item, domEvent }) {
79
95
console.log('key', key)
@@ -132,7 +148,13 @@ export default {
132
148
render () {
133
149
const { onEdit, $data: { pages } } = this
134
150
const panes = pages.map(page => {
135
- return (<a-tab-pane style={{ height: 0 }} tab={this.renderTabPane(page.meta.title, page.fullPath)} key={page.fullPath} closable={pages.length > 1}></a-tab-pane>)
151
+ return (
152
+ <a-tab-pane
153
+ style={{ height: 0 }}
154
+ tab={this.renderTabPane(page.meta.title, page.fullPath)}
155
+ key={page.fullPath} closable={pages.length > 1}
156
+ >
157
+ </a-tab-pane>)
136
158
})
137
159
138
160
return (
@@ -149,4 +171,4 @@ export default {
149
171
)
150
172
}
151
173
}
152
- </script>
174
+ </script>
0 commit comments