vxe-table 3.20.5 → 3.20.6

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.
Files changed (141) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +106 -106
  3. package/es/index.esm.js +1 -2
  4. package/es/style.css +1 -1
  5. package/es/table/src/methods.js +20 -0
  6. package/es/table/src/table.js +36 -0
  7. package/es/table/src/util.js +3 -4
  8. package/es/table/style.css +48 -18
  9. package/es/ui/index.js +1 -1
  10. package/es/ui/src/log.js +1 -1
  11. package/es/vxe-table/style.css +48 -18
  12. package/lib/index.common.js +1 -2
  13. package/lib/index.umd.js +3251 -1876
  14. package/lib/index.umd.min.js +1 -1
  15. package/lib/style.css +1 -1
  16. package/lib/table/src/methods.js +2 -1
  17. package/lib/table/src/methods.min.js +1 -1
  18. package/lib/table/src/table.js +44 -0
  19. package/lib/table/src/table.min.js +1 -1
  20. package/lib/table/src/util.js +4 -6
  21. package/lib/table/src/util.min.js +1 -1
  22. package/lib/table/style/style.css +48 -18
  23. package/lib/ui/index.js +1 -1
  24. package/lib/ui/index.min.js +1 -1
  25. package/lib/ui/src/log.js +1 -1
  26. package/lib/ui/src/log.min.js +1 -1
  27. package/lib/v-x-e-table/index.js +1 -2
  28. package/lib/v-x-e-table/index.min.js +1 -1
  29. package/lib/vxe-colgroup/index.js +1 -2
  30. package/lib/vxe-colgroup/index.min.js +1 -1
  31. package/lib/vxe-column/index.js +1 -2
  32. package/lib/vxe-column/index.min.js +1 -1
  33. package/lib/vxe-grid/index.js +1 -2
  34. package/lib/vxe-grid/index.min.js +1 -1
  35. package/lib/vxe-table/index.js +1 -2
  36. package/lib/vxe-table/index.min.js +1 -1
  37. package/lib/vxe-table/style/style.css +48 -18
  38. package/lib/vxe-toolbar/index.js +1 -2
  39. package/lib/vxe-toolbar/index.min.js +1 -1
  40. package/lib/vxe-ui/index.js +1 -2
  41. package/lib/vxe-ui/index.min.js +1 -1
  42. package/lib/vxe-v-x-e-table/index.js +1 -2
  43. package/lib/vxe-v-x-e-table/index.min.js +1 -1
  44. package/package.json +93 -93
  45. package/packages/colgroup/index.ts +22 -22
  46. package/packages/column/index.ts +22 -22
  47. package/packages/components.ts +42 -42
  48. package/packages/grid/index.ts +22 -22
  49. package/packages/grid/src/grid.ts +1935 -1935
  50. package/packages/index.ts +4 -4
  51. package/packages/locale/lang/ar-EG.ts +832 -832
  52. package/packages/locale/lang/de-DE.ts +832 -832
  53. package/packages/locale/lang/en-US.ts +832 -832
  54. package/packages/locale/lang/es-ES.ts +832 -832
  55. package/packages/locale/lang/fr-FR.ts +832 -832
  56. package/packages/locale/lang/hu-HU.ts +832 -832
  57. package/packages/locale/lang/hy-AM.ts +832 -832
  58. package/packages/locale/lang/id-ID.ts +832 -832
  59. package/packages/locale/lang/it-IT.ts +832 -832
  60. package/packages/locale/lang/ja-JP.ts +832 -832
  61. package/packages/locale/lang/ko-KR.ts +832 -832
  62. package/packages/locale/lang/ms-MY.ts +832 -832
  63. package/packages/locale/lang/nb-NO.ts +832 -832
  64. package/packages/locale/lang/pt-BR.ts +832 -832
  65. package/packages/locale/lang/ru-RU.ts +832 -832
  66. package/packages/locale/lang/th-TH.ts +832 -832
  67. package/packages/locale/lang/ug-CN.ts +832 -832
  68. package/packages/locale/lang/uk-UA.ts +832 -832
  69. package/packages/locale/lang/uz-UZ.ts +832 -832
  70. package/packages/locale/lang/vi-VN.ts +832 -832
  71. package/packages/locale/lang/zh-CHT.ts +832 -832
  72. package/packages/locale/lang/zh-CN.ts +832 -832
  73. package/packages/locale/lang/zh-HK.ts +3 -3
  74. package/packages/locale/lang/zh-MO.ts +3 -3
  75. package/packages/locale/lang/zh-TC.ts +3 -3
  76. package/packages/locale/lang/zh-TW.ts +3 -3
  77. package/packages/table/index.ts +49 -49
  78. package/packages/table/module/custom/mixin.ts +369 -369
  79. package/packages/table/module/custom/panel.ts +1461 -1461
  80. package/packages/table/module/edit/mixin.ts +1123 -1123
  81. package/packages/table/module/export/export-panel.ts +658 -658
  82. package/packages/table/module/export/import-panel.ts +319 -319
  83. package/packages/table/module/export/mixin.ts +1693 -1693
  84. package/packages/table/module/export/util.ts +24 -24
  85. package/packages/table/module/filter/mixin.ts +507 -507
  86. package/packages/table/module/filter/panel.ts +329 -329
  87. package/packages/table/module/keyboard/mixin.ts +513 -513
  88. package/packages/table/module/menu/mixin.ts +329 -329
  89. package/packages/table/module/menu/panel.ts +212 -212
  90. package/packages/table/module/validator/mixin.ts +626 -626
  91. package/packages/table/render/index.ts +1456 -1456
  92. package/packages/table/src/body.ts +969 -969
  93. package/packages/table/src/cell.ts +1285 -1285
  94. package/packages/table/src/column.ts +205 -205
  95. package/packages/table/src/columnInfo.ts +228 -228
  96. package/packages/table/src/footer.ts +388 -388
  97. package/packages/table/src/group.ts +51 -51
  98. package/packages/table/src/header.ts +602 -602
  99. package/packages/table/src/methods.ts +12939 -12920
  100. package/packages/table/src/props.ts +311 -311
  101. package/packages/table/src/store.ts +15 -15
  102. package/packages/table/src/table.ts +2502 -2460
  103. package/packages/table/src/util.ts +1012 -1012
  104. package/packages/toolbar/index.ts +18 -18
  105. package/packages/toolbar/src/toolbar.ts +856 -856
  106. package/packages/ui/index.ts +530 -530
  107. package/packages/ui/src/anime.ts +52 -52
  108. package/packages/ui/src/comp.ts +3 -3
  109. package/packages/ui/src/dom.ts +236 -236
  110. package/packages/ui/src/log.ts +8 -8
  111. package/packages/ui/src/utils.ts +56 -56
  112. package/packages/ui/src/vn.ts +65 -65
  113. package/packages/v-x-e-table/index.ts +4 -4
  114. package/styles/all.scss +7 -7
  115. package/styles/base.scss +16 -16
  116. package/styles/components/grid.scss +89 -89
  117. package/styles/components/icon.scss +225 -225
  118. package/styles/components/old-icon.scss +715 -715
  119. package/styles/components/table-module/all.scss +6 -6
  120. package/styles/components/table-module/custom.scss +527 -527
  121. package/styles/components/table-module/export.scss +130 -130
  122. package/styles/components/table-module/filter.scss +130 -130
  123. package/styles/components/table-module/menu.scss +81 -81
  124. package/styles/components/table.scss +2679 -2679
  125. package/styles/components/toolbar.scss +119 -119
  126. package/styles/default.scss +2 -2
  127. package/styles/helpers/baseMixin.scss +95 -95
  128. package/styles/index.scss +3 -3
  129. package/styles/modules.scss +5 -5
  130. package/styles/theme/base.scss +93 -93
  131. package/styles/theme/dark.scss +49 -49
  132. package/styles/theme/light.scss +44 -44
  133. package/styles/variable.scss +43 -43
  134. package/types/all.d.ts +53 -53
  135. package/types/index.d.ts +4 -4
  136. /package/es/{iconfont.1773710661615.ttf → iconfont.1773972972913.ttf} +0 -0
  137. /package/es/{iconfont.1773710661615.woff → iconfont.1773972972913.woff} +0 -0
  138. /package/es/{iconfont.1773710661615.woff2 → iconfont.1773972972913.woff2} +0 -0
  139. /package/lib/{iconfont.1773710661615.ttf → iconfont.1773972972913.ttf} +0 -0
  140. /package/lib/{iconfont.1773710661615.woff → iconfont.1773972972913.woff} +0 -0
  141. /package/lib/{iconfont.1773710661615.woff2 → iconfont.1773972972913.woff2} +0 -0
