@ibiz-template/runtime 0.1.30 → 0.1.31

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.
package/dist/index.esm.js CHANGED
@@ -27917,10 +27917,12 @@ var TreeController = class extends MDControlController {
27917
27917
  initState() {
27918
27918
  super.initState();
27919
27919
  this.state.defaultExpandedKeys = [];
27920
+ this.state.expandedKeys = [];
27920
27921
  this.state.size = 0;
27921
27922
  }
27922
27923
  async onCreated() {
27923
27924
  await super.onCreated();
27925
+ this.state.expandedKeys = [...this.state.defaultExpandedKeys];
27924
27926
  this.service = new TreeService(this.model);
27925
27927
  await this.service.init(this.context);
27926
27928
  this.model.detreeNodes.forEach((node) => {
@@ -27946,8 +27948,17 @@ var TreeController = class extends MDControlController {
27946
27948
  */
27947
27949
  async load(args = {}) {
27948
27950
  const isInitialLoad = args.isInitialLoad === true;
27949
- const nodes = await this.loadNodes();
27950
- this.state.expandedKeys = this.calcExpandedKeys(nodes);
27951
+ if (isInitialLoad) {
27952
+ await this.startLoading();
27953
+ }
27954
+ let nodes;
27955
+ try {
27956
+ nodes = await this.loadNodes();
27957
+ } finally {
27958
+ if (isInitialLoad) {
27959
+ await this.endLoading();
27960
+ }
27961
+ }
27951
27962
  await this.afterLoad(args, nodes);
27952
27963
  this.state.isLoaded = true;
27953
27964
  await this.evt.emit("onLoadSuccess", {
@@ -27965,19 +27976,12 @@ var TreeController = class extends MDControlController {
27965
27976
  async loadNodes(parentNode) {
27966
27977
  const params = await this.getFetchParams();
27967
27978
  const hasQuery = !!params.query;
27968
- const defaultExpandedKeys = !parentNode ? this.state.defaultExpandedKeys : void 0;
27969
- await this.startLoading();
27970
- let nodes;
27971
- try {
27972
- nodes = await this.service.fetchChildNodes(parentNode, {
27973
- context: this.context.clone(),
27974
- params,
27975
- hasQuery,
27976
- defaultExpandedKeys
27977
- }) || [];
27978
- } finally {
27979
- await this.endLoading();
27980
- }
27979
+ const nodes = await this.service.fetchChildNodes(parentNode, {
27980
+ context: this.context.clone(),
27981
+ params,
27982
+ hasQuery,
27983
+ defaultExpandedKeys: this.state.expandedKeys
27984
+ }) || [];
27981
27985
  if (parentNode) {
27982
27986
  parentNode.children = nodes;
27983
27987
  } else {
@@ -27990,6 +27994,7 @@ var TreeController = class extends MDControlController {
27990
27994
  this.state.items.push(node);
27991
27995
  }
27992
27996
  );
27997
+ this.state.expandedKeys = this.calcExpandedKeys(nodes);
27993
27998
  return nodes;
27994
27999
  }
27995
28000
  /**
@@ -28015,6 +28020,24 @@ var TreeController = class extends MDControlController {
28015
28020
  await this.setActive(nodeData);
28016
28021
  }
28017
28022
  }
28023
+ /**
28024
+ * 树节点数据变更事件处理
28025
+ * @author lxm
28026
+ * @date 2023-09-28 01:48:05
28027
+ * @param {ITreeNodeData} nodeData
28028
+ * @param {boolean} isExpand true为展开,false为折叠
28029
+ */
28030
+ onExpandChange(nodeData, isExpand) {
28031
+ const hasKey = this.state.expandedKeys.includes(nodeData.id);
28032
+ if (isExpand && !hasKey) {
28033
+ this.state.expandedKeys.push(nodeData.id);
28034
+ } else if (!isExpand && hasKey) {
28035
+ const index = this.state.expandedKeys.indexOf(nodeData.id);
28036
+ if (index !== -1) {
28037
+ this.state.expandedKeys.splice(index, 1);
28038
+ }
28039
+ }
28040
+ }
28018
28041
  /**
28019
28042
  * 树节点双击事件
28020
28043
  * @author lxm
@@ -28098,7 +28121,7 @@ var TreeController = class extends MDControlController {
28098
28121
  };
28099
28122
  }
28100
28123
  /**
28101
- * 计算展开节点集合
28124
+ * 计算展开节点集合(根据加载的子节点计算所有的展开节点标识集合)
28102
28125
  * @author lxm
28103
28126
  * @date 2023-08-09 05:19:36
28104
28127
  * @param {ITreeNodeData[]} nodes
@@ -28106,17 +28129,14 @@ var TreeController = class extends MDControlController {
28106
28129
  * @return {*} {string[]}
28107
28130
  */
28108
28131
  calcExpandedKeys(nodes) {
28109
- let expandedKeys = [];
28132
+ let expandedKeys = [...this.state.expandedKeys];
28110
28133
  recursiveIterate6({ children: nodes }, (node) => {
28111
28134
  var _a;
28112
28135
  if ((_a = node.children) == null ? void 0 : _a.length) {
28113
28136
  expandedKeys.push(node.id);
28114
28137
  }
28115
28138
  });
28116
- if (this.state.defaultExpandedKeys.length) {
28117
- expandedKeys.push(...this.state.defaultExpandedKeys);
28118
- expandedKeys = Array.from(new Set(expandedKeys));
28119
- }
28139
+ expandedKeys = Array.from(new Set(expandedKeys));
28120
28140
  return expandedKeys;
28121
28141
  }
28122
28142
  /**