bri-components 1.3.67 → 1.3.69

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