bri-components 1.3.90 → 1.3.92

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