24
24
*/
25
25
import { isFunction , find } from '@opentiny/vue-renderless/grid/static/'
26
26
import { isNull } from '@opentiny/vue-renderless/common/type'
27
- import { updateCellTitle , emitEvent , getClass , getFuncText , getRowid , formatText } from '@opentiny/vue-renderless/grid/utils'
27
+ import {
28
+ updateCellTitle ,
29
+ emitEvent ,
30
+ getClass ,
31
+ getFuncText ,
32
+ getRowid ,
33
+ formatText
34
+ } from '@opentiny/vue-renderless/grid/utils'
28
35
import { getCellLabel } from '../../tools'
29
36
import GlobalConfig from '../../config'
30
37
import { iconChevronRight , iconChevronDown } from '@opentiny/vue-icon'
31
38
import { h , hooks , $prefix } from '@opentiny/vue-common'
32
39
import { getTreeChildrenKey , getTreeShowKey , getTableCellKey } from '../../table/src/strategy'
33
40
34
41
// 滚动、拖动过程中不需要触发
35
- const isOperateMouse = ( $table ) => $table . _isResize || ( $table . lastScrollTime && Date . now ( ) < $table . lastScrollTime + $table . optimizeOpts . delayHover )
42
+ const isOperateMouse = ( $table ) =>
43
+ $table . _isResize || ( $table . lastScrollTime && Date . now ( ) < $table . lastScrollTime + $table . optimizeOpts . delayHover )
36
44
37
45
// 解决静态扫描驼峰变量问题
38
46
const classMap = {
@@ -343,7 +351,17 @@ const setColumnEvents = (args1) => {
343
351
// 双击事件处理
344
352
addListenerDblclick ( { $table, evntParams, tableListeners, tdOns, triggerDblclick } )
345
353
346
- return { commonParams, args, cellOverflow, showTitle, showTooltip, showEllipsis, hasEllipsis, tdOns, fixedHiddenColumn }
354
+ return {
355
+ commonParams,
356
+ args,
357
+ cellOverflow,
358
+ showTitle,
359
+ showTooltip,
360
+ showEllipsis,
361
+ hasEllipsis,
362
+ tdOns,
363
+ fixedHiddenColumn
364
+ }
347
365
}
348
366
349
367
/**
@@ -364,9 +382,19 @@ function renderColumn(args1) {
364
382
let hasDefaultTip = editRules && ( message === 'default' ? height || tableData . length > 1 : message === 'inline' )
365
383
let { align, className, editor, showTip } = column
366
384
let cellAlign = align || allAlign
367
- let columnActived = editConfig && editor && actived . row === row && ( actived . column === column || editConfig . mode === 'row' )
368
-
369
- let { commonParams, args, showTitle, showTooltip, showEllipsis, tdOns = { } , hasEllipsis, fixedHiddenColumn } = setColumnEvents ( args1 )
385
+ let columnActived =
386
+ editConfig && editor && actived . row === row && ( actived . column === column || editConfig . mode === 'row' )
387
+
388
+ let {
389
+ commonParams,
390
+ args,
391
+ showTitle,
392
+ showTooltip,
393
+ showEllipsis,
394
+ tdOns = { } ,
395
+ hasEllipsis,
396
+ fixedHiddenColumn
397
+ } = setColumnEvents ( args1 )
370
398
let params = { $seq, data : tableData , ...commonParams }
371
399
// 索引列、选择列如果不配置对齐方式则默认为居中对齐
372
400
cellAlign = modifyCellAlign ( { cellAlign, column } )
@@ -409,7 +437,11 @@ function renderRowGroupTds(args) {
409
437
expand : ! group . fold
410
438
} )
411
439
} else {
412
- groupTitleVNode = [ < span class = "row-group-title" > { header } </ span > , `:${ value } ` , < span class = "tiny-badge" > { group . children . length } </ span > ]
440
+ groupTitleVNode = [
441
+ < span class = "row-group-title" > { header } </ span > ,
442
+ `:${ value } ` ,
443
+ < span class = "tiny-badge" > { group . children . length } </ span >
444
+ ]
413
445
}
414
446
tds . push (
415
447
< td colspan = { tableColumn . length - index } class = "tiny-grid-body__column" >
@@ -469,8 +501,7 @@ function renderRowGroupData({ groupData, groupFolds, row, rowGroup, rowid, rows,
469
501
}
470
502
} )
471
503
}
472
- } }
473
- >
504
+ } } >
474
505
{ tds }
475
506
</ tr >
476
507
)
@@ -501,7 +532,11 @@ function renderRow(args) {
501
532
'tiny-hide' : groupFolds . includes ( row ) ,
502
533
[ classMap . rowActived ] : rowActived
503
534
} ,
504
- rowClassName ? ( isFunction ( rowClassName ) ? rowClassName ( { $table, $seq, seq, fixedType, rowLevel, row, rowIndex, $rowIndex } ) : rowClassName ) : ''
535
+ rowClassName
536
+ ? isFunction ( rowClassName )
537
+ ? rowClassName ( { $table, $seq, seq, fixedType, rowLevel, row, rowIndex, $rowIndex } )
538
+ : rowClassName
539
+ : ''
505
540
] ,
506
541
attrs : {
507
542
'data-rowid' : rowid
@@ -522,7 +557,8 @@ function renderRow(args) {
522
557
}
523
558
524
559
function renderRowAfter ( { $table, h, row, rowIndex, rows, tableData } ) {
525
- typeof $table . renderRowAfter === 'function' && $table . renderRowAfter ( { rows, row, data : tableData , rowIndex, renderColumn } , h )
560
+ typeof $table . renderRowAfter === 'function' &&
561
+ $table . renderRowAfter ( { rows, row, data : tableData , rowIndex, renderColumn } , h )
526
562
}
527
563
528
564
function renderRowExpanded ( args ) {
@@ -578,13 +614,15 @@ function renderRowTree(args, renderRows) {
578
614
let { rows, seq, seqCount, tableColumn, treeConfig, treeExpandeds } = args
579
615
let { scrollYLoad } = $table
580
616
617
+ // 如果没有树表配置或者树表展开行数为零,则直接跳过
581
618
if ( ! treeConfig || ! treeExpandeds . length ) {
582
619
return
583
620
}
584
621
585
622
let childrenKey = getTreeChildrenKey ( { scrollYLoad, treeConfig } )
586
623
let rowChildren = row [ childrenKey ]
587
624
625
+ // 若果当前行不是展开行或者子节点个数为零,则跳过
588
626
if ( ! rowChildren || ! rowChildren . length || ! ~ treeExpandeds . indexOf ( row ) ) {
589
627
return
590
628
}
@@ -630,20 +668,27 @@ function renderRows({ h, _vm, $table, $seq, rowLevel, fixedType, tableData, tabl
630
668
// 事件绑定
631
669
addRowListenerMouseenter ( { $table, highlightHoverRow, row, rowIndex, trOn } )
632
670
let rowid = getRowid ( $table , row )
671
+
672
+ // 如果有表格分组信息,则执行分组逻辑
633
673
renderRowGroupData ( { groupData, groupFolds, row, rowGroup, rowid, rows, tableColumn } )
634
674
let args = { $rowIndex, $seq, $table, _vm, editStore, fixedType, groupFolds, h, row, rowActived }
635
675
Object . assign ( args , { rowClassName, rowIndex, rowKey, rowLevel, rowid, rows, selection, seq } )
636
676
Object . assign ( args , { tableColumn, trOn, treeConfig } )
637
677
678
+ // 输入表格行列的vnode节点列表
638
679
renderRow ( args )
680
+
681
+ // 允许用户自定义表格行渲染后的逻辑
639
682
renderRowAfter ( { $table, h, row, rowIndex, rows, tableData } )
640
683
args = { $table, expandMethod, expandeds, fixedType, h, row, rowIndex, rowLevel }
641
684
Object . assign ( args , { rowid, rows, seq, tableColumn, trOn, treeConfig } )
642
- // 如果行被展开了
685
+
686
+ // 如果行被展开了,这里渲染展开行的vnode节点
643
687
renderRowExpanded ( args )
644
688
args = { $seq, $table, _vm, fixedType, h, row, rowLevel, rows }
645
689
Object . assign ( args , { seq, seqCount, tableColumn, treeConfig, treeExpandeds } )
646
- // 如果是树形表格
690
+
691
+ // 如果是树形表格,则会递归渲染已展开行的子节点
647
692
renderRowTree ( args , renderRows )
648
693
} )
649
694
@@ -812,13 +857,19 @@ function renderTable({ $table, _vm, clearHoverRow, fixedType, tableColumn, table
812
857
tableColumn . map ( ( column , columnIndex ) => h ( 'col' , { attrs : { name : column . id } , key : columnIndex } ) )
813
858
) ,
814
859
// 内容
815
- h ( 'tbody' , { ref : 'tbody' , on : { mouseleave : clearHoverRow } } , renderRows ( { h, _vm, $table, $seq : '' , rowLevel : 0 , fixedType, tableData, tableColumn } ) )
860
+ h (
861
+ 'tbody' ,
862
+ { ref : 'tbody' , on : { mouseleave : clearHoverRow } } ,
863
+ renderRows ( { h, _vm, $table, $seq : '' , rowLevel : 0 , fixedType, tableData, tableColumn } )
864
+ )
816
865
]
817
866
)
818
867
}
819
868
820
869
function renderYSpace ( { scrollLoad } ) {
821
- return h ( 'div' , { class : 'tiny-grid-body__y-space visual' , ref : 'ySpace' } , [ scrollLoad ? h ( 'div' , { class : 'tiny-grid-body__y-scrollbar' } ) : [ null ] ] )
870
+ return h ( 'div' , { class : 'tiny-grid-body__y-space visual' , ref : 'ySpace' } , [
871
+ scrollLoad ? h ( 'div' , { class : 'tiny-grid-body__y-scrollbar' } ) : [ null ]
872
+ ] )
822
873
}
823
874
824
875
function renderXSpace ( { fixedType } ) {
@@ -877,7 +928,11 @@ export default {
877
928
'div' ,
878
929
{
879
930
ref : 'body' ,
880
- class : [ 'tiny-grid__body-wrapper' , fixedType ? `fixed-${ fixedType } __wrapper` : 'body__wrapper' , { [ classMap . isScrollload ] : scrollLoad } ]
931
+ class : [
932
+ 'tiny-grid__body-wrapper' ,
933
+ fixedType ? `fixed-${ fixedType } __wrapper` : 'body__wrapper' ,
934
+ { [ classMap . isScrollload ] : scrollLoad }
935
+ ]
881
936
} ,
882
937
[
883
938
renderXSpace ( { fixedType } ) ,
0 commit comments