@sy-common/organize-select-help 1.0.0-beta.62 → 1.0.0-beta.64

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.
@@ -54,13 +54,34 @@ export default {
54
54
  return {
55
55
  data: [],
56
56
  manageUnitId: '',
57
- loading: true
57
+ loading: true,
58
+ // 内部状态存储禁用懒加载的标识
59
+ isDisableLazyLoad: false
58
60
  };
59
61
  },
60
62
  mounted() {
61
- this.initData();
63
+ // 优先使用 props 的 disableLazyLoad,覆盖内部状态
64
+ this.isDisableLazyLoad = this.disableLazyLoad;
65
+ // 优先使用 props 的 isCustomTree,覆盖内部判断
66
+ this.isCustomTree = this.isCustomTree;
67
+ // 仅在未禁用懒加载且非自定义树时执行 initData
68
+ if (!this.isDisableLazyLoad && !this.isCustomTree) {
69
+ this.initData();
70
+ } else {
71
+ // 直接使用父组件传递的树数据
72
+ this.loading = false;
73
+ let tree = deepCopy(this.treeList);
74
+ this.initTree(tree);
75
+ this.data = tree;
76
+ }
77
+
62
78
  },
63
79
  methods: {
80
+ setDisableLazyLoad(disabled) {
81
+ this.isDisableLazyLoad = disabled;
82
+ // 同时标记为自定义树,跳过子组件自身的 initData 逻辑
83
+ this.isCustomTree = disabled;
84
+ },
64
85
  safeDeepCopy(obj, hash = new WeakMap()) {
65
86
  if (obj === null || typeof obj !== 'object') {
66
87
  return obj;
@@ -108,14 +129,15 @@ export default {
108
129
  return copy;
109
130
  },
110
131
  async initData() {
111
- if (this.isCustomTree) {
132
+ // 优先判断内部禁用状态,而非仅依赖 isCustomTree prop
133
+ if (this.isCustomTree || this.isDisableLazyLoad) {
112
134
  this.loading = false;
113
135
  let tree = deepCopy(this.treeList);
114
136
  this.initTree(tree);
115
137
  this.data = tree;
116
138
  return;
117
139
  }
118
- // 仅在非自定义树场景下生效
140
+ // 仅在非自定义/非禁用场景下执行原有逻辑
119
141
  let data = await this.getOrgChildren();
120
142
  this.loading = false;
121
143
  this.data = data;
@@ -179,7 +201,23 @@ export default {
179
201
  },
180
202
 
181
203
  async loadData(item, callback) {
182
- // 自定义树场景(defaultOrgUnitId 不为空):原有逻辑不变
204
+ // 核心修改:即使禁用懒加载,也允许加载已有子节点
205
+ if (this.disableLazyLoad) {
206
+ let children = item.orgChildrenList || item.children || [];
207
+ const formattedChildren = this.safeDeepCopy(children).map(child => ({
208
+ ...child,
209
+ title: child.orgUnitName || child.orgNodeName || child.name || `未命名组织(${child.orgUnitId || child.id || ''})`,
210
+ checked: false,
211
+ expand: false,
212
+ leafNode: child.leafNode || false,
213
+ orgChildrenList: child.orgChildrenList || [],
214
+ children: child.children || []
215
+ }));
216
+ callback(formattedChildren);
217
+ return;
218
+ }
219
+
220
+ // 原有逻辑保持不变
183
221
  if (this.isCustomTree) {
184
222
  let children = item.orgChildrenList || item.children || [];
185
223
  const formattedChildren = this.safeDeepCopy(children).map(child => ({
@@ -201,7 +239,6 @@ export default {
201
239
  });
202
240
  if (res.data.code === 1) {
203
241
  const apiChildren = res.data.data || [];
204
- // 关键:对接口返回的二级节点进行 initTree 初始化
205
242
  const initializedApiChildren = this.initTree(apiChildren);
206
243
  const apiFormattedChildren = initializedApiChildren.map(child => ({
207
244
  ...child,
@@ -225,18 +262,16 @@ export default {
225
262
  return;
226
263
  }
227
264
 
228
- // 非自定义树场景(defaultOrgUnitId 为空):补充子节点初始化
229
- if (this.disableLazyLoad) {
230
- callback([]);
231
- return;
232
- }
233
- // 加载子节点后,先经过 initTree 处理再返回
234
265
  let children = await this.getOrgChildren(item.orgUnitId);
235
266
  const initializedChildren = this.initTree(children);
236
267
  callback(initializedChildren);
237
268
  },
238
269
 
239
270
  getOrgChildren(orgUnitId = '') {
271
+ // 优先判断内部禁用状态
272
+ if (this.isDisableLazyLoad) {
273
+ return Promise.resolve([]);
274
+ }
240
275
  if (this.isCustomTree) {
241
276
  return Promise.resolve([]);
242
277
  }
@@ -517,18 +552,38 @@ export default {
517
552
  'treeList': {
518
553
  handler(val) {
519
554
  // 自定义树场景:直接使用父组件传递的树数据,不初始化旧接口
520
- if (this.isCustomTree) {
521
- let tree = deepCopy(val);
555
+ if (this.isCustomTree || this.isDisableLazyLoad) {
556
+ let tree = this.safeDeepCopy(val);
522
557
  this.initTree(tree);
523
558
  this.data = tree;
524
559
  return;
525
560
  }
526
- // 原有逻辑
527
561
  let tree = deepCopy(val);
528
562
  this.initTree(tree);
529
563
  this.data = tree;
530
564
  },
531
565
  deep: true
566
+ },
567
+ // 监听 isCustomTree 变化
568
+ isCustomTree(newVal) {
569
+ if (newVal) {
570
+ this.isDisableLazyLoad = true;
571
+ this.loading = false;
572
+ let tree = this.safeDeepCopy(this.treeList);
573
+ this.initTree(tree);
574
+ this.data = tree;
575
+ }
576
+ },
577
+ // 监听 disableLazyLoad 变化
578
+ disableLazyLoad(newVal) {
579
+ this.isDisableLazyLoad = newVal;
580
+ if (newVal) {
581
+ this.isCustomTree = true;
582
+ this.loading = false;
583
+ let tree = this.safeDeepCopy(this.treeList);
584
+ this.initTree(tree);
585
+ this.data = tree;
586
+ }
532
587
  }
533
588
  }
534
589
  };
@@ -624,4 +679,4 @@ export default {
624
679
  text-shadow: none !important;
625
680
  background: none !important;
626
681
  }
627
- </style>
682
+ </style>