From 8b857fe737ae302734f1a517e56164cc5164dd63 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 17 Sep 2022 23:11:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?chore=EF=BC=9A=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../abstract.treevaluechooser.js | 145 ++++++++++-------- 1 file changed, 78 insertions(+), 67 deletions(-) diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js index 40c10350c..db31a1500 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.js +++ b/src/component/treevaluechooser/abstract.treevaluechooser.js @@ -532,70 +532,81 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { var checkState = op.checkState || {}; var parentValues = op.parentValues || []; var selectedValues = op.selectedValues || {}; - var valueMap = {}; - // if (judgeState(parentValues, selectedValues, checkState)) { - valueMap = dealWithSelectedValue(parentValues, selectedValues); - // } - var nodes = this._getChildren(parentValues); - for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { - var state = getCheckState(nodes[i].value, parentValues, valueMap, checkState); - result.push({ - id: nodes[i].id, - pId: nodes[i].pId, - value: nodes[i].value, - text: nodes[i].text, - times: 1, - isParent: nodes[i].getChildrenLength() > 0, - checked: state[0], - halfCheck: state[1], - open: o.open || nodes[i].open, - disabled: nodes[i].disabled, - title: nodes[i].title || nodes[i].text, - warningTitle: nodes[i].warningTitle, - }); - } - // 如果指定节点全部打开 - if (o.open) { - var allNodes = []; - // 获取所有节点 - BI.each(nodes, function (idx, node) { - allNodes = BI.concat(allNodes, self._getAllChildren(parentValues.concat([node.value]))); - }); - var lastFind; - BI.each(allNodes, function (idx, node) { - var valueMap = dealWithSelectedValue(node.parentValues, selectedValues); - // REPORT-24409 fix: 设置节点全部展开,添加的节点没有给状态 - var parentCheckState = {}; - var find = BI.find(result, function (idx, pNode) { - return pNode.id === node.pId; - }); - if (find) { - parentCheckState.checked = find.halfCheck ? false : find.checked; - parentCheckState.half = find.halfCheck; - // 默认展开也需要重置父节点的halfCheck - if (BI.isNotNull(lastFind) && (lastFind !== find || allNodes.length - 1 === idx)) { - lastFind.half = lastFind.halfCheck; - lastFind.halfCheck = false; - } - } - lastFind = find; - var state = getCheckState(node.value, node.parentValues, valueMap, parentCheckState); + function getResult(parentValues) { + var valueMap = {}; + // if (judgeState(parentValues, selectedValues, checkState)) { + valueMap = dealWithSelectedValue(parentValues, selectedValues); + // } + var nodes = self._getChildren(parentValues); + for (var i = (times - 1) * self._const.perPage; nodes[i] && i < times * self._const.perPage; i++) { + var state = getCheckState(nodes[i].value, parentValues, valueMap, checkState); + var openState = o.open || nodes[i].open; result.push({ - id: node.id, - pId: node.pId, - value: node.value, - text: node.text, + id: nodes[i].id, + pId: nodes[i].pId, + value: nodes[i].value, + text: nodes[i].text, times: 1, - isParent: node.getChildrenLength() > 0, + isParent: nodes[i].getChildrenLength() > 0, checked: state[0], - halfCheck: state[1], - open: true, - disabled: node.disabled, - title: node.title || node.text, - warningTitle: node.warningTitle, + half: state[1], + halfCheck: openState ? false : state[1], + open: openState, + disabled: nodes[i].disabled, + title: nodes[i].title || nodes[i].text, + warningTitle: nodes[i].warningTitle, }); - }); + if (openState) { + getResult(parentValues.concat([nodes[i].value])); + } + } } + + getResult(parentValues); + + // 如果指定节点全部打开 + // if (o.open) { + // var allNodes = []; + // // 获取所有节点 + // BI.each(nodes, function (idx, node) { + // allNodes = BI.concat(allNodes, self._getAllChildren(parentValues.concat([node.value]))); + // }); + // var lastFind; + // BI.each(allNodes, function (idx, node) { + // var valueMap = dealWithSelectedValue(node.parentValues, selectedValues); + // // REPORT-24409 fix: 设置节点全部展开,添加的节点没有给状态 + // var parentCheckState = {}; + // var find = BI.find(result, function (idx, pNode) { + // return pNode.id === node.pId; + // }); + // if (find) { + // parentCheckState.checked = find.halfCheck ? false : find.checked; + // parentCheckState.half = find.halfCheck; + // // 默认展开也需要重置父节点的halfCheck + // if (BI.isNotNull(lastFind) && (lastFind !== find || allNodes.length - 1 === idx)) { + // lastFind.half = lastFind.halfCheck; + // lastFind.halfCheck = false; + // } + // } + // lastFind = find; + // var state = getCheckState(node.value, node.parentValues, valueMap, parentCheckState); + // result.push({ + // id: node.id, + // pId: node.pId, + // value: node.value, + // text: node.text, + // times: 1, + // isParent: node.getChildrenLength() > 0, + // checked: state[0], + // halfCheck: state[1], + // open: true, + // disabled: node.disabled, + // title: node.title || node.text, + // warningTitle: node.warningTitle, + // }); + // }); + // } + // 深层嵌套的比较麻烦,这边先实现的是在根节点添加 if (parentValues.length === 0 && times === 1) { result = BI.concat(self._getAddedValueNode(parentValues, selectedValues), result); @@ -603,17 +614,17 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { BI.nextTick(function () { callback({ items: result, - hasNext: nodes.length > times * self._const.perPage + hasNext: self._getChildren(parentValues).length > times * self._const.perPage }); }); - function judgeState(parentValues, selected_value, checkState) { - var checked = checkState.checked, half = checkState.half; - if (parentValues.length > 0 && !checked) { - return false; - } - return (parentValues.length === 0 || (checked && half) && !BI.isEmpty(selected_value)); - } + // function judgeState(parentValues, selected_value, checkState) { + // var checked = checkState.checked, half = checkState.half; + // if (parentValues.length > 0 && !checked) { + // return false; + // } + // return (parentValues.length === 0 || (checked && half) && !BI.isEmpty(selected_value)); + // } function dealWithSelectedValue(parentValues, selectedValues) { var valueMap = {}, parents = (parentValues || []).slice(0); From b1dd1b0954c9af7b4dc652875206a0514e23da11 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 17 Sep 2022 23:24:32 +0800 Subject: [PATCH 2/2] =?UTF-8?q?chore=EF=BC=9A=20=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/component/treevaluechooser/abstract.treevaluechooser.js | 6 +++--- src/component/treevaluechooser/pane.treevaluechooser.js | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js index db31a1500..53e31298f 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.js +++ b/src/component/treevaluechooser/abstract.treevaluechooser.js @@ -532,7 +532,7 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { var checkState = op.checkState || {}; var parentValues = op.parentValues || []; var selectedValues = op.selectedValues || {}; - function getResult(parentValues) { + function getResult(parentValues, checkState) { var valueMap = {}; // if (judgeState(parentValues, selectedValues, checkState)) { valueMap = dealWithSelectedValue(parentValues, selectedValues); @@ -557,12 +557,12 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { warningTitle: nodes[i].warningTitle, }); if (openState) { - getResult(parentValues.concat([nodes[i].value])); + getResult(parentValues.concat([nodes[i].value]), {checked: state[0], half: state[1]}); } } } - getResult(parentValues); + getResult(parentValues, checkState); // 如果指定节点全部打开 // if (o.open) { diff --git a/src/component/treevaluechooser/pane.treevaluechooser.js b/src/component/treevaluechooser/pane.treevaluechooser.js index e6fc4f07a..66486711a 100644 --- a/src/component/treevaluechooser/pane.treevaluechooser.js +++ b/src/component/treevaluechooser/pane.treevaluechooser.js @@ -29,6 +29,9 @@ BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, { this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () { self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE); }); + if (BI.isNotNull(o.value)) { + this.pane.setSelectedValue(o.value); + } if (BI.isNotNull(o.items)) { this._initData(o.items); this.pane.populate();