bri-components 1.3.91 → 1.3.93

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.
@@ -59,17 +59,17 @@ export default {
59
59
  event: "changeNode"
60
60
  },
61
61
 
62
- createBrotherNode: {
62
+ canCreateBrother: {
63
63
  name: "添加同级节点",
64
- type: "createBrotherNode",
64
+ type: "canCreateBrother",
65
65
  icon: "md-add",
66
- event: "createBrotherNode"
66
+ event: "clickCreate"
67
67
  },
68
- createChildNode: {
68
+ canCreateChildNode: {
69
69
  name: "添加子节点",
70
- type: "createChildNode",
70
+ type: "canCreateChildNode",
71
71
  icon: "md-add",
72
- event: "createChildNode"
72
+ event: "clickCreateChild"
73
73
  },
74
74
  deleteSelfAndChildNodes: {
75
75
  name: "删除该节点",
@@ -77,27 +77,27 @@ export default {
77
77
  icon: "md-trash",
78
78
  color: "red",
79
79
  divided: true,
80
- event: "deleteSelfAndChildNodes"
80
+ event: "clickDelete"
81
81
  },
82
82
  deleteChildNodes: {
83
83
  name: "删除所有子节点",
84
84
  type: "deleteChildNodes",
85
85
  icon: "md-trash",
86
86
  color: "red",
87
- event: "deleteChildNodes"
87
+ event: "clickDeleteChilds"
88
88
  },
89
89
  clearNode: {
90
90
  name: "清除该节点内容",
91
91
  type: "clearNode",
92
92
  icon: "md-trash",
93
93
  divided: true,
94
- event: "clearNode"
94
+ event: "clickClearNode"
95
95
  },
96
96
  clearChildNodes: {
97
97
  name: "清除所有子节点内容",
98
98
  type: "clearChildNodes",
99
99
  icon: "md-trash",
100
- event: "clearChildNodes"
100
+ event: "clickClearChildNodes"
101
101
  }
102
102
  }
103
103
  };
@@ -108,9 +108,13 @@ export default {
108
108
  _treeForm: [],
109
109
  ...this.commonPropsObj,
110
110
 
111
+ _maxLevel: this.commonPropsObj._maxLevel || 3, // 最大级数
111
112
  _contentHeight: this.propsObj._contentHeight || 400 // 表格最大高度
112
113
  };
113
114
  },
115
+ maxLevel () {
116
+ return this.selfPropsObj._maxLevel;
117
+ },
114
118
 
115
119
  allTreeData () {
116
120
  // console.log("allTreeData");
@@ -149,29 +153,14 @@ export default {
149
153
  this.$set(treeFormItem, "level", treeFormIndex + 1);
150
154
  this.$set(treeFormItem, "canDelete", true);
151
155
  });
152
-
153
- // 循环遍树,给根节点赋值
154
- let loop = (nodes = []) => {
155
- nodes.forEach(node => {
156
- if (node.children && node.children.length) {
157
- loop(node.children);
158
- } else {
159
- // 根节点下所有表格字段加上监测,注入到节点对象中,必须$set,牵扯_rely值再出现并没有检测
160
- this.selfColumns.forEach(subFormItem => {
161
- this.$set(node, subFormItem._key, node[subFormItem._key]);
162
- });
163
- }
164
- });
165
- };
166
- loop(this.data);
167
156
  },
168
157
 
169
- /* ----- 表头操作 ------ */
170
- // 点击表头
158
+ /* ----------- 操作 ---------- */
159
+ // 表头操作 -点击
171
160
  clickTh (operationItem, col, colIndex) {
172
161
  this.$emit("clickTh", col, colIndex);
173
162
  },
