From 8d19e433a7ab60f32bdd11f6e9338e4014dce214 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E5=84=80=E5=BC=8F?= <854085467@qq.com> Date: Mon, 3 Oct 2022 06:47:02 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B(component):=20update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package/component/src/component/tree/tree.ts | 25 +++++++++++++------ package/document-component/src/view/index.vue | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/package/component/src/component/tree/tree.ts b/package/component/src/component/tree/tree.ts index 7184f951..32a50a6d 100644 --- a/package/component/src/component/tree/tree.ts +++ b/package/component/src/component/tree/tree.ts @@ -133,15 +133,26 @@ class Tree { return node; } + treeForeach (tree: any, func: Function) { + tree.forEach((data: any) => { + data.children && this.treeForeach(data.children, func) // 遍历子树 + func(data) + }) + } + setChildrenChecked(checked: boolean, nodes: TreeData[]) { + var ableCount = 0; + var checkCount = 0; const len = nodes.length; - /** - * 判断所有子项, 如果存在选中项, 并且全选, 取消所有选中 - * - * 如果存在选中项, 未全部选着, 选中全部 - * - * 如果不存在选中项, 选中全部可选 - */ + this.treeForeach(nodes ,(node: any) => { + if(!node.isDisabled) { + ableCount = ableCount + 1; + if(node.isChecked) { + checkCount = checkCount + 1; + } + } + }) + checkCount < ableCount ? checked = true : checked = false; for (let i = 0; i < len; i++) { if(!nodes[i].isDisabled || (nodes[i].isDisabled && nodes[i].children.length > 0)) { nodes[i].isChecked = checked; diff --git a/package/document-component/src/view/index.vue b/package/document-component/src/view/index.vue index 9a429878..78060513 100644 --- a/package/document-component/src/view/index.vue +++ b/package/document-component/src/view/index.vue @@ -43,7 +43,7 @@ rel="nofollow" class="site-star" > - Star 1514 + Star 1576