Browse Source

Merge pull request #176258 in DEC/fineui from master to feature/x

* commit '59b83beae81c4e8da5d03e8d33cb8066989b4f37':
  chore: 优化
  chore: 优化
research/test
superman 2 years ago
parent
commit
eaa22a82b8
  1. 145
      src/component/treevaluechooser/abstract.treevaluechooser.js
  2. 3
      src/component/treevaluechooser/pane.treevaluechooser.js

145
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, checkState) {
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]), {checked: state[0], half: state[1]});
}
}
}
getResult(parentValues, checkState);
// 如果指定节点全部打开
// 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);

3
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();

Loading…
Cancel
Save