From 8aac9606ecea43bbeb6957e66c1f16517eee4e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joker=2EWang-=E7=8E=8B=E9=A1=BA?= Date: Tue, 17 Jan 2023 15:10:21 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-14109=20refactor:componet/treevaluechoos?= =?UTF-8?q?er=E6=96=87=E4=BB=B6es6=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/case/ztree/tree.display.js | 3 +- src/case/ztree/treeview.js | 3 +- src/component/index.js | 3 + .../abstract.treevaluechooser.js | 887 ++++++++++-------- .../abstract.treevaluechooser.list.js | 289 +++--- .../combo.listtreevaluechooser.js | 175 ++-- .../combo.treevaluechooser.insert.js | 177 ++-- .../combo.treevaluechooser.js | 194 ++-- src/component/treevaluechooser/index.js | 6 + .../treevaluechooser/pane.treevaluechooser.js | 76 +- src/widget/multitree/multi.tree.combo.js | 12 +- 11 files changed, 988 insertions(+), 837 deletions(-) create mode 100644 src/component/treevaluechooser/index.js diff --git a/src/case/ztree/tree.display.js b/src/case/ztree/tree.display.js index c6f090544..fe8f274fc 100644 --- a/src/case/ztree/tree.display.js +++ b/src/case/ztree/tree.display.js @@ -1,4 +1,4 @@ -import { extend } from "@/core"; +import { extend, shortcut } from "@/core"; import { TreeView } from "./treeview"; /** @@ -8,6 +8,7 @@ import { TreeView } from "./treeview"; * @extends BI.TreeView */ +@shortcut() export class DisplayTree extends TreeView { static xtype = "bi.display_tree"; static EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/case/ztree/treeview.js b/src/case/ztree/treeview.js index df4009092..195c31e4d 100644 --- a/src/case/ztree/treeview.js +++ b/src/case/ztree/treeview.js @@ -20,7 +20,8 @@ import { shortcut, VerticalLayout, Layout, - DefaultLayout + DefaultLayout, + some } from "@/core"; import { Msg, Pane, LoadingBar, Text } from "@/base"; diff --git a/src/component/index.js b/src/component/index.js index 6a57959bf..97b0ba2c6 100644 --- a/src/component/index.js +++ b/src/component/index.js @@ -1,18 +1,21 @@ export * as allvaluechooser from "./allvaluechooser"; export * as form from "./form"; export * as valueChooser from "./valuechooser"; +export * as treeValueChooser from "./treevaluechooser"; export { AllValueMultiTextValueCombo } from "./allvaluemultitextvaluecombo/allvalue.multitextvalue.combo"; // Object.assign(BI, { // ...allvaluechooser, // ...form, // ...valueChooser, +// ......treeValueChooser, // AllValueMultiTextValueCombo, // }); // export * from "./allvaluechooser"; // export * from "./form"; // export * from "./valuechooser"; +// export * from "./treevaluechooser"; // export { // AllValueMultiTextValueCombo // }; diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.js b/src/component/treevaluechooser/abstract.treevaluechooser.js index f1a7665d5..73f5b4616 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.js +++ b/src/component/treevaluechooser/abstract.treevaluechooser.js @@ -1,158 +1,195 @@ -BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { - - _const: { - perPage: 100 - }, - - _defaultConfig: function () { - return BI.extend(BI.AbstractTreeValueChooser.superclass._defaultConfig.apply(this, arguments), { +import { + Widget, + extend, + emptyFn, + isNotNull, + some, + Tree, + isEmpty, + each, + clone, + isNull, + UUID, + size, + i18nText, + deepClone, + isNotEmptyArray, + last, + has, + nextTick, + concat, + filter, + Func, + any, + every, + map, + difference, + keys, + isPlainObject, + get, + set +} from "@/core"; +import { TreeView } from "@/case"; + +export class AbstractTreeValueChooser extends Widget { + _const = { perPage: 100 }; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { items: null, - itemsCreator: BI.emptyFn, - open: false + itemsCreator: emptyFn, + open: false, }); - }, + } - _valueFormatter: function (v) { - var text = v; + _valueFormatter(v) { + let text = v; if (this.options.valueFormatter) { return this.options.valueFormatter(v); } - if (BI.isNotNull(this.items)) { - BI.some(this.items, function (i, item) { - if (item.value === v || item.value + "" === v) { + if (isNotNull(this.items)) { + some(this.items, (i, item) => { + if (item.value === v || `${item.value}` === v) { text = item.text; + return true; } }); } + return text; - }, + } - _initData: function (items) { + _initData(items) { this.items = items; - var nodes = BI.Tree.treeFormat(items); - this.tree = new BI.Tree(); + const nodes = Tree.treeFormat(items); + this.tree = new Tree(); this.tree.initTree(nodes); - }, + } - _itemsCreator: function (options, callback) { - var self = this, o = this.options; + _itemsCreator(options, callback) { + const call = () => { + switch (options.type) { + case TreeView.REQ_TYPE_INIT_DATA: + this._reqInitTreeNode(options, callback); + break; + case TreeView.REQ_TYPE_ADJUST_DATA: + this._reqAdjustTreeNode(options, callback); + break; + case TreeView.REQ_TYPE_SELECT_DATA: + this._reqSelectedTreeNode(options, callback); + break; + case TreeView.REQ_TYPE_GET_SELECTED_DATA: + this._reqDisplayTreeNode(options, callback); + break; + default: + this._reqTreeNode(options, callback); + break; + } + }; + const o = this.options; if (!this.items) { - o.itemsCreator({}, function (items) { - self._initData(items); + o.itemsCreator({}, items => { + this._initData(items); call(); }); } else { call(); } + } - function call() { - switch (options.type) { - case BI.TreeView.REQ_TYPE_INIT_DATA: - self._reqInitTreeNode(options, callback); - break; - case BI.TreeView.REQ_TYPE_ADJUST_DATA: - self._reqAdjustTreeNode(options, callback); - break; - case BI.TreeView.REQ_TYPE_SELECT_DATA: - self._reqSelectedTreeNode(options, callback); - break; - case BI.TreeView.REQ_TYPE_GET_SELECTED_DATA: - self._reqDisplayTreeNode(options, callback); - break; - default : - self._reqTreeNode(options, callback); - break; - } - } - }, - - _reqDisplayTreeNode: function (op, callback) { - var self = this; - var result = []; - var selectedValues = op.selectedValues; + _reqDisplayTreeNode(op, callback) { + const result = []; + const selectedValues = op.selectedValues; - if (selectedValues == null || BI.isEmpty(selectedValues)) { + if (selectedValues == null || isEmpty(selectedValues)) { callback({}); + return; } - doCheck([], this.tree.getRoot(), selectedValues); + const getCount = (jo, parentValues) => { + if (jo == null) { + return 0; + } + if (isEmpty(jo)) { + return this._getChildCount(parentValues); + } - callback({ - items: result - }); + return size(jo); + }; - function doCheck(parentValues, node, selected) { - if (selected == null || BI.isEmpty(selected)) { - BI.each(node.getChildren(), function (i, child) { - var newParents = BI.clone(parentValues); + const doCheck = (parentValues, node, selected) => { + if (selected == null || isEmpty(selected)) { + each(node.getChildren(), (i, child) => { + const newParents = clone(parentValues); newParents.push(child.value); - var llen = self._getChildCount(newParents); + const llen = this._getChildCount(newParents); createOneJson(child, node.id, llen); doCheck(newParents, child, {}); }); + return; } - BI.each(selected, function (k) { - var node = self._getTreeNode(parentValues, k); + each(selected, k => { + const node = this._getTreeNode(parentValues, k); // 找不到就是新增值 - if(BI.isNull(node)) { - createOneJson({ - id: BI.UUID(), - text: k, - value: k - }, BI.UUID(), 0); + if (isNull(node)) { + createOneJson( + { + id: UUID(), + text: k, + value: k, + }, + UUID(), + 0 + ); } else { - var newParents = BI.clone(parentValues); + const newParents = clone(parentValues); newParents.push(node.value); createOneJson(node, node.parent && node.parent.id, getCount(selected[k], newParents)); doCheck(newParents, node, selected[k]); } }); - } + }; - function getCount(jo, parentValues) { - if (jo == null) { - return 0; - } - if (BI.isEmpty(jo)) { - return self._getChildCount(parentValues); - } + doCheck([], this.tree.getRoot(), selectedValues); - return BI.size(jo); - } + callback({ + items: result, + }); function createOneJson(node, pId, llen) { result.push({ id: node.id, - pId: pId, - text: node.text + (llen > 0 ? ("(" + BI.i18nText("BI-Basic_Altogether") + llen + BI.i18nText("BI-Basic_Count") + ")") : ""), + pId, + text: + node.text + + (llen > 0 ? `(${i18nText("BI-Basic_Altogether")}${llen}${i18nText("BI-Basic_Count")})` : ""), value: node.value, open: true, - disabled: node.disabled + disabled: node.disabled, }); } - }, + } - _reqSelectedTreeNode: function (op, callback) { - var self = this; - var selectedValues = BI.deepClone(op.selectedValues); - var notSelectedValue = op.notSelectedValue || {}; - var keyword = op.keyword || ""; - var parentValues = op.parentValues || []; + _reqSelectedTreeNode(op, callback) { + const selectedValues = deepClone(op.selectedValues); + const notSelectedValue = op.notSelectedValue || {}; + const keyword = op.keyword || ""; + const parentValues = op.parentValues || []; - if (selectedValues == null || BI.isEmpty(selectedValues)) { + if (selectedValues == null || isEmpty(selectedValues)) { callback({}); + return; } dealWithSelectedValues(selectedValues); callback(selectedValues); - - function dealWithSelectedValues(selectedValues) { - var p = parentValues.concat(notSelectedValue); + const dealWithSelectedValues = selectedValues => { + let p = parentValues.concat(notSelectedValue); // 存储的值中存在这个值就把它删掉 // 例如选中了中国-江苏-南京, 取消中国或江苏或南京 // p长度不大于selectedValues的情况才可能找到,这样可以直接删除selectedValues的节点 @@ -160,21 +197,21 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { // 如果搜索的值在父亲链中 if (isSearchValueInParent(p)) { // 例如选中了 中国-江苏, 搜索江苏, 取消江苏(干掉了江苏) - self._deleteNode(selectedValues, p); + this._deleteNode(selectedValues, p); } else { - var searched = []; + const searched = []; // 要找到所有以notSelectedValue为叶子节点的链路 - var find = search(parentValues, notSelectedValue, [], searched); - if (find && BI.isNotEmptyArray(searched)) { - BI.each(searched, function (i, arr) { - var node = self._getNode(selectedValues, arr); + const find = search(parentValues, notSelectedValue, [], searched); + if (find && isNotEmptyArray(searched)) { + each(searched, (i, arr) => { + const node = this._getNode(selectedValues, arr); if (node) { // 例如选中了 中国-江苏, 搜索江苏, 取消中国(实际上只想删除中国-江苏,因为搜的是江苏) // 例如选中了 中国-江苏-南京,搜索南京,取消中国(实际上只想删除中国-江苏-南京,因为搜的是南京) - self._deleteNode(selectedValues, arr); + this._deleteNode(selectedValues, arr); } else { // 例如选中了 中国-江苏,搜索南京,取消中国(实际上只想删除中国-江苏-南京,因为搜的是南京) - expandSelectedValue(selectedValues, arr, BI.last(arr)); + expandSelectedValue(selectedValues, arr, last(arr)); } }); } @@ -185,7 +222,8 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { // 例如选中了中国-江苏,取消南京 // important 选中了中国-江苏,取消了江苏,但是搜索的是南京 if (isChild(selectedValues, p)) { - var result = [], find = false; + const result = []; + let find = false; // 如果parentValues中有匹配的值,说明搜索结果不在当前值下 if (isSearchValueInParent(p)) { find = true; @@ -200,42 +238,45 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { expandSelectedValue(selectedValues, p, notSelectedValue); // 添加去掉搜索的结果集 if (result.length > 0) { - BI.each(result, function (i, strs) { - self._buildTree(selectedValues, strs); + each(result, (i, strs) => { + this._buildTree(selectedValues, strs); }); } } } + }; - } - - function expandSelectedValue(selectedValues, parents, notSelectedValue) { - var next = selectedValues; - var childrenCount = []; - var path = []; + const expandSelectedValue = (selectedValues, parents, notSelectedValue) => { + let next = selectedValues; + const childrenCount = []; + const path = []; // 去掉点击的节点之后的结果集 - BI.some(parents, function (i, v) { - var t = next[v]; + some(parents, (i, v) => { + const t = next[v]; if (t == null) { if (i === 0) { return true; } - if (BI.isEmpty(next)) { - var split = parents.slice(0, i); - var expanded = self._getChildren(split); + if (isEmpty(next)) { + const split = parents.slice(0, i); + const expanded = this._getChildren(split); path.push(split); childrenCount.push(expanded.length); // 如果只有一个值且取消的就是这个值 - if (i === parents.length - 1 && expanded.length === 1 && expanded[0].value === notSelectedValue) { - for (var j = childrenCount.length - 1; j >= 0; j--) { + if ( + i === parents.length - 1 && + expanded.length === 1 && + expanded[0].value === notSelectedValue + ) { + for (let j = childrenCount.length - 1; j >= 0; j--) { if (childrenCount[j] === 1) { - self._deleteNode(selectedValues, path[j]); + this._deleteNode(selectedValues, path[j]); } else { break; } } } else { - BI.each(expanded, function (m, child) { + each(expanded, (m, child) => { if (i === parents.length - 1 && child.value === notSelectedValue) { return true; } @@ -252,22 +293,23 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { next = t; } }); - } + }; - function search(parents, current, result, searched) { - var newParents = BI.clone(parents); + const search = (parents, current, result, searched) => { + const newParents = clone(parents); newParents.push(current); - if (self._isMatch(parents, current, keyword)) { + if (this._isMatch(parents, current, keyword)) { searched && searched.push(newParents); + return true; } - var children = self._getChildren(newParents); + const children = this._getChildren(newParents); - var notSearch = []; - var can = false; + const notSearch = []; + let can = false; - BI.each(children, function (i, child) { + each(children, (i, child) => { if (search(newParents, child.value, result, searched)) { can = true; } else { @@ -275,117 +317,119 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } }); if (can === true) { - BI.each(notSearch, function (i, v) { - var next = BI.clone(newParents); + each(notSearch, (i, v) => { + const next = clone(newParents); next.push(v); result.push(next); }); } + return can; - } + }; - function isSearchValueInParent(parentValues) { - for (var i = 0, len = parentValues.length; i < len; i++) { - if (self._isMatch(parentValues.slice(0, i), parentValues[i], keyword)) { + const isSearchValueInParent = parentValues => { + for (let i = 0, len = parentValues.length; i < len; i++) { + if (this._isMatch(parentValues.slice(0, i), parentValues[i], keyword)) { return true; } } + return false; - } + }; function canFindKey(selectedValues, parents) { - var t = selectedValues; - for (var i = 0; i < parents.length; i++) { - var v = parents[i]; + let t = selectedValues; + for (let i = 0; i < parents.length; i++) { + const v = parents[i]; t = t[v]; if (t == null) { return false; } } + return true; } function isChild(selectedValues, parents) { - var t = selectedValues; - for (var i = 0; i < parents.length; i++) { - var v = parents[i]; - if (!BI.has(t, v)) { + let t = selectedValues; + for (let i = 0; i < parents.length; i++) { + const v = parents[i]; + if (!has(t, v)) { return false; } t = t[v]; - if (BI.isEmpty(t)) { + if (isEmpty(t)) { return true; } } + return false; } - }, + } - _reqAdjustTreeNode: function (op, callback) { - var self = this; - var result = []; - var selectedValues = op.selectedValues; - if (selectedValues == null || BI.isEmpty(selectedValues)) { + _reqAdjustTreeNode(op, callback) { + const result = []; + const selectedValues = op.selectedValues; + if (selectedValues == null || isEmpty(selectedValues)) { callback({}); + return; } - BI.each(selectedValues, function (k, v) { + each(selectedValues, (k, v) => { result.push([k]); }); dealWithSelectedValues(selectedValues, []); - var jo = {}; - BI.each(result, function (i, strs) { - self._buildTree(jo, strs); + const jo = {}; + each(result, (i, strs) => { + this._buildTree(jo, strs); }); callback(jo); function dealWithSelectedValues(selected, parents) { - if (selected == null || BI.isEmpty(selected)) { + if (selected == null || isEmpty(selected)) { return true; } - var can = true; - BI.each(selected, function (k, v) { - var p = BI.clone(parents); + let can = true; + each(selected, (k, v) => { + const p = clone(parents); p.push(k); if (!dealWithSelectedValues(selected[k], p)) { - BI.each(selected[k], function (nk, nv) { - var t = BI.clone(p); + each(selected[k], (nk, nv) => { + const t = clone(p); t.push(nk); result.push(t); }); can = false; } }); + return can && isAllSelected(selected, parents); } - function isAllSelected(selected, parents) { - return BI.isEmpty(selected) || self._getChildCount(parents) === BI.size(selected); - } - }, - - _reqInitTreeNode: function (op, callback) { - var self = this; - var result = []; - var keyword = op.keyword || ""; - var selectedValues = op.selectedValues; - var lastSearchValue = op.lastSearchValue || ""; // 一次请求100个,但是搜索是拿全部的,lastSearchValue是上一次遍历到的节点索引 - var output = search(); - BI.nextTick(function () { + const isAllSelected = (selected, parents) => isEmpty(selected) || this._getChildCount(parents) === size(selected); + } + + _reqInitTreeNode(op, callback) { + let result = []; + const keyword = op.keyword || ""; + const selectedValues = op.selectedValues; + const lastSearchValue = op.lastSearchValue || ""; // 一次请求100个,但是搜索是拿全部的,lastSearchValue是上一次遍历到的节点索引 + const output = search(); + nextTick(() => { callback({ - hasNext: output.length > self._const.perPage, + hasNext: output.length > this._const.perPage, items: result, - lastSearchValue: BI.last(output) + lastSearchValue: last(output), }); }); - function search() { - var children = self._getChildren([]); - var start = children.length; + const search = () => { + const children = this._getChildren([]); + let start = children.length; if (lastSearchValue !== "") { - for (var j = 0, len = start; j < len; j++) { + for (let j = 0, len = start; j < len; j++) { if (children[j].value === lastSearchValue) { start = j + 1; break; @@ -394,47 +438,63 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } else { start = 0; } - var output = []; - for (var i = start, len = children.length; i < len; i++) { - if (output.length < self._const.perPage) { - var find = nodeSearch(1, [], children[i].value, false, result); - } else if (output.length === self._const.perPage) { - var find = nodeSearch(1, [], children[i].value, false, []); + const output = []; + for (let i = start, len = children.length; i < len; i++) { + let find; + if (output.length < this._const.perPage) { + find = nodeSearch(1, [], children[i].value, false, result); + } else if (output.length === this._const.perPage) { + find = nodeSearch(1, [], children[i].value, false, []); } if (find[0] === true) { output.push(children[i].value); } - if (output.length > self._const.perPage) { + if (output.length > this._const.perPage) { break; } } // 深层嵌套的比较麻烦,这边先实现的是在根节点添加 if (op.times === 1) { - var nodes = self._getAddedValueNode([], selectedValues); - result = BI.concat(BI.filter(nodes, function (idx, node) { - var find = BI.Func.getSearchResult([node.text || node.value], keyword); - return find.find.length > 0 || find.match.length > 0; - }), result); - } + const nodes = this._getAddedValueNode([], selectedValues); + result = concat( + filter(nodes, (idx, node) => { + const find = Func.getSearchResult([node.text || node.value], keyword); + + return find.find.length > 0 || find.match.length > 0; + }), + result + ); + } + return output; - } - - function nodeSearch(deep, parentValues, current, isAllSelect, result) { - if (self._isMatch(parentValues, current, keyword)) { - var checked = isAllSelect || isSelected(parentValues, current); - createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result); + }; + + const nodeSearch = (deep, parentValues, current, isAllSelect, result) => { + if (this._isMatch(parentValues, current, keyword)) { + const checked = isAllSelect || isSelected(parentValues, current); + createOneJson( + parentValues, + current, + false, + checked, + !isAllSelect && isHalf(parentValues, current), + true, + result + ); + return [true, checked]; } - var newParents = BI.clone(parentValues); + const newParents = clone(parentValues); newParents.push(current); - var children = self._getChildren(newParents); + const children = this._getChildren(newParents); - var can = false, checked = false; + let can = false, + checked = false; - var isCurAllSelected = isAllSelect || isAllSelected(parentValues, current); - BI.each(children, function (i, child) { - var state = nodeSearch(deep + 1, newParents, child.value, isCurAllSelected, result); + const isCurAllSelected = isAllSelect || isAllSelected(parentValues, current); + each(children, (i, child) => { + const state = nodeSearch(deep + 1, newParents, child.value, isCurAllSelected, result); // 当前节点的子节点是否选中,并不确定全选还是半选 if (state[1] === true) { checked = true; @@ -449,11 +509,12 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { checked = isCurAllSelected || (isSelected(parentValues, current) && checked); createOneJson(parentValues, current, true, checked, false, false, result); } + return [can, checked]; - } + }; - function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { - var node = self._getTreeNode(parentValues, value); + const createOneJson = (parentValues, value, isOpen, checked, half, flag, result) => { + const node = this._getTreeNode(parentValues, value); result.push({ id: node.id, pId: node.pId, @@ -462,21 +523,22 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { title: node.title, isParent: node.getChildrenLength() > 0, open: isOpen, - checked: checked, + checked, halfCheck: half, - flag: flag, - disabled: node.disabled + flag, + disabled: node.disabled, }); - } + }; function isHalf(parentValues, value) { - var find = findSelectedObj(parentValues); + const find = findSelectedObj(parentValues); if (find == null) { return null; } - return BI.any(find, function (v, ob) { + + return any(find, (v, ob) => { if (v === value) { - if (ob != null && !BI.isEmpty(ob)) { + if (ob != null && !isEmpty(ob)) { return true; } } @@ -484,13 +546,14 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } function isAllSelected(parentValues, value) { - var find = findSelectedObj(parentValues); + const find = findSelectedObj(parentValues); if (find == null) { return null; } - return BI.any(find, function (v, ob) { + + return any(find, (v, ob) => { if (v === value) { - if (ob != null && BI.isEmpty(ob)) { + if (ob != null && isEmpty(ob)) { return true; } } @@ -498,11 +561,12 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } function isSelected(parentValues, value) { - var find = findSelectedObj(parentValues); + const find = findSelectedObj(parentValues); if (find == null) { return false; } - return BI.any(find, function (v) { + + return any(find, v => { if (v === value) { return true; } @@ -510,37 +574,116 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } function findSelectedObj(parentValues) { - var find = selectedValues; + let find = selectedValues; if (find == null) { return null; } - BI.every(parentValues, function (i, v) { + every(parentValues, (i, v) => { find = find[v]; if (find == null) { return false; } + return true; }); + return find; } - }, - - _reqTreeNode: function (op, callback) { - var self = this, o = this.options; - var result = []; - var times = op.times; - var checkState = op.checkState || {}; - var parentValues = op.parentValues || []; - var selectedValues = op.selectedValues || {}; - function getResult(parentValues, checkState) { - var valueMap = {}; + } + + _reqTreeNode(op, callback) { + const o = this.options; + let result = []; + const times = op.times; + const checkState = op.checkState || {}; + const parentValues = op.parentValues || []; + const selectedValues = op.selectedValues || {}; + const getCheckState = (current, parentValues, valueMap, checkState) => { + // 节点本身的checked和half优先级最高 + const checked = checkState.checked, + half = checkState.half; + let tempCheck = false, + halfCheck = false; + if (has(valueMap, current)) { + // 可能是半选 + if (valueMap[current][0] === 1) { + const values = clone(parentValues); + values.push(current); + const childCount = this._getChildCount(values); + if (childCount > 0 && childCount !== valueMap[current][1]) { + halfCheck = true; + } + } else if (valueMap[current][0] === 2) { + tempCheck = true; + } + } + let check; + // 展开的节点checked为false 且没有明确得出当前子节点是半选或者全选, 则check状态取决于valueMap + if (!checked && !halfCheck && !tempCheck) { + check = has(valueMap, current); + } else { + // 不是上面那种情况就先看在节点没有带有明确半选的时候,通过节点自身的checked和valueMap的状态能都得到选中信息 + check = ((tempCheck || checked) && !half) || has(valueMap, current); + } + + return [check, halfCheck]; + }; + const getResult = (parentValues, checkState) => { + let valueMap = {}; // if (judgeState(parentValues, selectedValues, checkState)) { + const isAllSelected = (selected, parents) => { + if (isEmpty(selected)) { + return true; + } + + if (this._getChildCount(parents) !== size(selected)) { + return false; + } + + return every(selected, value => isAllSelected(selected[value], concat(parents, value))); + }; + + function dealWithSelectedValue(parentValues, selectedValues) { + const valueMap = {}, + parents = (parentValues || []).slice(0); + each(parentValues, (i, v) => { + parents.push(v); + + selectedValues = selectedValues[v] || {}; + }); + each(selectedValues, (value, obj) => { + const currentParents = concat(parents, value); + + if (isNull(obj)) { + valueMap[value] = [0, 0]; + + return; + } + if (isEmpty(obj)) { + valueMap[value] = [2, 0]; + + return; + } + const nextNames = {}; + each(obj, (t, o) => { + if (isNull(o) || isEmpty(o)) { + nextNames[t] = true; + } else { + isAllSelected(o, concat(currentParents, [t])) && (nextNames[t] = true); + } + }); + // valueMap的数组第一个参数为不选: 0, 半选: 1, 全选:2, 第二个参数为改节点下选中的子节点个数(子节点全选或者不存在) + valueMap[value] = [1, size(nextNames)]; + }); + + return valueMap; + } 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; + const nodes = this._getChildren(parentValues); + for (let i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { + const state = getCheckState(nodes[i].value, parentValues, valueMap, checkState); + const openState = o.open || nodes[i].open; result.push({ id: nodes[i].id, pId: nodes[i].pId, @@ -557,10 +700,10 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { warningTitle: nodes[i].warningTitle, }); if (openState) { - getResult(parentValues.concat([nodes[i].value]), {checked: state[0], half: state[1]}); + getResult(parentValues.concat([nodes[i].value]), { checked: state[0], half: state[1] }); } } - } + }; getResult(parentValues, checkState); @@ -568,22 +711,22 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { // if (o.open) { // var allNodes = []; // // 获取所有节点 - // BI.each(nodes, function (idx, node) { - // allNodes = BI.concat(allNodes, self._getAllChildren(parentValues.concat([node.value]))); + // each(nodes, function (idx, node) { + // allNodes = concat(allNodes, self._getAllChildren(parentValues.concat([node.value]))); // }); // var lastFind; - // BI.each(allNodes, function (idx, node) { + // each(allNodes, function (idx, node) { // var valueMap = dealWithSelectedValue(node.parentValues, selectedValues); // // REPORT-24409 fix: 设置节点全部展开,添加的节点没有给状态 // var parentCheckState = {}; - // var find = BI.find(result, function (idx, pNode) { + // var find = 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)) { + // if (isNotNull(lastFind) && (lastFind !== find || allNodes.length - 1 === idx)) { // lastFind.half = lastFind.halfCheck; // lastFind.halfCheck = false; // } @@ -609,12 +752,12 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { // 深层嵌套的比较麻烦,这边先实现的是在根节点添加 if (parentValues.length === 0 && times === 1) { - result = BI.concat(self._getAddedValueNode(parentValues, selectedValues), result); + result = concat(this._getAddedValueNode(parentValues, selectedValues), result); } - BI.nextTick(function () { + nextTick(() => { callback({ items: result, - hasNext: self._getChildren(parentValues).length > times * self._const.perPage + hasNext: this._getChildren(parentValues).length > times * this._const.perPage, }); }); @@ -623,90 +766,17 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { // if (parentValues.length > 0 && !checked) { // return false; // } - // return (parentValues.length === 0 || (checked && half) && !BI.isEmpty(selected_value)); + // return (parentValues.length === 0 || (checked && half) && !isEmpty(selected_value)); // } + } - function dealWithSelectedValue(parentValues, selectedValues) { - var valueMap = {}, parents = (parentValues || []).slice(0); - BI.each(parentValues, function (i, v) { - parents.push(v); - - selectedValues = selectedValues[v] || {}; - }); - BI.each(selectedValues, function (value, obj) { - var currentParents = BI.concat(parents, value); - - if (BI.isNull(obj)) { - valueMap[value] = [0, 0]; - return; - } - if (BI.isEmpty(obj)) { - valueMap[value] = [2, 0]; - return; - } - var nextNames = {}; - BI.each(obj, function (t, o) { - if (BI.isNull(o) || BI.isEmpty(o)) { - nextNames[t] = true; - } else { - isAllSelected(o, BI.concat(currentParents, [t])) && (nextNames[t] = true); - } - }); - // valueMap的数组第一个参数为不选: 0, 半选: 1, 全选:2, 第二个参数为改节点下选中的子节点个数(子节点全选或者不存在) - valueMap[value] = [1, BI.size(nextNames)]; - }); - return valueMap; - } - - function isAllSelected(selected, parents) { - if (BI.isEmpty(selected)) { - return true; - } - - if (self._getChildCount(parents) !== BI.size(selected)) { - return false; - } - - return BI.every(selected, function (value) { - return isAllSelected(selected[value], BI.concat(parents, value)); - }); - } - - function getCheckState(current, parentValues, valueMap, checkState) { - // 节点本身的checked和half优先级最高 - var checked = checkState.checked, half = checkState.half; - var tempCheck = false, halfCheck = false; - if (BI.has(valueMap, current)) { - // 可能是半选 - if (valueMap[current][0] === 1) { - var values = BI.clone(parentValues); - values.push(current); - var childCount = self._getChildCount(values); - if (childCount > 0 && childCount !== valueMap[current][1]) { - halfCheck = true; - } - } else if (valueMap[current][0] === 2) { - tempCheck = true; - } - } - var check; - // 展开的节点checked为false 且没有明确得出当前子节点是半选或者全选, 则check状态取决于valueMap - if (!checked && !halfCheck && !tempCheck) { - check = BI.has(valueMap, current); - } else { - // 不是上面那种情况就先看在节点没有带有明确半选的时候,通过节点自身的checked和valueMap的状态能都得到选中信息 - check = ((tempCheck || checked) && !half) || BI.has(valueMap, current); - } - return [check, halfCheck]; - } - }, - - _getAddedValueNode: function (parentValues, selectedValues) { - var nodes = this._getChildren(parentValues); - return BI.map(BI.difference(BI.keys(selectedValues), BI.map(nodes, "value")), function (idx, v) { + _getAddedValueNode(parentValues, selectedValues) { + const nodes = this._getChildren(parentValues); + + return map(difference(keys(selectedValues), map(nodes, "value")), (idx, v) => { return { - id: BI.UUID(), - pId: nodes.length > 0 ? nodes[0].pId : BI.UUID(), + id: UUID(), + pId: nodes.length > 0 ? nodes[0].pId : UUID(), value: v, text: v, times: 1, @@ -715,27 +785,28 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { halfCheck: false, }; }); - }, + } - _getNode: function (selectedValues, parentValues) { - var pNode = selectedValues; - for (var i = 0, len = parentValues.length; i < len; i++) { + _getNode(selectedValues, parentValues) { + let pNode = selectedValues; + for (let i = 0, len = parentValues.length; i < len; i++) { if (pNode == null) { return null; } pNode = pNode[parentValues[i]]; } + return pNode; - }, + } - _deleteNode: function (selectedValues, values) { - var name = values[values.length - 1]; - var p = values.slice(0, values.length - 1); - var pNode = this._getNode(selectedValues, p); + _deleteNode(selectedValues, values) { + let name = values[values.length - 1]; + let p = values.slice(0, values.length - 1); + let pNode = this._getNode(selectedValues, p); if (pNode != null && pNode[name]) { delete pNode[name]; // 递归删掉空父节点 - while (p.length > 0 && BI.isEmpty(pNode)) { + while (p.length > 0 && isEmpty(pNode)) { name = p[p.length - 1]; p = p.slice(0, p.length - 1); pNode = this._getNode(selectedValues, p); @@ -744,40 +815,42 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { } } } - }, + } - _buildTree: function (jo, values) { - var t = jo; - BI.each(values, function (i, v) { - if (!BI.has(t, v)) { + _buildTree(jo, values) { + let t = jo; + each(values, (i, v) => { + if (!has(t, v)) { t[v] = {}; } t = t[v]; }); - }, + } - _isMatch: function (parentValues, value, keyword) { - var o = this.options; - var node = this._getTreeNode(parentValues, value); + _isMatch(parentValues, value, keyword) { + const o = this.options; + const node = this._getTreeNode(parentValues, value); if (!node) { return false; } - var find = BI.Func.getSearchResult([node.text || node.value], keyword); - if(o.allowSearchValue && node.value) { - var valueFind = BI.Func.getSearchResult([node.value], keyword); - return valueFind.find.length > 0 || valueFind.match.length > 0 || - find.find.length > 0 || find.match.length > 0; + const find = Func.getSearchResult([node.text || node.value], keyword); + if (o.allowSearchValue && node.value) { + const valueFind = Func.getSearchResult([node.value], keyword); + + return ( + valueFind.find.length > 0 || valueFind.match.length > 0 || find.find.length > 0 || find.match.length > 0 + ); } + return find.find.length > 0 || find.match.length > 0; - }, - - _getTreeNode: function (parentValues, v) { - var self = this; - var findParentNode; - var index = 0; - var currentParent = this.tree.getRoot(); - this.tree.traverse(function (node) { - if (self.tree.isRoot(node)) { + } + + _getTreeNode(parentValues, v) { + let findParentNode; + let index = 0; + let currentParent = this.tree.getRoot(); + this.tree.traverse(node => { + if (this.tree.isRoot(node)) { return; } if (index > parentValues.length) { @@ -809,109 +882,111 @@ BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { }); return findParentNode; - }, + } - _getChildren: function (parentValues) { + _getChildren(parentValues) { + let parent; if (parentValues.length > 0) { - var value = BI.last(parentValues); - var parent = this._getTreeNode(parentValues.slice(0, parentValues.length - 1), value); + const value = last(parentValues); + parent = this._getTreeNode(parentValues.slice(0, parentValues.length - 1), value); } else { - var parent = this.tree.getRoot(); + parent = this.tree.getRoot(); } return parent ? parent.getChildren() : []; - }, + } - _getAllChildren: function(parentValues) { - var children = this._getChildren(parentValues); - var nodes = [].concat(children); - BI.each(nodes, function (idx, node) { + _getAllChildren(parentValues) { + const children = this._getChildren(parentValues); + let nodes = [].concat(children); + each(nodes, (idx, node) => { node.parentValues = parentValues; }); - var queue = BI.map(children, function (idx, node) { + let queue = map(children, (idx, node) => { return { - parentValues: parentValues, - value: node.value + parentValues, + value: node.value, }; }); - while (BI.isNotEmptyArray(queue)) { - var node = queue.shift(); - var pValues = (node.parentValues).concat(node.value); - var childNodes = this._getChildren(pValues); - BI.each(childNodes, function (idx, node) { + while (isNotEmptyArray(queue)) { + const node = queue.shift(); + const pValues = node.parentValues.concat(node.value); + const childNodes = this._getChildren(pValues); + each(childNodes, (idx, node) => { node.parentValues = pValues; }); queue = queue.concat(childNodes); nodes = nodes.concat(childNodes); } + return nodes; - }, + } - _getChildCount: function (parentValues) { + _getChildCount(parentValues) { return this._getChildren(parentValues).length; - }, + } - assertSelectedValue: function (selectedValues, items = []) { - if (BI.isPlainObject(selectedValues)) { + assertSelectedValue(selectedValues, items = []) { + if (isPlainObject(selectedValues)) { return selectedValues; } - var tree = BI.Tree.transformToTreeFormat(items); - var value2ParentMap = {}; - BI.Tree.traversal(tree, function (index, node, pNode) { + const tree = Tree.transformToTreeFormat(items); + const value2ParentMap = {}; + Tree.traversal(tree, (index, node, pNode) => { value2ParentMap[node.value] = pNode; }); - var result = {}; - BI.each(selectedValues, function (index, value) { - var curr = value; - var parentPath = []; + const result = {}; + each(selectedValues, (index, value) => { + let curr = value; + const parentPath = []; while (curr) { parentPath.unshift(curr); curr = value2ParentMap[curr]?.value; } - BI.each(parentPath, function (index) { - if (BI.isNull(BI.get(result, parentPath.slice(0, index + 1)))) { - BI.set(result, parentPath.slice(0, index + 1), {}); + each(parentPath, index => { + if (isNull(get(result, parentPath.slice(0, index + 1)))) { + set(result, parentPath.slice(0, index + 1), {}); } }); // 执行完一条路径,check一下 - var lengths = BI.size(BI.get(result, parentPath.slice(0, -1))); + const lengths = size(get(result, parentPath.slice(0, -1))); if (lengths === value2ParentMap[value]?.children?.length) { - BI.set(result, parentPath.slice(0, -1), {}); + set(result, parentPath.slice(0, -1), {}); } }); return result; - }, + } - buildCompleteTree: function (selectedValues) { - var self = this; - var result = {}; + buildCompleteTree(selectedValues) { + const result = {}; - if (selectedValues !== null && !BI.isEmpty(selectedValues)) { + if (selectedValues !== null && !isEmpty(selectedValues)) { fill([], this.tree.getRoot(), selectedValues, result); } return result; function fill(parentValues, node, selected, r) { - if (selected === null || BI.isEmpty(selected)) { - BI.each(node.getChildren(), function (i, child) { - var newParents = BI.clone(parentValues); + if (selected === null || isEmpty(selected)) { + each(node.getChildren(), (i, child) => { + const newParents = clone(parentValues); newParents.push(child.value); r[child.value] = {}; fill(newParents, child, null, r[child.value]); }); + return; } - BI.each(selected, function (k) { - var node = self._getTreeNode(parentValues, k); - var newParents = BI.clone(parentValues); + each(selected, k => { + const node = this._getTreeNode(parentValues, k); + const newParents = clone(parentValues); newParents.push(node.value); r[k] = {}; fill(newParents, node, selected[k], r[k]); }); } - }, -}); + } +} diff --git a/src/component/treevaluechooser/abstract.treevaluechooser.list.js b/src/component/treevaluechooser/abstract.treevaluechooser.list.js index 0a44af0f1..9c84e13ba 100644 --- a/src/component/treevaluechooser/abstract.treevaluechooser.list.js +++ b/src/component/treevaluechooser/abstract.treevaluechooser.list.js @@ -1,36 +1,60 @@ -BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { +import { + isEmpty, + values, + each, + isNull, + UUID, + has, + nextTick, + last, + concat, + filter, + Func, + clone, + any, + isEqual, + every, + flatten, + map, + difference +} from "@/core"; +import { AbstractTreeValueChooser } from "./abstract.treevaluechooser"; - _reqDisplayTreeNode: function (op, callback) { - var self = this; - var result = {}; - var selectedValues = op.selectedValues; +export class AbstractListTreeValueChooser extends AbstractTreeValueChooser { + _reqDisplayTreeNode(op, callback) { + const result = {}; + const selectedValues = op.selectedValues; - if (selectedValues == null || BI.isEmpty(selectedValues)) { + if (selectedValues == null || isEmpty(selectedValues)) { callback({}); + return; } doCheck([], this.tree.getRoot(), selectedValues); callback({ - items: BI.values(result) + items: values(result), }); function doCheck(parentValues, node, selected) { - BI.each(selected, function (idx, path) { - BI.each(path, function (id, value) { - var nodeValue = value; - var node = self._getTreeNode(path.slice(0, id), nodeValue); + each(selected, (idx, path) => { + each(path, (id, value) => { + const nodeValue = value; + const node = this._getTreeNode(path.slice(0, id), nodeValue); // 找不到就是新增值 - if (BI.isNull(node)) { - createOneJson({ - id: BI.UUID(), - text: nodeValue, - value: nodeValue, - isLeaf: true - }, BI.UUID()); + if (isNull(node)) { + createOneJson( + { + id: UUID(), + text: nodeValue, + value: nodeValue, + isLeaf: true, + }, + UUID() + ); } else { - if(!BI.has(result, node.id)) { + if (!has(result, node.id)) { createOneJson(node, node.parent && node.parent.id); } result[node.id].isLeaf !== true && (result[node.id].isLeaf = id === path.length - 1); @@ -42,35 +66,34 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { function createOneJson(node, pId) { result[node.id] = { id: node.id, - pId: pId, + pId, text: node.text, value: node.value, open: true, - isLeaf: node.isLeaf + isLeaf: node.isLeaf, }; } - }, + } - _reqInitTreeNode: function (op, callback) { - var self = this; - var result = []; - var keyword = op.keyword || ""; - var selectedValues = op.selectedValues; - var lastSearchValue = op.lastSearchValue || ""; // 一次请求100个,但是搜索是拿全部的,lastSearchValue是上一次遍历到的节点索引 - var output = search(); - BI.nextTick(function () { + _reqInitTreeNode(op, callback) { + let result = []; + const keyword = op.keyword || ""; + const selectedValues = op.selectedValues; + const lastSearchValue = op.lastSearchValue || ""; // 一次请求100个,但是搜索是拿全部的,lastSearchValue是上一次遍历到的节点索引 + const output = search(); + nextTick(() => { callback({ - hasNext: output.length > self._const.perPage, + hasNext: output.length > this._const.perPage, items: result, - lastSearchValue: BI.last(output) + lastSearchValue: last(output), }); }); - function search() { - var children = self._getChildren([]); - var start = children.length; + const search = () => { + const children = this._getChildren([]); + let start = children.length; if (lastSearchValue !== "") { - for (var j = 0, len = start; j < len; j++) { + for (let j = 0, len = start; j < len; j++) { if (children[j].value === lastSearchValue) { start = j + 1; break; @@ -79,46 +102,72 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { } else { start = 0; } - var output = []; - for (var i = start, len = children.length; i < len; i++) { - if (output.length < self._const.perPage) { - var find = nodeSearch(1, [], children[i].value, result); - } else if (output.length === self._const.perPage) { - var find = nodeSearch(1, [], children[i].value, []); + const output = []; + let find; + for (let i = start, len = children.length; i < len; i++) { + if (output.length < this._const.perPage) { + find = nodeSearch(1, [], children[i].value, result); + } else if (output.length === this._const.perPage) { + find = nodeSearch(1, [], children[i].value, []); } if (find[0] === true) { output.push(children[i].value); } - if (output.length > self._const.perPage) { + if (output.length > this._const.perPage) { break; } } // 深层嵌套的比较麻烦,这边先实现的是在根节点添加 if (op.times === 1) { - var nodes = self._getAddedValueNode([], selectedValues); - result = BI.concat(BI.filter(nodes, function (idx, node) { - var find = BI.Func.getSearchResult([node.text || node.value], keyword); - return find.find.length > 0 || find.match.length > 0; - }), result); + const nodes = this._getAddedValueNode([], selectedValues); + result = concat( + filter(nodes, (idx, node) => { + const find = Func.getSearchResult([node.text || node.value], keyword); + + return find.find.length > 0 || find.match.length > 0; + }), + result + ); } + return output; - } + }; + + const createOneJson = (parentValues, value, isOpen, checked, flag, result) => { + const node = this._getTreeNode(parentValues, value); + result.push({ + id: node.id, + pId: node.pId, + text: node.text, + value: node.value, + title: node.title, + isParent: node.getChildrenLength() > 0, + open: isOpen, + checked, + halfCheck: false, + flag, + disabled: node.disabled, + }); + }; - function nodeSearch(deep, parentValues, current, result) { - if (self._isMatch(parentValues, current, keyword)) { - var checked = isSelected(parentValues, current); + const nodeSearch = (deep, parentValues, current, result) => { + let checked; + if (this._isMatch(parentValues, current, keyword)) { + checked = isSelected(parentValues, current); createOneJson(parentValues, current, false, checked, true, result); + return [true, checked]; } - var newParents = BI.clone(parentValues); + const newParents = clone(parentValues); newParents.push(current); - var children = self._getChildren(newParents); + const children = this._getChildren(newParents); - var can = false, checked = false; + let can = false; + checked = false; - BI.each(children, function (i, child) { - var state = nodeSearch(deep + 1, newParents, child.value, result); + each(children, (i, child) => { + const state = nodeSearch(deep + 1, newParents, child.value, result); if (state[1] === true) { checked = true; } @@ -130,48 +179,36 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { checked = isSelected(parentValues, current); createOneJson(parentValues, current, true, checked, false, result); } + return [can, checked]; - } - - function createOneJson(parentValues, value, isOpen, checked, flag, result) { - var node = self._getTreeNode(parentValues, value); - result.push({ - id: node.id, - pId: node.pId, - text: node.text, - value: node.value, - title: node.title, - isParent: node.getChildrenLength() > 0, - open: isOpen, - checked: checked, - halfCheck: false, - flag: flag, - disabled: node.disabled - }); - } + }; + // eslint-disable-next-line no-unused-vars function isHalf(parentValues, value) { - var find = findSelectedObj(parentValues); + const find = findSelectedObj(parentValues); if (find == null) { return null; } - return BI.any(find, function (v, ob) { + + return any(find, (v, ob) => { if (v === value) { - if (ob != null && !BI.isEmpty(ob)) { + if (ob != null && !isEmpty(ob)) { return true; } } }); } + // eslint-disable-next-line no-unused-vars function isAllSelected(parentValues, value) { - var find = findSelectedObj(parentValues); + const find = findSelectedObj(parentValues); if (find == null) { return null; } - return BI.any(find, function (v, ob) { + + return any(find, (v, ob) => { if (v === value) { - if (ob != null && BI.isEmpty(ob)) { + if (ob != null && isEmpty(ob)) { return true; } } @@ -179,37 +216,37 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { } function isSelected(parentValues, value) { - return BI.any(selectedValues, function (idx, array) { - return BI.isEqual(parentValues, array.slice(0, parentValues.length)) && BI.last(array) === value; - }); + return any(selectedValues, (idx, array) => isEqual(parentValues, array.slice(0, parentValues.length)) && last(array) === value); } function findSelectedObj(parentValues) { - var find = selectedValues; + let find = selectedValues; if (find == null) { return null; } - BI.every(parentValues, function (i, v) { + every(parentValues, (i, v) => { find = find[v]; if (find == null) { return false; } + return true; }); + return find; } - }, + } - _reqTreeNode: function (op, callback) { - var self = this, o = this.options; - var result = []; - var times = op.times; - var parentValues = op.parentValues || []; - var selectedValues = op.selectedValues || []; - var 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 checked = BI.has(valueMap, nodes[i].value); + _reqTreeNode(op, callback) { + const o = this.options; + let result = []; + const times = op.times; + const parentValues = op.parentValues || []; + const selectedValues = op.selectedValues || []; + const valueMap = dealWithSelectedValue(parentValues, selectedValues); + const nodes = this._getChildren(parentValues); + for (let i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { + const checked = has(valueMap, nodes[i].value); result.push({ id: nodes[i].id, pId: nodes[i].pId, @@ -217,22 +254,22 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { text: nodes[i].text, times: 1, isParent: nodes[i].getChildrenLength() > 0, - checked: checked, + checked, halfCheck: false, open: o.open, - disabled: nodes[i].disabled + disabled: nodes[i].disabled, }); } // 如果指定节点全部打开 if (o.open) { - var allNodes = []; + let allNodes = []; // 获取所有节点 - BI.each(nodes, function (idx, node) { - allNodes = BI.concat(allNodes, self._getAllChildren(parentValues.concat([node.value]))); + each(nodes, (idx, node) => { + allNodes = concat(allNodes, this._getAllChildren(parentValues.concat([node.value]))); }); - BI.each(allNodes, function (idx, node) { - var valueMap = dealWithSelectedValue(node.parentValues, selectedValues); - var checked = BI.has(valueMap, node.value); + each(allNodes, (idx, node) => { + const valueMap = dealWithSelectedValue(node.parentValues, selectedValues); + const checked = has(valueMap, node.value); result.push({ id: node.id, pId: node.pId, @@ -240,51 +277,53 @@ BI.AbstractListTreeValueChooser = BI.inherit(BI.AbstractTreeValueChooser, { text: node.text, times: 1, isParent: node.getChildrenLength() > 0, - checked: checked, + checked, halfCheck: false, open: o.open, - disabled: node.disabled + disabled: node.disabled, }); }); } // 深层嵌套的比较麻烦,这边先实现的是在根节点添加 if (parentValues.length === 0 && times === 1) { - result = BI.concat(self._getAddedValueNode(parentValues, selectedValues), result); + result = concat(this._getAddedValueNode(parentValues, selectedValues), result); } - BI.nextTick(function () { + nextTick(() => { callback({ items: result, - hasNext: nodes.length > times * self._const.perPage + hasNext: nodes.length > times * this._const.perPage, }); }); function dealWithSelectedValue(parentValues, selectedValues) { - var valueMap = {}; - BI.each(selectedValues, function (idx, v) { - if (BI.isEqual(parentValues, v.slice(0, parentValues.length))) { - valueMap[BI.last(v)] = [2, 0]; + const valueMap = {}; + each(selectedValues, (idx, v) => { + if (isEqual(parentValues, v.slice(0, parentValues.length))) { + valueMap[last(v)] = [2, 0]; } }); + return valueMap; } - }, + } - _getAddedValueNode: function (parentValues, selectedValues) { - var nodes = this._getChildren(parentValues); - var values = BI.flatten(BI.filter(selectedValues, function (idx, array) { - return array.length === 1; - })); - return BI.map(BI.difference(values, BI.map(nodes, "value")), function (idx, v) { + _getAddedValueNode(parentValues, selectedValues) { + const nodes = this._getChildren(parentValues); + const values = flatten( + filter(selectedValues, (idx, array) => array.length === 1) + ); + + return map(difference(values, map(nodes, "value")), (idx, v) => { return { - id: BI.UUID(), - pId: nodes.length > 0 ? nodes[0].pId : BI.UUID(), + id: UUID(), + pId: nodes.length > 0 ? nodes[0].pId : UUID(), value: v, text: v, times: 1, isParent: false, checked: true, - halfCheck: false + halfCheck: false, }; }); } -}); \ No newline at end of file +} diff --git a/src/component/treevaluechooser/combo.listtreevaluechooser.js b/src/component/treevaluechooser/combo.listtreevaluechooser.js index 0366a4bbc..847280947 100644 --- a/src/component/treevaluechooser/combo.listtreevaluechooser.js +++ b/src/component/treevaluechooser/combo.listtreevaluechooser.js @@ -1,31 +1,39 @@ -/** - * 简单的复选下拉树控件, 适用于数据量少的情况, 可以自增值 - * - * Created by GUY on 2015/10/29. - * @class BI.ListTreeValueChooserInsertCombo - * @extends BI.Widget - */ -BI.ListTreeValueChooserInsertCombo = BI.inherit(BI.AbstractListTreeValueChooser, { +import { shortcut, extend, emptyFn, isNotNull, createWidget, bind } from "@/core"; +import { AbstractListTreeValueChooser } from "./abstract.treevaluechooser.list"; +import { MultiTreeListCombo, MultiTreeCombo } from "@/widget"; +import { TreeValueChooserInsertCombo } from "./combo.treevaluechooser.insert"; - _defaultConfig: function () { - return BI.extend(BI.ListTreeValueChooserInsertCombo.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export class ListTreeValueChooserInsertCombo extends AbstractListTreeValueChooser { + static xtype = "bi.list_tree_value_chooser_insert_combo"; + + static EVENT_FOCUS = "EVENT_FOCUS"; + static EVENT_BLUR = "EVENT_BLUR"; + static EVENT_STOP = "EVENT_STOP"; + static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM"; + static EVENT_SEARCHING = "EVENT_SEARCHING"; + static EVENT_CONFIRM = "EVENT_CONFIRM"; + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-list-tree-value-chooser-insert-combo", width: 200, height: 24, items: null, - itemsCreator: BI.emptyFn, + itemsCreator: emptyFn, isNeedAdjustWidth: true, }); - }, + } - _init: function () { - BI.ListTreeValueChooserInsertCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNotNull(o.items)) { + _init() { + super._init(...arguments); + const o = this.options; + if (isNotNull(o.items)) { this._initData(o.items); } - this.combo = BI.createWidget({ - type: "bi.multi_tree_list_combo", + this.combo = createWidget({ + type: MultiTreeListCombo.xtype, simple: o.simple, isNeedAdjustWidth: o.isNeedAdjustWidth, element: this, @@ -35,94 +43,93 @@ BI.ListTreeValueChooserInsertCombo = BI.inherit(BI.AbstractListTreeValueChooser, watermark: o.watermark, allowInsertValue: o.allowInsertValue, allowEdit: o.allowEdit, - itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: BI.bind(this._valueFormatter, this), + itemsCreator: bind(this._itemsCreator, this), + valueFormatter: bind(this._valueFormatter, this), width: o.width, height: o.height, - listeners: [{ - eventName: BI.MultiTreeListCombo.EVENT_FOCUS, - action: function () { - self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_FOCUS); - } - }, { - eventName: BI.MultiTreeListCombo.EVENT_BLUR, - action: function () { - self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_BLUR); - } - }, { - eventName: BI.MultiTreeListCombo.EVENT_STOP, - action: function () { - self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_STOP); + listeners: [ + { + eventName: MultiTreeListCombo.EVENT_FOCUS, + action: () => { + this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_FOCUS); + }, + }, + { + eventName: MultiTreeListCombo.EVENT_BLUR, + action: () => { + this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_BLUR); + }, + }, + { + eventName: MultiTreeListCombo.EVENT_STOP, + action: () => { + this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_STOP); + }, + }, + { + eventName: MultiTreeListCombo.EVENT_CLICK_ITEM, + action: v => { + this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v); + }, + }, + { + eventName: MultiTreeListCombo.EVENT_SEARCHING, + action: () => { + this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_SEARCHING); + }, + }, + { + eventName: MultiTreeListCombo.EVENT_CONFIRM, + action: () => { + this.fireEvent(ListTreeValueChooserInsertCombo.EVENT_CONFIRM); + }, + }, + { + eventName: MultiTreeCombo.EVENT_BEFORE_POPUPVIEW, + action: () => { + this.fireEvent(TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW); + }, } - }, { - eventName: BI.MultiTreeListCombo.EVENT_CLICK_ITEM, - action: function (v) { - self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v); - } - }, { - eventName: BI.MultiTreeListCombo.EVENT_SEARCHING, - action: function () { - self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_SEARCHING); - } - }, { - eventName: BI.MultiTreeListCombo.EVENT_CONFIRM, - action: function () { - self.fireEvent(BI.ListTreeValueChooserInsertCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_BEFORE_POPUPVIEW, - action: function () { - self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW); - } - }] + ], }); - }, + } - showView: function () { + showView() { this.combo.showView(); - }, + } - hideView: function () { + hideView() { this.combo.hideView(); - }, + } - getSearcher: function () { + getSearcher() { return this.combo.getSearcher(); - }, + } - setValue: function (v) { + setValue(v) { this.combo.setValue(v); - }, + } - getValue: function () { + getValue() { return this.combo.getValue(); - }, + } - populate: function (items) { - if (BI.isNotNull(items)) { + populate(items) { + if (isNotNull(items)) { this._initData(items); } this.combo.populate(); - }, + } - focus: function () { + focus() { this.combo.focus(); - }, + } - blur: function () { + blur() { this.combo.blur(); - }, + } - setWaterMark: function (v) { + setWaterMark(v) { this.combo.setWaterMark(v); } -}); - -BI.ListTreeValueChooserInsertCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.ListTreeValueChooserInsertCombo.EVENT_BLUR = "EVENT_BLUR"; -BI.ListTreeValueChooserInsertCombo.EVENT_STOP = "EVENT_STOP"; -BI.ListTreeValueChooserInsertCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM"; -BI.ListTreeValueChooserInsertCombo.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.ListTreeValueChooserInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.ListTreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.list_tree_value_chooser_insert_combo", BI.ListTreeValueChooserInsertCombo); +} diff --git a/src/component/treevaluechooser/combo.treevaluechooser.insert.js b/src/component/treevaluechooser/combo.treevaluechooser.insert.js index f9c6ebf4b..1eba57884 100644 --- a/src/component/treevaluechooser/combo.treevaluechooser.insert.js +++ b/src/component/treevaluechooser/combo.treevaluechooser.insert.js @@ -1,31 +1,39 @@ -/** - * 简单的复选下拉树控件, 适用于数据量少的情况, 可以自增值 - * - * Created by GUY on 2015/10/29. - * @class BI.TreeValueChooserInsertCombo - * @extends BI.Widget - */ -BI.TreeValueChooserInsertCombo = BI.inherit(BI.AbstractTreeValueChooser, { +import { shortcut, extend, emptyFn, isNotNull, createWidget, bind } from "@/core"; +import { AbstractTreeValueChooser } from "./abstract.treevaluechooser"; +import { MultiTreeInsertCombo, MultiTreeCombo } from "@/widget"; +import { TreeValueChooserCombo } from "./combo.treevaluechooser"; - _defaultConfig: function () { - return BI.extend(BI.TreeValueChooserInsertCombo.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export class TreeValueChooserInsertCombo extends AbstractTreeValueChooser { + static xtype = "bi.tree_value_chooser_insert_combo"; + + static EVENT_FOCUS = "EVENT_FOCUS"; + static EVENT_BLUR = "EVENT_BLUR"; + static EVENT_STOP = "EVENT_STOP"; + static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM"; + static EVENT_SEARCHING = "EVENT_SEARCHING"; + static EVENT_CONFIRM = "EVENT_CONFIRM"; + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-tree-value-chooser-insert-combo", width: 200, height: 24, items: null, - itemsCreator: BI.emptyFn, - isNeedAdjustWidth: true + itemsCreator: emptyFn, + isNeedAdjustWidth: true, }); - }, + } - _init: function () { - BI.TreeValueChooserInsertCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNotNull(o.items)) { + _init() { + super._init(...arguments); + const o = this.options; + if (isNotNull(o.items)) { this._initData(o.items); } - this.combo = BI.createWidget({ - type: "bi.multi_tree_insert_combo", + this.combo = createWidget({ + type: MultiTreeInsertCombo.xtype, simple: o.simple, isNeedAdjustWidth: o.isNeedAdjustWidth, allowEdit: o.allowEdit, @@ -34,94 +42,93 @@ BI.TreeValueChooserInsertCombo = BI.inherit(BI.AbstractTreeValueChooser, { value: o.value, watermark: o.watermark, element: this, - itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: BI.bind(this._valueFormatter, this), + itemsCreator: bind(this._itemsCreator, this), + valueFormatter: bind(this._valueFormatter, this), width: o.width, height: o.height, - listeners: [{ - eventName: BI.MultiTreeInsertCombo.EVENT_FOCUS, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_FOCUS); - } - }, { - eventName: BI.MultiTreeInsertCombo.EVENT_BLUR, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_BLUR); - } - }, { - eventName: BI.MultiTreeInsertCombo.EVENT_STOP, - action: function () { - self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_STOP); + listeners: [ + { + eventName: MultiTreeInsertCombo.EVENT_FOCUS, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_FOCUS); + }, + }, + { + eventName: MultiTreeInsertCombo.EVENT_BLUR, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_BLUR); + }, + }, + { + eventName: MultiTreeInsertCombo.EVENT_STOP, + action: () => { + this.fireEvent(TreeValueChooserInsertCombo.EVENT_STOP); + }, + }, + { + eventName: MultiTreeInsertCombo.EVENT_CLICK_ITEM, + action: v => { + this.fireEvent(TreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v); + }, + }, + { + eventName: MultiTreeInsertCombo.EVENT_SEARCHING, + action: () => { + this.fireEvent(TreeValueChooserInsertCombo.EVENT_SEARCHING); + }, + }, + { + eventName: MultiTreeInsertCombo.EVENT_CONFIRM, + action: () => { + this.fireEvent(TreeValueChooserInsertCombo.EVENT_CONFIRM); + }, + }, + { + eventName: MultiTreeCombo.EVENT_BEFORE_POPUPVIEW, + action: () => { + this.fireEvent(TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW); + }, } - }, { - eventName: BI.MultiTreeInsertCombo.EVENT_CLICK_ITEM, - action: function (v) { - self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_CLICK_ITEM, v); - } - }, { - eventName: BI.MultiTreeInsertCombo.EVENT_SEARCHING, - action: function () { - self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_SEARCHING); - } - }, { - eventName: BI.MultiTreeInsertCombo.EVENT_CONFIRM, - action: function () { - self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_BEFORE_POPUPVIEW, - action: function () { - self.fireEvent(BI.TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW); - } - }] + ], }); - }, + } - showView: function () { + showView() { this.combo.showView(); - }, + } - hideView: function () { + hideView() { this.combo.hideView(); - }, + } - getSearcher: function () { + getSearcher() { return this.combo.getSearcher(); - }, + } - setValue: function (v) { + setValue(v) { this.combo.setValue(v); - }, + } - getValue: function () { + getValue() { return this.combo.getValue(); - }, + } - populate: function (items) { - if (BI.isNotNull(items)) { + populate(items) { + if (isNotNull(items)) { this._initData(items); } this.combo.populate(); - }, + } - focus: function () { + focus() { this.combo.focus(); - }, + } - blur: function () { + blur() { this.combo.blur(); - }, + } - setWaterMark: function (v) { + setWaterMark(v) { this.combo.setWaterMark(v); } -}); - -BI.TreeValueChooserInsertCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.TreeValueChooserInsertCombo.EVENT_BLUR = "EVENT_BLUR"; -BI.TreeValueChooserInsertCombo.EVENT_STOP = "EVENT_STOP"; -BI.TreeValueChooserInsertCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM"; -BI.TreeValueChooserInsertCombo.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.TreeValueChooserInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.TreeValueChooserInsertCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.tree_value_chooser_insert_combo", BI.TreeValueChooserInsertCombo); +} diff --git a/src/component/treevaluechooser/combo.treevaluechooser.js b/src/component/treevaluechooser/combo.treevaluechooser.js index 2c0709d67..51ee25614 100644 --- a/src/component/treevaluechooser/combo.treevaluechooser.js +++ b/src/component/treevaluechooser/combo.treevaluechooser.js @@ -1,31 +1,40 @@ -/** - * 简单的复选下拉树控件, 适用于数据量少的情况 - * - * Created by GUY on 2015/10/29. - * @class BI.TreeValueChooserCombo - * @extends BI.Widget - */ -BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, { +import { shortcut, extend, emptyFn, isNotNull, createWidget, bind } from "@/core"; +import { AbstractTreeValueChooser } from "./abstract.treevaluechooser"; +import { MultiTreeCombo } from "@/widget"; - _defaultConfig: function () { - return BI.extend(BI.TreeValueChooserCombo.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export class TreeValueChooserCombo extends AbstractTreeValueChooser { + // TODO:该组件有问题,未报错,但不显示pane,该问题看起来是其他组件es6化导致 + static xtype = "bi.tree_value_chooser_combo"; + + static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + static EVENT_CONFIRM = "EVENT_CONFIRM"; + static EVENT_FOCUS = "EVENT_FOCUS"; + static EVENT_BLUR = "EVENT_BLUR"; + static EVENT_STOP = "EVENT_STOP"; + static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM"; + static EVENT_SEARCHING = "EVENT_SEARCHING"; + static EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-tree-value-chooser-combo", width: 200, height: 24, items: null, - itemsCreator: BI.emptyFn, - isNeedAdjustWidth: true + itemsCreator: emptyFn, + isNeedAdjustWidth: true, }); - }, + } - _init: function () { - BI.TreeValueChooserCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNotNull(o.items)) { + _init() { + super._init(...arguments); + const o = this.options; + if (isNotNull(o.items)) { this._initData(o.items); } - this.combo = BI.createWidget({ - type: "bi.multi_tree_combo", + this.combo = createWidget({ + type: MultiTreeCombo.xtype, simple: o.simple, text: o.text, defaultText: o.defaultText, @@ -33,105 +42,104 @@ BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, { value: this.assertSelectedValue(o.value, o.items), watermark: o.watermark, element: this, - itemsCreator: BI.bind(this._itemsCreator, this), - valueFormatter: BI.bind(this._valueFormatter, this), + itemsCreator: bind(this._itemsCreator, this), + valueFormatter: bind(this._valueFormatter, this), width: o.width, height: o.height, isNeedAdjustWidth: o.isNeedAdjustWidth, - listeners: [{ - eventName: BI.MultiTreeCombo.EVENT_FOCUS, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_FOCUS); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_BLUR, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_BLUR); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_STOP, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_STOP); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_CLICK_ITEM, - action: function (v) { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_CLICK_ITEM, v); + listeners: [ + { + eventName: MultiTreeCombo.EVENT_FOCUS, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_FOCUS); + }, + }, + { + eventName: MultiTreeCombo.EVENT_BLUR, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_BLUR); + }, + }, + { + eventName: MultiTreeCombo.EVENT_STOP, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_STOP); + }, + }, + { + eventName: MultiTreeCombo.EVENT_CLICK_ITEM, + action: v => { + this.fireEvent(TreeValueChooserCombo.EVENT_CLICK_ITEM, v); + }, + }, + { + eventName: MultiTreeCombo.EVENT_SEARCHING, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_SEARCHING); + }, + }, + { + eventName: MultiTreeCombo.EVENT_CONFIRM, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_CONFIRM); + }, + }, + { + eventName: MultiTreeCombo.EVENT_BEFORE_POPUPVIEW, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_BEFORE_POPUPVIEW); + }, + }, + { + eventName: MultiTreeCombo.EVENT_AFTER_HIDEVIEW, + action: () => { + this.fireEvent(TreeValueChooserCombo.EVENT_AFTER_HIDEVIEW); + }, } - }, { - eventName: BI.MultiTreeCombo.EVENT_SEARCHING, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_SEARCHING); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_CONFIRM, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_BEFORE_POPUPVIEW, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_BEFORE_POPUPVIEW); - } - }, { - eventName: BI.MultiTreeCombo.EVENT_AFTER_HIDEVIEW, - action: function () { - self.fireEvent(BI.TreeValueChooserCombo.EVENT_AFTER_HIDEVIEW); - } - }] + ], }); - }, + } - showView: function () { + showView() { this.combo.showView(); - }, + } - hideView: function () { + hideView() { this.combo.hideView(); - }, + } - getSearcher: function () { + getSearcher() { return this.combo.getSearcher(); - }, + } - setValue: function (v) { + setValue(v) { this.combo.setValue(v); - }, + } - getValue: function () { + getValue() { return this.combo.getValue(); - }, + } - getAllValue: function () { + getAllValue() { return this.buildCompleteTree(this.combo.getValue()); - }, + } - populate: function (items) { - if (BI.isNotNull(items)) { + populate(items) { + if (isNotNull(items)) { this._initData(items); } this.combo.populate(); - }, + } - focus: function () { + focus() { this.combo.focus(); - }, + } - blur: function () { + blur() { this.combo.blur(); - }, + } - setWaterMark: function (v) { + setWaterMark(v) { this.combo.setWaterMark(v); } -}); - -BI.TreeValueChooserCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.TreeValueChooserCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.TreeValueChooserCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.TreeValueChooserCombo.EVENT_BLUR = "EVENT_BLUR"; -BI.TreeValueChooserCombo.EVENT_STOP = "EVENT_STOP"; -BI.TreeValueChooserCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM"; -BI.TreeValueChooserCombo.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.TreeValueChooserCombo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; -BI.shortcut("bi.tree_value_chooser_combo", BI.TreeValueChooserCombo); +} diff --git a/src/component/treevaluechooser/index.js b/src/component/treevaluechooser/index.js new file mode 100644 index 000000000..6b439bb08 --- /dev/null +++ b/src/component/treevaluechooser/index.js @@ -0,0 +1,6 @@ +export { AbstractTreeValueChooser } from "./abstract.treevaluechooser"; +export { AbstractListTreeValueChooser } from "./abstract.treevaluechooser.list"; +export { ListTreeValueChooserInsertCombo } from "./combo.listtreevaluechooser"; +export { TreeValueChooserInsertCombo } from "./combo.treevaluechooser.insert"; +export { TreeValueChooserCombo } from "./combo.treevaluechooser"; +export { TreeValueChooserPane } from "./pane.treevaluechooser"; diff --git a/src/component/treevaluechooser/pane.treevaluechooser.js b/src/component/treevaluechooser/pane.treevaluechooser.js index 8171c04d8..aad0bf08d 100644 --- a/src/component/treevaluechooser/pane.treevaluechooser.js +++ b/src/component/treevaluechooser/pane.treevaluechooser.js @@ -1,66 +1,66 @@ -/** - * 简单的树面板, 适用于数据量少的情况 - * - * Created by GUY on 2015/10/29. - * @class BI.TreeValueChooserPane - * @extends BI.AbstractTreeValueChooser - */ -BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, { +import { shortcut, extend, emptyFn, createWidget, bind, isNotNull } from "@/core"; +import { AbstractTreeValueChooser } from "./abstract.treevaluechooser"; +import { MultiSelectTree } from "@/widget/multiselecttree/multiselecttree"; +import { MultiSelectTreePopup } from "@/widget/multiselecttree/multiselecttree.popup"; - _defaultConfig: function () { - return BI.extend(BI.TreeValueChooserPane.superclass._defaultConfig.apply(this, arguments), { +@shortcut() +export class TreeValueChooserPane extends AbstractTreeValueChooser { + static xtype = "bi.tree_value_chooser_pane"; + + static EVENT_CHANGE = "EVENT_CHANGE"; + + _defaultConfig() { + return extend(super._defaultConfig(...arguments), { baseCls: "bi-tree-value-chooser-pane", items: null, - itemsCreator: BI.emptyFn, - showLine: true + itemsCreator: emptyFn, + showLine: true, }); - }, + } - _init: function () { - BI.TreeValueChooserPane.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.pane = BI.createWidget({ - type: o.hideSearch ? "bi.multi_select_tree_popup" : "bi.multi_select_tree", + _init() { + super._init(...arguments); + const o = this.options; + this.pane = createWidget({ + type: o.hideSearch ? MultiSelectTreePopup.xtype : MultiSelectTree.xtype, element: this, showLine: o.showLine, - itemsCreator: BI.bind(this._itemsCreator, this) + itemsCreator: bind(this._itemsCreator, this), }); - this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () { - self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE); + this.pane.on(MultiSelectTree.EVENT_CHANGE, () => { + this.fireEvent(TreeValueChooserPane.EVENT_CHANGE); }); - if (BI.isNotNull(o.value)) { - var selectedValues = this.assertSelectedValue(o.value, o.items); + if (isNotNull(o.value)) { + const selectedValues = this.assertSelectedValue(o.value, o.items); this.pane.setSelectedValue(selectedValues); } - if (BI.isNotNull(o.items)) { + if (isNotNull(o.items)) { this._initData(o.items); this.pane.populate(); } - }, + } - setSelectedValue: function (v) { + setSelectedValue(v) { this.pane.setSelectedValue(v); - }, + } - setValue: function (v) { + setValue(v) { this.pane.setValue(v); - }, + } - getValue: function () { + getValue() { return this.pane.getValue(); - }, + } - getAllValue: function() { + getAllValue() { return this.buildCompleteTree(this.pane.getValue()); - }, + } - populate: function (items) { - if (BI.isNotNull(items)) { + populate(items) { + if (isNotNull(items)) { this._initData(items); } this.pane.populate(); } -}); -BI.TreeValueChooserPane.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.tree_value_chooser_pane", BI.TreeValueChooserPane); +} diff --git a/src/widget/multitree/multi.tree.combo.js b/src/widget/multitree/multi.tree.combo.js index 7ae95930e..1eac4b54b 100644 --- a/src/widget/multitree/multi.tree.combo.js +++ b/src/widget/multitree/multi.tree.combo.js @@ -16,6 +16,8 @@ import { MultiTreePopup } from "./multi.tree.popup"; import { MultiSelectTrigger } from "../multiselect/multiselect.trigger"; import { TriggerIconButton } from "@/case"; import { MultiSelectCheckSelectedSwitcher } from "../multiselect/trigger/switcher.checkselected"; +import { MultiTreeCheckSelectedButton } from "./trigger/multi.tree.button.checkselected"; +import { MultiTreeCheckPane } from "./check/multi.tree.check.pane"; @shortcut() export class MultiTreeCombo extends Single { @@ -42,6 +44,8 @@ export class MultiTreeCombo extends Single { } _init() { + const self = this, + o = this.options; const triggerBtn = createWidget({ type: TriggerIconButton.xtype, width: o.height, @@ -50,8 +54,6 @@ export class MultiTreeCombo extends Single { }); let clear; let change; - const self = this, - o = this.options; super._init(...arguments); let isInit = false; let want2showCounter = false; @@ -293,10 +295,12 @@ export class MultiTreeCombo extends Single { this.numberCounter = createWidget({ type: "bi.multi_select_check_selected_switcher", el: { - type: "bi.multi_tree_check_selected_button", + // type: "bi.multi_tree_check_selected_button", + type: MultiTreeCheckSelectedButton.xtype, }, popup: { - type: "bi.multi_tree_check_pane", + // type: "bi.multi_tree_check_pane", + type: MultiTreeCheckPane.xtype, }, masker: { offset: {