ocpview-plus 1.1.9 → 1.2.0

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.
@@ -34,7 +34,7 @@ export default {
34
34
  className:'efutre-tree-node'
35
35
  },
36
36
  myConfig: {
37
-
37
+
38
38
  },
39
39
  gridConfig:{
40
40
 
@@ -52,7 +52,7 @@ export default {
52
52
  outsideHeight:0,
53
53
  treeData:[],
54
54
  asyncLoad:false
55
-
55
+
56
56
  };
57
57
  },
58
58
  created () {
@@ -74,12 +74,12 @@ export default {
74
74
  init() {
75
75
  //获取初期默认值
76
76
  this.myConfig = Object.assign({}, this.globalConfig, this.myConfig);
77
-
77
+
78
78
  //获取配置
79
79
  if (this.config) {
80
80
  this.myConfig = Object.assign({}, this.myConfig, this.config);
81
81
  }
82
-
82
+
83
83
  let rootCode = '0';
84
84
  let rootName = '根节点';
85
85
  if (this.myConfig.showRootNode) {
@@ -98,7 +98,7 @@ export default {
98
98
  this.rootNode[this.myConfig.responseCode] = rootCode + '';
99
99
  this.rootNode[this.myConfig.responseName] = rootName;
100
100
  if (this.myConfig.idClass !== undefined) {
101
- this.rootNode[this.myConfig.idClass] = 0;
101
+ this.rootNode[this.myConfig.idClass] = 0;
102
102
  }
103
103
  //多选 才允许出现复选框
104
104
  if (this.myConfig.multiSelect !== true) {
@@ -118,9 +118,9 @@ export default {
118
118
  setIcon(data) {
119
119
  let nodeClass = data[this.myConfig.idClass];
120
120
  if (!nodeClass) {
121
- nodeClass = 0;
121
+ nodeClass = 0;
122
122
  } else {
123
- nodeClass = Number(nodeClass);
123
+ nodeClass = Number(nodeClass);
124
124
  }
125
125
  if (!this.myConfig.showRootNode) {
126
126
  if (nodeClass && nodeClass !== 0) {
@@ -130,18 +130,102 @@ export default {
130
130
  if (nodeClass >= this.myConfig.showIconList.length) {
131
131
  nodeClass = this.myConfig.showIconList.length - 1;
132
132
  }
133
-
133
+
134
134
  const icon = this.myConfig.showIconList[nodeClass];
135
- data.icon = icon.type;
135
+ data.icon = icon.type;
136
136
  if (icon.size) {
137
- data.iconSize = icon.size;
137
+ data.iconSize = icon.size;
138
138
  }
139
139
  if (icon.color) {
140
- data.iconColor = icon.color;
140
+ data.iconColor = icon.color;
141
141
  }
142
142
  return data;
143
143
  },
144
- iconRender(h,params) {
144
+ iconRender(h, params) {
145
+
146
+ let icon = params.data.icon
147
+ let size = params.data.iconSize
148
+ let color = params.data.iconColor
149
+
150
+ const hasChildren =
151
+ params.data.children &&
152
+ params.data.children.length > 0
153
+
154
+ if (!icon) {
155
+ if (hasChildren) {
156
+ icon = params.data.expand
157
+ ? '_base_mulu'
158
+ : '_base_close_mulu'
159
+ } else {
160
+ icon = '_base_wenjian'
161
+ }
162
+ }
163
+
164
+ if (!size) {
165
+ size = 14
166
+ }
167
+
168
+ let para = {
169
+ type: icon,
170
+ size,
171
+ color
172
+ }
173
+
174
+ if (this.myConfig.setTreeNodeIcon) {
175
+ para = this.myConfig.setTreeNodeIcon(params, para)
176
+ } else if (this.setTreeNodeIcon) {
177
+ para = this.setTreeNodeIcon(params, para)
178
+ }
179
+
180
+ // 处理自定义 iconfont
181
+ if (para.type && para.type.startsWith('_')) {
182
+ const resultIcon =
183
+ 'iconfont icon-' + para.type.substring(1)
184
+
185
+ para.custom = resultIcon
186
+ delete para.type
187
+ }
188
+
189
+ let nodeClass = 'efuture-treenode'
190
+
191
+ if (this.myConfig.setNodeClass) {
192
+ nodeClass = this.myConfig.setNodeClass(params)
193
+ }
194
+
195
+ return h(
196
+ 'div',
197
+ {
198
+ class: { [nodeClass]: true },
199
+ style: {
200
+ display: 'flex',
201
+ userSelect: 'none'
202
+ },
203
+ onDblclick: () => {
204
+ this.$nextTick(() => {
205
+ this.setExpend(params.data)
206
+ })
207
+ this.$emit('dbclick', params.data)
208
+ }
209
+ },
210
+ [
211
+ h(
212
+ 'div',
213
+ {
214
+ style: { paddingLeft: '5px' }
215
+ },
216
+ [
217
+ h(resolveComponent('Icon'), para)
218
+ ]
219
+ ),
220
+
221
+ h(resolveComponent('ShowText'), {
222
+ label: params.data.title,
223
+ contentAlign: 'left'
224
+ })
225
+ ]
226
+ )
227
+ },
228
+ iconRenderOld(h,params) {
145
229
  let icon = params.data.icon;
146
230
  let size = params.data.iconSize;
147
231
  let color = params.data.iconColor;
@@ -152,7 +236,7 @@ export default {
152
236
  } else {
153
237
  icon = '_base_close_mulu';
154
238
  }
155
-
239
+
156
240
  } else {
157
241
  icon = '_base_wenjian';
158
242
  }
@@ -163,7 +247,7 @@ export default {
163
247
  let para = {
164
248
  type:icon,
165
249
  size:size,
166
- color:color
250
+ color:color
167
251
  }
168
252
  if (this.myConfig.setTreeNodeIcon) {
169
253
  para = this.myConfig.setTreeNodeIcon(params,para);
@@ -175,7 +259,7 @@ export default {
175
259
  resulIcon = 'iconfont icon-' + resulIcon;
176
260
  para.custom = resulIcon;
177
261
  delete para.type;
178
- }
262
+ }
179
263
  let nodeClass = 'efuture-treenode';
180
264
  if (this.myConfig.setNodeClass) {
181
265
  nodeClass =this.myConfig.setNodeClass(params)
@@ -213,7 +297,7 @@ export default {
213
297
  label:params.data.title,
214
298
  contentAlign:'left'
215
299
  })
216
- ]);
300
+ ]);
217
301
  },
218
302
  toTreeData () {
219
303
  let pos = {};
@@ -227,7 +311,7 @@ export default {
227
311
  while (data.length !== 0) {
228
312
  // 解决找不到节点,而导致的死循环
229
313
  const index = tempData.findIndex(item => item[this.myConfig.idField] === data[i][this.myConfig.parentField]);
230
-
314
+
231
315
  if (data[i][this.myConfig.parentField] === this.rootNode[this.myConfig.idField] || index < 0) {
232
316
  tree.push(data[i]);
233
317
  pos[data[i][this.myConfig.idField]] = [tree.length - 1];
@@ -267,7 +351,7 @@ export default {
267
351
  if (this.myConfig.showIcon) {
268
352
  if (this.myConfig.idClass && this.myConfig.showIconList && this.myConfig.showIconList.length > 0) {
269
353
  root[this.myConfig.idClass] = 0;
270
- root = this.setIcon(root);
354
+ root = this.setIcon(root);
271
355
  }
272
356
  }
273
357
  if (this.myConfig.nodeRender) {
@@ -279,7 +363,7 @@ export default {
279
363
  } else {
280
364
  return tree;
281
365
  }
282
-
366
+
283
367
  },
284
368
  setSelected (reTemp) {
285
369
  if (this.myConfig.expand) {
@@ -311,7 +395,7 @@ export default {
311
395
  }
312
396
  if (this.myConfig.showIcon) {
313
397
  if (this.myConfig.idClass && this.myConfig.showIconList && this.myConfig.showIconList.length > 0) {
314
- reTemp = this.setIcon(reTemp);
398
+ reTemp = this.setIcon(reTemp);
315
399
  }
316
400
  }
317
401
 
@@ -333,7 +417,7 @@ export default {
333
417
  },
334
418
  refurbish(para) {
335
419
  if(!para) {
336
- para = {};
420
+ para = {};
337
421
  }
338
422
  if (this.asyncLoad) {
339
423
  para[this.myConfig.idClass] = 1;
@@ -386,17 +470,39 @@ export default {
386
470
  getRootNode () {
387
471
  return this.$Method.copy(this.rootNode);
388
472
  },
473
+
389
474
  getData() {
390
- let data = null;
391
- if (this.$refs.tree) {
392
- if (this.myConfig.showCheckBox) {
393
- data = this.$refs.tree.getCheckedNodes();
394
- } else {
395
- data = this.$refs.tree.getSelectedNodes();
475
+ if (!this.treeData) return []
476
+
477
+ return this.myConfig.showCheckBox
478
+ ? this.getNodesByKey('checked', this.treeData)
479
+ : this.getNodesByKey('selected', this.treeData)
480
+ },
481
+ // getNodesByKey(key, data, result = []) {
482
+ // data.forEach(item => {
483
+ // if (item[key]) {
484
+ // result.push(item)
485
+ // }
486
+ // if (Array.isArray(item.children)) {
487
+ // this.getNodesByKey(key, item.children, result)
488
+ // }
489
+ // })
490
+ // return result
491
+ // },
492
+
493
+ getNodesByKey(key, data, result = []) {
494
+ data.forEach(item => {
495
+ if (item[key]) {
496
+ result.push(item)
396
497
  }
397
- }
398
- return data;
498
+ if (Array.isArray(item.children) && item.children.length > 0) {
499
+ this.getNodesByKey(key, item.children, result)
500
+ }
501
+ })
502
+ return result
399
503
  },
504
+
505
+
400
506
  setData(data) {
401
507
  this.selectedData = this.$Method.copy(data);
402
508
  this.oldData = this.$Method.copy(data);
@@ -413,7 +519,7 @@ export default {
413
519
  setPro(data) {
414
520
  if (data) {
415
521
  this.myConfig = Object.assign({},this.myConfig,data);
416
- }
522
+ }
417
523
  },
418
524
  getPro(name) {
419
525
  return this.myConfig[name];
@@ -469,7 +575,7 @@ export default {
469
575
  self.synchroPost(self.myConfig.resources,self.myConfig.method,searchParam,function(data) {
470
576
  if (data && data[self.myConfig.response]) {
471
577
  reData = data[self.myConfig.response];
472
- }
578
+ }
473
579
  },null);
474
580
  return reData;
475
581
  },
@@ -484,9 +590,12 @@ export default {
484
590
  getSelectedNodes() {
485
591
  return this.$refs.tree.getSelectedNodes();
486
592
  },
593
+
487
594
  getCheckedNodes() {
488
- return this.$refs.tree.getCheckedNodes();
595
+ if (!this.treeData) return []
596
+ return this.getNodesByKey('checked', this.treeData)
489
597
  },
598
+
490
599
  getCheckedAndIndeterminateNodes() {
491
600
  return this.$refs.tree.getCheckedAndIndeterminateNodes();
492
601
  },
@@ -581,16 +690,23 @@ export default {
581
690
  } else {
582
691
  tempName = 'selected';
583
692
  }
584
- }
585
- if (this.$refs.tree && this.$refs.tree.flatState) {
586
- this.$refs.tree.flatState.forEach(el => {
587
- if (el.node[tempName] !== value) {
588
- let obj ={};
589
- obj[tempName] = value;
590
- Object.assign(el.node,obj);
693
+ }
694
+ const updateNode = (nodes) => {
695
+ if (!nodes) return
696
+
697
+ nodes.forEach(node => {
698
+ if (node[tempName] !== value) {
699
+ node[tempName] = value
591
700
  }
592
- });
701
+
702
+ if (node.children && node.children.length > 0) {
703
+ updateNode(node.children)
704
+ }
705
+ })
593
706
  }
707
+
708
+ updateNode(this.data)
709
+
594
710
  },
595
711
  setNodes(data, name, value) {
596
712
  let tempName = name;
@@ -604,24 +720,32 @@ export default {
604
720
  }
605
721
  }
606
722
  let responseId = this.myConfig.responseId;
607
- this.$refs.tree.flatState.forEach(el => {
608
- let index = data.findIndex(
609
- el2 => el.node[responseId] === el2[responseId]
610
- );
611
- if (index > -1) {
612
- if (el.node[tempName] !== value) {
613
- let obj ={};
614
- obj[tempName] = value;
615
- Object.assign(el.node,obj);
723
+ // 把目标列表变成 Set,提高查找效率
724
+ const idSet = new Set(
725
+ data.map(item => item[responseId])
726
+ )
727
+
728
+ const updateNode = (nodes) => {
729
+ if (!nodes) return
730
+
731
+ nodes.forEach(node => {
732
+
733
+ const exists = idSet.has(node[responseId])
734
+
735
+ const newValue = exists ? value : !value
736
+
737
+ if (node[tempName] !== newValue) {
738
+ node[tempName] = newValue
616
739
  }
617
- } else {
618
- if (el.node[tempName] !== !value) {
619
- let obj ={};
620
- obj[tempName] = !value;
621
- Object.assign(el.node,obj);
740
+
741
+ if (node.children && node.children.length > 0) {
742
+ updateNode(node.children)
622
743
  }
623
- }
624
- });
744
+
745
+ })
746
+ }
747
+
748
+ updateNode(this.data)
625
749
  },
626
750
  updateNode(data,flag) {
627
751
  let tmp = data;
@@ -675,21 +799,21 @@ export default {
675
799
  let tmp = {expand:!this.$refs.tree.flatState[index].node.expand};
676
800
  if (tmp.expand && this.asyncLoad) {
677
801
  if (!this.$refs.tree.flatState[index].node.loading && this.$refs.tree.flatState[index].node.children.length === 0) {
678
- tmp.loading = true;
802
+ tmp.loading = true;
679
803
  };
680
804
  let callback = (data) => {
681
805
  data.forEach(el => {
682
806
  el.selected = false;
683
807
  this.$refs.tree.flatState[index].node.children.push(el);
684
808
  })
685
- Object.assign(this.$refs.tree.flatState[index].node,{loading:false});
809
+ Object.assign(this.$refs.tree.flatState[index].node,{loading:false});
686
810
  }
687
811
  if (this.$refs.tree.flatState[index].node.children.length === 0){
688
812
  this.loadData(data,callback);
689
813
  }
690
-
814
+
691
815
  }
692
- Object.assign(this.$refs.tree.flatState[index].node,tmp);
816
+ Object.assign(this.$refs.tree.flatState[index].node,tmp);
693
817
  }
694
818
  },
695
819
  loadData (item, callback) {
@@ -698,7 +822,7 @@ export default {
698
822
  let data = this.getAsyncNode(para);
699
823
  setTimeout(() => {
700
824
  data.forEach(el => {
701
- this.setSelected(el);
825
+ this.setSelected(el);
702
826
  });
703
827
  callback(data);
704
828
  }, 200);
@@ -13,8 +13,8 @@
13
13
  <p>
14
14
  {{config.title}}
15
15
  </p>
16
- </template>
17
- <Tree ref="tree" :data="treeData" :class="myConfig.className" :show-checkbox="myConfig.showCheckBox" @on-select-change="onSelectChange" @on-check-change="onCheckChange" @on-toggle-expand="onToggleExpand" :load-data="loadData"/>
16
+ </template>
17
+ <CompatTree ref="tree" :data="treeData" :class="myConfig.className" :show-checkbox="myConfig.showCheckBox" @on-select-change="onSelectChange" @on-check-change="onCheckChange" @on-toggle-expand="onToggleExpand" :load-data="loadData"/>
18
18
  </Card>
19
19
  <ViewGrid v-show="!showTree" ref="grid" :config="gridConfig" :dictData="dictData" @dbclick="dbclick"/>
20
20
  </Row>
@@ -23,28 +23,30 @@
23
23
  <script>
24
24
  import Base from '@/components/tree/treedatabase.vue';
25
25
  import elementResizeDetectorMaker from 'element-resize-detector';
26
+ import CompatTree from "@/components/tree/CompatTree.vue";
26
27
  export default {
27
28
  name:'treedata',
29
+ components: {CompatTree},
28
30
  extends: Base,
29
31
  mounted () {
30
32
  this.observer = elementResizeDetectorMaker();
31
33
  if (this.$refs.condition) {
32
34
  this.observer.listenTo(this.$refs.condition, this.setExtraHeight);
33
35
  }
34
-
36
+
35
37
  },
36
38
  beforeUnmount() {
37
39
  if (this.$refs.condition) {
38
40
  this.observer.removeListener(this.$refs.condition, this.setExtraHeight);
39
41
  }
40
-
42
+
41
43
  }
42
44
  };
43
45
  </script>
44
46
 
45
47
  <style>
46
48
  .customLayout{
47
- OVERFLOW-Y: auto;
49
+ OVERFLOW-Y: auto;
48
50
  /*background: url('./images/bg.jpg') no-repeat 4px 5px;*/
49
51
  }
50
52
  </style>