@@ -49,8 +49,10 @@ export default {
4949 remove (targetKey ) {
5050 this .pages = this .pages .filter (page => page .fullPath !== targetKey)
5151 this .fullPathList = this .fullPathList .filter (path => path !== targetKey)
52- // 跳转到最后一个还存在的标签页
53- this .selectedLastPath ()
52+ // 判断当前标签是否关闭,若关闭则跳转到最后一个还存在的标签页
53+ if (! this .fullPathList .includes (this .activeKey )) {
54+ this .selectedLastPath ()
55+ }
5456 },
5557 selectedLastPath () {
5658 this .activeKey = this .fullPathList [this .fullPathList .length - 1 ]
@@ -65,15 +67,29 @@ export default {
6567 // TODO
6668 console .log (' close left' , e)
6769 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 (' 左侧没有标签' )
7074 }
7175 },
7276 closeRight (e ) {
7377 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+ }
7484 },
7585 closeAll (e ) {
7686 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+ })
7793 },
7894 closeMenuClick ({ key, item, domEvent }) {
7995 console .log (' key' , key)
@@ -132,7 +148,13 @@ export default {
132148 render () {
133149 const { onEdit , $data: { pages } } = this
134150 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> )
136158 })
137159
138160 return (
@@ -149,4 +171,4 @@ export default {
149171 )
150172 }
151173}
152- </script >
174+ </script >
0 commit comments