174
- // 树形表头列 -添加
163
+ // 表头操作 -树形表头-添加一列
175
164
  createCol (operationItem, col, colIndex) {
176
165
  if (col.colType === "tree" && col.level === this.treeColumns.length) {
177
166
  this.treeColumns.push({
@@ -188,7 +177,7 @@ export default {
188
177
  this.change("createCol", col);
189
178
  }
190
179
  },
191
- // 树形表头列 -删除
180
+ // 表头操作 -树形表头-删除一列
192
181
  deleteCol (operationItem, col, colIndex) {
193
182
  if (col.colType === "tree" && col.canDelete !== false) {
194
183
  this.isDeleteColStatus = true; // isDeleteStatus不用在data中定义
@@ -199,14 +188,15 @@ export default {
199
188
  }
200
189
  },
201
190
 
202
- /* ----- 树节点操作 ------ */
203
- // 点击节点
204
- clickNode (operationItem, col, row, nodeData) {
191
+ // 树形、汇总节点操作 -点击
192
+ clickNode (operationItem, col, row, rowIndex) {
205
193
  if (col.colType === "tree") {
206
- nodeData.isEdit = true;
207
- this.$nextTick(() => {
208
- this.$refs[`${col._id}${row._id}`][0] && this.$refs[`${col._id}${row._id}`][0].focus();
209
- });
194
+ if (!this.getRowIsDftDisabled(row) || col._readonlyOnDftRow !== true) {
195
+ row.isEdit = true;
196
+ this.$nextTick(() => {
197
+ this.$refs[`${col._id}${row._id}`][0] && this.$refs[`${col._id}${row._id}`][0].focus();
198
+ });
199
+ }
210
200
  } else if (col.colType === "summary") {
211
201
  this.$Modal.warning({
212
202
  title: "该汇总单元格自动计算,不准手动输入!",
@@ -216,274 +206,73 @@ export default {
216
206
  });
217
207
  }
218
208
  },
219
- // 节点失去焦点
220
- blurNode (operationItem, col, row, nodeData) {
221
- nodeData.isEdit = false;
209
+ // 树形节点操作 -失去焦点
210
+ blurNode (operationItem, col, row, rowIndex) {
211
+ row.isEdit = false;
222
212
  },
223
- // 改变节点名
224
- changeNode (operationItem, col, row, nodeData) {
225
- this.change("changeNode", col, row, nodeData);
213
+ // 树形节点操作 -值改变
214
+ changeNode (operationItem, col, row, rowIndex) {
215
+ this.change("changeNode", col, row, rowIndex);
226
216
  },
227
217
 
228
- /* ---- 节点操作 ----- */
229
- // 添加同级节点
230
- createBrotherNode (operationItem, row, rowIndex, col) {
231
- let nodeData = this.getNodeData(row, rowIndex, col);
232
- let newNode = this.getNewNode(nodeData.level, nodeData.brotherList);
218
+ // 节点操作 -插入一行
219
+ clickCreate (operationItem, row, rowIndex, col) {
220
+ const nodeData = this.getNodeData(col, row, rowIndex);
221
+ const newNode = this.getNewNode(nodeData.level, nodeData.brotherList);
233
222
  nodeData.brotherList.splice(nodeData.index + 1, 0, newNode);
234
223
 
235
- this.change("createBrotherNode", col, row, nodeData);
224
+ this.change("createRow", col, row, rowIndex);
236
225
  },
237
- // 添加子节点
238
- createChildNode (operationItem, row, rowIndex, col) {
239
- let nodeData = this.getNodeData(row, rowIndex, col);
240
- let newNode = this.getNewNode(nodeData.level + 1, nodeData.childList);
226
+ // 节点操作 -添加子行
227
+ clickCreateChild (operationItem, row, rowIndex, col) {
228
+ const nodeData = this.getNodeData(col, row, rowIndex);
229
+ const newNode = this.getNewNode(nodeData.level + 1, nodeData.childList);
241
230
  nodeData.childList.splice(nodeData.childList.length, 0, newNode);
242
231
 
243
- this.change("createChildNode", col, row, nodeData);
232
+ this.change("createChildRow", col, row, rowIndex);
244
233
  },
245
- // 删除该节点
246
- deleteSelfAndChildNodes (operationItem, row, rowIndex, col) {
247
- let nodeData = this.getNodeData(row, rowIndex, col);
234
+ // 节点操作 -删除该行
235
+ clickDelete (operationItem, row, rowIndex, col) {
236
+ const nodeData = this.getNodeData(col, row, rowIndex);
248
237
  nodeData.brotherList.splice(nodeData.index, 1);
249
238
  // 此处应该判断子节点是否是最后一个,是的话就要添加一个一直到叶子节点,不过现在只需要添加一个子节点,transforBriTreeData会捎带着处理了
250
239
  if (!nodeData.brotherList.length) {
251
- let newNode = this.getNewNode(nodeData.level, nodeData.brotherList);
240
+ const newNode = this.getNewNode(nodeData.level, nodeData.brotherList);
252
241
  nodeData.brotherList.push(newNode);
253
242
  }
254
243
 
255
- this.change("deleteSelfAndChildNodes", col, row, nodeData);
244
+ this.change("deleteRow", col, row, rowIndex);
256
245
  },
257
- // 删除所有子节点
258
- deleteChildNodes (operationItem, row, rowIndex, col) {
259
- let nodeData = this.getNodeData(row, rowIndex, col);
246
+ // 节点操作 -删除所有子行
247
+ clickDeleteChilds (operationItem, row, rowIndex, col) {
248
+ const nodeData = this.getNodeData(col, row, rowIndex);
260
249
  nodeData.childList.splice(0);
261
250
  // 删除完应该添加一个子节点一直到叶子节点,不过现在只需要添加一个子节点,transforBriTreeData会捎带着处理了
262
- let newNode = this.getNewNode(nodeData.level + 1, nodeData.childList);
251
+ const newNode = this.getNewNode(nodeData.level + 1, nodeData.childList);
263
252
  nodeData.childList.push(newNode);
264
253
 
265
- this.change("deleteChildNodes", col, row, nodeData);
254
+ this.change("deleteChildRows", col, row, rowIndex);
266
255
  },
267
- // 清除该节点内容
268
- clearNode (operationItem, row, rowIndex, col) {
269
- let nodeData = this.getNodeData(row, rowIndex, col);
256
+ // 节点操作 -清除该节点内容
257
+ clickClearNode (operationItem, row, rowIndex, col) {
258
+ const nodeData = this.getNodeData(col, row, rowIndex);
270
259
  nodeData.dataObj.name = "";
271
260
 
272
- this.change("clearNode", col, row, nodeData);
261
+ this.change("clearNode", col, row, rowIndex);
273
262
  },
274
- // 清除所有子节点内容
275
- clearChildNodes (operationItem, row, rowIndex, col) {
276
- let nodeData = this.getNodeData(row, rowIndex, col);
263
+ // 节点操作 -清除所有子节点内容
264
+ clickClearChildNodes (operationItem, row, rowIndex, col) {
265
+ let nodeData = this.getNodeData(col, row, rowIndex);
277
266
  this.$clearPropertyValToLeaf(nodeData.childList);
278
267
 
279
- this.change("clearChildNodes", col, row, nodeData);
280
- },
281
- // 发生变动
282
- change (...params) {
283
- this.$emit("change", this.tableDataObj, ...params);
284
- },
285
-
286
- /* ---- 工具方法 ---- */
287
- // 合并表头
288
- mergeColumns (treeForm = [], subForm = []) {
289
- return treeForm
290
- .reduce((arr, treeFormItem, treeFormIndex) => {
291
- return arr.concat(
292
- {
293
- ...treeFormItem,
294
- colType: "tree"
295
- },
296
- treeFormItem._treeSubForm.map(treeSubFormItem => (
297
- {
298
- ...treeSubFormItem,
299
- nodeKey: treeFormItem._key,
300
- colType: "summary"
301
- }
302
- ))
303
- );
304
- }, [])
305
- .concat(
306
- subForm.filter(subFormItem =>
307
- this.hideStatus === true
308
- ? !this.hideColKeys.includes(subFormItem._key)
309
- : true
310
- ).map(subFormItem => (
311
- {
312
- ...subFormItem,
313
- nodeKey: treeForm[treeForm.length - 1]._key,
314
- colType: "data"
315
- }
316
- ))
317
- );
318
- },
319
- // 转化树数据
320
- getCalcuedTree (nodes = [], treeForm = [], subForm = []) {
321
- treeForm.forEach((treeFormItem, treeFormIndex) => {
322
- treeFormItem.canDelete = true; // 每次计算,重置一下
323
- treeFormItem.level = treeFormIndex + 1; // treeColumns更新,缺少level
324
- });
325
-
326
- // 循环遍树节点
327
- const loop = (nodes = []) => {
328
- nodes.forEach(node => {
329
- // 初始化树节点的数据,给节点加上一些属性并监测,注入到节点对象中
330
- let curCol = treeForm[node.level - 1];
331
- this.$setObj(node, {
332
- _key: curCol._key,
333
- level: curCol.level,
334
- isEdit: false,
335
- isLeaf: false,
336
- total: 1
337
- });
338
-
339
- // 最后一列(根节点)
340
- if (node.level === treeForm.length) {
341
- // 处理删除了最后一列后,把根节点上的subForm属性值全部给上级节点
342
- if (this.isDeleteColStatus) {
343
- let subNode = node.children[0];
344
- subForm.forEach(subFormItem => {
345
- // 用$set也可以
346
- node[subFormItem._key] = subNode[subFormItem._key];
347
- });
348
- }
349
-
350
- node.children = [];
351
- node.isLeaf = true;
352
- }
353
- // 非最后一列(最后一列前的列,非根节点),需继续向下循环
354
- else {
355
- // 判断是否能删除最后一列(1.判断条件:判断根节点列的前一列的所有节点 都必须只有一个子结点 2.canDelete放在表头treeForm最后一项,默认true)
356
- if (node.level === treeForm.length - 1) {
357
- if (node.children.length > 1) {
358
- treeForm[node.level].canDelete = false;
359
- }
360
- }
361
-
362
- // 非最后一列的 正常的非根节点
363
- if (node.children && node.children.length) {
364
- loop(node.children);
365
- }
366
- // 非最后一列的 新增的非根节点(此时是新增一列或新增非根节点行) -添加一个子节点,并把该节点上的subForm属性值全部给下级节点
367
- // 特别提示:新增的是根节点行,不会走此处代码
368
- else {
369
- const newNode = this.getNewNode(node.level + 1, node.children);
370
- subForm.forEach(subFormItem => {
371
- // 用$set也可以
372
- newNode[subFormItem._key] = node[subFormItem._key];
373
- delete node[subFormItem._key];
374
- });
375
- node.children.push(newNode);
376
-
377
- loop(node.children);
378
- }
379
- }
380
- });
381
- };
382
- loop(nodes);
383
- this.isDeleteColStatus = false;
384
-
385
- return nodes;
386
- },
387
- // 转化渲染使用的columns数组
388
- transformRowColumnsArr (nodes = [], treeForm = [], subForm = []) {
389
- let loop = (nodes, rowColumnsArr) => {
390
- nodes = this.getFilteredNodes(nodes);
391
-
392
- return nodes.reduce((rowColumnsArr, node, nodeIndex) => {
393
- if (nodeIndex !== 0 || rowColumnsArr.length === 0) {
394
- rowColumnsArr.push(
395
- this.mergeColumns(treeForm.slice(node.level - 1), subForm)
396
- );
397
- }
398
-
399
- if (node.children && node.children.length) {
400
- return loop(node.children, rowColumnsArr);
401
- } else {
402
- return rowColumnsArr;
403
- }
404
- }, rowColumnsArr);
405
- };
406
-
407
- return loop(nodes, []);
408
- },
409
- // 转化表格数据
410
- transformRows (nodes = [], treeForm = []) {
411
- const loop = (nodes, rows) => {
412
- nodes = this.getFilteredNodes(nodes);
413
-
414
- return nodes.reduce((rows, node, nodeIndex) => {
415
- // 创建行,并把节点数据(对象类型)注入到行对象内
416
- if (nodeIndex !== 0 || rows.length === 0) {
417
- rows.push({ _id: this.$ObjectID().str });
418
- }
419
- const curCol = treeForm[node.level - 1];
420
- const curRow = rows[rows.length - 1];
421
- Object.assign(curRow, { [curCol._key]: node });
422
-
423
- // 判断是否叶子节点,做对应操作
424
- if (node.children && node.children.length) {
425
- const oldLength = rows.length - 1;
426
- const newRows = loop(node.children, rows);
427
- node.total = newRows.length - oldLength;
428
- return newRows;
429
- } else {
430
- return rows;
431
- }
432
- }, rows);
433
- };
434
- return loop(nodes, []);
435
- },
436
- getFilteredNodes (nodes = []) {
437
- const loop = (nodes = []) => {
438
- return nodes.filter(node => {
439
- if (node.children && node.children.length) {
440
- const children = loop(node.children);
441
- return !!children.length;
442
- } else {
443
- return this.$isAdvRelyAccord(this.finalTableAdvSearch, node);
444
- }
445
- });
446
- };
447
-
448
- return loop(nodes);
449
- },
450
- // 获取节点数据
451
- getNodeData (row, rowIndex, col) {
452
- let parentNode = this.getParentNode(row, rowIndex, col);
453
- return {
454
- level: col.level,
455
- dataObj: row[col._key],
456
- childList: row[col._key].children,
457
- brotherList: parentNode.children,
458
- index: parentNode.children.findIndex(item => item._id === row[col._key]._id)
459
- };
268
+ this.change("clearChildNodes", col, row, rowIndex);
460
269
  },
461
- // 获取父节点数据
462
- getParentNode (row, rowIndex, col, treeForm = this.treeColumns) {
463
- if (col.level === 1) {
464
- return {
465
- children: this.allTreeData
466
- };
467
- } else {
468
- let parentCol = treeForm[col.level - 2];
469
- let loop = (row, rowIndex) => row[parentCol._key] || loop(this.showListData[rowIndex - 1], rowIndex - 1);
470
- return loop(row, rowIndex);
471
- }
472
- },
473
- // 获取节点数据
474
- getNewNode (level, list) {
475
- return {
476
- ...this.$deepCopy(this.selfRowDefault),
477
- _id: this.$ObjectID().str,
478
- name: `${this.$numToChinese(level)}级节点${list.length + 1}`,
479
- level: level,
480
- // isLeaf: true,
481
- children: []
482
- };
270
+ change (eventType, col, row, rowIndex, ...params) {
271
+ this.$emit("change", this.tableDataObj, eventType, col, row, rowIndex, ...params);
483
272
  },
484
273
 
485
- /* ----- 渲染函数 ---- */
486
- // 表格头部渲染函数
274
+ /* ----------- 渲染函数 ---------- */
275
+ // 表格表头渲染函数
487
276
  getTableHeadRender () {
488
277
  return (h) => {
489
278
  return h("div", {
@@ -505,13 +294,11 @@ export default {
505
294
  }, [
506
295
  h(
507
296
  "tr",
508
- {
509
- class: ""
510
- },
297
+ {},
511
298
  this.showColumns.map((column, colIndex) => {
512
299
  return h("th", {
513
300
  key: column._id,
514
- class: "table-th bri-table-th",
301
+ class: "bri-table-th",
515
302
  style: this.getThStyle(column, "th"),
516
303
  on: {
517
304
  click: () => {
@@ -556,25 +343,25 @@ export default {
556
343
  class: ""
557
344
  }, [
558
345
  this.showListData.length
559
- ? this.showListData.map((row, rowIndex) => {
346
+ ? this.showListData.map((mixedRow, rowIndex) => {
560
347
  return h(
561
348
  "tr",
562
349
  {
563
- key: row._id,
564
- class: "table-row"
350
+ key: mixedRow._id,
351
+ class: ""
565
352
  },
566
353
  this.rowColumnsArr[rowIndex].map(column => {
567
354
  return ["tree", "summary"].includes(column.colType)
568
355
  // 树节点单元格、汇总单元格
569
- ? this.getTreeTdRender(column, row, rowIndex)(h)
356
+ ? this.getTreeTdRender(column, mixedRow[column.nodeKey || column._key], rowIndex)(h)
570
357
  // 普通单元格
571
- : this.getTdRender(column, row, rowIndex)(h);
358
+ : this.getTdRender(column, mixedRow[column.nodeKey], rowIndex)(h);
572
359
  })
573
360
  );
574
361
  })
575
362
  // 无数据
576
363
  : h("tr", {
577
- class: "table-nodata"
364
+ class: "bri-table-nodata"
578
365
  }, [
579
366
  h("td", {
580
367
  style: {
@@ -607,44 +394,7 @@ export default {
607
394
  }),
608
395
 
609
396
  // 级联最末级表头的下拉
610
- (
611
- !this.isSearching &&
612
- column.colType === "tree" &&
613
- column.level === this.treeColumns.length &&
614
- this.$getOperationList(this.getTreeThBtns(column)).length
615
- )
616
- ? h("dsh-dropdown", {
617
- class: "table-th-dropdown",
618
- props: {
619
- menuClass: "table-th-dropdown-list",
620
- trigger: "hover",
621
- list: this.$getOperationList(this.getTreeThBtns(column))
622
- },
623
- on: {
624
- click: (operationItem) => {
625
- this.$dispatchEvent(operationItem, column, colIndex);
626
- }
627
- },
628
- nativeOn: {
629
- click: (e) => {
630
- e.stopPropagation();
631
- }
632
- }
633
- }, [
634
- h("a", {
635
- attrs: {
636
- href: "javascript:void(0)"
637
- }
638
- }, [
639
- h("Icon", {
640
- props: {
641
- type: "md-add-circle",
642
- size: "20"
643
- }
644
- })
645
- ])
646
- ])
647
- : undefined
397
+ this.getDropdownRender(h, "th", column, colIndex)
648
398
  ]);
649
399
  };
650
400
  },
@@ -653,45 +403,44 @@ export default {
653
403
  return (h) => {
654
404
  return h("td", {
655
405
  class: {
656
- [`table-td-${column.colType}`]: true,
657
- "bri-table-td": true, // 可以不要,为了position: relative,上面有
406
+ "bri-table-td": true, // 可以不要,为了position: relative,下面有
407
+ [`bri-table-td-${column.colType}`]: true,
658
408
  "bri-table-td-edit": this.canEdit
659
409
  },
660
- style: this.getTdStyle(column, row[column.nodeKey]),
410
+ style: this.getTdStyle(column, row, rowIndex),
661
411
  attrs: {
662
- rowspan: this.getTdRowSpan(column, row[column.nodeKey || column._key]),
663
- colspan: this.getTdColSpan(column, row[column.nodeKey])
412
+ rowspan: this.getTdRowSpan(column, row, rowIndex),
413
+ colspan: this.getTdColSpan(column, row, rowIndex)
664
414
  },
665
415
  on: {
666
416
  click: () => {
667
- this.$dispatchEvent(this.operationMap.clickNode, column, row, row[column._key]);
417
+ this.$dispatchEvent(this.operationMap.clickNode, column, row, rowIndex);
668
418
  }
669
419
  }
670
420
  }, [
671
421
  column.colType === "tree"
672
422
  // 树节点单元格
673
- ? row[column._key].isEdit
423
+ ? row.isEdit
674
424
  // 编辑状态
675
425
  ? h("Input", {
676
426
  ref: `${column._id}${row._id}`,
677
- class: "textarea",
678
427
  props: {
679
- value: row[column._key].name,
428
+ value: row.name,
680
429
  type: "textarea",
681
430
  autosize: {
682
- minRows: this.getTdRowSpan(column, row[column.nodeKey || column._key]) * 3 - 1,
431
+ minRows: this.getTdRowSpan(column, row, rowIndex) * 3 - 1,
683
432
  maxRows: 100
684
433
  }
685
434
  },
686
435
  on: {
687
436
  input: val => {
688
- row[column._key].name = val;
437
+ row.name = val;
689
438
  },
690
439
  "on-blur": () => {
691
- this.$dispatchEvent(this.operationMap.blurNode, column, row, row[column._key]);
440
+ this.$dispatchEvent(this.operationMap.blurNode, column, row, rowIndex);
692
441
  },
693
442
  "on-change": () => {
694
- this.$dispatchEvent(this.operationMap.changeNode, column, row, row[column._key]);
443
+ this.$dispatchEvent(this.operationMap.changeNode, column, row, rowIndex);
695
444
  }
696
445
  }
697
446
  })
@@ -699,80 +448,100 @@ export default {
699
448
  : [
700
449
  h("bri-tooltip", {
701
450
  props: {
702
- content: this.$transformEnterToBr(row[column._key].name),
451
+ content: this.$transformEnterToBr(row.name),
703
452
  transfer: true
704
453
  }
705
454
  }, [
706
455
  h("span", {
707
456
  domProps: {
708
- innerHTML: this.$transformEnterToBr(row[column._key].name)
457
+ innerHTML: this.$transformEnterToBr(row.name)
709
458
  }
710
459
  })
711
460
  ]),
712
461
 
713
462
  // 操作下拉
714
- !this.isSearching && this.$getOperationList(this.getTreeTdBtns(column, row, row[column._key])).length
715
- ? h("dsh-dropdown", {
716
- class: "table-td-tree-dropdown",
717
- props: {
718
- menuClass: "table-td-tree-dropdown-list",
719
- trigger: "hover",
720
- list: this.$getOperationList(this.getTreeTdBtns(column, row, row[column._key]))
721
- },
722
- on: {
723
- click: (operationItem) => {
724
- this.$dispatchEvent(operationItem, row, rowIndex, column);
725
- }
726
- },
727
- nativeOn: {
728
- click: (e) => {
729
- e.stopPropagation();
730
- }
731
- }
732
- }, [
733
- h("a", {
734
- attrs: {
735
- href: "javascript:void(0)"
736
- }
737
- }, [
738
- h("Icon", {
739
- props: {
740
- type: "md-add-circle",
741
- size: "20"
742
- }
743
- })
744
- ])
745
- ])
746
- : undefined
463
+ this.getDropdownRender(h, "td", column, undefined, row, rowIndex)
747
464
  ]
748
465
  // 汇总单元格
749
- : h("span", this.getSummaryVal(column, row[column.nodeKey]))
466
+ : h("span", this.getSummaryTdVal(column, row, rowIndex))
750
467
  ]);
751
468
  };
752
469
  },
753
470
  // 普通单元格渲染函数
754
471
  getTdRender (column, row, rowIndex) {
755
472
  return (h) => {
756
- row = row[column.nodeKey];
757
-
758
473
  return h(
759
474
  "td",
760
475
  {
761
- class: this.tablePropsObj.cellStyleOption.bodyCellClass({ column, row, rowIndex }),
762
- style: this.getTdStyle(column, row)
476
+ class: this.tablePropsObj.cellStyleOption.bodyCellClass({ row, rowIndex, column }),
477
+ style: this.getTdStyle(column, row, rowIndex)
763
478
  },
764
479
  column
765
- ? column.renderBodyCell({ column, row, rowIndex }, h)
480
+ ? column.renderBodyCell({ row, rowIndex, column }, h)
766
481
  : undefined
767
482
  );
768
483
  };
769
484
  },
485
+ // 下拉渲染函数
486
+ getDropdownRender (h, position = "th", column, colIndex, row, rowIndex) {
487
+ const list = position === "th"
488
+ ? this.$getOperationList(this.getTreeThBtns(column, colIndex))
489
+ : this.$getOperationList(this.getTreeTdBtns(column, row, rowIndex));
490
+
491
+ return !this.isSearching &&
492
+ list.length &&
493
+ (
494
+ position === "th"
495
+ ? column.colType === "tree" && column.level === this.treeColumns.length
496
+ : true
497
+ )
498
+ ? h("dsh-dropdown", {
499
+ class: "bri-table-dropdown",
500
+ props: {
501
+ menuClass: "bri-table-dropdown-list",
502
+ trigger: "hover",
503
+ list: list
504
+ },
505
+ on: {
506
+ click: (operationItem) => {
507
+ position === "th"
508
+ ? this.$dispatchEvent(operationItem, column, colIndex)
509
+ : this.$dispatchEvent(operationItem, row, rowIndex, column);
510
+ }
511
+ },
512
+ nativeOn: {
513
+ click: (e) => {
514
+ e.stopPropagation();
515
+ }
516
+ }
517
+ }, [
518
+ h("a", {
519
+ style: {
520
+ fontWeight: "500",
521
+ color: this.appColor
522
+ },
523
+ attrs: {
524
+ href: "javascript:void(0)"
525
+ }
526
+ }, [
527
+ h("Icon", {
528
+ props: {
529
+ type: "md-arrow-dropdown-circle",
530
+ size: "16"
531
+ }
532
+ })
533
+ ])
534
+ ])
535
+ : undefined;
536
+ },
770
537
 
771
- /* ----- 方法 ---- */
772
- getThStyle (col, position) {
538
+ /* ----------- 方法 ---------- */
539
+ // 表头 -获取样式
540
+ getThStyle (col, position = "th") {
773
541
  const boxColWidth = this.boxWidth / this.showColumns.length;
774
- const defaultWidth = Math.max(boxColWidth, this.widthMap[col._type], (col._name ? col._name.length * 14 : 36) + (col._type === "reference" ? 200 : 26));
775
- const width = col._width || defaultWidth;
542
+ const calcWidth = (col._name ? col._name.length * 12 : 48) + (col._type === "reference" ? 200 : 32);
543
+ const dftWidth = Math.max(boxColWidth, this.widthMap[col._type], calcWidth);
544
+ const width = col._width || dftWidth;
776
545
 
777
546
  const selfStyle = col.colType === "tree"
778
547
  ? {
@@ -781,7 +550,6 @@ export default {
781
550
  }
782
551
  : col.colType === "summary"
783
552
  ? {
784
- // backgroundColor: "#eeeeee",
785
553
  textAlign: col._align || "right"
786
554
  }
787
555
  : {
@@ -799,19 +567,31 @@ export default {
799
567
  ...selfStyle
800
568
  };
801
569
  },
802
- getTdStyle (col, row) {
570
+ // 表头 -树节点表头-获取下拉操作
571
+ getTreeThBtns (col) {
572
+ return [
573
+ ...(col.level <= this.maxLevel ? ["createCol"] : []), // 限制最大添加到几级
574
+ ...(col.level > 1 && col.canDelete === true ? ["deleteCol"] : []) // 只有一级和最后两级节点数不一致时,不能删
575
+ ];
576
+ },
577
+
578
+ // 单元格 -获取样式
579
+ getTdStyle (col, row, rowIndex) {
803
580
  return {
804
- ...this.getThStyle(col),
805
- backgroundColor: row ? "" : "#fff"
581
+ ...this.getThStyle(col, "td"),
582
+ backgroundColor: ["tree"].includes(col.colType) ? "#fbfbfb" : "#ffffff"
806
583
  };
807
584
  },
808
- getTdRowSpan (col, row) {
585
+ // 单元格 -获取行合并数
586
+ getTdRowSpan (col, row, rowIndex) {
809
587
  return row.total || 1;
810
588
  },
811
- getTdColSpan (col, row) {
589
+ // 单元格 -获取列合并数
590
+ getTdColSpan (col, row, rowIndex) {
812
591
  return 1;
813
592
  },
814
- getSummaryVal (col, row) {
593
+ // 单元格 -汇总节点单元格-获取值
594
+ getSummaryTdVal (col, row, rowIndex) {
815
595
  if (col._calField && col._operator) {
816
596
  const calFieldFormItem = this.selfColumns.find(item => item._key === col._calField);
817
597
 
@@ -840,21 +620,216 @@ export default {
840
620
  : "未选择算法";
841
621
  }
842
622
  },
843
- getTreeThBtns (col) {
844
- return [
845
- "createCol",
846
- ...(
847
- col.level > 1 && col.canDelete === true
848
- ? ["deleteCol"]
849
- : []
850
- )
851
- ];
623
+ // 单元格 -树节点单元格-获取下拉操作
624
+ getTreeTdBtns (col, row, rowIndex) {
625
+ return row.children.length === 0
626
+ ? ["canCreateBrother", "deleteSelfAndChildNodes", "clearNode"]
627
+ : ["canCreateBrother", "canCreateChildNode", "deleteSelfAndChildNodes", "deleteChildNodes", "clearNode", "clearChildNodes"];
628
+ },
629
+ // 单元格 -普通单元格-获取节点系列数据
630
+ getNodeData (col, row, rowIndex) {
631
+ const parentRow = this.getParentRow(row, this.data);
632
+
633
+ return {
634
+ level: col.level,
635
+ dataObj: row,
636
+ childList: row.children,
637
+ brotherList: parentRow.children,
638
+ index: parentRow.children.findIndex(childRowItem => childRowItem._id === row._id)
639
+ };
640
+ },
641
+ // 单元格 -普通单元格-新增节点数据
642
+ getNewNode (level, list) {
643
+ return {
644
+ ...this.$deepCopy(this.selfRowDefault),
645
+ _id: this.$ObjectID().str,
646
+ name: `${this.$numToChinese(level)}级节点${list.length + 1}`,
647
+ level: level,
648
+ isLeaf: true,
649
+ children: [],
650
+ // __old__: false,
651
+ __isDefault__: this.controlKey === "_default",
652
+ __isRendered__: true,
653
+ __isShow__: true,
654
+ __isTmpShow__: true,
655
+ __isSearchShow__: false
656
+ };
657
+ },
658
+
659
+ /* ----------- 工具方法 ---------- */
660
+ // 合并表头
661
+ mergeColumns (treeForm = [], subForm = []) {
662
+ return treeForm
663
+ .reduce((arr, treeFormItem, treeFormIndex) => {
664
+ return arr.concat(
665
+ {
666
+ ...treeFormItem,
667
+ colType: "tree"
668
+ },
669
+ treeFormItem._treeSubForm.map(treeSubFormItem => (
670
+ {
671
+ ...treeSubFormItem,
672
+ nodeKey: treeFormItem._key,
673
+ colType: "summary"
674
+ }
675
+ ))
676
+ );
677
+ }, [])
678
+ .concat(
679
+ subForm.filter(subFormItem =>
680
+ this.hideStatus === true
681
+ ? !this.hideColKeys.includes(subFormItem._key)
682
+ : true
683
+ ).map(subFormItem => (
684
+ {
685
+ ...subFormItem,
686
+ nodeKey: treeForm[treeForm.length - 1]._key,
687
+ colType: "data"
688
+ }
689
+ ))
690
+ );
852
691
  },
853
- // 获得节点的 操作下拉列表
854
- getTreeTdBtns (col, row, nodeData) {
855
- return nodeData.children.length === 0
856
- ? ["createBrotherNode", "deleteSelfAndChildNodes", "clearNode"]
857
- : ["createBrotherNode", "createChildNode", "deleteSelfAndChildNodes", "deleteChildNodes", "clearNode", "clearChildNodes"];
692
+ // 转化树数据
693
+ getCalcuedTree (nodes = [], treeForm = [], subForm = []) {
694
+ treeForm.forEach((treeFormItem, treeFormIndex) => {
695
+ treeFormItem.canDelete = true; // 每次计算,重置一下
696
+ treeFormItem.level = treeFormIndex + 1; // treeColumns更新,缺少level
697
+ });
698
+
699
+ // 循环遍树节点
700
+ const loop = (nodes = []) => {
701
+ nodes.forEach(rowItem => {
702
+ // 初始化树节点的数据,给节点加上一些属性并监测,注入到节点对象中
703
+ let curCol = treeForm[rowItem.level - 1];
704
+ this.$setObj(rowItem, {
705
+ _key: curCol._key,
706
+ level: curCol.level,
707
+ isEdit: false,
708
+ isLeaf: false,
709
+ total: 1
710
+ });
711
+
712
+ // 最后一列(根节点)
713
+ if (rowItem.level === treeForm.length) {
714
+ // 处理删除了最后一列后,把根节点上的subForm属性值全部给上级节点
715
+ if (this.isDeleteColStatus) {
716
+ let subNode = rowItem.children[0];
717
+ subForm.forEach(subFormItem => {
718
+ // 用$set也可以
719
+ rowItem[subFormItem._key] = subNode[subFormItem._key];
720
+ });
721
+ }
722
+
723
+ rowItem.children = [];
724
+ rowItem.isLeaf = true;
725
+ }
726
+ // 非最后一列(最后一列前的列,非根节点),需继续向下循环
727
+ else {
728
+ // 判断是否能删除最后一列(1.判断条件:判断根节点列的前一列的所有节点 都必须只有一个子结点 2.canDelete放在表头treeForm最后一项,默认true)
729
+ if (rowItem.level === treeForm.length - 1) {
730
+ if (rowItem.children.length > 1) {
731
+ treeForm[rowItem.level].canDelete = false;
732
+ }
733
+ }
734
+
735
+ // 非最后一列的 正常的非根节点
736
+ if (rowItem.children && rowItem.children.length) {
737
+ loop(rowItem.children);
738
+ }
739
+ // 非最后一列的 新增的非根节点(此时是新增一列或新增非根节点行) -添加一个子节点,并把该节点上的subForm属性值全部给下级节点
740
+ // 特别提示:新增的是根节点行,不会走此处代码
741
+ else {
742
+ const newNode = this.getNewNode(rowItem.level + 1, rowItem.children);
743
+ subForm.forEach(subFormItem => {
744
+ // 用$set也可以
745
+ newNode[subFormItem._key] = rowItem[subFormItem._key];
746
+ delete rowItem[subFormItem._key];
747
+ });
748
+ rowItem.children.push(newNode);
749
+
750
+ loop(rowItem.children);
751
+ }
752
+ }
753
+
754
+ this.fixRowItem(rowItem);
755
+ });
756
+ };
757
+ loop(nodes);
758
+
759
+ this.isDeleteColStatus = false;
760
+ this.initFlag = false;
761
+ return nodes;
762
+ },
763
+ // 转化渲染使用的columns数组
764
+ transformRowColumnsArr (nodes = [], treeForm = [], subForm = []) {
765
+ let loop = (nodes, rowColumnsArr) => {
766
+ nodes = this.getFilteredNodes(nodes);
767
+
768
+ return nodes.reduce((rowColumnsArr, node, nodeIndex) => {
769
+ if (nodeIndex !== 0 || rowColumnsArr.length === 0) {
770
+ rowColumnsArr.push(
771
+ this.mergeColumns(treeForm.slice(node.level - 1), subForm)
772
+ );
773
+ }
774
+
775
+ if (node.children && node.children.length) {
776
+ return loop(node.children, rowColumnsArr);
777
+ } else {
778
+ return rowColumnsArr;
779
+ }
780
+ }, rowColumnsArr);
781
+ };
782
+
783
+ return loop(nodes, []);
784
+ },
785
+ // 转化表格数据
786
+ transformRows (nodes = [], treeForm = []) {
787
+ const loop = (nodes, rows) => {
788
+ nodes = this.getFilteredNodes(nodes);
789
+
790
+ return nodes.reduce((rows, node, nodeIndex) => {
791
+ // 创建行,并把节点数据(对象类型)注入到行对象内
792
+ if (nodeIndex !== 0 || rows.length === 0) {
793
+ rows.push({ _id: this.$ObjectID().str });
794
+ }
795
+ const curCol = treeForm[node.level - 1];
796
+ const curRow = rows[rows.length - 1];
797
+ Object.assign(curRow, { [curCol._key]: node });
798
+
799
+ // 判断是否叶子节点,做对应操作
800
+ if (node.children && node.children.length) {
801
+ const oldLength = rows.length - 1;
802
+ const newRows = loop(node.children, rows);
803
+ node.total = newRows.length - oldLength;
804
+ return newRows;
805
+ } else {
806
+ return rows;
807
+ }
808
+ }, rows);
809
+ };
810
+ return loop(nodes, []);
811
+ },
812
+ getFilteredNodes (nodes = []) {
813
+ const loop = (nodes = []) => {
814
+ return nodes.filter(rowItem => {
815
+ if (rowItem.children && rowItem.children.length) {
816
+ const children = loop(rowItem.children);
817
+ return !!children.length;
818
+ } else {
819
+ const bool = this.$isAdvRelyAccord(this.finalTableAdvSearch, rowItem);
820
+ // 重置
821
+ rowItem.__isSearchShow__ = false;
822
+ if (bool) {
823
+ rowItem.__isRendered__ = true;
824
+ rowItem.__isSearchShow__ = true;
825
+ }
826
+
827
+ return bool;
828
+ }
829
+ });
830
+ };
831
+
832
+ return loop(nodes);
858
833
  }
859
834
  }
860
835
  };