@@ -1,969 +1,969 @@
1
- import { PropType, CreateElement } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import { VxeUI } from '../../ui'
4
- import { isEnableConf, getClass } from '../../ui/src/utils'
5
- import { getRowid, createHandleGetRowId, getCellRestHeight } from './util'
6
- import { updateCellTitle } from '../../ui/src/dom'
7
- import { getSlotVNs } from '../../ui/src/vn'
8
-
9
- import type { VxeTableConstructor, VxeTableDefines, TableInternalData, VxeTablePrivateMethods, TableReactData, VxeComponentStyleType, VxeComponentSlotType } from '../../../types'
10
-
11
- const { getI18n, renderer, renderEmptyElement } = VxeUI
12
-
13
- const sourceType = 'table'
14
- const renderType = 'body'
15
-
16
- // 滚动、拖动过程中不需要触发
17
- const isVMScrollProcess = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) => {
18
- const tableProps = $xeTable
19
- const tableReactData = $xeTable as unknown as TableReactData
20
- const tableInternalData = $xeTable as unknown as TableInternalData
21
-
22
- const { delayHover } = tableProps
23
- const { isDragResize } = tableReactData
24
- const { lastSTime } = tableInternalData
25
- return !!(isDragResize || (lastSTime && Date.now() < lastSTime + (delayHover as number)))
26
- }
27
-
28
- function renderLine (h: CreateElement, $xeTable : VxeTableConstructor & VxeTablePrivateMethods, rowid: string, params: VxeTableDefines.CellRenderBodyParams, cellHeight: number): VxeComponentSlotType[] {
29
- const tableProps = $xeTable
30
- const tableInternalData = $xeTable as unknown as TableInternalData
31
-
32
- const { column } = params
33
- const { treeConfig } = tableProps
34
- const cellOpts = $xeTable.computeCellOpts
35
- const rowOpts = $xeTable.computeRowOpts
36
- const defaultRowHeight = $xeTable.computeDefaultRowHeight
37
- const treeOpts = $xeTable.computeTreeOpts
38
- const { slots, treeNode } = column
39
- const { fullAllDataRowIdData } = tableInternalData
40
- if (treeConfig && treeNode && (treeOpts.showLine || treeOpts.line)) {
41
- if (slots && (slots as any).line) {
42
- return $xeTable.callSlot((slots as any).line, params, h)
43
- }
44
- const rowRest = fullAllDataRowIdData[rowid]
45
- let rLevel = 0
46
- let prevRow = null
47
- let parentRow = null
48
- let lineHeight = ''
49
- if (rowRest) {
50
- rLevel = rowRest.level
51
- prevRow = rowRest.items[rowRest.treeIndex - 1]
52
- parentRow = rowRest.parent
53
- }
54
- if (!rLevel && !treeOpts.showRootLine) {
55
- return []
56
- }
57
- if (prevRow) {
58
- const prevRowRest = fullAllDataRowIdData[getRowid($xeTable, prevRow)] || {}
59
- lineHeight = `${prevRowRest.lineHeight || 0}px`
60
- } else if (rLevel && parentRow) {
61
- const parentRowRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)] || {}
62
- lineHeight = `calc(-1em + ${Math.floor(cellHeight / 2 + getCellRestHeight(parentRowRest, cellOpts, rowOpts, defaultRowHeight) / 2)}px)`
63
- }
64
- return [
65
- h('div', {
66
- key: 'tl',
67
- class: 'vxe-tree--line-wrapper'
68
- }, [
69
- h('div', {
70
- class: 'vxe-tree--line',
71
- style: {
72
- height: lineHeight,
73
- bottom: `-${Math.floor(cellHeight / 2)}px`,
74
- left: `calc(${(rLevel * treeOpts.indent)}px + 1em)`
75
- }
76
- })
77
- ])
78
- ]
79
- }
80
- return []
81
- }
82
-
83
- /**
84
- * 渲染列
85
- */
86
- function renderTdColumn (
87
- h: CreateElement,
88
- $xeTable: VxeTableConstructor & VxeTablePrivateMethods,
89
- seq: number | string,
90
- rowid: string,
91
- fixedType: 'left' | 'right' | '',
92
- isOptimizeMode: boolean,
93
- rowLevel: number,
94
- row: any,
95
- rowIndex: number,
96
- $rowIndex: number,
97
- _rowIndex: number,
98
- column: VxeTableDefines.ColumnInfo,
99
- $columnIndex: number,
100
- columns: VxeTableDefines.ColumnInfo[],
101
- items: any[]
102
- ) {
103
- const tableProps = $xeTable
104
- const tableReactData = $xeTable as unknown as TableReactData
105
- const tableInternalData = $xeTable as unknown as TableInternalData
106
- const $xeGrid = $xeTable.$xeGrid
107
- const $xeGantt = $xeTable.$xeGantt
108
-
109
- const { columnKey, resizable: allResizable, showOverflow: allShowOverflow, border, height, treeConfig, cellClassName: allCellClassName, cellStyle, align: allAlign, spanMethod, mouseConfig, editConfig, editRules, tooltipConfig, padding: allPadding } = tableProps
110
- const { tableData, tableColumn, dragRow, overflowX, overflowY, currentColumn, scrollXLoad, scrollYLoad, mergeBodyFlag, calcCellHeightFlag, resizeHeightFlag, resizeWidthFlag, editStore, isAllOverflow, validErrorMaps } = tableReactData
111
- const { fullAllDataRowIdData, fullColumnIdData, mergeBodyCellMaps, visibleColumn, afterFullData, mergeBodyList, scrollXStore, scrollYStore, keepUpdateFieldMaps } = tableInternalData
112
- const cellOpts = $xeTable.computeCellOpts
113
- const validOpts = $xeTable.computeValidOpts
114
- const checkboxOpts = $xeTable.computeCheckboxOpts
115
- const editOpts = $xeTable.computeEditOpts
116
- const tooltipOpts = $xeTable.computeTooltipOpts
117
- const virtualXOpts = $xeTable.computeVirtualXOpts
118
- const virtualYOpts = $xeTable.computeVirtualYOpts
119
- const { isAllColumnDrag, isAllRowDrag } = $xeTable.resizableOpts
120
- const rowOpts = $xeTable.computeRowOpts
121
- const rowDragOpts = $xeTable.computeRowDragOpts
122
- const defaultRowHeight = $xeTable.computeDefaultRowHeight
123
- const customCellHeight = calcCellHeightFlag ? (cellOpts.height || rowOpts.height) : 0
124
- const { disabledMethod: dragDisabledMethod, isCrossDrag, isPeerDrag } = rowDragOpts
125
- const columnOpts = $xeTable.computeColumnOpts
126
- const mouseOpts = $xeTable.computeMouseOpts
127
- const areaOpts = $xeTable.computeAreaOpts
128
- const cellOffsetWidth = $xeTable.computeCellOffsetWidth
129
- const { selectCellToRow } = areaOpts
130
- const { field, type, cellRender, editRender, align, showOverflow, className, treeNode, rowResize, padding, verticalAlign, slots } = column
131
- const { verticalAlign: allVerticalAlign } = cellOpts
132
- const { actived } = editStore
133
- const rowRest = fullAllDataRowIdData[rowid] || {}
134
- const colid = column.id
135
- const colRest = fullColumnIdData[colid] || {}
136
- const renderOpts = editRender || cellRender
137
- const compConf = renderOpts ? renderer.get(renderOpts.name) : null
138
- const compCellClassName = compConf ? (compConf.tableCellClassName || compConf.cellClassName) : null
139
- const compCellStyle = compConf ? (compConf.tableCellStyle || compConf.cellStyle) : ''
140
- const showAllTip = tooltipOpts.showAll
141
- const columnIndex = colRest.index
142
- const _columnIndex = colRest._index
143
- const isEdit = isEnableConf(editRender)
144
- const resizeHeight = resizeHeightFlag ? rowRest.resizeHeight : 0
145
- let fixedHiddenColumn = overflowX && (fixedType ? column.fixed !== fixedType : !!column.fixed)
146
- const isCellPadding = XEUtils.eqNull(padding) ? (allPadding === null ? cellOpts.padding : allPadding) : padding
147
- const cellOverflow = XEUtils.eqNull(showOverflow) ? allShowOverflow : showOverflow
148
- const showEllipsis = cellOverflow === 'ellipsis'
149
- const showTitle = cellOverflow === 'title'
150
- const showTooltip = cellOverflow === true || cellOverflow === 'tooltip'
151
- const hasEllipsis = isAllOverflow || showTitle || showTooltip || showEllipsis
152
- const showResizable = (XEUtils.isBoolean(column.resizable) ? column.resizable : (columnOpts.resizable || allResizable))
153
- const isCsHeight = !!customCellHeight
154
- const isRsHeight = resizeHeight > 0
155
- let isDirty
156
- const tdOns: any = {}
157
- const cellAlign = align || (compConf ? compConf.tableCellAlign : '') || allAlign
158
- const cellVerticalAlign = XEUtils.eqNull(verticalAlign) ? allVerticalAlign : verticalAlign
159
- const errorValidItem = validErrorMaps[`${rowid}:${colid}`]
160
- const showValidTip = editRules && validOpts.showErrorMessage && (validOpts.message === 'default' ? (height || tableData.length > 1) : validOpts.message === 'inline')
161
- const tdAttrs: any = { colid }
162
- const cellParams: VxeTableDefines.CellRenderBodyParams & {
163
- $table: VxeTableConstructor<any> & VxeTablePrivateMethods
164
- } = {
165
- $table: $xeTable,
166
- $grid: $xeGrid,
167
- $gantt: $xeGantt,
168
- isEdit: false,
169
- seq,
170
- rowid,
171
- row,
172
- rowIndex,
173
- $rowIndex,
174
- _rowIndex,
175
- column,
176
- columnIndex,
177
- $columnIndex,
178
- _columnIndex,
179
- fixed: fixedType,
180
- source: sourceType,
181
- type: renderType,
182
- isHidden: !!fixedHiddenColumn,
183
- level: rowLevel,
184
- visibleData: afterFullData,
185
- data: tableData,
186
- items
187
- }
188
- let isRowDragCell = false
189
- let isDisabledDrag = false
190
- if (rowOpts.drag) {
191
- isRowDragCell = rowDragOpts.trigger === 'row' || (column.dragSort && rowDragOpts.trigger === 'cell')
192
- }
193
- if (isRowDragCell) {
194
- isDisabledDrag = !!(dragDisabledMethod && dragDisabledMethod(cellParams))
195
- }
196
- // hover 进入事件
197
- if (showTitle || showTooltip || showAllTip || tooltipConfig) {
198
- tdOns.mouseover = (evnt: MouseEvent) => {
199
- if (!isVMScrollProcess($xeTable)) {
200
- if (showTitle) {
201
- updateCellTitle(evnt.currentTarget, column)
202
- } else if (showTooltip || showAllTip) {
203
- // 如果配置了显示 tooltip
204
- $xeTable.triggerBodyTooltipEvent(evnt, cellParams)
205
- }
206
- }
207
- $xeTable.dispatchEvent('cell-mouseenter', Object.assign({ cell: evnt.currentTarget }, cellParams), evnt)
208
- }
209
- }
210
- // hover 退出事件
211
- if (showTooltip || showAllTip || tooltipConfig) {
212
- tdOns.mouseleave = (evnt: MouseEvent) => {
213
- if (!isVMScrollProcess($xeTable)) {
214
- if (showTooltip || showAllTip) {
215
- $xeTable.handleTargetLeaveEvent(evnt)
216
- }
217
- }
218
- $xeTable.dispatchEvent('cell-mouseleave', Object.assign({ cell: evnt.currentTarget }, cellParams), evnt)
219
- }
220
- }
221
- // 按下事件处理
222
- if (isRowDragCell || checkboxOpts.range || mouseConfig) {
223
- tdOns.mousedown = (evnt: MouseEvent) => {
224
- $xeTable.triggerCellMousedownEvent(evnt, cellParams)
225
- }
226
- }
227
- // 拖拽列事件
228
- if (isRowDragCell) {
229
- tdOns.mouseup = $xeTable.triggerCellMouseupEvent
230
- }
231
- // 点击事件处理
232
- tdOns.click = (evnt: MouseEvent) => {
233
- $xeTable.triggerCellClickEvent(evnt, cellParams)
234
- }
235
- // 双击事件处理
236
- tdOns.dblclick = (evnt: MouseEvent) => {
237
- $xeTable.triggerCellDblclickEvent(evnt, cellParams)
238
- }
239
- let isMergeCell = false
240
- let mergeColspan = 1
241
- let mergeRowspan = 1
242
- // 合并行或列
243
- if (mergeBodyFlag && mergeBodyList.length) {
244
- const spanRest = mergeBodyCellMaps[`${_rowIndex}:${_columnIndex}`]
245
- if (spanRest) {
246
- const { rowspan, colspan } = spanRest
247
- if (!rowspan || !colspan) {
248
- return renderEmptyElement($xeTable)
249
- }
250
- if (rowspan > 1) {
251
- isMergeCell = true
252
- mergeRowspan = rowspan
253
- tdAttrs.rowspan = rowspan
254
- }
255
- if (colspan > 1) {
256
- isMergeCell = true
257
- mergeColspan = colspan
258
- tdAttrs.colspan = colspan
259
- }
260
- }
261
- } else if (spanMethod) {
262
- // 自定义合并行或列的方法
263
- const { rowspan = 1, colspan = 1 } = spanMethod(cellParams) || {}
264
- if (!rowspan || !colspan) {
265
- return renderEmptyElement($xeTable)
266
- }
267
- if (rowspan > 1) {
268
- isMergeCell = true
269
- mergeRowspan = rowspan
270
- tdAttrs.rowspan = rowspan
271
- }
272
- if (colspan > 1) {
273
- isMergeCell = true
274
- mergeColspan = colspan
275
- tdAttrs.colspan = colspan
276
- }
277
- }
278
- // 如果被合并不可隐藏
279
- if (fixedHiddenColumn && isMergeCell) {
280
- if (tdAttrs.colspan > 1 || tdAttrs.rowspan > 1) {
281
- fixedHiddenColumn = false
282
- }
283
- }
284
- // 如果编辑列开启显示状态
285
- if (!fixedHiddenColumn && editConfig && (editOpts.showStatus || editOpts.showUpdateStatus) && keepUpdateFieldMaps[field]) {
286
- isDirty = $xeTable.isUpdateByRow(row, field)
287
- }
288
-
289
- const isVNAutoHeight = !hasEllipsis && (scrollYLoad || scrollXLoad)
290
- let cellHeight = getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight)
291
-
292
- const isLastColumn = $columnIndex === columns.length - 1
293
- const isAutoCellWidth = !column.resizeWidth && (column.minWidth === 'auto' || column.width === 'auto')
294
-
295
- let isVNPreEmptyStatus = false
296
- if (!isMergeCell) {
297
- if (!dragRow || getRowid($xeTable, dragRow) !== rowid) {
298
- if (overflowY && scrollYLoad && !treeConfig && tableData.length > 16 && !virtualYOpts.immediate && (_rowIndex < scrollYStore.visibleStartIndex - scrollYStore.preloadSize || _rowIndex > scrollYStore.visibleEndIndex + scrollYStore.preloadSize)) {
299
- isVNPreEmptyStatus = true
300
- } else if (overflowX && scrollXLoad && tableColumn.length > 10 && !virtualXOpts.immediate && !column.fixed && (_columnIndex < scrollXStore.visibleStartIndex - scrollXStore.preloadSize || _columnIndex > scrollXStore.visibleEndIndex + scrollXStore.preloadSize)) {
301
- isVNPreEmptyStatus = true
302
- }
303
- }
304
- }
305
-
306
- if (mergeRowspan > 1) {
307
- const mEndRow = afterFullData[_rowIndex + mergeRowspan - 1]
308
- if (mEndRow) {
309
- const meRowRest = fullAllDataRowIdData[getRowid($xeTable, mEndRow)]
310
- if (meRowRest) {
311
- cellHeight += meRowRest.oTop + getCellRestHeight(meRowRest, cellOpts, rowOpts, defaultRowHeight) - rowRest.oTop - getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight)
312
- }
313
- }
314
- }
315
-
316
- const tcStyle: Record<string, string> = {}
317
- if (hasEllipsis && resizeWidthFlag) {
318
- let mergeColWidth = 0
319
- if (mergeColspan > 1) {
320
- for (let index = 1; index < mergeColspan; index++) {
321
- const nextColumn = visibleColumn[columnIndex + index]
322
- if (nextColumn) {
323
- mergeColWidth += nextColumn.renderWidth
324
- }
325
- }
326
- }
327
- tcStyle.width = `${column.renderWidth + mergeColWidth - cellOffsetWidth}px`
328
- }
329
- if (scrollYLoad || scrollXLoad || hasEllipsis || isCsHeight || isRsHeight) {
330
- tcStyle.height = `${cellHeight}px`
331
- } else {
332
- tcStyle.minHeight = `${cellHeight}px`
333
- }
334
-
335
- const tdVNs: VxeComponentSlotType[] = []
336
- if (fixedHiddenColumn && isAllOverflow) {
337
- tdVNs.push(
338
- h('div', {
339
- key: 'tc',
340
- class: ['vxe-cell', {
341
- 'c--title': showTitle,
342
- 'c--tooltip': showTooltip,
343
- 'c--ellipsis': showEllipsis
344
- }],
345
- style: tcStyle
346
- })
347
- )
348
- } else {
349
- // 渲染单元格
350
- if (treeConfig) {
351
- tdVNs.push(...renderLine(h, $xeTable, rowid, cellParams, cellHeight))
352
- }
353
- tdVNs.push(
354
- h('div', {
355
- key: 'tc',
356
- class: ['vxe-cell', {
357
- 'c--title': showTitle,
358
- 'c--tooltip': showTooltip,
359
- 'c--ellipsis': showEllipsis
360
- }],
361
- style: tcStyle,
362
- attrs: {
363
- title: showTitle ? $xeTable.getCellLabel(row, column) : null
364
- }
365
- }, isVNPreEmptyStatus
366
- ? []
367
- : [
368
- h('div', {
369
- attrs: {
370
- colid,
371
- rowid
372
- },
373
- class: 'vxe-cell--wrapper vxe-body-cell--wrapper'
374
- }, column.renderCell(h, cellParams))
375
- ])
376
- )
377
- if (showValidTip && errorValidItem) {
378
- const errRule = errorValidItem.rule
379
- const validSlot = slots ? slots.valid : null
380
- const validParams = { ...cellParams, ...errorValidItem, rule: errorValidItem }
381
- tdVNs.push(
382
- h('div', {
383
- key: 'tcv',
384
- class: ['vxe-cell--valid-error-tip', getClass(validOpts.className, errorValidItem)],
385
- style: errRule && errRule.maxWidth
386
- ? {
387
- width: `${errRule.maxWidth}px`
388
- }
389
- : undefined
390
- }, [
391
- h('div', {
392
- class: `vxe-cell--valid-error-wrapper vxe-cell--valid-error-theme-${validOpts.theme || 'normal'}`
393
- }, [
394
- validSlot
395
- ? $xeTable.callSlot(validSlot, validParams, h)
396
- : [
397
- h('span', {
398
- class: 'vxe-cell--valid-error-msg'
399
- }, errorValidItem.content)
400
- ]
401
- ])
402
- ])
403
- )
404
- }
405
- }
406
-
407
- let showAreaRowStatus = false
408
- if (mouseConfig && mouseOpts.area && !_columnIndex && selectCellToRow) {
409
- showAreaRowStatus = true
410
- }
411
-
412
- if (!fixedHiddenColumn && showResizable && isAllColumnDrag) {
413
- tdVNs.push(
414
- h('div', {
415
- key: 'tcc',
416
- class: ['vxe-cell--col-resizable', {
417
- 'is--line': !border || border === 'none'
418
- }],
419
- on: {
420
- mousedown: (evnt: MouseEvent) => $xeTable.handleColResizeMousedownEvent(evnt, fixedType, cellParams),
421
- dblclick: (evnt: MouseEvent) => $xeTable.handleColResizeDblclickEvent(evnt, cellParams)
422
- }
423
- })
424
- )
425
- }
426
-
427
- if ((rowResize || isAllRowDrag) && rowOpts.resizable) {
428
- tdVNs.push(
429
- h('div', {
430
- key: 'tcr',
431
- class: 'vxe-cell--row-resizable',
432
- on: {
433
- mousedown: (evnt: MouseEvent) => $xeTable.handleRowResizeMousedownEvent(evnt, cellParams),
434
- dblclick: (evnt: MouseEvent) => $xeTable.handleRowResizeDblclickEvent(evnt, cellParams)
435
- }
436
- })
437
- )
438
- }
439
-
440
- return h('td', {
441
- class: [
442
- 'vxe-table--column vxe-body--column',
443
- colid,
444
- cellVerticalAlign ? `col--vertical-${cellVerticalAlign}` : '',
445
- cellAlign ? `col--${cellAlign}` : '',
446
- type ? `col--${type}` : '',
447
- {
448
- 'col--last': isLastColumn,
449
- 'col--tree-node': treeNode,
450
- 'col--edit': isEdit,
451
- 'col--ellipsis': hasEllipsis,
452
- 'col--cs-height': isCsHeight,
453
- 'col--rs-height': isRsHeight,
454
- 'col--to-row': showAreaRowStatus,
455
- 'col--auto-height': isVNAutoHeight,
456
- 'fixed--width': !isAutoCellWidth,
457
- 'fixed--hidden': fixedHiddenColumn,
458
- 'is--padding': isCellPadding,
459
- 'is--progress': (fixedHiddenColumn && isAllOverflow) || isVNPreEmptyStatus,
460
- 'is--drag-cell': isRowDragCell && (isCrossDrag || isPeerDrag || !rowLevel),
461
- 'is--drag-disabled': isDisabledDrag,
462
- 'col--dirty': isDirty,
463
- 'col--active': editConfig && isEdit && (actived.row === row && (actived.column === column || editOpts.mode === 'row')),
464
- 'col--valid-error': !!errorValidItem,
465
- 'show--valid-bg': errorValidItem && validOpts.showErrorBackground,
466
- 'col--current': currentColumn === column
467
- },
468
- getClass(compCellClassName, cellParams),
469
- getClass(className, cellParams),
470
- getClass(allCellClassName, cellParams)
471
- ],
472
- key: columnKey || scrollXLoad || scrollYLoad || columnOpts.useKey || rowOpts.useKey || columnOpts.drag ? column.id : $columnIndex,
473
- attrs: tdAttrs,
474
- style: Object.assign({}, XEUtils.isFunction(compCellStyle) ? compCellStyle(cellParams) : compCellStyle, XEUtils.isFunction(cellStyle) ? cellStyle(cellParams) : cellStyle),
475
- on: tdOns
476
- }, isOptimizeMode && fixedHiddenColumn ? [] : tdVNs)
477
- }
478
-
479
- function renderRows (h: CreateElement, _vm: any, fixedType: 'left' | 'right' | '', isOptimizeMode: boolean, tableData: any[], tableColumn: VxeTableDefines.ColumnInfo[]) {
480
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
481
- const tableProps = $xeTable
482
- const tableReactData = $xeTable as unknown as TableReactData
483
- const tableInternalData = $xeTable as unknown as TableInternalData
484
- const $xeGrid = $xeTable.$xeGrid
485
- const $xeGantt = $xeTable.$xeGantt
486
-
487
- const { stripe, rowKey, highlightHoverRow, rowClassName, rowStyle, editConfig, treeConfig } = tableProps
488
- const { hasFixedColumn, treeExpandedFlag, scrollXLoad, scrollYLoad, isAllOverflow, rowExpandedFlag, expandColumn, selectRadioRow, pendingRowFlag, rowExpandHeightFlag, isRowGroupStatus } = tableReactData
489
- const { fullAllDataRowIdData, fullColumnIdData, treeExpandedMaps, pendingRowMaps, rowExpandedMaps } = tableInternalData
490
- const checkboxOpts = $xeTable.computeCheckboxOpts
491
- const radioOpts = $xeTable.computeRadioOpts
492
- const treeOpts = $xeTable.computeTreeOpts
493
- const editOpts = $xeTable.computeEditOpts
494
- const rowOpts = $xeTable.computeRowOpts
495
- const columnOpts = $xeTable.computeColumnOpts
496
- const { transform, seqMode } = treeOpts
497
- const childrenField = treeOpts.children || treeOpts.childrenField
498
- const rows: any[] = []
499
- const { handleGetRowId } = createHandleGetRowId($xeTable)
500
- const isDeepRow = treeConfig || isRowGroupStatus
501
- tableData.forEach((row, $rowIndex) => {
502
- const trOn: Record<string, any> = {}
503
- const rowid = handleGetRowId(row)
504
- const rowRest = fullAllDataRowIdData[rowid] || {}
505
- let rowIndex = $rowIndex
506
- let rowLevel = 0
507
- let seq: string | number = -1
508
- let _rowIndex = -1
509
- const hasRowGroupAggregate = isRowGroupStatus && row.isAggregate
510
- // 当前行事件
511
- if (rowOpts.isHover || highlightHoverRow) {
512
- trOn.mouseover = (evnt: MouseEvent) => {
513
- if (isVMScrollProcess($xeTable)) {
514
- return
515
- }
516
- $xeTable.triggerHoverEvent(evnt, { row, rowIndex })
517
- }
518
- trOn.mouseleave = () => {
519
- if (isVMScrollProcess($xeTable)) {
520
- return
521
- }
522
- $xeTable.clearHoverRow()
523
- }
524
- }
525
- if (rowRest) {
526
- rowIndex = rowRest.index
527
- _rowIndex = rowRest._index
528
- rowLevel = rowRest.level
529
- seq = rowRest.seq
530
- if (hasRowGroupAggregate || (treeConfig && transform && seqMode === 'increasing')) {
531
- seq = rowRest._index + 1
532
- } else if ((treeConfig && seqMode === 'fixed')) {
533
- seq = rowRest._tIndex + 1
534
- }
535
- }
536
- const params = {
537
- $table: $xeTable,
538
- seq,
539
- rowid,
540
- fixed: fixedType,
541
- type: renderType,
542
- level: rowLevel,
543
- row,
544
- rowIndex,
545
- $rowIndex,
546
- _rowIndex
547
- }
548
- // 行是否被展开
549
- const isExpandRow = expandColumn && !!rowExpandedFlag && !!rowExpandedMaps[rowid]
550
- // 树节点是否被展开
551
- let isExpandTree = false
552
- let rowChildren = []
553
- // 是否新增行
554
- let isNewRow = false
555
- if (editConfig) {
556
- isNewRow = $xeTable.isInsertByRow(row)
557
- }
558
- if (treeConfig && !scrollYLoad && !transform) {
559
- rowChildren = row[childrenField]
560
- isExpandTree = !!treeExpandedFlag && rowChildren && rowChildren.length > 0 && !!treeExpandedMaps[rowid]
561
- }
562
- // 拖拽行事件
563
- if (rowOpts.drag && !isRowGroupStatus && (!treeConfig || transform)) {
564
- trOn.dragstart = $xeTable.handleRowDragDragstartEvent
565
- trOn.dragend = $xeTable.handleRowDragDragendEvent
566
- trOn.dragover = $xeTable.handleRowDragDragoverEvent
567
- }
568
- const trClass = [
569
- 'vxe-body--row',
570
- isDeepRow ? `row--level-${rowLevel}` : '',
571
- {
572
- 'row--stripe': stripe && (_rowIndex + 1) % 2 === 0,
573
- 'is--new': isNewRow,
574
- 'is--expand-row': isExpandRow,
575
- 'is--expand-tree': isExpandTree,
576
- 'row--new': isNewRow && (editOpts.showStatus || editOpts.showInsertStatus),
577
- 'row--radio': radioOpts.highlight && selectRadioRow === row,
578
- 'row--checked': checkboxOpts.highlight && $xeTable.isCheckedByCheckboxRow(row),
579
- 'row--pending': !!pendingRowFlag && !!pendingRowMaps[rowid],
580
- 'row--group': hasRowGroupAggregate
581
- },
582
- rowClassName ? (XEUtils.isFunction(rowClassName) ? rowClassName(params) : rowClassName) : ''
583
- ]
584
- const tdVNs = tableColumn.map((column, $columnIndex) => {
585
- return renderTdColumn(h, $xeTable, seq, rowid, fixedType, isOptimizeMode, rowLevel, row, rowIndex, $rowIndex, _rowIndex, column, $columnIndex, tableColumn, tableData)
586
- })
587
- rows.push(
588
- h('tr', {
589
- class: trClass,
590
- attrs: {
591
- rowid
592
- },
593
- style: rowStyle ? (XEUtils.isFunction(rowStyle) ? rowStyle(params) : rowStyle) as VxeComponentStyleType : undefined,
594
- key: rowKey || scrollXLoad || scrollYLoad || rowOpts.useKey || rowOpts.drag || columnOpts.drag || isRowGroupStatus || treeConfig ? rowid : $rowIndex,
595
- on: trOn
596
- }, tdVNs)
597
- )
598
- // 如果行被展开了
599
- if (isExpandRow) {
600
- const expandOpts = $xeTable.computeExpandOpts
601
- const { height: expandHeight, padding, mode: expandMode } = expandOpts
602
- if (expandMode === 'fixed') {
603
- const currExpHeight = rowRest.expandHeight
604
- let expHeight = 0
605
- if (rowExpandHeightFlag) {
606
- if (currExpHeight || expandHeight) {
607
- expHeight = (currExpHeight || expandHeight || 0) + 1
608
- }
609
- }
610
- rows.push(
611
- h('tr', {
612
- class: 'vxe-body--row-expanded-place',
613
- key: `expand_${rowid}`,
614
- attrs: {
615
- rowid
616
- }
617
- }, [
618
- h('td', {
619
- class: 'vxe-body--row-expanded-place-column',
620
- attrs: {
621
- colspan: tableColumn.length
622
- },
623
- style: {
624
- height: `${expHeight}px`
625
- }
626
- })
627
- ])
628
- )
629
- } else {
630
- const cellStyle: any = {}
631
- if (expandHeight) {
632
- cellStyle.height = `${expandHeight}px`
633
- }
634
- if (treeConfig) {
635
- cellStyle.paddingLeft = `${(rowLevel * treeOpts.indent) + 30}px`
636
- }
637
- const { showOverflow } = expandColumn || {}
638
- const colid = expandColumn.id
639
- const colRest = fullColumnIdData[colid] || {}
640
- const hasEllipsis = XEUtils.eqNull(showOverflow) ? isAllOverflow : showOverflow
641
- let columnIndex = -1
642
- let $columnIndex = -1
643
- let _columnIndex = -1
644
- if (colRest) {
645
- columnIndex = colRest.index
646
- $columnIndex = colRest.$index
647
- _columnIndex = colRest._index
648
- }
649
- const expandParams: VxeTableDefines.CellRenderDataParams = {
650
- $grid: $xeGrid,
651
- $table: $xeTable,
652
- $gantt: $xeGantt,
653
- seq,
654
- column: expandColumn as VxeTableDefines.ColumnInfo,
655
- columnIndex,
656
- $columnIndex,
657
- _columnIndex,
658
- fixed: fixedType,
659
- source: sourceType,
660
- type: renderType,
661
- level: rowLevel,
662
- row,
663
- rowid,
664
- rowIndex,
665
- $rowIndex,
666
- _rowIndex,
667
- isHidden: false,
668
- isEdit: false,
669
- visibleData: [],
670
- data: [],
671
- items: []
672
- }
673
- rows.push(
674
- h('tr', {
675
- class: ['vxe-body--expanded-row', {
676
- 'is--padding': padding
677
- }],
678
- key: `expand_${rowid}`
679
- }, [
680
- h('td', {
681
- class: ['vxe-body--expanded-column', {
682
- 'fixed--hidden': fixedType && !hasFixedColumn,
683
- 'col--ellipsis': hasEllipsis
684
- }],
685
- attrs: {
686
- colspan: tableColumn.length
687
- }
688
- }, [
689
- h('div', {
690
- class: ['vxe-body--expanded-cell', {
691
- 'is--ellipsis': expandHeight
692
- }],
693
- style: cellStyle
694
- }, [
695
- expandColumn.renderData(h, expandParams)
696
- ])
697
- ])
698
- ])
699
- )
700
- }
701
- }
702
- // 如果是树形表格
703
- if (isExpandTree) {
704
- rows.push(...renderRows(h, _vm, fixedType, isOptimizeMode, rowChildren, tableColumn))
705
- }
706
- })
707
- return rows
708
- }
709
-
710
- export default {
711
- name: 'VxeTableBody',
712
- props: {
713
- tableData: Array as PropType<any[]>,
714
- tableColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
715
- fixedColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
716
- fixedType: {
717
- type: String as PropType<'right' | 'left' | ''>,
718
- default: ''
719
- }
720
- },
721
- mounted (this: any) {
722
- const _vm = this
723
- const props = _vm
724
- const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
725
- const tableInternalData = $xeTable as unknown as TableInternalData
726
-
727
- const { fixedType } = props
728
- const { elemStore } = tableInternalData
729
- const prefix = `${fixedType || 'main'}-body-`
730
- elemStore[`${prefix}wrapper`] = _vm.$refs.refElem
731
- elemStore[`${prefix}scroll`] = _vm.$refs.refBodyScroll
732
- elemStore[`${prefix}table`] = _vm.$refs.refBodyTable
733
- elemStore[`${prefix}colgroup`] = _vm.$refs.refBodyColgroup
734
- elemStore[`${prefix}list`] = _vm.$refs.refBodyTBody
735
- elemStore[`${prefix}xSpace`] = _vm.$refs.refBodyXSpace
736
- elemStore[`${prefix}ySpace`] = _vm.$refs.refBodyYSpace
737
- elemStore[`${prefix}emptyBlock`] = _vm.$refs.refBodyEmptyBlock
738
- },
739
- destroyed (this: any) {
740
- const props = this
741
- const $xeTable = this.$parent as VxeTableConstructor & VxeTablePrivateMethods
742
- const tableInternalData = $xeTable as unknown as TableInternalData
743
-
744
- const { fixedType } = props
745
- const { elemStore } = tableInternalData
746
- const prefix = `${fixedType || 'main'}-body-`
747
- elemStore[`${prefix}wrapper`] = null
748
- elemStore[`${prefix}scroll`] = null
749
- elemStore[`${prefix}table`] = null
750
- elemStore[`${prefix}colgroup`] = null
751
- elemStore[`${prefix}list`] = null
752
- elemStore[`${prefix}xSpace`] = null
753
- elemStore[`${prefix}ySpace`] = null
754
- elemStore[`${prefix}emptyBlock`] = null
755
- },
756
- render (this: any, h: CreateElement) {
757
- const props = this
758
- const $xeTable = this.$parent as VxeTableConstructor & VxeTablePrivateMethods
759
- const tableProps = $xeTable
760
- const tableReactData = $xeTable as unknown as TableReactData
761
- const tableInternalData = $xeTable as unknown as TableInternalData
762
- const $xeGrid = $xeTable.$xeGrid
763
- const $xeGantt = $xeTable.$xeGantt
764
- const slots = $xeTable.$scopedSlots
765
-
766
- const { xID } = $xeTable
767
- const { fixedColumn, fixedType, tableColumn } = props
768
-
769
- const { mouseConfig } = tableProps
770
- const { isGroup, tableData, isColLoading, overflowX, scrollXLoad, scrollYLoad, dragRow, dragCol } = tableReactData
771
- const { visibleColumn, fullAllDataRowIdData, fullColumnIdData } = tableInternalData
772
- const emptyOpts = $xeTable.computeEmptyOpts
773
- const mouseOpts = $xeTable.computeMouseOpts
774
- const isBodyRenderOptimize = $xeTable.computeIsBodyRenderOptimize
775
-
776
- let renderDataList = tableData
777
- let renderColumnList = tableColumn as VxeTableDefines.ColumnInfo[]
778
- const isOptimizeMode = isBodyRenderOptimize
779
-
780
- if (!isColLoading && (fixedType || !overflowX)) {
781
- renderColumnList = visibleColumn
782
- }
783
-
784
- if (fixedType) {
785
- if (isOptimizeMode) {
786
- renderColumnList = fixedColumn || []
787
- }
788
- }
789
-
790
- // 行拖拽
791
- if (scrollYLoad && dragRow) {
792
- if (renderDataList.length > 2) {
793
- const dRowRest = fullAllDataRowIdData[getRowid($xeTable, dragRow)]
794
- if (dRowRest) {
795
- const drIndex = dRowRest._index
796
- const firstRow = renderDataList[0]
797
- const lastRow = renderDataList[renderDataList.length - 1]
798
- const firstRowRest = fullAllDataRowIdData[getRowid($xeTable, firstRow)]
799
- const lastRowRest = fullAllDataRowIdData[getRowid($xeTable, lastRow)]
800
- if (firstRowRest && lastRowRest) {
801
- const frIndex = firstRowRest._index
802
- const lrIndex = lastRowRest._index
803
- if (drIndex < frIndex) {
804
- renderDataList = [dragRow].concat(renderDataList)
805
- } else if (drIndex > lrIndex) {
806
- renderDataList = renderDataList.concat([dragRow])
807
- }
808
- }
809
- }
810
- }
811
- }
812
-
813
- if (!fixedType && !isGroup) {
814
- // 列拖拽
815
- if (scrollXLoad && dragCol) {
816
- if (renderColumnList.length > 2) {
817
- const dCowRest = fullColumnIdData[dragCol.id]
818
- if (dCowRest) {
819
- const dcIndex = dCowRest._index
820
- const firstCol = renderColumnList[0]
821
- const lastCol = renderColumnList[renderColumnList.length - 1]
822
- const firstColRest = fullColumnIdData[firstCol.id]
823
- const lastColRest = fullColumnIdData[lastCol.id]
824
- if (firstColRest && lastColRest) {
825
- const fcIndex = firstColRest._index
826
- const lcIndex = lastColRest._index
827
- if (dcIndex < fcIndex) {
828
- renderColumnList = [dragCol].concat(renderColumnList)
829
- } else if (dcIndex > lcIndex) {
830
- renderColumnList = renderColumnList.concat([dragCol])
831
- }
832
- }
833
- }
834
- }
835
- }
836
- }
837
-
838
- let emptyContent
839
- const emptySlot = slots ? slots.empty : null
840
- const emptyParams = { $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt }
841
- if (emptySlot) {
842
- emptyContent = emptySlot.call($xeTable, emptyParams)
843
- } else {
844
- const compConf = emptyOpts.name ? renderer.get(emptyOpts.name) : null
845
- const rtEmptyView = compConf ? (compConf.renderTableEmpty || compConf.renderTableEmptyView || compConf.renderEmpty) : null
846
- if (rtEmptyView) {
847
- emptyContent = getSlotVNs(rtEmptyView.call($xeTable, h, emptyOpts, emptyParams))
848
- } else {
849
- emptyContent = tableProps.emptyText || getI18n('vxe.table.emptyText')
850
- }
851
- }
852
-
853
- return h('div', {
854
- ref: 'refElem',
855
- class: ['vxe-table--body-wrapper', fixedType ? `fixed-${fixedType}--wrapper` : 'body--wrapper'],
856
- attrs: {
857
- xid: xID
858
- }
859
- }, [
860
- h('div', {
861
- ref: 'refBodyScroll',
862
- class: 'vxe-table--body-inner-wrapper',
863
- on: {
864
- scroll (evnt: Event) {
865
- $xeTable.triggerBodyScrollEvent(evnt, fixedType)
866
- }
867
- }
868
- }, [
869
- fixedType
870
- ? renderEmptyElement($xeTable)
871
- : h('div', {
872
- ref: 'refBodyXSpace',
873
- class: 'vxe-body--x-space'
874
- }),
875
- h('div', {
876
- ref: 'refBodyYSpace',
877
- class: 'vxe-body--y-space'
878
- }),
879
- h('table', {
880
- ref: 'refBodyTable',
881
- class: 'vxe-table--body',
882
- attrs: {
883
- xid: xID,
884
- cellspacing: 0,
885
- cellpadding: 0,
886
- border: 0,
887
- xvm: isOptimizeMode ? '1' : null
888
- }
889
- }, [
890
- /**
891
- * 列宽
892
- */
893
- h('colgroup', {
894
- ref: 'refBodyColgroup'
895
- }, renderColumnList.map((column, $columnIndex) => {
896
- return h('col', {
897
- attrs: {
898
- name: column.id
899
- },
900
- key: $columnIndex,
901
- style: {
902
- width: `${column.renderWidth}px`
903
- }
904
- })
905
- })),
906
- /**
907
- * 内容
908
- */
909
- h('tbody', {
910
- ref: 'refBodyTBody'
911
- }, renderRows(h, this, fixedType, isOptimizeMode, renderDataList, renderColumnList))
912
- ]),
913
- h('div', {
914
- class: 'vxe-table--checkbox-range'
915
- }),
916
- mouseConfig && mouseOpts.area
917
- ? h('div', {
918
- class: 'vxe-table--cell-area',
919
- attrs: {
920
- xid: xID
921
- }
922
- }, [
923
- h('span', {
924
- class: 'vxe-table--cell-main-area'
925
- }, mouseOpts.extension
926
- ? [
927
- h('span', {
928
- class: 'vxe-table--cell-main-area-btn',
929
- on: {
930
- mousedown (evnt: MouseEvent) {
931
- if ($xeTable.triggerCellAreaExtendMousedownEvent) {
932
- $xeTable.triggerCellAreaExtendMousedownEvent(evnt, { $table: $xeTable, fixed: fixedType, type: renderType })
933
- }
934
- }
935
- }
936
- })
937
- ]
938
- : null),
939
- h('span', {
940
- class: 'vxe-table--cell-clip-area'
941
- }),
942
- h('span', {
943
- class: 'vxe-table--cell-extend-area'
944
- }),
945
- h('span', {
946
- class: 'vxe-table--cell-multi-area'
947
- }),
948
- h('span', {
949
- class: 'vxe-table--cell-active-area'
950
- }),
951
- h('span', {
952
- class: 'vxe-table--cell-row-status-area'
953
- })
954
- ])
955
- : renderEmptyElement($xeTable),
956
- !fixedType
957
- ? h('div', {
958
- class: 'vxe-table--empty-block',
959
- ref: 'emptyBlock'
960
- }, [
961
- h('div', {
962
- class: 'vxe-table--empty-content'
963
- }, emptyContent)
964
- ])
965
- : renderEmptyElement($xeTable)
966
- ])
967
- ])
968
- }
969
- }
1
+ import { PropType, CreateElement } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import { VxeUI } from '../../ui'
4
+ import { isEnableConf, getClass } from '../../ui/src/utils'
5
+ import { getRowid, createHandleGetRowId, getCellRestHeight } from './util'
6
+ import { updateCellTitle } from '../../ui/src/dom'
7
+ import { getSlotVNs } from '../../ui/src/vn'
8
+
9
+ import type { VxeTableConstructor, VxeTableDefines, TableInternalData, VxeTablePrivateMethods, TableReactData, VxeComponentStyleType, VxeComponentSlotType } from '../../../types'
10
+
11
+ const { getI18n, renderer, renderEmptyElement } = VxeUI
12
+
13
+ const sourceType = 'table'
14
+ const renderType = 'body'
15
+
16
+ // 滚动、拖动过程中不需要触发
17
+ const isVMScrollProcess = ($xeTable: VxeTableConstructor & VxeTablePrivateMethods) => {
18
+ const tableProps = $xeTable
19
+ const tableReactData = $xeTable as unknown as TableReactData
20
+ const tableInternalData = $xeTable as unknown as TableInternalData
21
+
22
+ const { delayHover } = tableProps
23
+ const { isDragResize } = tableReactData
24
+ const { lastSTime } = tableInternalData
25
+ return !!(isDragResize || (lastSTime && Date.now() < lastSTime + (delayHover as number)))
26
+ }
27
+
28
+ function renderLine (h: CreateElement, $xeTable : VxeTableConstructor & VxeTablePrivateMethods, rowid: string, params: VxeTableDefines.CellRenderBodyParams, cellHeight: number): VxeComponentSlotType[] {
29
+ const tableProps = $xeTable
30
+ const tableInternalData = $xeTable as unknown as TableInternalData
31
+
32
+ const { column } = params
33
+ const { treeConfig } = tableProps
34
+ const cellOpts = $xeTable.computeCellOpts
35
+ const rowOpts = $xeTable.computeRowOpts
36
+ const defaultRowHeight = $xeTable.computeDefaultRowHeight
37
+ const treeOpts = $xeTable.computeTreeOpts
38
+ const { slots, treeNode } = column
39
+ const { fullAllDataRowIdData } = tableInternalData
40
+ if (treeConfig && treeNode && (treeOpts.showLine || treeOpts.line)) {
41
+ if (slots && (slots as any).line) {
42
+ return $xeTable.callSlot((slots as any).line, params, h)
43
+ }
44
+ const rowRest = fullAllDataRowIdData[rowid]
45
+ let rLevel = 0
46
+ let prevRow = null
47
+ let parentRow = null
48
+ let lineHeight = ''
49
+ if (rowRest) {
50
+ rLevel = rowRest.level
51
+ prevRow = rowRest.items[rowRest.treeIndex - 1]
52
+ parentRow = rowRest.parent
53
+ }
54
+ if (!rLevel && !treeOpts.showRootLine) {
55
+ return []
56
+ }
57
+ if (prevRow) {
58
+ const prevRowRest = fullAllDataRowIdData[getRowid($xeTable, prevRow)] || {}
59
+ lineHeight = `${prevRowRest.lineHeight || 0}px`
60
+ } else if (rLevel && parentRow) {
61
+ const parentRowRest = fullAllDataRowIdData[getRowid($xeTable, parentRow)] || {}
62
+ lineHeight = `calc(-1em + ${Math.floor(cellHeight / 2 + getCellRestHeight(parentRowRest, cellOpts, rowOpts, defaultRowHeight) / 2)}px)`
63
+ }
64
+ return [
65
+ h('div', {
66
+ key: 'tl',
67
+ class: 'vxe-tree--line-wrapper'
68
+ }, [
69
+ h('div', {
70
+ class: 'vxe-tree--line',
71
+ style: {
72
+ height: lineHeight,
73
+ bottom: `-${Math.floor(cellHeight / 2)}px`,
74
+ left: `calc(${(rLevel * treeOpts.indent)}px + 1em)`
75
+ }
76
+ })
77
+ ])
78
+ ]
79
+ }
80
+ return []
81
+ }
82
+
83
+ /**
84
+ * 渲染列
85
+ */
86
+ function renderTdColumn (
87
+ h: CreateElement,
88
+ $xeTable: VxeTableConstructor & VxeTablePrivateMethods,
89
+ seq: number | string,
90
+ rowid: string,
91
+ fixedType: 'left' | 'right' | '',
92
+ isOptimizeMode: boolean,
93
+ rowLevel: number,
94
+ row: any,
95
+ rowIndex: number,
96
+ $rowIndex: number,
97
+ _rowIndex: number,
98
+ column: VxeTableDefines.ColumnInfo,
99
+ $columnIndex: number,
100
+ columns: VxeTableDefines.ColumnInfo[],
101
+ items: any[]
102
+ ) {
103
+ const tableProps = $xeTable
104
+ const tableReactData = $xeTable as unknown as TableReactData
105
+ const tableInternalData = $xeTable as unknown as TableInternalData
106
+ const $xeGrid = $xeTable.$xeGrid
107
+ const $xeGantt = $xeTable.$xeGantt
108
+
109
+ const { columnKey, resizable: allResizable, showOverflow: allShowOverflow, border, height, treeConfig, cellClassName: allCellClassName, cellStyle, align: allAlign, spanMethod, mouseConfig, editConfig, editRules, tooltipConfig, padding: allPadding } = tableProps
110
+ const { tableData, tableColumn, dragRow, overflowX, overflowY, currentColumn, scrollXLoad, scrollYLoad, mergeBodyFlag, calcCellHeightFlag, resizeHeightFlag, resizeWidthFlag, editStore, isAllOverflow, validErrorMaps } = tableReactData
111
+ const { fullAllDataRowIdData, fullColumnIdData, mergeBodyCellMaps, visibleColumn, afterFullData, mergeBodyList, scrollXStore, scrollYStore, keepUpdateFieldMaps } = tableInternalData
112
+ const cellOpts = $xeTable.computeCellOpts
113
+ const validOpts = $xeTable.computeValidOpts
114
+ const checkboxOpts = $xeTable.computeCheckboxOpts
115
+ const editOpts = $xeTable.computeEditOpts
116
+ const tooltipOpts = $xeTable.computeTooltipOpts
117
+ const virtualXOpts = $xeTable.computeVirtualXOpts
118
+ const virtualYOpts = $xeTable.computeVirtualYOpts
119
+ const { isAllColumnDrag, isAllRowDrag } = $xeTable.resizableOpts
120
+ const rowOpts = $xeTable.computeRowOpts
121
+ const rowDragOpts = $xeTable.computeRowDragOpts
122
+ const defaultRowHeight = $xeTable.computeDefaultRowHeight
123
+ const customCellHeight = calcCellHeightFlag ? (cellOpts.height || rowOpts.height) : 0
124
+ const { disabledMethod: dragDisabledMethod, isCrossDrag, isPeerDrag } = rowDragOpts
125
+ const columnOpts = $xeTable.computeColumnOpts
126
+ const mouseOpts = $xeTable.computeMouseOpts
127
+ const areaOpts = $xeTable.computeAreaOpts
128
+ const cellOffsetWidth = $xeTable.computeCellOffsetWidth
129
+ const { selectCellToRow } = areaOpts
130
+ const { field, type, cellRender, editRender, align, showOverflow, className, treeNode, rowResize, padding, verticalAlign, slots } = column
131
+ const { verticalAlign: allVerticalAlign } = cellOpts
132
+ const { actived } = editStore
133
+ const rowRest = fullAllDataRowIdData[rowid] || {}
134
+ const colid = column.id
135
+ const colRest = fullColumnIdData[colid] || {}
136
+ const renderOpts = editRender || cellRender
137
+ const compConf = renderOpts ? renderer.get(renderOpts.name) : null
138
+ const compCellClassName = compConf ? (compConf.tableCellClassName || compConf.cellClassName) : null
139
+ const compCellStyle = compConf ? (compConf.tableCellStyle || compConf.cellStyle) : ''
140
+ const showAllTip = tooltipOpts.showAll
141
+ const columnIndex = colRest.index
142
+ const _columnIndex = colRest._index
143
+ const isEdit = isEnableConf(editRender)
144
+ const resizeHeight = resizeHeightFlag ? rowRest.resizeHeight : 0
145
+ let fixedHiddenColumn = overflowX && (fixedType ? column.fixed !== fixedType : !!column.fixed)
146
+ const isCellPadding = XEUtils.eqNull(padding) ? (allPadding === null ? cellOpts.padding : allPadding) : padding
147
+ const cellOverflow = XEUtils.eqNull(showOverflow) ? allShowOverflow : showOverflow
148
+ const showEllipsis = cellOverflow === 'ellipsis'
149
+ const showTitle = cellOverflow === 'title'
150
+ const showTooltip = cellOverflow === true || cellOverflow === 'tooltip'
151
+ const hasEllipsis = isAllOverflow || showTitle || showTooltip || showEllipsis
152
+ const showResizable = (XEUtils.isBoolean(column.resizable) ? column.resizable : (columnOpts.resizable || allResizable))
153
+ const isCsHeight = !!customCellHeight
154
+ const isRsHeight = resizeHeight > 0
155
+ let isDirty
156
+ const tdOns: any = {}
157
+ const cellAlign = align || (compConf ? compConf.tableCellAlign : '') || allAlign
158
+ const cellVerticalAlign = XEUtils.eqNull(verticalAlign) ? allVerticalAlign : verticalAlign
159
+ const errorValidItem = validErrorMaps[`${rowid}:${colid}`]
160
+ const showValidTip = editRules && validOpts.showErrorMessage && (validOpts.message === 'default' ? (height || tableData.length > 1) : validOpts.message === 'inline')
161
+ const tdAttrs: any = { colid }
162
+ const cellParams: VxeTableDefines.CellRenderBodyParams & {
163
+ $table: VxeTableConstructor<any> & VxeTablePrivateMethods
164
+ } = {
165
+ $table: $xeTable,
166
+ $grid: $xeGrid,
167
+ $gantt: $xeGantt,
168
+ isEdit: false,
169
+ seq,
170
+ rowid,
171
+ row,
172
+ rowIndex,
173
+ $rowIndex,
174
+ _rowIndex,
175
+ column,
176
+ columnIndex,
177
+ $columnIndex,
178
+ _columnIndex,
179
+ fixed: fixedType,
180
+ source: sourceType,
181
+ type: renderType,
182
+ isHidden: !!fixedHiddenColumn,
183
+ level: rowLevel,
184
+ visibleData: afterFullData,
185
+ data: tableData,
186
+ items
187
+ }
188
+ let isRowDragCell = false
189
+ let isDisabledDrag = false
190
+ if (rowOpts.drag) {
191
+ isRowDragCell = rowDragOpts.trigger === 'row' || (column.dragSort && rowDragOpts.trigger === 'cell')
192
+ }
193
+ if (isRowDragCell) {
194
+ isDisabledDrag = !!(dragDisabledMethod && dragDisabledMethod(cellParams))
195
+ }
196
+ // hover 进入事件
197
+ if (showTitle || showTooltip || showAllTip || tooltipConfig) {
198
+ tdOns.mouseover = (evnt: MouseEvent) => {
199
+ if (!isVMScrollProcess($xeTable)) {
200
+ if (showTitle) {
201
+ updateCellTitle(evnt.currentTarget, column)
202
+ } else if (showTooltip || showAllTip) {
203
+ // 如果配置了显示 tooltip
204
+ $xeTable.triggerBodyTooltipEvent(evnt, cellParams)
205
+ }
206
+ }
207
+ $xeTable.dispatchEvent('cell-mouseenter', Object.assign({ cell: evnt.currentTarget }, cellParams), evnt)
208
+ }
209
+ }
210
+ // hover 退出事件
211
+ if (showTooltip || showAllTip || tooltipConfig) {
212
+ tdOns.mouseleave = (evnt: MouseEvent) => {
213
+ if (!isVMScrollProcess($xeTable)) {
214
+ if (showTooltip || showAllTip) {
215
+ $xeTable.handleTargetLeaveEvent(evnt)
216
+ }
217
+ }
218
+ $xeTable.dispatchEvent('cell-mouseleave', Object.assign({ cell: evnt.currentTarget }, cellParams), evnt)
219
+ }
220
+ }
221
+ // 按下事件处理
222
+ if (isRowDragCell || checkboxOpts.range || mouseConfig) {
223
+ tdOns.mousedown = (evnt: MouseEvent) => {
224
+ $xeTable.triggerCellMousedownEvent(evnt, cellParams)
225
+ }
226
+ }
227
+ // 拖拽列事件
228
+ if (isRowDragCell) {
229
+ tdOns.mouseup = $xeTable.triggerCellMouseupEvent
230
+ }
231
+ // 点击事件处理
232
+ tdOns.click = (evnt: MouseEvent) => {
233
+ $xeTable.triggerCellClickEvent(evnt, cellParams)
234
+ }
235
+ // 双击事件处理
236
+ tdOns.dblclick = (evnt: MouseEvent) => {
237
+ $xeTable.triggerCellDblclickEvent(evnt, cellParams)
238
+ }
239
+ let isMergeCell = false
240
+ let mergeColspan = 1
241
+ let mergeRowspan = 1
242
+ // 合并行或列
243
+ if (mergeBodyFlag && mergeBodyList.length) {
244
+ const spanRest = mergeBodyCellMaps[`${_rowIndex}:${_columnIndex}`]
245
+ if (spanRest) {
246
+ const { rowspan, colspan } = spanRest
247
+ if (!rowspan || !colspan) {
248
+ return renderEmptyElement($xeTable)
249
+ }
250
+ if (rowspan > 1) {
251
+ isMergeCell = true
252
+ mergeRowspan = rowspan
253
+ tdAttrs.rowspan = rowspan
254
+ }
255
+ if (colspan > 1) {
256
+ isMergeCell = true
257
+ mergeColspan = colspan
258
+ tdAttrs.colspan = colspan
259
+ }
260
+ }
261
+ } else if (spanMethod) {
262
+ // 自定义合并行或列的方法
263
+ const { rowspan = 1, colspan = 1 } = spanMethod(cellParams) || {}
264
+ if (!rowspan || !colspan) {
265
+ return renderEmptyElement($xeTable)
266
+ }
267
+ if (rowspan > 1) {
268
+ isMergeCell = true
269
+ mergeRowspan = rowspan
270
+ tdAttrs.rowspan = rowspan
271
+ }
272
+ if (colspan > 1) {
273
+ isMergeCell = true
274
+ mergeColspan = colspan
275
+ tdAttrs.colspan = colspan
276
+ }
277
+ }
278
+ // 如果被合并不可隐藏
279
+ if (fixedHiddenColumn && isMergeCell) {
280
+ if (tdAttrs.colspan > 1 || tdAttrs.rowspan > 1) {
281
+ fixedHiddenColumn = false
282
+ }
283
+ }
284
+ // 如果编辑列开启显示状态
285
+ if (!fixedHiddenColumn && editConfig && (editOpts.showStatus || editOpts.showUpdateStatus) && keepUpdateFieldMaps[field]) {
286
+ isDirty = $xeTable.isUpdateByRow(row, field)
287
+ }
288
+
289
+ const isVNAutoHeight = !hasEllipsis && (scrollYLoad || scrollXLoad)
290
+ let cellHeight = getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight)
291
+
292
+ const isLastColumn = $columnIndex === columns.length - 1
293
+ const isAutoCellWidth = !column.resizeWidth && (column.minWidth === 'auto' || column.width === 'auto')
294
+
295
+ let isVNPreEmptyStatus = false
296
+ if (!isMergeCell) {
297
+ if (!dragRow || getRowid($xeTable, dragRow) !== rowid) {
298
+ if (overflowY && scrollYLoad && !treeConfig && tableData.length > 16 && !virtualYOpts.immediate && (_rowIndex < scrollYStore.visibleStartIndex - scrollYStore.preloadSize || _rowIndex > scrollYStore.visibleEndIndex + scrollYStore.preloadSize)) {
299
+ isVNPreEmptyStatus = true
300
+ } else if (overflowX && scrollXLoad && tableColumn.length > 10 && !virtualXOpts.immediate && !column.fixed && (_columnIndex < scrollXStore.visibleStartIndex - scrollXStore.preloadSize || _columnIndex > scrollXStore.visibleEndIndex + scrollXStore.preloadSize)) {
301
+ isVNPreEmptyStatus = true
302
+ }
303
+ }
304
+ }
305
+
306
+ if (mergeRowspan > 1) {
307
+ const mEndRow = afterFullData[_rowIndex + mergeRowspan - 1]
308
+ if (mEndRow) {
309
+ const meRowRest = fullAllDataRowIdData[getRowid($xeTable, mEndRow)]
310
+ if (meRowRest) {
311
+ cellHeight += meRowRest.oTop + getCellRestHeight(meRowRest, cellOpts, rowOpts, defaultRowHeight) - rowRest.oTop - getCellRestHeight(rowRest, cellOpts, rowOpts, defaultRowHeight)
312
+ }
313
+ }
314
+ }
315
+
316
+ const tcStyle: Record<string, string> = {}
317
+ if (hasEllipsis && resizeWidthFlag) {
318
+ let mergeColWidth = 0
319
+ if (mergeColspan > 1) {
320
+ for (let index = 1; index < mergeColspan; index++) {
321
+ const nextColumn = visibleColumn[columnIndex + index]
322
+ if (nextColumn) {
323
+ mergeColWidth += nextColumn.renderWidth
324
+ }
325
+ }
326
+ }
327
+ tcStyle.width = `${column.renderWidth + mergeColWidth - cellOffsetWidth}px`
328
+ }
329
+ if (scrollYLoad || scrollXLoad || hasEllipsis || isCsHeight || isRsHeight) {
330
+ tcStyle.height = `${cellHeight}px`
331
+ } else {
332
+ tcStyle.minHeight = `${cellHeight}px`
333
+ }
334
+
335
+ const tdVNs: VxeComponentSlotType[] = []
336
+ if (fixedHiddenColumn && isAllOverflow) {
337
+ tdVNs.push(
338
+ h('div', {
339
+ key: 'tc',
340
+ class: ['vxe-cell', {
341
+ 'c--title': showTitle,
342
+ 'c--tooltip': showTooltip,
343
+ 'c--ellipsis': showEllipsis
344
+ }],
345
+ style: tcStyle
346
+ })
347
+ )
348
+ } else {
349
+ // 渲染单元格
350
+ if (treeConfig) {
351
+ tdVNs.push(...renderLine(h, $xeTable, rowid, cellParams, cellHeight))
352
+ }
353
+ tdVNs.push(
354
+ h('div', {
355
+ key: 'tc',
356
+ class: ['vxe-cell', {
357
+ 'c--title': showTitle,
358
+ 'c--tooltip': showTooltip,
359
+ 'c--ellipsis': showEllipsis
360
+ }],
361
+ style: tcStyle,
362
+ attrs: {
363
+ title: showTitle ? $xeTable.getCellLabel(row, column) : null
364
+ }
365
+ }, isVNPreEmptyStatus
366
+ ? []
367
+ : [
368
+ h('div', {
369
+ attrs: {
370
+ colid,
371
+ rowid
372
+ },
373
+ class: 'vxe-cell--wrapper vxe-body-cell--wrapper'
374
+ }, column.renderCell(h, cellParams))
375
+ ])
376
+ )
377
+ if (showValidTip && errorValidItem) {
378
+ const errRule = errorValidItem.rule
379
+ const validSlot = slots ? slots.valid : null
380
+ const validParams = { ...cellParams, ...errorValidItem, rule: errorValidItem }
381
+ tdVNs.push(
382
+ h('div', {
383
+ key: 'tcv',
384
+ class: ['vxe-cell--valid-error-tip', getClass(validOpts.className, errorValidItem)],
385
+ style: errRule && errRule.maxWidth
386
+ ? {
387
+ width: `${errRule.maxWidth}px`
388
+ }
389
+ : undefined
390
+ }, [
391
+ h('div', {
392
+ class: `vxe-cell--valid-error-wrapper vxe-cell--valid-error-theme-${validOpts.theme || 'normal'}`
393
+ }, [
394
+ validSlot
395
+ ? $xeTable.callSlot(validSlot, validParams, h)
396
+ : [
397
+ h('span', {
398
+ class: 'vxe-cell--valid-error-msg'
399
+ }, errorValidItem.content)
400
+ ]
401
+ ])
402
+ ])
403
+ )
404
+ }
405
+ }
406
+
407
+ let showAreaRowStatus = false
408
+ if (mouseConfig && mouseOpts.area && !_columnIndex && selectCellToRow) {
409
+ showAreaRowStatus = true
410
+ }
411
+
412
+ if (!fixedHiddenColumn && showResizable && isAllColumnDrag) {
413
+ tdVNs.push(
414
+ h('div', {
415
+ key: 'tcc',
416
+ class: ['vxe-cell--col-resizable', {
417
+ 'is--line': !border || border === 'none'
418
+ }],
419
+ on: {
420
+ mousedown: (evnt: MouseEvent) => $xeTable.handleColResizeMousedownEvent(evnt, fixedType, cellParams),
421
+ dblclick: (evnt: MouseEvent) => $xeTable.handleColResizeDblclickEvent(evnt, cellParams)
422
+ }
423
+ })
424
+ )
425
+ }
426
+
427
+ if ((rowResize || isAllRowDrag) && rowOpts.resizable) {
428
+ tdVNs.push(
429
+ h('div', {
430
+ key: 'tcr',
431
+ class: 'vxe-cell--row-resizable',
432
+ on: {
433
+ mousedown: (evnt: MouseEvent) => $xeTable.handleRowResizeMousedownEvent(evnt, cellParams),
434
+ dblclick: (evnt: MouseEvent) => $xeTable.handleRowResizeDblclickEvent(evnt, cellParams)
435
+ }
436
+ })
437
+ )
438
+ }
439
+
440
+ return h('td', {
441
+ class: [
442
+ 'vxe-table--column vxe-body--column',
443
+ colid,
444
+ cellVerticalAlign ? `col--vertical-${cellVerticalAlign}` : '',
445
+ cellAlign ? `col--${cellAlign}` : '',
446
+ type ? `col--${type}` : '',
447
+ {
448
+ 'col--last': isLastColumn,
449
+ 'col--tree-node': treeNode,
450
+ 'col--edit': isEdit,
451
+ 'col--ellipsis': hasEllipsis,
452
+ 'col--cs-height': isCsHeight,
453
+ 'col--rs-height': isRsHeight,
454
+ 'col--to-row': showAreaRowStatus,
455
+ 'col--auto-height': isVNAutoHeight,
456
+ 'fixed--width': !isAutoCellWidth,
457
+ 'fixed--hidden': fixedHiddenColumn,
458
+ 'is--padding': isCellPadding,
459
+ 'is--progress': (fixedHiddenColumn && isAllOverflow) || isVNPreEmptyStatus,
460
+ 'is--drag-cell': isRowDragCell && (isCrossDrag || isPeerDrag || !rowLevel),
461
+ 'is--drag-disabled': isDisabledDrag,
462
+ 'col--dirty': isDirty,
463
+ 'col--active': editConfig && isEdit && (actived.row === row && (actived.column === column || editOpts.mode === 'row')),
464
+ 'col--valid-error': !!errorValidItem,
465
+ 'show--valid-bg': errorValidItem && validOpts.showErrorBackground,
466
+ 'col--current': currentColumn === column
467
+ },
468
+ getClass(compCellClassName, cellParams),
469
+ getClass(className, cellParams),
470
+ getClass(allCellClassName, cellParams)
471
+ ],
472
+ key: columnKey || scrollXLoad || scrollYLoad || columnOpts.useKey || rowOpts.useKey || columnOpts.drag ? column.id : $columnIndex,
473
+ attrs: tdAttrs,
474
+ style: Object.assign({}, XEUtils.isFunction(compCellStyle) ? compCellStyle(cellParams) : compCellStyle, XEUtils.isFunction(cellStyle) ? cellStyle(cellParams) : cellStyle),
475
+ on: tdOns
476
+ }, isOptimizeMode && fixedHiddenColumn ? [] : tdVNs)
477
+ }
478
+
479
+ function renderRows (h: CreateElement, _vm: any, fixedType: 'left' | 'right' | '', isOptimizeMode: boolean, tableData: any[], tableColumn: VxeTableDefines.ColumnInfo[]) {
480
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
481
+ const tableProps = $xeTable
482
+ const tableReactData = $xeTable as unknown as TableReactData
483
+ const tableInternalData = $xeTable as unknown as TableInternalData
484
+ const $xeGrid = $xeTable.$xeGrid
485
+ const $xeGantt = $xeTable.$xeGantt
486
+
487
+ const { stripe, rowKey, highlightHoverRow, rowClassName, rowStyle, editConfig, treeConfig } = tableProps
488
+ const { hasFixedColumn, treeExpandedFlag, scrollXLoad, scrollYLoad, isAllOverflow, rowExpandedFlag, expandColumn, selectRadioRow, pendingRowFlag, rowExpandHeightFlag, isRowGroupStatus } = tableReactData
489
+ const { fullAllDataRowIdData, fullColumnIdData, treeExpandedMaps, pendingRowMaps, rowExpandedMaps } = tableInternalData
490
+ const checkboxOpts = $xeTable.computeCheckboxOpts
491
+ const radioOpts = $xeTable.computeRadioOpts
492
+ const treeOpts = $xeTable.computeTreeOpts
493
+ const editOpts = $xeTable.computeEditOpts
494
+ const rowOpts = $xeTable.computeRowOpts
495
+ const columnOpts = $xeTable.computeColumnOpts
496
+ const { transform, seqMode } = treeOpts
497
+ const childrenField = treeOpts.children || treeOpts.childrenField
498
+ const rows: any[] = []
499
+ const { handleGetRowId } = createHandleGetRowId($xeTable)
500
+ const isDeepRow = treeConfig || isRowGroupStatus
501
+ tableData.forEach((row, $rowIndex) => {
502
+ const trOn: Record<string, any> = {}
503
+ const rowid = handleGetRowId(row)
504
+ const rowRest = fullAllDataRowIdData[rowid] || {}
505
+ let rowIndex = $rowIndex
506
+ let rowLevel = 0
507
+ let seq: string | number = -1
508
+ let _rowIndex = -1
509
+ const hasRowGroupAggregate = isRowGroupStatus && row.isAggregate
510
+ // 当前行事件
511
+ if (rowOpts.isHover || highlightHoverRow) {
512
+ trOn.mouseover = (evnt: MouseEvent) => {
513
+ if (isVMScrollProcess($xeTable)) {
514
+ return
515
+ }
516
+ $xeTable.triggerHoverEvent(evnt, { row, rowIndex })
517
+ }
518
+ trOn.mouseleave = () => {
519
+ if (isVMScrollProcess($xeTable)) {
520
+ return
521
+ }
522
+ $xeTable.clearHoverRow()
523
+ }
524
+ }
525
+ if (rowRest) {
526
+ rowIndex = rowRest.index
527
+ _rowIndex = rowRest._index
528
+ rowLevel = rowRest.level
529
+ seq = rowRest.seq
530
+ if (hasRowGroupAggregate || (treeConfig && transform && seqMode === 'increasing')) {
531
+ seq = rowRest._index + 1
532
+ } else if ((treeConfig && seqMode === 'fixed')) {
533
+ seq = rowRest._tIndex + 1
534
+ }
535
+ }
536
+ const params = {
537
+ $table: $xeTable,
538
+ seq,
539
+ rowid,
540
+ fixed: fixedType,
541
+ type: renderType,
542
+ level: rowLevel,
543
+ row,
544
+ rowIndex,
545
+ $rowIndex,
546
+ _rowIndex
547
+ }
548
+ // 行是否被展开
549
+ const isExpandRow = expandColumn && !!rowExpandedFlag && !!rowExpandedMaps[rowid]
550
+ // 树节点是否被展开
551
+ let isExpandTree = false
552
+ let rowChildren = []
553
+ // 是否新增行
554
+ let isNewRow = false
555
+ if (editConfig) {
556
+ isNewRow = $xeTable.isInsertByRow(row)
557
+ }
558
+ if (treeConfig && !scrollYLoad && !transform) {
559
+ rowChildren = row[childrenField]
560
+ isExpandTree = !!treeExpandedFlag && rowChildren && rowChildren.length > 0 && !!treeExpandedMaps[rowid]
561
+ }
562
+ // 拖拽行事件
563
+ if (rowOpts.drag && !isRowGroupStatus && (!treeConfig || transform)) {
564
+ trOn.dragstart = $xeTable.handleRowDragDragstartEvent
565
+ trOn.dragend = $xeTable.handleRowDragDragendEvent
566
+ trOn.dragover = $xeTable.handleRowDragDragoverEvent
567
+ }
568
+ const trClass = [
569
+ 'vxe-body--row',
570
+ isDeepRow ? `row--level-${rowLevel}` : '',
571
+ {
572
+ 'row--stripe': stripe && (_rowIndex + 1) % 2 === 0,
573
+ 'is--new': isNewRow,
574
+ 'is--expand-row': isExpandRow,
575
+ 'is--expand-tree': isExpandTree,
576
+ 'row--new': isNewRow && (editOpts.showStatus || editOpts.showInsertStatus),
577
+ 'row--radio': radioOpts.highlight && selectRadioRow === row,
578
+ 'row--checked': checkboxOpts.highlight && $xeTable.isCheckedByCheckboxRow(row),
579
+ 'row--pending': !!pendingRowFlag && !!pendingRowMaps[rowid],
580
+ 'row--group': hasRowGroupAggregate
581
+ },
582
+ rowClassName ? (XEUtils.isFunction(rowClassName) ? rowClassName(params) : rowClassName) : ''
583
+ ]
584
+ const tdVNs = tableColumn.map((column, $columnIndex) => {
585
+ return renderTdColumn(h, $xeTable, seq, rowid, fixedType, isOptimizeMode, rowLevel, row, rowIndex, $rowIndex, _rowIndex, column, $columnIndex, tableColumn, tableData)
586
+ })
587
+ rows.push(
588
+ h('tr', {
589
+ class: trClass,
590
+ attrs: {
591
+ rowid
592
+ },
593
+ style: rowStyle ? (XEUtils.isFunction(rowStyle) ? rowStyle(params) : rowStyle) as VxeComponentStyleType : undefined,
594
+ key: rowKey || scrollXLoad || scrollYLoad || rowOpts.useKey || rowOpts.drag || columnOpts.drag || isRowGroupStatus || treeConfig ? rowid : $rowIndex,
595
+ on: trOn
596
+ }, tdVNs)
597
+ )
598
+ // 如果行被展开了
599
+ if (isExpandRow) {
600
+ const expandOpts = $xeTable.computeExpandOpts
601
+ const { height: expandHeight, padding, mode: expandMode } = expandOpts
602
+ if (expandMode === 'fixed') {
603
+ const currExpHeight = rowRest.expandHeight
604
+ let expHeight = 0
605
+ if (rowExpandHeightFlag) {
606
+ if (currExpHeight || expandHeight) {
607
+ expHeight = (currExpHeight || expandHeight || 0) + 1
608
+ }
609
+ }
610
+ rows.push(
611
+ h('tr', {
612
+ class: 'vxe-body--row-expanded-place',
613
+ key: `expand_${rowid}`,
614
+ attrs: {
615
+ rowid
616
+ }
617
+ }, [
618
+ h('td', {
619
+ class: 'vxe-body--row-expanded-place-column',
620
+ attrs: {
621
+ colspan: tableColumn.length
622
+ },
623
+ style: {
624
+ height: `${expHeight}px`
625
+ }
626
+ })
627
+ ])
628
+ )
629
+ } else {
630
+ const cellStyle: any = {}
631
+ if (expandHeight) {
632
+ cellStyle.height = `${expandHeight}px`
633
+ }
634
+ if (treeConfig) {
635
+ cellStyle.paddingLeft = `${(rowLevel * treeOpts.indent) + 30}px`
636
+ }
637
+ const { showOverflow } = expandColumn || {}
638
+ const colid = expandColumn.id
639
+ const colRest = fullColumnIdData[colid] || {}
640
+ const hasEllipsis = XEUtils.eqNull(showOverflow) ? isAllOverflow : showOverflow
641
+ let columnIndex = -1
642
+ let $columnIndex = -1
643
+ let _columnIndex = -1
644
+ if (colRest) {
645
+ columnIndex = colRest.index
646
+ $columnIndex = colRest.$index
647
+ _columnIndex = colRest._index
648
+ }
649
+ const expandParams: VxeTableDefines.CellRenderDataParams = {
650
+ $grid: $xeGrid,
651
+ $table: $xeTable,
652
+ $gantt: $xeGantt,
653
+ seq,
654
+ column: expandColumn as VxeTableDefines.ColumnInfo,
655
+ columnIndex,
656
+ $columnIndex,
657
+ _columnIndex,
658
+ fixed: fixedType,
659
+ source: sourceType,
660
+ type: renderType,
661
+ level: rowLevel,
662
+ row,
663
+ rowid,
664
+ rowIndex,
665
+ $rowIndex,
666
+ _rowIndex,
667
+ isHidden: false,
668
+ isEdit: false,
669
+ visibleData: [],
670
+ data: [],
671
+ items: []
672
+ }
673
+ rows.push(
674
+ h('tr', {
675
+ class: ['vxe-body--expanded-row', {
676
+ 'is--padding': padding
677
+ }],
678
+ key: `expand_${rowid}`
679
+ }, [
680
+ h('td', {
681
+ class: ['vxe-body--expanded-column', {
682
+ 'fixed--hidden': fixedType && !hasFixedColumn,
683
+ 'col--ellipsis': hasEllipsis
684
+ }],
685
+ attrs: {
686
+ colspan: tableColumn.length
687
+ }
688
+ }, [
689
+ h('div', {
690
+ class: ['vxe-body--expanded-cell', {
691
+ 'is--ellipsis': expandHeight
692
+ }],
693
+ style: cellStyle
694
+ }, [
695
+ expandColumn.renderData(h, expandParams)
696
+ ])
697
+ ])
698
+ ])
699
+ )
700
+ }
701
+ }
702
+ // 如果是树形表格
703
+ if (isExpandTree) {
704
+ rows.push(...renderRows(h, _vm, fixedType, isOptimizeMode, rowChildren, tableColumn))
705
+ }
706
+ })
707
+ return rows
708
+ }
709
+
710
+ export default {
711
+ name: 'VxeTableBody',
712
+ props: {
713
+ tableData: Array as PropType<any[]>,
714
+ tableColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
715
+ fixedColumn: Array as PropType<VxeTableDefines.ColumnInfo[]>,
716
+ fixedType: {
717
+ type: String as PropType<'right' | 'left' | ''>,
718
+ default: ''
719
+ }
720
+ },
721
+ mounted (this: any) {
722
+ const _vm = this
723
+ const props = _vm
724
+ const $xeTable = _vm.$parent as VxeTableConstructor & VxeTablePrivateMethods
725
+ const tableInternalData = $xeTable as unknown as TableInternalData
726
+
727
+ const { fixedType } = props
728
+ const { elemStore } = tableInternalData
729
+ const prefix = `${fixedType || 'main'}-body-`
730
+ elemStore[`${prefix}wrapper`] = _vm.$refs.refElem
731
+ elemStore[`${prefix}scroll`] = _vm.$refs.refBodyScroll
732
+ elemStore[`${prefix}table`] = _vm.$refs.refBodyTable
733
+ elemStore[`${prefix}colgroup`] = _vm.$refs.refBodyColgroup
734
+ elemStore[`${prefix}list`] = _vm.$refs.refBodyTBody
735
+ elemStore[`${prefix}xSpace`] = _vm.$refs.refBodyXSpace
736
+ elemStore[`${prefix}ySpace`] = _vm.$refs.refBodyYSpace
737
+ elemStore[`${prefix}emptyBlock`] = _vm.$refs.refBodyEmptyBlock
738
+ },
739
+ destroyed (this: any) {
740
+ const props = this
741
+ const $xeTable = this.$parent as VxeTableConstructor & VxeTablePrivateMethods
742
+ const tableInternalData = $xeTable as unknown as TableInternalData
743
+
744
+ const { fixedType } = props
745
+ const { elemStore } = tableInternalData
746
+ const prefix = `${fixedType || 'main'}-body-`
747
+ elemStore[`${prefix}wrapper`] = null
748
+ elemStore[`${prefix}scroll`] = null
749
+ elemStore[`${prefix}table`] = null
750
+ elemStore[`${prefix}colgroup`] = null
751
+ elemStore[`${prefix}list`] = null
752
+ elemStore[`${prefix}xSpace`] = null
753
+ elemStore[`${prefix}ySpace`] = null
754
+ elemStore[`${prefix}emptyBlock`] = null
755
+ },
756
+ render (this: any, h: CreateElement) {
757
+ const props = this
758
+ const $xeTable = this.$parent as VxeTableConstructor & VxeTablePrivateMethods
759
+ const tableProps = $xeTable
760
+ const tableReactData = $xeTable as unknown as TableReactData
761
+ const tableInternalData = $xeTable as unknown as TableInternalData
762
+ const $xeGrid = $xeTable.$xeGrid
763
+ const $xeGantt = $xeTable.$xeGantt
764
+ const slots = $xeTable.$scopedSlots
765
+
766
+ const { xID } = $xeTable
767
+ const { fixedColumn, fixedType, tableColumn } = props
768
+
769
+ const { mouseConfig } = tableProps
770
+ const { isGroup, tableData, isColLoading, overflowX, scrollXLoad, scrollYLoad, dragRow, dragCol } = tableReactData
771
+ const { visibleColumn, fullAllDataRowIdData, fullColumnIdData } = tableInternalData
772
+ const emptyOpts = $xeTable.computeEmptyOpts
773
+ const mouseOpts = $xeTable.computeMouseOpts
774
+ const isBodyRenderOptimize = $xeTable.computeIsBodyRenderOptimize
775
+
776
+ let renderDataList = tableData
777
+ let renderColumnList = tableColumn as VxeTableDefines.ColumnInfo[]
778
+ const isOptimizeMode = isBodyRenderOptimize
779
+
780
+ if (!isColLoading && (fixedType || !overflowX)) {
781
+ renderColumnList = visibleColumn
782
+ }
783
+
784
+ if (fixedType) {
785
+ if (isOptimizeMode) {
786
+ renderColumnList = fixedColumn || []
787
+ }
788
+ }
789
+
790
+ // 行拖拽
791
+ if (scrollYLoad && dragRow) {
792
+ if (renderDataList.length > 2) {
793
+ const dRowRest = fullAllDataRowIdData[getRowid($xeTable, dragRow)]
794
+ if (dRowRest) {
795
+ const drIndex = dRowRest._index
796
+ const firstRow = renderDataList[0]
797
+ const lastRow = renderDataList[renderDataList.length - 1]
798
+ const firstRowRest = fullAllDataRowIdData[getRowid($xeTable, firstRow)]
799
+ const lastRowRest = fullAllDataRowIdData[getRowid($xeTable, lastRow)]
800
+ if (firstRowRest && lastRowRest) {
801
+ const frIndex = firstRowRest._index
802
+ const lrIndex = lastRowRest._index
803
+ if (drIndex < frIndex) {
804
+ renderDataList = [dragRow].concat(renderDataList)
805
+ } else if (drIndex > lrIndex) {
806
+ renderDataList = renderDataList.concat([dragRow])
807
+ }
808
+ }
809
+ }
810
+ }
811
+ }
812
+
813
+ if (!fixedType && !isGroup) {
814
+ // 列拖拽
815
+ if (scrollXLoad && dragCol) {
816
+ if (renderColumnList.length > 2) {
817
+ const dCowRest = fullColumnIdData[dragCol.id]
818
+ if (dCowRest) {
819
+ const dcIndex = dCowRest._index
820
+ const firstCol = renderColumnList[0]
821
+ const lastCol = renderColumnList[renderColumnList.length - 1]
822
+ const firstColRest = fullColumnIdData[firstCol.id]
823
+ const lastColRest = fullColumnIdData[lastCol.id]
824
+ if (firstColRest && lastColRest) {
825
+ const fcIndex = firstColRest._index
826
+ const lcIndex = lastColRest._index
827
+ if (dcIndex < fcIndex) {
828
+ renderColumnList = [dragCol].concat(renderColumnList)
829
+ } else if (dcIndex > lcIndex) {
830
+ renderColumnList = renderColumnList.concat([dragCol])
831
+ }
832
+ }
833
+ }
834
+ }
835
+ }
836
+ }
837
+
838
+ let emptyContent
839
+ const emptySlot = slots ? slots.empty : null
840
+ const emptyParams = { $table: $xeTable, $grid: $xeGrid, $gantt: $xeGantt }
841
+ if (emptySlot) {
842
+ emptyContent = emptySlot.call($xeTable, emptyParams)
843
+ } else {
844
+ const compConf = emptyOpts.name ? renderer.get(emptyOpts.name) : null
845
+ const rtEmptyView = compConf ? (compConf.renderTableEmpty || compConf.renderTableEmptyView || compConf.renderEmpty) : null
846
+ if (rtEmptyView) {
847
+ emptyContent = getSlotVNs(rtEmptyView.call($xeTable, h, emptyOpts, emptyParams))
848
+ } else {
849
+ emptyContent = tableProps.emptyText || getI18n('vxe.table.emptyText')
850
+ }
851
+ }
852
+
853
+ return h('div', {
854
+ ref: 'refElem',
855
+ class: ['vxe-table--body-wrapper', fixedType ? `fixed-${fixedType}--wrapper` : 'body--wrapper'],
856
+ attrs: {
857
+ xid: xID
858
+ }
859
+ }, [
860
+ h('div', {
861
+ ref: 'refBodyScroll',
862
+ class: 'vxe-table--body-inner-wrapper',
863
+ on: {
864
+ scroll (evnt: Event) {
865
+ $xeTable.triggerBodyScrollEvent(evnt, fixedType)
866
+ }
867
+ }
868
+ }, [
869
+ fixedType
870
+ ? renderEmptyElement($xeTable)
871
+ : h('div', {
872
+ ref: 'refBodyXSpace',
873
+ class: 'vxe-body--x-space'
874
+ }),
875
+ h('div', {
876
+ ref: 'refBodyYSpace',
877
+ class: 'vxe-body--y-space'
878
+ }),
879
+ h('table', {
880
+ ref: 'refBodyTable',
881
+ class: 'vxe-table--body',
882
+ attrs: {
883
+ xid: xID,
884
+ cellspacing: 0,
885
+ cellpadding: 0,
886
+ border: 0,
887
+ xvm: isOptimizeMode ? '1' : null
888
+ }
889
+ }, [
890
+ /**
891
+ * 列宽
892
+ */
893
+ h('colgroup', {
894
+ ref: 'refBodyColgroup'
895
+ }, renderColumnList.map((column, $columnIndex) => {
896
+ return h('col', {
897
+ attrs: {
898
+ name: column.id
899
+ },
900
+ key: $columnIndex,
901
+ style: {
902
+ width: `${column.renderWidth}px`
903
+ }
904
+ })
905
+ })),
906
+ /**
907
+ * 内容
908
+ */
909
+ h('tbody', {
910
+ ref: 'refBodyTBody'
911
+ }, renderRows(h, this, fixedType, isOptimizeMode, renderDataList, renderColumnList))
912
+ ]),
913
+ h('div', {
914
+ class: 'vxe-table--checkbox-range'
915
+ }),
916
+ mouseConfig && mouseOpts.area
917
+ ? h('div', {
918
+ class: 'vxe-table--cell-area',
919
+ attrs: {
920
+ xid: xID
921
+ }
922
+ }, [
923
+ h('span', {
924
+ class: 'vxe-table--cell-main-area'
925
+ }, mouseOpts.extension
926
+ ? [
927
+ h('span', {
928
+ class: 'vxe-table--cell-main-area-btn',
929
+ on: {
930
+ mousedown (evnt: MouseEvent) {
931
+ if ($xeTable.triggerCellAreaExtendMousedownEvent) {
932
+ $xeTable.triggerCellAreaExtendMousedownEvent(evnt, { $table: $xeTable, fixed: fixedType, type: renderType })
933
+ }
934
+ }
935
+ }
936
+ })
937
+ ]
938
+ : null),
939
+ h('span', {
940
+ class: 'vxe-table--cell-clip-area'
941
+ }),
942
+ h('span', {
943
+ class: 'vxe-table--cell-extend-area'
944
+ }),
945
+ h('span', {
946
+ class: 'vxe-table--cell-multi-area'
947
+ }),
948
+ h('span', {
949
+ class: 'vxe-table--cell-active-area'
950
+ }),
951
+ h('span', {
952
+ class: 'vxe-table--cell-row-status-area'
953
+ })
954
+ ])
955
+ : renderEmptyElement($xeTable),
956
+ !fixedType
957
+ ? h('div', {
958
+ class: 'vxe-table--empty-block',
959
+ ref: 'emptyBlock'
960
+ }, [
961
+ h('div', {
962
+ class: 'vxe-table--empty-content'
963
+ }, emptyContent)
964
+ ])
965
+ : renderEmptyElement($xeTable)
966
+ ])
967
+ ])
968
+ }
969
+ }