From 984d2b761ec9a6ef53675e8dfcd8640f016b7c61 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 19 Aug 2022 09:27:53 +0800 Subject: [PATCH 1/4] Update assist.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit findComponentsDownward函数添加过滤机制 --- src/utils/assist.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/utils/assist.js b/src/utils/assist.js index 3097d2888..1bf24930b 100644 --- a/src/utils/assist.js +++ b/src/utils/assist.js @@ -212,8 +212,12 @@ export function findComponentDownward (context, componentName) { } // Find components downward -export function findComponentsDownward (context, componentName) { +export function findComponentsDownward(context, componentName, filterName) { return context.$children.reduce((components, child) => { + if (!child.$options.name) return components; + if (typeof filterName === 'function') { + if (filterName(child, components)) return components; + } else if (child.$options.name === filterName) return components; if (child.$options.name === componentName) components.push(child); const foundChilds = findComponentsDownward(child, componentName); return components.concat(foundChilds); From 3e3e074cffb560c863268137eb9addb76aebd060 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 19 Aug 2022 09:29:05 +0800 Subject: [PATCH 2/4] Update pane.vue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 配合Tabs改动 --- src/components/tabs/pane.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/tabs/pane.vue b/src/components/tabs/pane.vue index 2fed097fc..b406c88f1 100644 --- a/src/components/tabs/pane.vue +++ b/src/components/tabs/pane.vue @@ -16,7 +16,8 @@ default: '' }, icon: { - type: String + type: String, + default: '' }, disabled: { type: Boolean, From 184b5487630151a98b3b70580ef875b0225f7950 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 19 Aug 2022 09:32:36 +0800 Subject: [PATCH 3/4] Update tabs.vue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 取消用name分Tabs层级,改为配合增强过的findComponentsDownward,实现tabs嵌套过滤 --- src/components/tabs/tabs.vue | 38 +++++++++++++++--------------------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/components/tabs/tabs.vue b/src/components/tabs/tabs.vue index fcd12c5d9..6ee1c47bf 100644 --- a/src/components/tabs/tabs.vue +++ b/src/components/tabs/tabs.vue @@ -116,10 +116,6 @@ default: false }, beforeRemove: Function, - // Tabs 嵌套时,用 name 区分层级 - name: { - type: String - }, // 4.3.0 draggable: { type: Boolean, @@ -144,7 +140,8 @@ contextMenuStyles: { top: 0, left: 0 - } + }, + isRepeat: false //记录label是否重复 }; }, computed: { @@ -239,42 +236,39 @@ methods: { getTabs () { // return this.$children.filter(item => item.$options.name === 'TabPane'); - const AllTabPanes = findComponentsDownward(this, 'TabPane'); - const TabPanes = []; - - AllTabPanes.forEach(item => { - if (item.tab && this.name) { - if (item.tab === this.name) { - TabPanes.push(item); - } - } else { - TabPanes.push(item); + const repeat = {}; + let isRepeat = false; + const AllTabPanes = findComponentsDownward(this, 'TabPane', (child) => { + if (!isRepeat) { + if (repeat[child.name]) isRepeat = true; + else repeat[child.name] = true; } + if (child.$options.name === 'Tabs') return true; }); // 在 TabPane 使用 v-if 时,并不会按照预先的顺序渲染,这时可设置 index,并从小到大排序 - TabPanes.sort((a, b) => { + AllTabPanes.sort((a, b) => { if (a.index && b.index) { return a.index > b.index ? 1 : -1; } }); - return TabPanes; + return AllTabPanes; }, updateNav () { - this.navList = []; + //label无重时,pane.currentName无值时的默认值优先采用pane.label + if (!pane.currentName) pane.currentName = this.isRepeat ? index : pane.label; this.getTabs().forEach((pane, index) => { this.navList.push({ labelType: typeof pane.label, label: pane.label, - icon: pane.icon || '', - name: pane.currentName || index, + icon: pane.icon, + name: pane.currentName, disabled: pane.disabled, closable: pane.closable, contextMenu: pane.contextMenu }); - if (!pane.currentName) pane.currentName = index; if (index === 0) { - if (!this.activeKey) this.activeKey = pane.currentName || index; + if (!this.activeKey) this.activeKey = pane.currentName; } }); this.updateStatus(); From c991dd7bf8ec309d0516984518f7473d062ef744 Mon Sep 17 00:00:00 2001 From: bushixuanqi <57338301+bushixuanqi@users.noreply.github.com> Date: Fri, 19 Aug 2022 09:42:40 +0800 Subject: [PATCH 4/4] Update assist.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 去掉可能的破坏性修改 --- src/utils/assist.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/utils/assist.js b/src/utils/assist.js index 1bf24930b..1c357cf94 100644 --- a/src/utils/assist.js +++ b/src/utils/assist.js @@ -214,10 +214,9 @@ export function findComponentDownward (context, componentName) { // Find components downward export function findComponentsDownward(context, componentName, filterName) { return context.$children.reduce((components, child) => { - if (!child.$options.name) return components; if (typeof filterName === 'function') { if (filterName(child, components)) return components; - } else if (child.$options.name === filterName) return components; + } else if (filterName && child.$options.name === filterName) return components; if (child.$options.name === componentName) components.push(child); const foundChilds = findComponentsDownward(child, componentName); return components.concat(foundChilds);