@egova/egova-api 1.3.14 → 1.3.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11033,14 +11033,25 @@ var tree_ProjectTree = /** @class */function (_super) {
11033
11033
  * @param node
11034
11034
  */
11035
11035
  ProjectTree.prototype.match = function (node) {
11036
- var _this = this;
11037
- var matched = (node.title || node.name).indexOf(this.keyword) !== -1;
11036
+ // 关键词匹配
11037
+ var keywordMatched = !this.keyword || (node.title || node.name).indexOf(this.keyword) !== -1;
11038
+ // 方法匹配
11039
+ var methodMatched = this.type === "all" || !node.method || this.type === node.method;
11040
+ var selfMatched = keywordMatched && methodMatched;
11041
+ // 检查子节点匹配情况
11038
11042
  var childrenMatched = false;
11039
- if (!matched && node.children) {
11040
- node.children.forEach(function (v) {
11041
- childrenMatched = _this.match(v).matched || _this.match(v).childrenMatched || childrenMatched;
11042
- });
11043
+ if (node.children && node.children.length > 0) {
11044
+ for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
11045
+ var child = _a[_i];
11046
+ var result = this.match(child);
11047
+ if (result.matched || result.childrenMatched) {
11048
+ childrenMatched = true;
11049
+ break;
11050
+ }
11051
+ }
11043
11052
  }
11053
+ // 节点匹配成功或者有子节点匹配成功都认为是匹配的
11054
+ var matched = selfMatched || childrenMatched;
11044
11055
  return {
11045
11056
  matched: matched,
11046
11057
  childrenMatched: childrenMatched
@@ -11053,20 +11064,30 @@ var tree_ProjectTree = /** @class */function (_super) {
11053
11064
  ProjectTree.prototype.filterData = function (data) {
11054
11065
  var _this = this;
11055
11066
  if (!data || !Array.isArray(data)) return data;
11056
- var d = data.filter(function (v) {
11057
- return _this.match(v).childrenMatched;
11058
- });
11059
- d = d.map(function (v) {
11060
- if (v.children) {
11061
- v.expand = true;
11062
- v.children = _this.filterData(v.children);
11067
+ return data.map(function (node) {
11068
+ var newNode = node.$clone ? node.$clone() : __assign({}, node);
11069
+ var matchResult = _this.match(node);
11070
+ // 如果节点匹配或者有匹配的子节点,则保留在结果中
11071
+ if (matchResult.matched) {
11072
+ if (newNode.children && newNode.children.length > 0) {
11073
+ newNode.expand = true;
11074
+ newNode.children = _this.filterData(newNode.children);
11075
+ }
11076
+ return newNode;
11063
11077
  }
11064
- return v;
11078
+ // 如果当前节点不匹配,但有匹配的子节点,也保留在结果中
11079
+ if (matchResult.childrenMatched) {
11080
+ newNode.expand = true;
11081
+ if (newNode.children && newNode.children.length > 0) {
11082
+ newNode.children = _this.filterData(newNode.children);
11083
+ }
11084
+ return newNode;
11085
+ }
11086
+ // 节点不匹配也不包含匹配的子节点,则不包含在结果中
11087
+ return null;
11088
+ }).filter(function (node) {
11089
+ return node !== null;
11065
11090
  });
11066
- d = d.concat(data.filter(function (v) {
11067
- return _this.match(v).matched;
11068
- }));
11069
- return d;
11070
11091
  };
11071
11092
  ProjectTree.prototype.onSelectParent = function (group) {
11072
11093
  this.parent = group;
package/dist/index.umd.js CHANGED
@@ -11042,14 +11042,25 @@ var tree_ProjectTree = /** @class */function (_super) {
11042
11042
  * @param node
11043
11043
  */
11044
11044
  ProjectTree.prototype.match = function (node) {
11045
- var _this = this;
11046
- var matched = (node.title || node.name).indexOf(this.keyword) !== -1;
11045
+ // 关键词匹配
11046
+ var keywordMatched = !this.keyword || (node.title || node.name).indexOf(this.keyword) !== -1;
11047
+ // 方法匹配
11048
+ var methodMatched = this.type === "all" || !node.method || this.type === node.method;
11049
+ var selfMatched = keywordMatched && methodMatched;
11050
+ // 检查子节点匹配情况
11047
11051
  var childrenMatched = false;
11048
- if (!matched && node.children) {
11049
- node.children.forEach(function (v) {
11050
- childrenMatched = _this.match(v).matched || _this.match(v).childrenMatched || childrenMatched;
11051
- });
11052
+ if (node.children && node.children.length > 0) {
11053
+ for (var _i = 0, _a = node.children; _i < _a.length; _i++) {
11054
+ var child = _a[_i];
11055
+ var result = this.match(child);
11056
+ if (result.matched || result.childrenMatched) {
11057
+ childrenMatched = true;
11058
+ break;
11059
+ }
11060
+ }
11052
11061
  }
11062
+ // 节点匹配成功或者有子节点匹配成功都认为是匹配的
11063
+ var matched = selfMatched || childrenMatched;
11053
11064
  return {
11054
11065
  matched: matched,
11055
11066
  childrenMatched: childrenMatched
@@ -11062,20 +11073,30 @@ var tree_ProjectTree = /** @class */function (_super) {
11062
11073
  ProjectTree.prototype.filterData = function (data) {
11063
11074
  var _this = this;
11064
11075
  if (!data || !Array.isArray(data)) return data;
11065
- var d = data.filter(function (v) {
11066
- return _this.match(v).childrenMatched;
11067
- });
11068
- d = d.map(function (v) {
11069
- if (v.children) {
11070
- v.expand = true;
11071
- v.children = _this.filterData(v.children);
11076
+ return data.map(function (node) {
11077
+ var newNode = node.$clone ? node.$clone() : __assign({}, node);
11078
+ var matchResult = _this.match(node);
11079
+ // 如果节点匹配或者有匹配的子节点,则保留在结果中
11080
+ if (matchResult.matched) {
11081
+ if (newNode.children && newNode.children.length > 0) {
11082
+ newNode.expand = true;
11083
+ newNode.children = _this.filterData(newNode.children);
11084
+ }
11085
+ return newNode;
11072
11086
  }
11073
- return v;
11087
+ // 如果当前节点不匹配,但有匹配的子节点,也保留在结果中
11088
+ if (matchResult.childrenMatched) {
11089
+ newNode.expand = true;
11090
+ if (newNode.children && newNode.children.length > 0) {
11091
+ newNode.children = _this.filterData(newNode.children);
11092
+ }
11093
+ return newNode;
11094
+ }
11095
+ // 节点不匹配也不包含匹配的子节点,则不包含在结果中
11096
+ return null;
11097
+ }).filter(function (node) {
11098
+ return node !== null;
11074
11099
  });
11075
- d = d.concat(data.filter(function (v) {
11076
- return _this.match(v).matched;
11077
- }));
11078
- return d;
11079
11100
  };
11080
11101
  ProjectTree.prototype.onSelectParent = function (group) {
11081
11102
  this.parent = group;