|
@@ -20,7 +20,8 @@
|
|
data() {
|
|
data() {
|
|
return {
|
|
return {
|
|
children: null,
|
|
children: null,
|
|
- currentName: this.value || this.activeName
|
|
|
|
|
|
+ currentName: this.value || this.activeName,
|
|
|
|
+ panes: []
|
|
};
|
|
};
|
|
},
|
|
},
|
|
|
|
|
|
@@ -34,16 +35,9 @@
|
|
},
|
|
},
|
|
|
|
|
|
computed: {
|
|
computed: {
|
|
- tabPanes: {
|
|
|
|
- cache: false,
|
|
|
|
- get() {
|
|
|
|
- if (!this.$children) return [];
|
|
|
|
- return this.$children.filter(item => item.$options.componentName === 'ElTabPane');
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
currentTab() {
|
|
currentTab() {
|
|
let result;
|
|
let result;
|
|
- this.tabPanes.forEach(tab => {
|
|
|
|
|
|
+ this.panes.forEach(tab => {
|
|
if (this.currentName === (tab.name || tab.index)) {
|
|
if (this.currentName === (tab.name || tab.index)) {
|
|
result = tab;
|
|
result = tab;
|
|
}
|
|
}
|
|
@@ -53,22 +47,25 @@
|
|
},
|
|
},
|
|
|
|
|
|
methods: {
|
|
methods: {
|
|
- handleTabRemove(tab, event) {
|
|
|
|
|
|
+ handleTabRemove(pane, event) {
|
|
event.stopPropagation();
|
|
event.stopPropagation();
|
|
- const tabs = this.tabPanes;
|
|
|
|
|
|
+ const panes = this.panes;
|
|
const currentTab = this.currentTab;
|
|
const currentTab = this.currentTab;
|
|
|
|
|
|
- let index = tabs.indexOf(tab);
|
|
|
|
- tab.$destroy();
|
|
|
|
|
|
+ let index = panes.indexOf(pane);
|
|
|
|
+
|
|
|
|
+ if (index === -1) return;
|
|
|
|
+
|
|
|
|
+ panes.splice(index, 1);
|
|
|
|
+ pane.$destroy();
|
|
|
|
|
|
- this.$emit('tab-remove', tab);
|
|
|
|
- this.$forceUpdate();
|
|
|
|
|
|
+ this.$emit('tab-remove', pane);
|
|
|
|
|
|
this.$nextTick(_ => {
|
|
this.$nextTick(_ => {
|
|
- if (tab.active) {
|
|
|
|
- const tabs = this.tabPanes;
|
|
|
|
- let nextChild = tabs[index];
|
|
|
|
- let prevChild = tabs[index - 1];
|
|
|
|
|
|
+ if (pane.active) {
|
|
|
|
+ const panes = this.panes;
|
|
|
|
+ let nextChild = panes[index];
|
|
|
|
+ let prevChild = panes[index - 1];
|
|
let nextActiveTab = nextChild || prevChild || null;
|
|
let nextActiveTab = nextChild || prevChild || null;
|
|
|
|
|
|
if (nextActiveTab) {
|
|
if (nextActiveTab) {
|
|
@@ -88,44 +85,51 @@
|
|
setCurrentName(value) {
|
|
setCurrentName(value) {
|
|
this.currentName = value;
|
|
this.currentName = value;
|
|
this.$emit('input', value);
|
|
this.$emit('input', value);
|
|
|
|
+ },
|
|
|
|
+ addPanes(item) {
|
|
|
|
+ this.panes.push(item);
|
|
|
|
+ },
|
|
|
|
+ removePanes(item) {
|
|
|
|
+ const panes = this.panes;
|
|
|
|
+ const index = panes.indexOf(item);
|
|
|
|
+ if (index > -1) {
|
|
|
|
+ panes.splice(index, 1);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- mounted() {
|
|
|
|
- this.$forceUpdate();
|
|
|
|
- },
|
|
|
|
render(h) {
|
|
render(h) {
|
|
let {
|
|
let {
|
|
type,
|
|
type,
|
|
handleTabRemove,
|
|
handleTabRemove,
|
|
handleTabClick,
|
|
handleTabClick,
|
|
currentName,
|
|
currentName,
|
|
- tabPanes
|
|
|
|
|
|
+ panes
|
|
} = this;
|
|
} = this;
|
|
|
|
|
|
- const tabs = this._l(tabPanes, (tab, index) => {
|
|
|
|
- let tabName = tab.name || tab.index || index;
|
|
|
|
|
|
+ const tabs = this._l(panes, (pane, index) => {
|
|
|
|
+ let tabName = pane.name || pane.index || index;
|
|
if (currentName === undefined && index === 0) {
|
|
if (currentName === undefined && index === 0) {
|
|
this.setCurrentName(tabName);
|
|
this.setCurrentName(tabName);
|
|
}
|
|
}
|
|
|
|
|
|
- tab.index = index;
|
|
|
|
|
|
+ pane.index = index;
|
|
|
|
|
|
- const btnClose = tab.isClosable
|
|
|
|
- ? <span class="el-icon-close" on-click={(ev) => { handleTabRemove(tab, ev); }}></span>
|
|
|
|
|
|
+ const btnClose = pane.isClosable
|
|
|
|
+ ? <span class="el-icon-close" on-click={(ev) => { handleTabRemove(pane, ev); }}></span>
|
|
: null;
|
|
: null;
|
|
|
|
|
|
- const tabLabelContent = tab.$slots.label || tab.label;
|
|
|
|
|
|
+ const tabLabelContent = pane.$slots.label || pane.label;
|
|
return (
|
|
return (
|
|
<div
|
|
<div
|
|
class={{
|
|
class={{
|
|
'el-tabs__item': true,
|
|
'el-tabs__item': true,
|
|
- 'is-active': tab.active,
|
|
|
|
- 'is-disabled': tab.disabled,
|
|
|
|
- 'is-closable': tab.isClosable
|
|
|
|
|
|
+ 'is-active': pane.active,
|
|
|
|
+ 'is-disabled': pane.disabled,
|
|
|
|
+ 'is-closable': pane.isClosable
|
|
}}
|
|
}}
|
|
ref="tabs"
|
|
ref="tabs"
|
|
refInFor
|
|
refInFor
|
|
- on-click={(ev) => { handleTabClick(tab, tabName, ev); }}
|
|
|
|
|
|
+ on-click={(ev) => { handleTabClick(pane, tabName, ev); }}
|
|
>
|
|
>
|
|
{tabLabelContent}
|
|
{tabLabelContent}
|
|
{btnClose}
|
|
{btnClose}
|
|
@@ -140,7 +144,7 @@
|
|
'el-tabs--border-card': type === 'border-card'
|
|
'el-tabs--border-card': type === 'border-card'
|
|
}}>
|
|
}}>
|
|
<div class="el-tabs__header">
|
|
<div class="el-tabs__header">
|
|
- {!type ? <tab-bar tabs={tabPanes}></tab-bar> : null}
|
|
|
|
|
|
+ {!type ? <tab-bar tabs={panes}></tab-bar> : null}
|
|
{tabs}
|
|
{tabs}
|
|
</div>
|
|
</div>
|
|
<div class="el-tabs__content">
|
|
<div class="el-tabs__content">
|