vxe-table 4.23.7 → 4.23.9

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 (148) hide show
  1. package/dist/all.esm.js +5859 -4018
  2. package/es/colgroup/index.js +1 -1
  3. package/es/column/index.js +1 -1
  4. package/es/components.d.ts +3 -0
  5. package/es/components.js +4 -8
  6. package/es/grid/index.js +1 -1
  7. package/es/grid/src/emits.js +1 -15
  8. package/es/grid/src/grid.js +398 -121
  9. package/es/grid/src/props.js +1 -1
  10. package/es/index.esm.js +6 -0
  11. package/es/index.js +6 -0
  12. package/es/table/index.js +1 -1
  13. package/es/table/module/custom/hook.js +50 -43
  14. package/es/table/module/custom/panel.js +778 -528
  15. package/es/table/module/edit/hook.js +141 -63
  16. package/es/table/module/export/export-panel.js +400 -317
  17. package/es/table/module/export/hook.js +396 -338
  18. package/es/table/module/export/import-panel.js +153 -124
  19. package/es/table/module/filter/hook.js +17 -3
  20. package/es/table/module/filter/panel.js +147 -85
  21. package/es/table/module/keyboard/hook.js +9 -5
  22. package/es/table/module/menu/hook.js +1 -1
  23. package/es/table/module/menu/panel.js +198 -127
  24. package/es/table/module/validator/hook.js +1 -1
  25. package/es/table/render/index.js +152 -99
  26. package/es/table/src/body.js +356 -234
  27. package/es/table/src/cell.js +427 -270
  28. package/es/table/src/columnInfo.js +2 -1
  29. package/es/table/src/footer.js +145 -100
  30. package/es/table/src/group.js +7 -3
  31. package/es/table/src/header.js +230 -173
  32. package/es/table/src/props.js +1 -1
  33. package/es/table/src/table.js +1504 -1031
  34. package/es/table/src/util.js +15 -19
  35. package/es/toolbar/index.js +1 -1
  36. package/es/toolbar/src/toolbar.js +133 -76
  37. package/es/ui/index.d.ts +0 -1
  38. package/es/ui/index.js +1 -2
  39. package/es/ui/src/dom.js +9 -6
  40. package/es/ui/src/log.js +1 -1
  41. package/es/ui/src/utils.d.ts +1 -1
  42. package/es/v-x-e-table/index.d.ts +0 -1
  43. package/es/v-x-e-table/index.js +0 -1
  44. package/lib/colgroup/index.js +5 -5
  45. package/lib/column/index.js +5 -5
  46. package/lib/components.js +8 -12
  47. package/lib/grid/index.js +4 -4
  48. package/lib/grid/src/emits.js +1 -15
  49. package/lib/grid/src/grid.js +419 -142
  50. package/lib/grid/src/props.js +2 -2
  51. package/lib/index.common.js +6 -0
  52. package/lib/index.js +6 -0
  53. package/lib/index.umd.js +5825 -3945
  54. package/lib/index.umd.min.js +3 -3
  55. package/lib/table/index.js +5 -5
  56. package/lib/table/module/custom/hook.js +51 -44
  57. package/lib/table/module/custom/panel.js +790 -540
  58. package/lib/table/module/edit/hook.js +142 -64
  59. package/lib/table/module/export/export-panel.js +406 -323
  60. package/lib/table/module/export/hook.js +419 -361
  61. package/lib/table/module/export/import-panel.js +157 -128
  62. package/lib/table/module/filter/hook.js +18 -4
  63. package/lib/table/module/filter/panel.js +149 -87
  64. package/lib/table/module/keyboard/hook.js +10 -6
  65. package/lib/table/module/menu/hook.js +2 -2
  66. package/lib/table/module/menu/panel.js +199 -128
  67. package/lib/table/module/validator/hook.js +2 -2
  68. package/lib/table/render/index.js +153 -100
  69. package/lib/table/src/body.js +357 -235
  70. package/lib/table/src/cell.js +428 -271
  71. package/lib/table/src/columnInfo.js +3 -2
  72. package/lib/table/src/footer.js +146 -101
  73. package/lib/table/src/group.js +7 -3
  74. package/lib/table/src/header.js +231 -174
  75. package/lib/table/src/props.js +2 -2
  76. package/lib/table/src/table.js +1487 -1045
  77. package/lib/table/src/util.js +15 -19
  78. package/lib/toolbar/index.js +4 -4
  79. package/lib/toolbar/src/toolbar.js +135 -78
  80. package/lib/ui/index.js +1 -3
  81. package/lib/ui/src/dom.js +9 -6
  82. package/lib/ui/src/log.js +1 -1
  83. package/lib/v-x-e-table/index.js +0 -2
  84. package/package.json +8 -3
  85. package/packages/colgroup/index.ts +22 -22
  86. package/packages/column/index.ts +22 -22
  87. package/packages/components.ts +41 -43
  88. package/packages/grid/index.ts +18 -18
  89. package/packages/grid/src/emits.ts +5 -19
  90. package/packages/grid/src/grid.ts +2229 -1925
  91. package/packages/grid/src/props.ts +22 -23
  92. package/packages/index.ts +11 -4
  93. package/packages/locale/lang/fr-FR.ts +15 -15
  94. package/packages/locale/lang/it-IT.ts +4 -4
  95. package/packages/locale/lang/uk-UA.ts +1 -1
  96. package/packages/locale/lang/uz-UZ.ts +13 -13
  97. package/packages/locale/lang/zh-CN.ts +907 -907
  98. package/packages/table/index.ts +26 -26
  99. package/packages/table/module/custom/hook.ts +510 -503
  100. package/packages/table/module/custom/panel.ts +2002 -1743
  101. package/packages/table/module/edit/hook.ts +1224 -1131
  102. package/packages/table/module/export/export-panel.ts +697 -611
  103. package/packages/table/module/export/hook.ts +2160 -2059
  104. package/packages/table/module/export/import-panel.ts +319 -279
  105. package/packages/table/module/export/util.ts +25 -24
  106. package/packages/table/module/filter/hook.ts +519 -501
  107. package/packages/table/module/filter/panel.ts +368 -304
  108. package/packages/table/module/keyboard/hook.ts +498 -494
  109. package/packages/table/module/menu/hook.ts +330 -330
  110. package/packages/table/module/menu/panel.ts +272 -201
  111. package/packages/table/module/validator/hook.ts +653 -635
  112. package/packages/table/render/index.ts +1819 -1744
  113. package/packages/table/src/body.ts +1078 -955
  114. package/packages/table/src/cell.ts +1524 -1359
  115. package/packages/table/src/column.ts +192 -192
  116. package/packages/table/src/columnInfo.ts +232 -232
  117. package/packages/table/src/emits.ts +134 -134
  118. package/packages/table/src/footer.ts +425 -380
  119. package/packages/table/src/group.ts +67 -63
  120. package/packages/table/src/header.ts +642 -581
  121. package/packages/table/src/props.ts +336 -336
  122. package/packages/table/src/store.ts +14 -14
  123. package/packages/table/src/table.ts +16011 -15454
  124. package/packages/table/src/use/cell-view.ts +41 -44
  125. package/packages/table/src/use/index.ts +1 -1
  126. package/packages/table/src/util.ts +1206 -1216
  127. package/packages/toolbar/index.ts +18 -18
  128. package/packages/toolbar/src/toolbar.ts +768 -706
  129. package/packages/ui/index.ts +519 -521
  130. package/packages/ui/src/anime.ts +51 -52
  131. package/packages/ui/src/comp.ts +3 -3
  132. package/packages/ui/src/dom.ts +466 -463
  133. package/packages/ui/src/log.ts +19 -19
  134. package/packages/ui/src/utils.ts +66 -66
  135. package/packages/ui/src/vn.ts +55 -55
  136. package/packages/v-x-e-table/index.d.ts +3 -4
  137. package/packages/v-x-e-table/index.ts +3 -4
  138. package/types/all.d.ts +76 -76
  139. package/types/index.d.ts +4 -4
  140. /package/dist/{iconfont.1792979665397.ttf → iconfont.1793009263429.ttf} +0 -0
  141. /package/dist/{iconfont.1792979665397.woff → iconfont.1793009263429.woff} +0 -0
  142. /package/dist/{iconfont.1792979665397.woff2 → iconfont.1793009263429.woff2} +0 -0
  143. /package/es/{iconfont.1792979665397.ttf → iconfont.1793009263429.ttf} +0 -0
  144. /package/es/{iconfont.1792979665397.woff → iconfont.1793009263429.woff} +0 -0
  145. /package/es/{iconfont.1792979665397.woff2 → iconfont.1793009263429.woff2} +0 -0
  146. /package/lib/{iconfont.1792979665397.ttf → iconfont.1793009263429.ttf} +0 -0
  147. /package/lib/{iconfont.1792979665397.woff → iconfont.1793009263429.woff} +0 -0
  148. /package/lib/{iconfont.1792979665397.woff2 → iconfont.1793009263429.woff2} +0 -0
@@ -1,1359 +1,1524 @@
1
- import { h, VNode } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import { VxeUI } from '../../ui'
4
- import { getFuncText, isEnableConf, formatText, eqEmptyValue } from '../../ui/src/utils'
5
- import { updateCellTitle } from '../../ui/src/dom'
6
- import { createColumn, getRowid } from './util'
7
- import { getSlotVNs } from '../../ui/src/vn'
8
-
9
- import type { VxeTableConstructor, VxeTableDefines, VxeTablePrivateMethods, VxeComponentSlotType } from '../../../types'
10
-
11
- const { getConfig, getI18n, getIcon, renderer, renderEmptyElement } = VxeUI
12
-
13
- function renderTitlePrefixIcon (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
14
- const { $table, column } = params
15
- const titlePrefix = column.titlePrefix || column.titleHelp
16
- if (titlePrefix) {
17
- return h('span', {
18
- class: ['vxe-cell-title-prefix-icon', titlePrefix.iconStatus ? `theme--${titlePrefix.iconStatus}` : ''],
19
- onMouseenter (evnt: MouseEvent) {
20
- $table.triggerHeaderTitleEvent(evnt, titlePrefix, params)
21
- },
22
- onMouseleave (evnt: MouseEvent) {
23
- $table.handleTargetLeaveEvent(evnt)
24
- }
25
- }, [
26
- h('i', {
27
- class: titlePrefix.icon || getIcon().TABLE_TITLE_PREFIX
28
- })
29
- ])
30
- }
31
- return renderEmptyElement($table)
32
- }
33
-
34
- function renderTitleSuffixIcon (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
35
- const { $table, column } = params
36
- const titleSuffix = column.titleSuffix
37
- if (titleSuffix) {
38
- return h('span', {
39
- class: ['vxe-cell-title-suffix-icon', titleSuffix.iconStatus ? `theme--${titleSuffix.iconStatus}` : ''],
40
- onMouseenter (evnt: MouseEvent) {
41
- $table.triggerHeaderTitleEvent(evnt, titleSuffix, params)
42
- },
43
- onMouseleave (evnt: MouseEvent) {
44
- $table.handleTargetLeaveEvent(evnt)
45
- }
46
- }, [
47
- h('i', {
48
- class: titleSuffix.icon || getIcon().TABLE_TITLE_SUFFIX
49
- })
50
- ])
51
- }
52
- return renderEmptyElement($table)
53
- }
54
-
55
- function renderCellDragIcon (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
56
- const { $table, column } = params
57
- const { context } = $table
58
- const tableSlots = context.slots
59
- const tableProps = $table.props
60
- const { slots } = column
61
- const { dragConfig } = tableProps
62
- const { computeRowDragOpts } = $table.getComputeMaps()
63
- const rowDragOpts = computeRowDragOpts.value
64
- const { icon, trigger, disabledMethod } = rowDragOpts
65
- const rDisabledMethod = disabledMethod || (dragConfig ? dragConfig.rowDisabledMethod : null)
66
- const isDisabled = rDisabledMethod && rDisabledMethod(params)
67
- const rowDragIconSlot = (slots ? slots.rowDragIcon || slots['row-drag-icon'] : null) || tableSlots.rowDragIcon || tableSlots['row-drag-icon']
68
- const ons: Record<string, any> = {}
69
- if (trigger !== 'cell') {
70
- ons.onMousedown = (evnt: MouseEvent) => {
71
- if (!isDisabled) {
72
- $table.handleCellDragMousedownEvent(evnt, params)
73
- }
74
- }
75
- ons.onMouseup = $table.handleCellDragMouseupEvent
76
- }
77
- return h('span', {
78
- key: 'dg',
79
- class: ['vxe-cell--drag-handle', {
80
- 'is--disabled': isDisabled
81
- }],
82
- ...ons
83
- }, rowDragIconSlot
84
- ? $table.callSlot(rowDragIconSlot, params)
85
- : [
86
- h('i', {
87
- class: icon || (dragConfig ? dragConfig.rowIcon : '') || getIcon().TABLE_DRAG_ROW
88
- })
89
- ])
90
- }
91
-
92
- function renderCellBaseVNs (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, content: VxeComponentSlotType | VxeComponentSlotType[]) {
93
- const { $table, column, level } = params
94
- const { dragSort } = column
95
- const tableProps = $table.props
96
- const { treeConfig, dragConfig } = tableProps
97
- const { computeRowOpts, computeRowDragOpts, computeTreeOpts } = $table.getComputeMaps()
98
- const rowOpts = computeRowOpts.value
99
- const rowDragOpts = computeRowDragOpts.value
100
- const treeOpts = computeTreeOpts.value
101
- const { showIcon, isPeerDrag, isCrossDrag, visibleMethod } = rowDragOpts
102
- const rVisibleMethod = visibleMethod || (dragConfig ? dragConfig.rowVisibleMethod : null)
103
- const vns: VxeComponentSlotType[] = []
104
- if (dragSort && rowOpts.drag && ((showIcon || (dragConfig ? dragConfig.showRowIcon : false)) && (!rVisibleMethod || rVisibleMethod(params)))) {
105
- if (treeConfig) {
106
- if (treeOpts.transform && (isPeerDrag || isCrossDrag || !level)) {
107
- vns.push(
108
- renderCellDragIcon(params)
109
- )
110
- }
111
- } else {
112
- vns.push(
113
- renderCellDragIcon(params)
114
- )
115
- }
116
- }
117
- return vns.concat(XEUtils.isArray(content) ? content : [content])
118
- }
119
-
120
- function renderHeaderCellDragIcon (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
121
- const { $table, column } = params
122
- const { context } = $table
123
- const tableSlots = context.slots
124
- const { slots } = column
125
- const { computeColumnOpts, computeColumnDragOpts } = $table.getComputeMaps()
126
- const columnOpts = computeColumnOpts.value
127
- const columnDragOpts = computeColumnDragOpts.value
128
- const { showIcon, icon, trigger, isPeerDrag, isCrossDrag, visibleMethod, disabledMethod } = columnDragOpts
129
- if (columnOpts.drag && showIcon && (!visibleMethod || visibleMethod(params))) {
130
- if (!column.fixed && (isPeerDrag || isCrossDrag || !column.parentId)) {
131
- const isDisabled = disabledMethod && disabledMethod(params)
132
- const columnDragIconSlot = (slots ? slots.columnDragIcon || slots['column-drag-icon'] : null) || tableSlots.columnDragIcon || tableSlots['column-drag-icon']
133
- const ons: Record<string, any> = {}
134
- if (trigger !== 'cell') {
135
- ons.onMousedown = (evnt: MouseEvent) => {
136
- if (!isDisabled) {
137
- $table.handleHeaderCellDragMousedownEvent(evnt, params)
138
- }
139
- }
140
- ons.onMouseup = $table.handleHeaderCellDragMouseupEvent
141
- }
142
- return h('span', {
143
- key: 'dg',
144
- class: ['vxe-cell--drag-handle', {
145
- 'is--disabled': isDisabled
146
- }],
147
- ...ons
148
- }, columnDragIconSlot
149
- ? $table.callSlot(columnDragIconSlot, params)
150
- : [
151
- h('i', {
152
- class: icon || getIcon().TABLE_DRAG_COLUMN
153
- })
154
- ])
155
- }
156
- }
157
- return renderEmptyElement($table)
158
- }
159
-
160
- function renderHeaderCellBaseVNs (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, content: VNode | VNode[]) {
161
- const vns = [
162
- renderTitlePrefixIcon(params),
163
- renderHeaderCellDragIcon(params),
164
- ...(XEUtils.isArray(content) ? content : [content]),
165
- renderTitleSuffixIcon(params)
166
- ]
167
- return vns
168
- }
169
-
170
- function getRenderDefaultColumnTitle (column: VxeTableDefines.ColumnInfo, content: VxeComponentSlotType | VxeComponentSlotType[]) {
171
- if (column.type === 'html' && XEUtils.isString(content)) {
172
- return h('span', {
173
- key: 'ch',
174
- innerHTML: content
175
- })
176
- }
177
- return h('span', {
178
- key: 'ct'
179
- }, getSlotVNs(content))
180
- }
181
-
182
- function renderTitleContent (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, content: VxeComponentSlotType | VxeComponentSlotType[]) {
183
- const { $table, column } = params
184
- const tableProps = $table.props
185
- const tableReactData = $table.reactData
186
- const { computeHeaderTooltipOpts } = $table.getComputeMaps()
187
- const { showHeaderOverflow: allColumnHeaderOverflow } = tableProps
188
- const { isRowGroupStatus } = tableReactData
189
- const { showHeaderOverflow, slots } = column
190
- const titleSlot = slots ? slots.title : null
191
- const headerTooltipOpts = computeHeaderTooltipOpts.value
192
- const showAllTip = headerTooltipOpts.showAll
193
- const headOverflow = XEUtils.eqNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
194
- const showTitle = (headOverflow === true ? headerTooltipOpts.mode : headOverflow) === 'title'
195
- const showTooltip = (headOverflow === true ? headerTooltipOpts.mode : headOverflow) === 'tooltip'
196
- const ons: Record<string, any> = {}
197
- if (showTitle || showTooltip || showAllTip) {
198
- ons.onMouseenter = (evnt: MouseEvent) => {
199
- if (tableReactData.isDragResize) {
200
- return
201
- }
202
- if (showTitle) {
203
- updateCellTitle(evnt.currentTarget, column)
204
- } else if (showTooltip || showAllTip) {
205
- $table.triggerHeaderTooltipEvent(evnt, params)
206
- }
207
- }
208
- }
209
- if (showTooltip || showAllTip) {
210
- ons.onMouseleave = (evnt: MouseEvent) => {
211
- if (tableReactData.isDragResize) {
212
- return
213
- }
214
- if (showTooltip || showAllTip) {
215
- $table.handleTargetLeaveEvent(evnt)
216
- }
217
- }
218
- }
219
- const titleVN = getRenderDefaultColumnTitle(column, content)
220
- return [
221
- h('span', {
222
- class: 'vxe-cell--title',
223
- ...ons
224
- }, isRowGroupStatus && column.aggFunc && $table.getPivotTableAggregateRenderColTitles
225
- ? $table.getPivotTableAggregateRenderColTitles(column, titleVN)
226
- : titleSlot
227
- ? $table.callSlot(titleSlot, params)
228
- : [
229
- titleVN
230
- ])
231
- ]
232
- }
233
-
234
- function getFooterContent (params: VxeTableDefines.CellRenderFooterParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
235
- const { $table, column, row } = params
236
- const tableProps = $table.props
237
- const { editConfig } = tableProps
238
- const { slots, editRender, cellRender } = column
239
- const footerSlot = slots ? slots.footer : null
240
- if (footerSlot) {
241
- return $table.callSlot(footerSlot, params)
242
- }
243
- const isEnableEdit = editConfig && isEnableConf(editConfig)
244
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
245
- const cellRenderOpts = isEnableConf(cellRender) ? cellRender : null
246
- const renderOpts = editRenderOpts || cellRenderOpts
247
- const itemValue = $table.getFooterCellLabel(row, column)
248
- if (renderOpts) {
249
- const { computeRendererOpts } = $table.getComputeMaps()
250
- const rendererOpts = computeRendererOpts.value
251
- const compConf = renderOpts.name ? (rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)) : null
252
- if (compConf) {
253
- const rtFooter = compConf.renderTableFooter || compConf.renderFooter
254
- if (rtFooter) {
255
- const footParams = Object.assign(params, {
256
- cellValue: itemValue,
257
- itemValue
258
- })
259
- return getSlotVNs(rtFooter(renderOpts, footParams))
260
- }
261
- }
262
- }
263
- return [
264
- h('span', {
265
- class: 'vxe-cell--label'
266
- }, formatText(itemValue, 1))
267
- ]
268
- }
269
-
270
- function getDefaultCellLabel (params: VxeTableDefines.CellRenderBodyParams) {
271
- const { $table, row, column } = params
272
- return formatText($table.getCellLabel(row, column), 1)
273
- }
274
-
275
- function renderCellHandle (params: VxeTableDefines.CellRenderBodyParams & {
276
- $table: VxeTableConstructor & VxeTablePrivateMethods;
277
- }) {
278
- const { column, row, $table } = params
279
- const tableProps = $table.props
280
- const tableReactData = $table.reactData
281
- const { isRowGroupStatus } = tableReactData
282
- const { editConfig } = tableProps
283
- const { type, treeNode, rowGroupNode, editRender } = column
284
- const { computeEditOpts, computeCheckboxOpts, computeAggregateOpts } = $table.getComputeMaps()
285
- const aggregateOpts = computeAggregateOpts.value
286
- const { mode } = aggregateOpts
287
- const checkboxOpts = computeCheckboxOpts.value
288
- const editOpts = computeEditOpts.value
289
- const isDeepCell = treeNode || (isRowGroupStatus && (mode === 'column' ? column.field === row.groupField : rowGroupNode))
290
- switch (type) {
291
- case 'seq':
292
- return isDeepCell ? Cell.renderDeepIndexCell(params) : Cell.renderSeqCell(params)
293
- case 'radio':
294
- return isDeepCell ? Cell.renderDeepRadioCell(params) : Cell.renderRadioCell(params)
295
- case 'checkbox':
296
- return checkboxOpts.checkField ? (isDeepCell ? Cell.renderDeepSelectionCellByProp(params) : Cell.renderCheckboxCellByProp(params)) : (isDeepCell ? Cell.renderDeepSelectionCell(params) : Cell.renderCheckboxCell(params))
297
- case 'expand':
298
- return Cell.renderExpandCell(params)
299
- case 'html':
300
- return isDeepCell ? Cell.renderDeepHTMLCell(params) : Cell.renderHTMLCell(params)
301
- }
302
- const isEnableEdit = editConfig && isEnableConf(editConfig)
303
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
304
- if (editRenderOpts) {
305
- return editOpts.mode === 'cell' ? (isDeepCell ? Cell.renderDeepCellEdit(params) : Cell.renderCellEdit(params)) : (isDeepCell ? Cell.renderDeepRowEdit(params) : Cell.renderRowEdit(params))
306
- }
307
- return isDeepCell ? Cell.renderDeepCell(params) : Cell.renderDefaultCell(params)
308
- }
309
-
310
- function renderHeaderHandle (params: VxeTableDefines.CellRenderHeaderParams & {
311
- $table: VxeTableConstructor & VxeTablePrivateMethods;
312
- }) {
313
- const { column, $table } = params
314
- const tableProps = $table.props
315
- const { editConfig } = tableProps
316
- const { type, filters, sortable, editRender, slots } = column
317
-
318
- // 兼容已废弃方式
319
- if (getConfig().tableHeadeSlotToTitleSlot !== 'obsolete') {
320
- const headerSlot = slots ? slots.header : null
321
- if (headerSlot) {
322
- return renderTitleContent(params, $table.callSlot(headerSlot, params))
323
- }
324
- }
325
-
326
- switch (type) {
327
- case 'seq':
328
- return Cell.renderSeqHeader(params)
329
- case 'radio':
330
- return Cell.renderRadioHeader(params)
331
- case 'checkbox':
332
- return Cell.renderCheckboxHeader(params)
333
- case 'html':
334
- if (filters && sortable) {
335
- return Cell.renderSortAndFilterHeader(params)
336
- } else if (sortable) {
337
- return Cell.renderSortHeader(params)
338
- } else if (filters) {
339
- return Cell.renderFilterHeader(params)
340
- }
341
- break
342
- }
343
- const isEnableEdit = editConfig && isEnableConf(editConfig)
344
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
345
- if (editRenderOpts) {
346
- return Cell.renderEditHeader(params)
347
- } else if (filters && sortable) {
348
- return Cell.renderSortAndFilterHeader(params)
349
- } else if (sortable) {
350
- return Cell.renderSortHeader(params)
351
- } else if (filters) {
352
- return Cell.renderFilterHeader(params)
353
- }
354
- return Cell.renderDefaultHeader(params)
355
- }
356
-
357
- function renderFooterHandle (params: VxeTableDefines.CellRenderFooterParams & {
358
- $table: VxeTableConstructor & VxeTablePrivateMethods;
359
- }) {
360
- return Cell.renderDefaultFooter(params)
361
- }
362
-
363
- export const Cell = {
364
- createColumn ($xeTable: VxeTableConstructor & VxeTablePrivateMethods, columnOpts: VxeTableDefines.ColumnOptions | VxeTableDefines.ColumnInfo) {
365
- const { type } = columnOpts
366
- const renConfs: any = {
367
- renderHeader: renderHeaderHandle,
368
- renderCell: renderCellHandle,
369
- renderFooter: renderFooterHandle
370
- }
371
- if (type === 'expand') {
372
- renConfs.renderData = Cell.renderExpandData
373
- }
374
- return createColumn($xeTable, columnOpts, renConfs)
375
- },
376
- /**
377
- * 列头标题
378
- */
379
- renderHeaderTitle (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
380
- const { $table, column } = params
381
- const tableProps = $table.props
382
- const { editConfig } = tableProps
383
- const { slots, editRender, cellRender } = column
384
- const isEnableEdit = editConfig && isEnableConf(editConfig)
385
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
386
- const cellRenderOpts = isEnableConf(cellRender) ? cellRender : null
387
- const renderOpts = editRenderOpts || cellRenderOpts
388
-
389
- // 兼容已废弃方式
390
- if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
391
- const headerSlot = slots ? slots.header : null
392
- if (headerSlot) {
393
- return renderTitleContent(params, $table.callSlot(headerSlot, params))
394
- }
395
- }
396
-
397
- if (renderOpts) {
398
- const { computeRendererOpts } = $table.getComputeMaps()
399
- const rendererOpts = computeRendererOpts.value
400
- const compConf = renderOpts.name ? (rendererOpts[renderOpts.name] || renderer.get(renderOpts.name)) : null
401
- if (compConf) {
402
- const rtHeader = compConf.renderTableHeader || compConf.renderHeader
403
- if (rtHeader) {
404
- return renderTitleContent(params, getSlotVNs(rtHeader(renderOpts, params)))
405
- }
406
- }
407
- }
408
- return renderTitleContent(params, $table.getHeaderCellLabel(column))
409
- },
410
- renderDefaultHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
411
- return renderHeaderCellBaseVNs(params, Cell.renderHeaderTitle(params))
412
- },
413
- renderDefaultCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
414
- const { $table, row, column } = params
415
- const tableProps = $table.props
416
- const tableReactData = $table.reactData
417
- const tableInternalData = $table.internalData
418
- const { isRowGroupStatus } = tableReactData
419
- const { editConfig } = tableProps
420
- const { field, slots, editRender, cellRender, rowGroupNode, aggFunc } = column
421
- const isEnableEdit = editConfig && isEnableConf(editConfig)
422
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
423
- const cellRenderOpts = isEnableConf(cellRender) ? cellRender : null
424
- const defaultSlot = slots ? slots.default : null
425
- const gcSlot = slots ? (slots.groupContent || slots['group-content']) : null
426
- const gvSlot = slots ? (slots.groupValues || slots['group-values']) : null
427
- let cellValue: string | number | null = ''
428
- if (isRowGroupStatus && field && row.isAggregate) {
429
- const aggRow: VxeTableDefines.AggregateRowInfo = row
430
- const { fullColumnFieldData } = tableInternalData
431
- const { computeAggregateOpts } = $table.getComputeMaps()
432
- const aggregateOpts = computeAggregateOpts.value
433
- const { mode, showTotal, totalMethod, countFields, contentMethod, formatValuesMethod, mapChildrenField } = aggregateOpts
434
- const aggData = aggRow.aggData
435
- const currAggData = aggData ? aggData[field] : null
436
- const groupField = aggRow.groupField
437
- const groupContent = aggRow.groupContent
438
- const childList = mapChildrenField ? (aggRow[mapChildrenField] || []) : []
439
- const childCount = aggRow.childCount
440
- const colRest = fullColumnFieldData[groupField] || {}
441
- const ctParams = {
442
- $table,
443
- groupField,
444
- groupColumn: (colRest ? colRest.column : null) as VxeTableDefines.ColumnInfo,
445
- column,
446
- groupValue: groupContent,
447
- childList,
448
- childCount,
449
- aggValue: null as any,
450
-
451
- /**
452
- * 已废弃
453
- * @deprecated
454
- */
455
- children: childList,
456
- /**
457
- * 已废弃
458
- * @deprecated
459
- */
460
- totalValue: childCount
461
- }
462
- if (mode === 'column' ? field === aggRow.groupField : rowGroupNode) {
463
- cellValue = groupContent
464
- if (contentMethod) {
465
- cellValue = `${contentMethod(ctParams)}`
466
- }
467
- if (showTotal) {
468
- cellValue = getI18n('vxe.table.rowGroupContentTotal', [cellValue, totalMethod ? totalMethod(ctParams) : childCount, childCount])
469
- }
470
- if (gcSlot) {
471
- return renderCellBaseVNs(params, $table.callSlot(gcSlot, Object.assign({ groupField, groupContent, childList, childCount }, params)))
472
- }
473
- } else if ($table.getPivotTableAggregateCellAggValue) {
474
- cellValue = $table.getPivotTableAggregateCellAggValue(params)
475
- ctParams.aggValue = cellValue
476
- if (gvSlot) {
477
- return renderCellBaseVNs(params, $table.callSlot(gvSlot, Object.assign({ groupField, groupContent, childList, childCount }, params, ctParams)))
478
- }
479
- } else if (aggFunc === true || (countFields && countFields.includes(field))) {
480
- cellValue = currAggData ? currAggData.value : childCount
481
- ctParams.aggValue = cellValue
482
- if (formatValuesMethod) {
483
- cellValue = formatValuesMethod(ctParams)
484
- }
485
- if (gvSlot) {
486
- return renderCellBaseVNs(params, $table.callSlot(gvSlot, Object.assign({ groupField, groupContent, childList, childCount }, params, ctParams)))
487
- }
488
- }
489
- } else {
490
- if (defaultSlot) {
491
- return renderCellBaseVNs(params, $table.callSlot(defaultSlot, params))
492
- }
493
- const { computeRendererOpts } = $table.getComputeMaps()
494
- const rendererOpts = computeRendererOpts.value
495
- // 如果是编辑模式-查看:slot default > formatter > cellRender.renderTableDefault > editRender.renderTableCell > editRender.renderTableDefault > cellRender.tableCellFormatter > editRender.tableCellFormatter > field
496
- // 如果是查看表格:slot default > formatter > cellRender.renderTableDefault > cellRender.tableCellFormatter > field
497
- const cellCompConf = cellRenderOpts && cellRenderOpts.name ? (rendererOpts[cellRenderOpts.name] || renderer.get(cellRenderOpts.name)) : null
498
- if (cellRenderOpts) {
499
- const cellDefaultRenderFn = cellCompConf ? (cellCompConf.renderTableDefault || cellCompConf.renderDefault) : null
500
- if (cellDefaultRenderFn && cellRenderOpts) {
501
- return renderCellBaseVNs(params, getSlotVNs(cellDefaultRenderFn(cellRenderOpts, Object.assign({ $type: editRenderOpts ? 'edit' : 'cell' }, params))))
502
- }
503
- }
504
- if (editRenderOpts) {
505
- const editCompConf = editRenderOpts && editRenderOpts.name ? (rendererOpts[editRenderOpts.name] || renderer.get(editRenderOpts.name)) : null
506
- const editCellRenderFn = editCompConf
507
- ? (
508
- (editCompConf.renderTableCell || editCompConf.renderCell) ||
509
- (editCompConf.renderTableDefault || editCompConf.renderDefault))
510
- : null
511
- if (editCellRenderFn) {
512
- return renderCellBaseVNs(params, getSlotVNs(editCellRenderFn(editRenderOpts, Object.assign({ $type: editRenderOpts ? 'edit' : 'cell' }, params))))
513
- }
514
- }
515
-
516
- // 如果是编辑模式-查看:cellRender.tableCellFormatter > editRender.tableCellFormatter > field
517
- // 如果是查看表格:cellRender.tableCellFormatter > field
518
- cellValue = $table.getCellLabel(row, column)
519
- }
520
- const cellPlaceholder = editRenderOpts ? editRenderOpts.placeholder : ''
521
- return renderCellBaseVNs(params, [
522
- h('span', {
523
- class: 'vxe-cell--label'
524
- }, [
525
- // 如果设置占位符
526
- editRenderOpts && eqEmptyValue(cellValue)
527
- ? h('span', {
528
- class: 'vxe-cell--placeholder'
529
- }, formatText(getFuncText(cellPlaceholder), 1))
530
- : h('span', formatText(cellValue, 1))
531
- ]
532
- )
533
- ])
534
- },
535
- renderDeepCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
536
- return Cell.renderDeepNodeBtn(params, Cell.renderDefaultCell(params) as VNode[])
537
- },
538
- renderDefaultFooter (params: VxeTableDefines.CellRenderFooterParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
539
- return getFooterContent(params)
540
- },
541
-
542
- /**
543
- * 行分组
544
- */
545
- renderRowGroupBtn (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, cellVNodes: VxeComponentSlotType[]) {
546
- const { $table } = params
547
- const tableReactData = $table.reactData
548
- const tableInternalData = $table.internalData
549
- const { row, level } = params
550
- const { computeAggregateOpts } = $table.getComputeMaps()
551
- const { rowGroupExpandedFlag } = tableReactData
552
- const { rowGroupExpandedMaps } = tableInternalData
553
- const aggregateOpts = computeAggregateOpts.value
554
- const { mode, padding, indent, showIcon, iconOpen, iconClose } = aggregateOpts
555
- const rowid = getRowid($table, row)
556
- const isExpand = !!rowGroupExpandedFlag && !!rowGroupExpandedMaps[rowid]
557
- return h('div', {
558
- class: ['vxe-row-group--tree-node', {
559
- 'is--expanded': isExpand
560
- }],
561
- style: mode !== 'column' && padding && indent
562
- ? {
563
- paddingLeft: `${level * indent}px`
564
- }
565
- : undefined
566
- }, [
567
- showIcon && row.isAggregate
568
- ? h('span', {
569
- class: 'vxe-row-group--node-btn',
570
- onClick (evnt: MouseEvent) {
571
- $table.triggerRowGroupExpandEvent(evnt, params)
572
- }
573
- }, [
574
- h('i', {
575
- class: isExpand ? (iconOpen || getIcon().TABLE_ROW_GROUP_OPEN) : (iconClose || getIcon().TABLE_ROW_GROUP_CLOSE)
576
- })
577
- ])
578
- : renderEmptyElement($table),
579
- h('div', {
580
- class: 'vxe-row-group-cell'
581
- }, cellVNodes)
582
- ])
583
- },
584
- /**
585
- * 树
586
- */
587
- renderTreeNodeBtn (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, cellVNodes: VxeComponentSlotType[]) {
588
- const { $table, isHidden } = params
589
- const tableReactData = $table.reactData
590
- const tableInternalData = $table.internalData
591
- const { row, column, level } = params
592
- const { slots } = column
593
- const iconSlot = slots ? slots.icon : null
594
- if (iconSlot) {
595
- return $table.callSlot(iconSlot, params)
596
- }
597
- const { computeTreeOpts } = $table.getComputeMaps()
598
- const { treeExpandedFlag } = tableReactData
599
- const { fullAllDataRowIdData, treeExpandedMaps, treeExpandLazyLoadedMaps } = tableInternalData
600
- const treeOpts = computeTreeOpts.value
601
- const { padding, indent, lazy, trigger, visibleMethod, iconLoaded, showIcon, iconOpen, iconClose } = treeOpts
602
- const childrenField = treeOpts.children || treeOpts.childrenField
603
- const hasChildField = treeOpts.hasChild || treeOpts.hasChildField
604
- const rowChilds = row[childrenField]
605
- const hasChild = rowChilds && rowChilds.length
606
- let hasLazyChilds = false
607
- let isActive = false
608
- let isLazyLoading = false
609
- let isLazyLoaded = false
610
- const ons: Record<string, any> = {}
611
- if (!isHidden) {
612
- const rowid = getRowid($table, row)
613
- isActive = !!treeExpandedFlag && !!treeExpandedMaps[rowid]
614
- if (lazy) {
615
- const rest = fullAllDataRowIdData[rowid]
616
- isLazyLoading = !!treeExpandLazyLoadedMaps[rowid]
617
- hasLazyChilds = row[hasChildField]
618
- isLazyLoaded = !!rest.treeLoaded
619
- }
620
- }
621
- if (!trigger || trigger === 'default') {
622
- ons.onClick = (evnt: MouseEvent) => {
623
- $table.triggerTreeExpandEvent(evnt, params)
624
- }
625
- }
626
- return h('div', {
627
- class: ['vxe-cell--tree-node', {
628
- 'is--active': isActive
629
- }],
630
- style: padding && indent
631
- ? {
632
- paddingLeft: `${level * indent}px`
633
- }
634
- : undefined
635
- }, [
636
- showIcon && (lazy ? (isLazyLoaded ? hasChild : (hasChild || hasLazyChilds)) : hasChild) && (!visibleMethod || visibleMethod(params))
637
- ? [
638
- h('div', {
639
- class: 'vxe-cell--tree-btn',
640
- ...ons
641
- }, [
642
- h('i', {
643
- class: isLazyLoading ? (iconLoaded || getIcon().TABLE_TREE_LOADED) : (isActive ? (iconOpen || getIcon().TABLE_TREE_OPEN) : (iconClose || getIcon().TABLE_TREE_CLOSE))
644
- })
645
- ])
646
- ]
647
- : null,
648
- h('div', {
649
- class: 'vxe-tree-cell'
650
- }, cellVNodes)
651
- ])
652
- },
653
- /**
654
- * 层级节点。
655
- * 行分组、树结构
656
- */
657
- renderDeepNodeBtn (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, cellVNodes: VxeComponentSlotType[]) {
658
- const { $table, row, column } = params
659
- const { rowGroupNode } = column
660
- const tableReactData = $table.reactData
661
- const { rowGroupList } = tableReactData
662
- if (rowGroupList.length) {
663
- const { computeAggregateOpts } = $table.getComputeMaps()
664
- const aggregateOpts = computeAggregateOpts.value
665
- const { mode } = aggregateOpts
666
- if (mode === 'column') {
667
- if (row.groupField && column.field === row.groupField) {
668
- return [Cell.renderRowGroupBtn(params, cellVNodes)]
669
- }
670
- return cellVNodes
671
- } else if (rowGroupNode) {
672
- return [Cell.renderRowGroupBtn(params, cellVNodes)]
673
- }
674
- }
675
- return [Cell.renderTreeNodeBtn(params, cellVNodes)]
676
- },
677
-
678
- /**
679
- * 序号
680
- */
681
- renderSeqHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
682
- const { $table, column } = params
683
-
684
- // 兼容已废弃方式
685
- if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
686
- const { slots } = column
687
- const headerSlot = slots ? slots.header : null
688
- return renderHeaderCellBaseVNs(params, renderTitleContent(params, headerSlot ? $table.callSlot(headerSlot, params) : $table.getHeaderCellLabel(column)))
689
- }
690
-
691
- return renderHeaderCellBaseVNs(params, renderTitleContent(params, $table.getHeaderCellLabel(column)))
692
- },
693
- renderSeqCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
694
- const { $table, column } = params
695
- const tableProps = $table.props
696
- const { treeConfig } = tableProps
697
- const { computeSeqOpts } = $table.getComputeMaps()
698
- const seqOpts = computeSeqOpts.value
699
- const { slots } = column
700
- const defaultSlot = slots ? slots.default : null
701
- if (defaultSlot) {
702
- return renderCellBaseVNs(params, $table.callSlot(defaultSlot, params))
703
- }
704
- const { seq } = params
705
- const seqMd = seqOpts.seqMethod
706
- return renderCellBaseVNs(params, [
707
- h('span', `${formatText(seqMd ? seqMd(params) : treeConfig ? seq : (seqOpts.startIndex || 0) + (seq as number), 1)}`)
708
- ])
709
- },
710
- renderDeepIndexCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
711
- return Cell.renderDeepNodeBtn(params, Cell.renderSeqCell(params) as VNode[])
712
- },
713
-
714
- /**
715
- * 单选
716
- */
717
- renderRadioHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
718
- const { $table, column } = params
719
- const { slots } = column
720
- const titleSlot = slots ? slots.title : null
721
-
722
- // 兼容已废弃方式
723
- if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
724
- const headerSlot = slots ? slots.header : null
725
- return renderHeaderCellBaseVNs(params,
726
- renderTitleContent(params, headerSlot
727
- ? $table.callSlot(headerSlot, params)
728
- : [
729
- h('span', {
730
- class: 'vxe-radio--label'
731
- }, titleSlot ? $table.callSlot(titleSlot, params) : $table.getHeaderCellLabel(column))
732
- ])
733
- )
734
- }
735
-
736
- return renderHeaderCellBaseVNs(params,
737
- renderTitleContent(params, [
738
- h('span', {
739
- class: 'vxe-radio--label'
740
- }, titleSlot ? $table.callSlot(titleSlot, params) : $table.getHeaderCellLabel(column))
741
- ])
742
- )
743
- },
744
- renderRadioCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
745
- const { $table, column, isHidden } = params
746
- const tableReactData = $table.reactData
747
- const { computeRadioOpts } = $table.getComputeMaps()
748
- const { selectRadioRow } = tableReactData
749
- const radioOpts = computeRadioOpts.value
750
- const { slots } = column
751
- const { labelField, checkMethod, visibleMethod } = radioOpts
752
- const { row } = params
753
- const defaultSlot = slots ? slots.default : null
754
- const radioSlot = slots ? slots.radio : null
755
- const isChecked = $table.eqRow(row, selectRadioRow)
756
- const isVisible = !visibleMethod || visibleMethod({ $table, row })
757
- let isDisabled = !!checkMethod
758
- let ons
759
- if (!isHidden) {
760
- ons = {
761
- onClick (evnt: Event) {
762
- if (!isDisabled && isVisible) {
763
- $table.triggerRadioRowEvent(evnt, params)
764
- }
765
- }
766
- }
767
- if (checkMethod) {
768
- isDisabled = !checkMethod({ $table, row })
769
- }
770
- }
771
- const radioParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible }
772
- if (radioSlot) {
773
- return renderCellBaseVNs(params, $table.callSlot(radioSlot, radioParams))
774
- }
775
- const radioVNs: VNode[] = []
776
- if (isVisible) {
777
- radioVNs.push(
778
- h('span', {
779
- class: ['vxe-radio--icon', isChecked ? getIcon().TABLE_RADIO_CHECKED : (isDisabled ? getIcon().TABLE_RADIO_DISABLED_UNCHECKED : getIcon().TABLE_RADIO_UNCHECKED)]
780
- })
781
- )
782
- }
783
- if (defaultSlot || labelField) {
784
- radioVNs.push(
785
- h('span', {
786
- class: 'vxe-radio--label'
787
- }, defaultSlot ? $table.callSlot(defaultSlot, radioParams) : XEUtils.get(row, labelField as string))
788
- )
789
- }
790
- return renderCellBaseVNs(params, [
791
- h('span', {
792
- class: ['vxe-cell--radio', {
793
- 'is--checked': isChecked,
794
- 'is--disabled': isDisabled
795
- }],
796
- ...ons
797
- }, radioVNs)
798
- ])
799
- },
800
- renderDeepRadioCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
801
- return Cell.renderDeepNodeBtn(params, Cell.renderRadioCell(params))
802
- },
803
-
804
- /**
805
- * 多选
806
- */
807
- renderCheckboxHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
808
- const { $table, column, isHidden } = params
809
- const tableReactData = $table.reactData
810
- const { computeIsAllCheckboxDisabled, computeCheckboxOpts } = $table.getComputeMaps()
811
- const { isAllSelected: isAllCheckboxSelected, isIndeterminate: isAllCheckboxIndeterminate } = tableReactData
812
- const isAllCheckboxDisabled = computeIsAllCheckboxDisabled.value
813
- const { slots } = column
814
- const titleSlot = slots ? slots.title : null
815
- const checkboxOpts = computeCheckboxOpts.value
816
- const { checkStrictly, showHeader, headerTitle } = checkboxOpts
817
- const colTitle = $table.getHeaderCellLabel(column)
818
- const ons: Record<string, any> = {}
819
- if (!isHidden) {
820
- ons.onClick = (evnt: MouseEvent) => {
821
- if (!isAllCheckboxDisabled) {
822
- $table.triggerCheckAllEvent(evnt, !isAllCheckboxSelected)
823
- }
824
- }
825
- }
826
- const checkboxParams = { ...params, checked: isAllCheckboxSelected, disabled: isAllCheckboxDisabled, indeterminate: isAllCheckboxIndeterminate }
827
-
828
- // 兼容已废弃方式
829
- if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
830
- const headerSlot = slots ? slots.header : null
831
- if (headerSlot) {
832
- return renderHeaderCellBaseVNs(params, renderTitleContent(checkboxParams, $table.callSlot(headerSlot, checkboxParams)))
833
- }
834
- }
835
-
836
- if (checkStrictly ? !showHeader : showHeader === false) {
837
- return renderHeaderCellBaseVNs(params, renderTitleContent(checkboxParams, [
838
- h('span', {
839
- class: 'vxe-checkbox--label'
840
- }, titleSlot ? $table.callSlot(titleSlot, checkboxParams) : colTitle)
841
- ]))
842
- }
843
- return renderHeaderCellBaseVNs(params,
844
- renderTitleContent(checkboxParams, [
845
- h('span', {
846
- class: ['vxe-cell--checkbox', {
847
- 'is--checked': isAllCheckboxSelected,
848
- 'is--disabled': isAllCheckboxDisabled,
849
- 'is--indeterminate': isAllCheckboxIndeterminate
850
- }],
851
- title: XEUtils.eqNull(headerTitle) ? getI18n('vxe.table.allTitle') : `${headerTitle || ''}`,
852
- ...ons
853
- }, [
854
- h('span', {
855
- class: ['vxe-checkbox--icon', isAllCheckboxIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : (isAllCheckboxSelected ? getIcon().TABLE_CHECKBOX_CHECKED : (isAllCheckboxDisabled ? getIcon().TABLE_CHECKBOX_DISABLED_UNCHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED))]
856
- })
857
- ].concat(titleSlot || colTitle
858
- ? [
859
- h('span', {
860
- class: 'vxe-checkbox--label'
861
- }, titleSlot ? $table.callSlot(titleSlot, checkboxParams) : colTitle)
862
- ]
863
- : []))
864
- ])
865
- )
866
- },
867
- renderCheckboxCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
868
- const { $table, row, column, isHidden } = params
869
- const tableProps = $table.props
870
- const tableReactData = $table.reactData
871
- const tableInternalData = $table.internalData
872
- const { treeConfig } = tableProps
873
- const { updateCheckboxFlag, isRowGroupStatus } = tableReactData
874
- const { selectCheckboxMaps, treeIndeterminateRowMaps } = tableInternalData
875
- const { computeCheckboxOpts, computeAggregateOpts } = $table.getComputeMaps()
876
- const aggregateOpts = computeAggregateOpts.value
877
- const { mapChildrenField } = aggregateOpts
878
- const checkboxOpts = computeCheckboxOpts.value
879
- const { labelField, checkMethod, visibleMethod } = checkboxOpts
880
- const { slots } = column
881
- const defaultSlot = slots ? slots.default : null
882
- const checkboxSlot = slots ? slots.checkbox : null
883
- let indeterminate = false
884
- let isChecked = false
885
- let isVisible = true
886
- let isDisabled = false
887
- const ons: Record<string, any> = {}
888
- if (!isHidden) {
889
- const rowid = getRowid($table, row)
890
- isChecked = !!updateCheckboxFlag && !!selectCheckboxMaps[rowid]
891
- if (checkMethod && isRowGroupStatus && $table.isAggregateRecord(row)) {
892
- const childList: any[] = row[mapChildrenField || '']
893
- if (!childList || !childList.length || childList.every(item => !checkMethod({ $table, row: item }))) {
894
- isDisabled = true
895
- }
896
- } else {
897
- isVisible = !visibleMethod || visibleMethod({ $table, row })
898
- isDisabled = checkMethod ? !checkMethod({ $table, row }) : !!checkMethod
899
- }
900
- if (treeConfig || isRowGroupStatus) {
901
- indeterminate = !!treeIndeterminateRowMaps[rowid]
902
- }
903
- ons.onClick = (evnt: MouseEvent) => {
904
- if (!isDisabled && isVisible) {
905
- $table.triggerCheckRowEvent(evnt, params, !isChecked)
906
- }
907
- }
908
- }
909
- const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible, indeterminate }
910
- if (checkboxSlot) {
911
- return renderCellBaseVNs(params, $table.callSlot(checkboxSlot, checkboxParams))
912
- }
913
- const checkVNs: VNode[] = []
914
- if (isVisible) {
915
- checkVNs.push(
916
- h('span', {
917
- class: ['vxe-checkbox--icon', indeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : (isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : (isDisabled ? getIcon().TABLE_CHECKBOX_DISABLED_UNCHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED))]
918
- })
919
- )
920
- }
921
- if (defaultSlot || labelField) {
922
- checkVNs.push(
923
- h('span', {
924
- class: 'vxe-checkbox--label'
925
- }, defaultSlot ? $table.callSlot(defaultSlot, checkboxParams) : XEUtils.get(row, labelField as string))
926
- )
927
- }
928
- return renderCellBaseVNs(params, [
929
- h('span', {
930
- class: ['vxe-cell--checkbox', {
931
- 'is--checked': isChecked,
932
- 'is--disabled': isDisabled,
933
- 'is--indeterminate': indeterminate,
934
- 'is--hidden': !isVisible
935
- }],
936
- ...ons
937
- }, checkVNs)
938
- ])
939
- },
940
- renderDeepSelectionCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
941
- return Cell.renderDeepNodeBtn(params, Cell.renderCheckboxCell(params))
942
- },
943
- renderCheckboxCellByProp (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
944
- const { $table, row, column, isHidden } = params
945
- const tableProps = $table.props
946
- const tableReactData = $table.reactData
947
- const tableInternalData = $table.internalData
948
- const { treeConfig } = tableProps
949
- const { updateCheckboxFlag, isRowGroupStatus } = tableReactData
950
- const { treeIndeterminateRowMaps } = tableInternalData
951
- const { computeCheckboxOpts, computeAggregateOpts } = $table.getComputeMaps()
952
- const aggregateOpts = computeAggregateOpts.value
953
- const { mapChildrenField } = aggregateOpts
954
- const checkboxOpts = computeCheckboxOpts.value
955
- const { labelField, checkField, checkMethod, visibleMethod } = checkboxOpts
956
- const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
957
- const { slots } = column
958
- const defaultSlot = slots ? slots.default : null
959
- const checkboxSlot = slots ? slots.checkbox : null
960
- let indeterminate = false
961
- let isChecked = false
962
- let isVisible = true
963
- let isDisabled = false
964
- const ons: Record<string, any> = {}
965
- if (!isHidden) {
966
- const rowid = getRowid($table, row)
967
- isChecked = !!updateCheckboxFlag && XEUtils.get(row, checkField)
968
- if (checkMethod && isRowGroupStatus && $table.isAggregateRecord(row)) {
969
- const childList: any[] = row[mapChildrenField || '']
970
- if (!childList || !childList.length || childList.every(item => !checkMethod({ $table, row: item }))) {
971
- isDisabled = true
972
- }
973
- } else {
974
- isVisible = !visibleMethod || visibleMethod({ $table, row })
975
- isDisabled = checkMethod ? !checkMethod({ $table, row }) : !!checkMethod
976
- }
977
- if (treeConfig || isRowGroupStatus) {
978
- indeterminate = !!treeIndeterminateRowMaps[rowid]
979
- }
980
- ons.onClick = (evnt: MouseEvent) => {
981
- if (!isDisabled && isVisible) {
982
- $table.triggerCheckRowEvent(evnt, params, !isChecked)
983
- }
984
- }
985
- }
986
- const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible, indeterminate }
987
- if (checkboxSlot) {
988
- return renderCellBaseVNs(params, $table.callSlot(checkboxSlot, checkboxParams))
989
- }
990
- const checkVNs: VNode[] = []
991
- if (isVisible) {
992
- checkVNs.push(
993
- h('span', {
994
- class: ['vxe-checkbox--icon', indeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : (isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : (isDisabled ? getIcon().TABLE_CHECKBOX_DISABLED_UNCHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED))]
995
- })
996
- )
997
- if (defaultSlot || labelField) {
998
- checkVNs.push(
999
- h('span', {
1000
- class: 'vxe-checkbox--label'
1001
- }, defaultSlot ? $table.callSlot(defaultSlot, checkboxParams) : XEUtils.get(row, labelField as string))
1002
- )
1003
- }
1004
- }
1005
- return renderCellBaseVNs(params, [
1006
- h('span', {
1007
- class: ['vxe-cell--checkbox', {
1008
- 'is--checked': isChecked,
1009
- 'is--disabled': isDisabled,
1010
- 'is--indeterminate': indeterminateField && !isChecked ? row[indeterminateField] : indeterminate,
1011
- 'is--hidden': !isVisible
1012
- }],
1013
- ...ons
1014
- }, checkVNs)
1015
- ])
1016
- },
1017
- renderDeepSelectionCellByProp (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1018
- return Cell.renderDeepNodeBtn(params, Cell.renderCheckboxCellByProp(params))
1019
- },
1020
-
1021
- /**
1022
- * 展开行
1023
- */
1024
- renderExpandCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1025
- const { $table, isHidden, row, column } = params
1026
- const tableReactData = $table.reactData
1027
- const tableInternalData = $table.internalData
1028
- const { isRowGroupStatus } = tableReactData
1029
- const { rowExpandedMaps, rowExpandLazyLoadedMaps } = tableInternalData
1030
- const { computeExpandOpts } = $table.getComputeMaps()
1031
- const expandOpts = computeExpandOpts.value
1032
- const { lazy, labelField, iconLoaded, showIcon, iconOpen, iconClose, visibleMethod } = expandOpts
1033
- const { slots } = column
1034
- const defaultSlot = slots ? slots.default : null
1035
- const iconSlot = slots ? slots.icon : null
1036
- let isActive = false
1037
- let isLazyLoading = false
1038
- if (isRowGroupStatus && row.isAggregate) {
1039
- return renderCellBaseVNs(params, [])
1040
- }
1041
- if (iconSlot) {
1042
- return renderCellBaseVNs(params, $table.callSlot(iconSlot, params))
1043
- }
1044
- if (!isHidden) {
1045
- const rowid = getRowid($table, row)
1046
- isActive = !!rowExpandedMaps[rowid]
1047
- if (lazy) {
1048
- isLazyLoading = !!rowExpandLazyLoadedMaps[rowid]
1049
- }
1050
- }
1051
- return renderCellBaseVNs(params, [
1052
- showIcon && (!visibleMethod || visibleMethod(params))
1053
- ? h('div', {
1054
- class: ['vxe-table--expanded', {
1055
- 'is--active': isActive
1056
- }]
1057
- }, [
1058
- h('span', {
1059
- class: 'vxe-table--expand-btn',
1060
- onMousedown (evnt) {
1061
- evnt.stopPropagation()
1062
- },
1063
- onClick (evnt: MouseEvent) {
1064
- $table.triggerRowExpandEvent(evnt, params)
1065
- }
1066
- }, [
1067
- h('i', {
1068
- class: isLazyLoading ? (iconLoaded || getIcon().TABLE_EXPAND_LOADED) : (isActive ? (iconOpen || getIcon().TABLE_EXPAND_OPEN) : (iconClose || getIcon().TABLE_EXPAND_CLOSE))
1069
- })
1070
- ])
1071
- ])
1072
- : renderEmptyElement($table),
1073
- defaultSlot || labelField
1074
- ? h('div', {
1075
- class: 'vxe-table--expand-label'
1076
- }, defaultSlot ? $table.callSlot(defaultSlot, params) : XEUtils.get(row, labelField as string))
1077
- : renderEmptyElement($table)
1078
- ])
1079
- },
1080
- renderExpandData (params: VxeTableDefines.CellRenderDataParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1081
- const { $table, column } = params
1082
- const { slots, contentRender } = column
1083
- const contentSlot = slots ? slots.content : null
1084
- if (contentSlot) {
1085
- return $table.callSlot(contentSlot, params)
1086
- }
1087
- if (contentRender) {
1088
- const { computeRendererOpts } = $table.getComputeMaps()
1089
- const rendererOpts = computeRendererOpts.value
1090
- const compConf = contentRender.name ? (rendererOpts[contentRender.name] || renderer.get(contentRender.name)) : null
1091
- if (compConf) {
1092
- const rtExpand = compConf.renderTableExpand || compConf.renderExpand
1093
- if (rtExpand) {
1094
- return getSlotVNs(rtExpand(contentRender, params))
1095
- }
1096
- }
1097
- }
1098
- return []
1099
- },
1100
-
1101
- /**
1102
- * HTML 标签
1103
- */
1104
- renderHTMLCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1105
- const { $table, column } = params
1106
- const { slots } = column
1107
- const defaultSlot = slots ? slots.default : null
1108
- if (defaultSlot) {
1109
- return renderCellBaseVNs(params, $table.callSlot(defaultSlot, params))
1110
- }
1111
- return renderCellBaseVNs(params, [
1112
- h('span', {
1113
- class: 'vxe-cell--html',
1114
- innerHTML: getDefaultCellLabel(params)
1115
- })
1116
- ])
1117
- },
1118
- renderDeepHTMLCell (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1119
- return Cell.renderDeepNodeBtn(params, Cell.renderHTMLCell(params))
1120
- },
1121
-
1122
- /**
1123
- * 排序和筛选
1124
- */
1125
- renderSortAndFilterHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1126
- return renderHeaderCellBaseVNs(
1127
- params,
1128
- Cell.renderHeaderTitle(params).concat(Cell.renderSortIcon(params).concat(Cell.renderFilterIcon(params)))
1129
- )
1130
- },
1131
-
1132
- /**
1133
- * 排序
1134
- */
1135
- renderSortHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1136
- return renderHeaderCellBaseVNs(
1137
- params,
1138
- Cell.renderHeaderTitle(params).concat(Cell.renderSortIcon(params))
1139
- )
1140
- },
1141
- renderSortIcon (params: (VxeTableDefines.CellRenderHeaderParams | VxeTableDefines.CellRenderHeaderParams) & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1142
- const { $table, column } = params
1143
- const { computeSortOpts } = $table.getComputeMaps()
1144
- const sortOpts = computeSortOpts.value
1145
- const { showIcon, allowBtn, ascTitle, descTitle, iconLayout, iconAsc, iconDesc, iconVisibleMethod } = sortOpts
1146
- const { order, slots } = column
1147
- if (showIcon && (!iconVisibleMethod || iconVisibleMethod(params))) {
1148
- const sortSlot = slots ? slots.sort : null
1149
- return sortSlot
1150
- ? getSlotVNs($table.callSlot(sortSlot, params)) as VNode[]
1151
- : [
1152
- h('span', {
1153
- class: ['vxe-cell--sort', `vxe-cell--sort-${iconLayout}-layout`]
1154
- }, [
1155
- h('i', {
1156
- class: ['vxe-sort--asc-btn', iconAsc || getIcon().TABLE_SORT_ASC, {
1157
- 'sort--active': order === 'asc'
1158
- }],
1159
- title: XEUtils.eqNull(ascTitle) ? getI18n('vxe.table.sortAsc') : `${ascTitle || ''}`,
1160
- onClick: allowBtn
1161
- ? (evnt: Event) => {
1162
- evnt.stopPropagation()
1163
- $table.triggerSortEvent(evnt, column, 'asc')
1164
- }
1165
- : undefined
1166
- }),
1167
- h('i', {
1168
- class: ['vxe-sort--desc-btn', iconDesc || getIcon().TABLE_SORT_DESC, {
1169
- 'sort--active': order === 'desc'
1170
- }],
1171
- title: XEUtils.eqNull(descTitle) ? getI18n('vxe.table.sortDesc') : `${descTitle || ''}`,
1172
- onClick: allowBtn
1173
- ? (evnt: Event) => {
1174
- evnt.stopPropagation()
1175
- $table.triggerSortEvent(evnt, column, 'desc')
1176
- }
1177
- : undefined
1178
- })
1179
- ])
1180
- ]
1181
- }
1182
- return []
1183
- },
1184
-
1185
- /**
1186
- * 筛选
1187
- */
1188
- renderFilterHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1189
- return renderHeaderCellBaseVNs(params, Cell.renderHeaderTitle(params).concat(Cell.renderFilterIcon(params)))
1190
- },
1191
- renderFilterIcon (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1192
- const { $table, column, hasFilter } = params
1193
- const tableReactData = $table.reactData
1194
- const { filterStore } = tableReactData
1195
- const { computeFilterOpts } = $table.getComputeMaps()
1196
- const filterOpts = computeFilterOpts.value
1197
- const { showIcon, iconNone, iconMatch, iconVisibleMethod } = filterOpts
1198
- if (showIcon && (!iconVisibleMethod || iconVisibleMethod(params))) {
1199
- return [
1200
- h('span', {
1201
- class: ['vxe-cell--filter', {
1202
- 'is--active': filterStore.visible && filterStore.column === column
1203
- }],
1204
- onClick (evnt) {
1205
- if ($table.triggerFilterEvent) {
1206
- $table.triggerFilterEvent(evnt, params.column, params)
1207
- }
1208
- }
1209
- }, [
1210
- h('i', {
1211
- class: ['vxe-filter--btn', hasFilter ? (iconMatch || getIcon().TABLE_FILTER_MATCH) : (iconNone || getIcon().TABLE_FILTER_NONE)],
1212
- title: getI18n('vxe.table.filter')
1213
- })
1214
- ])
1215
- ]
1216
- }
1217
- return []
1218
- },
1219
-
1220
- /**
1221
- * 可编辑
1222
- */
1223
- renderEditHeader (params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1224
- const { $table, column } = params
1225
- const tableProps = $table.props
1226
- const { computeEditOpts } = $table.getComputeMaps()
1227
- const { editConfig, editRules } = tableProps
1228
- const editOpts = computeEditOpts.value
1229
- const { sortable, filters, editRender } = column
1230
- const isEnableEdit = editConfig && isEnableConf(editConfig)
1231
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1232
- let isRequired = false
1233
- if (editRules) {
1234
- const columnRules = column.rules ? column.rules : XEUtils.get(editRules, column.field)
1235
- if (columnRules) {
1236
- isRequired = columnRules.some((rule) => rule.required)
1237
- }
1238
- }
1239
- let editIconVNs: VNode[] = []
1240
- if (isEnableEdit) {
1241
- const { showAsterisk, showIcon, icon } = editOpts
1242
- editIconVNs = [
1243
- isRequired && showAsterisk
1244
- ? h('span', {
1245
- class: 'vxe-cell--required-icon'
1246
- }, [
1247
- h('i')
1248
- ])
1249
- : renderEmptyElement($table),
1250
- editRenderOpts && showIcon
1251
- ? h('span', {
1252
- class: 'vxe-cell--edit-icon'
1253
- }, XEUtils.isFunction(icon)
1254
- ? getSlotVNs(icon({}))
1255
- : [
1256
- h('i', {
1257
- class: icon || getIcon().TABLE_EDIT
1258
- })
1259
- ])
1260
- : renderEmptyElement($table)
1261
- ]
1262
- }
1263
- return renderHeaderCellBaseVNs(params,
1264
- editIconVNs.concat(Cell.renderHeaderTitle(params))
1265
- .concat(sortable ? Cell.renderSortIcon(params) : [])
1266
- .concat(filters ? Cell.renderFilterIcon(params) : [])
1267
- )
1268
- },
1269
- // 行格编辑模式
1270
- renderRowEdit (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1271
- const { $table, column } = params
1272
- const tableProps = $table.props
1273
- const { editConfig } = tableProps
1274
- const tableReactData = $table.reactData
1275
- const { editStore } = tableReactData
1276
- const { actived } = editStore
1277
- const { editRender } = column
1278
- const isEnableEdit = editConfig && isEnableConf(editConfig)
1279
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1280
- return Cell.runRenderer(params, !!(editRenderOpts && actived && actived.row === params.row))
1281
- },
1282
- renderDeepRowEdit (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1283
- return Cell.renderDeepNodeBtn(params, Cell.renderRowEdit(params) as VNode[])
1284
- },
1285
- // 单元格编辑模式
1286
- renderCellEdit (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1287
- const { $table, column } = params
1288
- const tableProps = $table.props
1289
- const { editConfig } = tableProps
1290
- const tableReactData = $table.reactData
1291
- const { editStore } = tableReactData
1292
- const { actived } = editStore
1293
- const { editRender } = column
1294
- const isEnableEdit = editConfig && isEnableConf(editConfig)
1295
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1296
- return Cell.runRenderer(params, !!(editRenderOpts && actived && actived.row === params.row && actived.column === params.column))
1297
- },
1298
- renderDeepCellEdit (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1299
- return Cell.renderDeepNodeBtn(params, Cell.renderCellEdit(params) as VNode[])
1300
- },
1301
- runRenderer (params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, isEdit: boolean) {
1302
- const { $table, row, column } = params
1303
- const tableProps = $table.props
1304
- const { editConfig } = tableProps
1305
- const tableReactData = $table.reactData
1306
- const { isRowGroupStatus } = tableReactData
1307
- const { slots, field, editRender, formatter } = column
1308
- const isEnableEdit = editConfig && isEnableConf(editConfig)
1309
- const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1310
- const defaultSlot = slots ? slots.default : null
1311
- const gcSlot = slots ? (slots.groupContent || slots['group-content']) : null
1312
- const editSlot = slots ? slots.edit : null
1313
- const cellParams = Object.assign({ $type: '', isEdit }, params)
1314
- if (isEdit && editRenderOpts) {
1315
- cellParams.$type = 'edit'
1316
- if (editSlot) {
1317
- return $table.callSlot(editSlot, cellParams)
1318
- }
1319
- const { computeRendererOpts } = $table.getComputeMaps()
1320
- const rendererOpts = computeRendererOpts.value
1321
- const compConf = editRenderOpts.name ? (rendererOpts[editRenderOpts.name] || renderer.get(editRenderOpts.name)) : null
1322
- const rtEdit = compConf ? (compConf.renderTableEdit || compConf.renderEdit) : null
1323
- if (rtEdit) {
1324
- return getSlotVNs(rtEdit(editRenderOpts, cellParams))
1325
- }
1326
- return []
1327
- }
1328
-
1329
- if (isRowGroupStatus && field && row.isAggregate) {
1330
- const aggRow: VxeTableDefines.AggregateRowInfo = row
1331
- const { computeAggregateOpts } = $table.getComputeMaps()
1332
- const aggregateOpts = computeAggregateOpts.value
1333
- const { mapChildrenField } = aggregateOpts
1334
- const groupField = aggRow.groupField
1335
- const groupContent = aggRow.groupContent
1336
- const childList = mapChildrenField ? (aggRow[mapChildrenField] || []) : []
1337
- const childCount = aggRow.childCount
1338
- if (gcSlot) {
1339
- return renderCellBaseVNs(params, $table.callSlot(gcSlot, Object.assign({ groupField, groupContent, childList, childCount }, params)))
1340
- }
1341
- } else {
1342
- if (defaultSlot) {
1343
- return renderCellBaseVNs(params, $table.callSlot(defaultSlot, cellParams))
1344
- }
1345
- }
1346
-
1347
- // slot default > formatter
1348
- if (formatter) {
1349
- return renderCellBaseVNs(params, [
1350
- h('span', {
1351
- class: 'vxe-cell--label'
1352
- }, getDefaultCellLabel(cellParams))
1353
- ])
1354
- }
1355
- return Cell.renderDefaultCell(cellParams)
1356
- }
1357
- }
1358
-
1359
- export default Cell
1
+ import { h, VNode } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import { VxeUI } from '@vxe-ui/core'
4
+ import { getFuncText, isEnableConf, formatText, eqEmptyValue } from '../../ui/src/utils'
5
+ import { updateCellTitle } from '../../ui/src/dom'
6
+ import { createColumn, getRowid } from './util'
7
+ import { getSlotVNs } from '../../ui/src/vn'
8
+
9
+ import type { VxeTableConstructor, VxeTableDefines, VxeTablePrivateMethods, VxeComponentSlotType } from '../../../types'
10
+
11
+ const { getConfig, getI18n, getIcon, renderer, renderEmptyElement } = VxeUI
12
+
13
+ function renderTitlePrefixIcon(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
14
+ const { $table, column } = params
15
+ const titlePrefix = column.titlePrefix || column.titleHelp
16
+ if (titlePrefix) {
17
+ return h(
18
+ 'span',
19
+ {
20
+ class: ['vxe-cell-title-prefix-icon', titlePrefix.iconStatus ? `theme--${titlePrefix.iconStatus}` : ''],
21
+ onMouseenter(evnt: MouseEvent) {
22
+ $table.triggerHeaderTitleEvent(evnt, titlePrefix, params)
23
+ },
24
+ onMouseleave(evnt: MouseEvent) {
25
+ $table.handleTargetLeaveEvent(evnt)
26
+ }
27
+ },
28
+ [
29
+ h('i', {
30
+ class: titlePrefix.icon || getIcon().TABLE_TITLE_PREFIX
31
+ })
32
+ ]
33
+ )
34
+ }
35
+ return renderEmptyElement($table)
36
+ }
37
+
38
+ function renderTitleSuffixIcon(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
39
+ const { $table, column } = params
40
+ const titleSuffix = column.titleSuffix
41
+ if (titleSuffix) {
42
+ return h(
43
+ 'span',
44
+ {
45
+ class: ['vxe-cell-title-suffix-icon', titleSuffix.iconStatus ? `theme--${titleSuffix.iconStatus}` : ''],
46
+ onMouseenter(evnt: MouseEvent) {
47
+ $table.triggerHeaderTitleEvent(evnt, titleSuffix, params)
48
+ },
49
+ onMouseleave(evnt: MouseEvent) {
50
+ $table.handleTargetLeaveEvent(evnt)
51
+ }
52
+ },
53
+ [
54
+ h('i', {
55
+ class: titleSuffix.icon || getIcon().TABLE_TITLE_SUFFIX
56
+ })
57
+ ]
58
+ )
59
+ }
60
+ return renderEmptyElement($table)
61
+ }
62
+
63
+ function renderCellDragIcon(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
64
+ const { $table, column } = params
65
+ const { context } = $table
66
+ const tableSlots = context.slots
67
+ const tableProps = $table.props
68
+ const { slots } = column
69
+ const { dragConfig } = tableProps
70
+ const { computeRowDragOpts } = $table.getComputeMaps()
71
+ const rowDragOpts = computeRowDragOpts.value
72
+ const { icon, trigger, disabledMethod } = rowDragOpts
73
+ const rDisabledMethod = disabledMethod || (dragConfig ? dragConfig.rowDisabledMethod : null)
74
+ const isDisabled = rDisabledMethod && rDisabledMethod(params)
75
+ const rowDragIconSlot = (slots ? slots.rowDragIcon || slots['row-drag-icon'] : null) || tableSlots.rowDragIcon || tableSlots['row-drag-icon']
76
+ const ons: Record<string, any> = {}
77
+ if (trigger !== 'cell') {
78
+ ons.onMousedown = (evnt: MouseEvent) => {
79
+ if (!isDisabled) {
80
+ $table.handleCellDragMousedownEvent(evnt, params)
81
+ }
82
+ }
83
+ ons.onMouseup = $table.handleCellDragMouseupEvent
84
+ }
85
+ return h(
86
+ 'span',
87
+ {
88
+ key: 'dg',
89
+ class: [
90
+ 'vxe-cell--drag-handle',
91
+ {
92
+ 'is--disabled': isDisabled
93
+ }
94
+ ],
95
+ ...ons
96
+ },
97
+ rowDragIconSlot
98
+ ? $table.callSlot(rowDragIconSlot, params)
99
+ : [
100
+ h('i', {
101
+ class: icon || (dragConfig ? dragConfig.rowIcon : '') || getIcon().TABLE_DRAG_ROW
102
+ })
103
+ ]
104
+ )
105
+ }
106
+
107
+ function renderCellBaseVNs(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, content: VxeComponentSlotType | VxeComponentSlotType[]) {
108
+ const { $table, column, level } = params
109
+ const { dragSort } = column
110
+ const tableProps = $table.props
111
+ const { treeConfig, dragConfig } = tableProps
112
+ const { computeRowOpts, computeRowDragOpts, computeTreeOpts } = $table.getComputeMaps()
113
+ const rowOpts = computeRowOpts.value
114
+ const rowDragOpts = computeRowDragOpts.value
115
+ const treeOpts = computeTreeOpts.value
116
+ const { showIcon, isPeerDrag, isCrossDrag, visibleMethod } = rowDragOpts
117
+ const rVisibleMethod = visibleMethod || (dragConfig ? dragConfig.rowVisibleMethod : null)
118
+ const vns: VxeComponentSlotType[] = []
119
+ if (dragSort && rowOpts.drag && (showIcon || (dragConfig ? dragConfig.showRowIcon : false)) && (!rVisibleMethod || rVisibleMethod(params))) {
120
+ if (treeConfig) {
121
+ if (treeOpts.transform && (isPeerDrag || isCrossDrag || !level)) {
122
+ vns.push(renderCellDragIcon(params))
123
+ }
124
+ } else {
125
+ vns.push(renderCellDragIcon(params))
126
+ }
127
+ }
128
+ return vns.concat(XEUtils.isArray(content) ? content : [content])
129
+ }
130
+
131
+ function renderHeaderCellDragIcon(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
132
+ const { $table, column } = params
133
+ const { context } = $table
134
+ const tableSlots = context.slots
135
+ const { slots } = column
136
+ const { computeColumnOpts, computeColumnDragOpts } = $table.getComputeMaps()
137
+ const columnOpts = computeColumnOpts.value
138
+ const columnDragOpts = computeColumnDragOpts.value
139
+ const { showIcon, icon, trigger, isPeerDrag, isCrossDrag, visibleMethod, disabledMethod } = columnDragOpts
140
+ if (columnOpts.drag && showIcon && (!visibleMethod || visibleMethod(params))) {
141
+ if (!column.fixed && (isPeerDrag || isCrossDrag || !column.parentId)) {
142
+ const isDisabled = disabledMethod && disabledMethod(params)
143
+ const columnDragIconSlot = (slots ? slots.columnDragIcon || slots['column-drag-icon'] : null) || tableSlots.columnDragIcon || tableSlots['column-drag-icon']
144
+ const ons: Record<string, any> = {}
145
+ if (trigger !== 'cell') {
146
+ ons.onMousedown = (evnt: MouseEvent) => {
147
+ if (!isDisabled) {
148
+ $table.handleHeaderCellDragMousedownEvent(evnt, params)
149
+ }
150
+ }
151
+ ons.onMouseup = $table.handleHeaderCellDragMouseupEvent
152
+ }
153
+ return h(
154
+ 'span',
155
+ {
156
+ key: 'dg',
157
+ class: [
158
+ 'vxe-cell--drag-handle',
159
+ {
160
+ 'is--disabled': isDisabled
161
+ }
162
+ ],
163
+ ...ons
164
+ },
165
+ columnDragIconSlot
166
+ ? $table.callSlot(columnDragIconSlot, params)
167
+ : [
168
+ h('i', {
169
+ class: icon || getIcon().TABLE_DRAG_COLUMN
170
+ })
171
+ ]
172
+ )
173
+ }
174
+ }
175
+ return renderEmptyElement($table)
176
+ }
177
+
178
+ function renderHeaderCellBaseVNs(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, content: VNode | VNode[]) {
179
+ const vns = [renderTitlePrefixIcon(params), renderHeaderCellDragIcon(params), ...(XEUtils.isArray(content) ? content : [content]), renderTitleSuffixIcon(params)]
180
+ return vns
181
+ }
182
+
183
+ function getRenderDefaultColumnTitle(column: VxeTableDefines.ColumnInfo, content: VxeComponentSlotType | VxeComponentSlotType[]) {
184
+ if (column.type === 'html' && XEUtils.isString(content)) {
185
+ return h('span', {
186
+ key: 'ch',
187
+ innerHTML: content
188
+ })
189
+ }
190
+ return h(
191
+ 'span',
192
+ {
193
+ key: 'ct'
194
+ },
195
+ getSlotVNs(content)
196
+ )
197
+ }
198
+
199
+ function renderTitleContent(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, content: VxeComponentSlotType | VxeComponentSlotType[]) {
200
+ const { $table, column } = params
201
+ const tableProps = $table.props
202
+ const tableReactData = $table.reactData
203
+ const { computeHeaderTooltipOpts } = $table.getComputeMaps()
204
+ const { showHeaderOverflow: allColumnHeaderOverflow } = tableProps
205
+ const { isRowGroupStatus } = tableReactData
206
+ const { showHeaderOverflow, slots } = column
207
+ const titleSlot = slots ? slots.title : null
208
+ const headerTooltipOpts = computeHeaderTooltipOpts.value
209
+ const showAllTip = headerTooltipOpts.showAll
210
+ const headOverflow = XEUtils.eqNull(showHeaderOverflow) ? allColumnHeaderOverflow : showHeaderOverflow
211
+ const showTitle = (headOverflow === true ? headerTooltipOpts.mode : headOverflow) === 'title'
212
+ const showTooltip = (headOverflow === true ? headerTooltipOpts.mode : headOverflow) === 'tooltip'
213
+ const ons: Record<string, any> = {}
214
+ if (showTitle || showTooltip || showAllTip) {
215
+ ons.onMouseenter = (evnt: MouseEvent) => {
216
+ if (tableReactData.isDragResize) {
217
+ return
218
+ }
219
+ if (showTitle) {
220
+ updateCellTitle(evnt.currentTarget, column)
221
+ } else if (showTooltip || showAllTip) {
222
+ $table.triggerHeaderTooltipEvent(evnt, params)
223
+ }
224
+ }
225
+ }
226
+ if (showTooltip || showAllTip) {
227
+ ons.onMouseleave = (evnt: MouseEvent) => {
228
+ if (tableReactData.isDragResize) {
229
+ return
230
+ }
231
+ if (showTooltip || showAllTip) {
232
+ $table.handleTargetLeaveEvent(evnt)
233
+ }
234
+ }
235
+ }
236
+ const titleVN = getRenderDefaultColumnTitle(column, content)
237
+ return [
238
+ h(
239
+ 'span',
240
+ {
241
+ class: 'vxe-cell--title',
242
+ ...ons
243
+ },
244
+ isRowGroupStatus && column.aggFunc && $table.getPivotTableAggregateRenderColTitles ? $table.getPivotTableAggregateRenderColTitles(column, titleVN) : titleSlot ? $table.callSlot(titleSlot, params) : [titleVN]
245
+ )
246
+ ]
247
+ }
248
+
249
+ function getFooterContent(params: VxeTableDefines.CellRenderFooterParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
250
+ const { $table, column, row } = params
251
+ const tableProps = $table.props
252
+ const { editConfig } = tableProps
253
+ const { slots, editRender, cellRender } = column
254
+ const footerSlot = slots ? slots.footer : null
255
+ if (footerSlot) {
256
+ return $table.callSlot(footerSlot, params)
257
+ }
258
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
259
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
260
+ const cellRenderOpts = isEnableConf(cellRender) ? cellRender : null
261
+ const renderOpts = editRenderOpts || cellRenderOpts
262
+ const itemValue = $table.getFooterCellLabel(row, column)
263
+ if (renderOpts) {
264
+ const { computeRendererOpts } = $table.getComputeMaps()
265
+ const rendererOpts = computeRendererOpts.value
266
+ const compConf = renderOpts.name ? rendererOpts[renderOpts.name] || renderer.get(renderOpts.name) : null
267
+ if (compConf) {
268
+ const rtFooter = compConf.renderTableFooter || compConf.renderFooter
269
+ if (rtFooter) {
270
+ const footParams = Object.assign(params, {
271
+ cellValue: itemValue,
272
+ itemValue
273
+ })
274
+ return getSlotVNs(rtFooter(renderOpts, footParams))
275
+ }
276
+ }
277
+ }
278
+ return [
279
+ h(
280
+ 'span',
281
+ {
282
+ class: 'vxe-cell--label'
283
+ },
284
+ formatText(itemValue, 1)
285
+ )
286
+ ]
287
+ }
288
+
289
+ function getDefaultCellLabel(params: VxeTableDefines.CellRenderBodyParams) {
290
+ const { $table, row, column } = params
291
+ return formatText($table.getCellLabel(row, column), 1)
292
+ }
293
+
294
+ function renderCellHandle(
295
+ params: VxeTableDefines.CellRenderBodyParams & {
296
+ $table: VxeTableConstructor & VxeTablePrivateMethods
297
+ }
298
+ ) {
299
+ const { column, row, $table } = params
300
+ const tableProps = $table.props
301
+ const tableReactData = $table.reactData
302
+ const { isRowGroupStatus } = tableReactData
303
+ const { editConfig } = tableProps
304
+ const { type, treeNode, rowGroupNode, editRender } = column
305
+ const { computeEditOpts, computeCheckboxOpts, computeAggregateOpts } = $table.getComputeMaps()
306
+ const aggregateOpts = computeAggregateOpts.value
307
+ const { mode } = aggregateOpts
308
+ const checkboxOpts = computeCheckboxOpts.value
309
+ const editOpts = computeEditOpts.value
310
+ const isDeepCell = treeNode || (isRowGroupStatus && (mode === 'column' ? column.field === row.groupField : rowGroupNode))
311
+ switch (type) {
312
+ case 'seq':
313
+ return isDeepCell ? Cell.renderDeepIndexCell(params) : Cell.renderSeqCell(params)
314
+ case 'radio':
315
+ return isDeepCell ? Cell.renderDeepRadioCell(params) : Cell.renderRadioCell(params)
316
+ case 'checkbox':
317
+ return checkboxOpts.checkField ? (isDeepCell ? Cell.renderDeepSelectionCellByProp(params) : Cell.renderCheckboxCellByProp(params)) : isDeepCell ? Cell.renderDeepSelectionCell(params) : Cell.renderCheckboxCell(params)
318
+ case 'expand':
319
+ return Cell.renderExpandCell(params)
320
+ case 'html':
321
+ return isDeepCell ? Cell.renderDeepHTMLCell(params) : Cell.renderHTMLCell(params)
322
+ }
323
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
324
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
325
+ if (editRenderOpts) {
326
+ return editOpts.mode === 'cell' ? (isDeepCell ? Cell.renderDeepCellEdit(params) : Cell.renderCellEdit(params)) : isDeepCell ? Cell.renderDeepRowEdit(params) : Cell.renderRowEdit(params)
327
+ }
328
+ return isDeepCell ? Cell.renderDeepCell(params) : Cell.renderDefaultCell(params)
329
+ }
330
+
331
+ function renderHeaderHandle(
332
+ params: VxeTableDefines.CellRenderHeaderParams & {
333
+ $table: VxeTableConstructor & VxeTablePrivateMethods
334
+ }
335
+ ) {
336
+ const { column, $table } = params
337
+ const tableProps = $table.props
338
+ const { editConfig } = tableProps
339
+ const { type, filters, sortable, editRender, slots } = column
340
+
341
+ // 兼容已废弃方式
342
+ if (getConfig().tableHeadeSlotToTitleSlot !== 'obsolete') {
343
+ const headerSlot = slots ? slots.header : null
344
+ if (headerSlot) {
345
+ return renderTitleContent(params, $table.callSlot(headerSlot, params))
346
+ }
347
+ }
348
+
349
+ switch (type) {
350
+ case 'seq':
351
+ return Cell.renderSeqHeader(params)
352
+ case 'radio':
353
+ return Cell.renderRadioHeader(params)
354
+ case 'checkbox':
355
+ return Cell.renderCheckboxHeader(params)
356
+ case 'html':
357
+ if (filters && sortable) {
358
+ return Cell.renderSortAndFilterHeader(params)
359
+ } else if (sortable) {
360
+ return Cell.renderSortHeader(params)
361
+ } else if (filters) {
362
+ return Cell.renderFilterHeader(params)
363
+ }
364
+ break
365
+ }
366
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
367
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
368
+ if (editRenderOpts) {
369
+ return Cell.renderEditHeader(params)
370
+ } else if (filters && sortable) {
371
+ return Cell.renderSortAndFilterHeader(params)
372
+ } else if (sortable) {
373
+ return Cell.renderSortHeader(params)
374
+ } else if (filters) {
375
+ return Cell.renderFilterHeader(params)
376
+ }
377
+ return Cell.renderDefaultHeader(params)
378
+ }
379
+
380
+ function renderFooterHandle(
381
+ params: VxeTableDefines.CellRenderFooterParams & {
382
+ $table: VxeTableConstructor & VxeTablePrivateMethods
383
+ }
384
+ ) {
385
+ return Cell.renderDefaultFooter(params)
386
+ }
387
+
388
+ export const Cell = {
389
+ createColumn($xeTable: VxeTableConstructor & VxeTablePrivateMethods, columnOpts: VxeTableDefines.ColumnOptions | VxeTableDefines.ColumnInfo) {
390
+ const { type } = columnOpts
391
+ const renConfs: any = {
392
+ renderHeader: renderHeaderHandle,
393
+ renderCell: renderCellHandle,
394
+ renderFooter: renderFooterHandle
395
+ }
396
+ if (type === 'expand') {
397
+ renConfs.renderData = Cell.renderExpandData
398
+ }
399
+ return createColumn($xeTable, columnOpts, renConfs)
400
+ },
401
+ /**
402
+ * 列头标题
403
+ */
404
+ renderHeaderTitle(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
405
+ const { $table, column } = params
406
+ const tableProps = $table.props
407
+ const { editConfig } = tableProps
408
+ const { slots, editRender, cellRender } = column
409
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
410
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
411
+ const cellRenderOpts = isEnableConf(cellRender) ? cellRender : null
412
+ const renderOpts = editRenderOpts || cellRenderOpts
413
+
414
+ // 兼容已废弃方式
415
+ if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
416
+ const headerSlot = slots ? slots.header : null
417
+ if (headerSlot) {
418
+ return renderTitleContent(params, $table.callSlot(headerSlot, params))
419
+ }
420
+ }
421
+
422
+ if (renderOpts) {
423
+ const { computeRendererOpts } = $table.getComputeMaps()
424
+ const rendererOpts = computeRendererOpts.value
425
+ const compConf = renderOpts.name ? rendererOpts[renderOpts.name] || renderer.get(renderOpts.name) : null
426
+ if (compConf) {
427
+ const rtHeader = compConf.renderTableHeader || compConf.renderHeader
428
+ if (rtHeader) {
429
+ return renderTitleContent(params, getSlotVNs(rtHeader(renderOpts, params)))
430
+ }
431
+ }
432
+ }
433
+ return renderTitleContent(params, $table.getHeaderCellLabel(column))
434
+ },
435
+ renderDefaultHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
436
+ return renderHeaderCellBaseVNs(params, Cell.renderHeaderTitle(params))
437
+ },
438
+ renderDefaultCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
439
+ const { $table, row, column } = params
440
+ const tableProps = $table.props
441
+ const tableReactData = $table.reactData
442
+ const tableInternalData = $table.internalData
443
+ const { isRowGroupStatus } = tableReactData
444
+ const { editConfig } = tableProps
445
+ const { field, slots, editRender, cellRender, rowGroupNode, aggFunc } = column
446
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
447
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
448
+ const cellRenderOpts = isEnableConf(cellRender) ? cellRender : null
449
+ const defaultSlot = slots ? slots.default : null
450
+ const gcSlot = slots ? slots.groupContent || slots['group-content'] : null
451
+ const gvSlot = slots ? slots.groupValues || slots['group-values'] : null
452
+ let cellValue: string | number | null = ''
453
+ if (isRowGroupStatus && field && row.isAggregate) {
454
+ const aggRow: VxeTableDefines.AggregateRowInfo = row
455
+ const { fullColumnFieldData } = tableInternalData
456
+ const { computeAggregateOpts } = $table.getComputeMaps()
457
+ const aggregateOpts = computeAggregateOpts.value
458
+ const { mode, showTotal, totalMethod, countFields, contentMethod, formatValuesMethod, mapChildrenField } = aggregateOpts
459
+ const aggData = aggRow.aggData
460
+ const currAggData = aggData ? aggData[field] : null
461
+ const groupField = aggRow.groupField
462
+ const groupContent = aggRow.groupContent
463
+ const childList = mapChildrenField ? aggRow[mapChildrenField] || [] : []
464
+ const childCount = aggRow.childCount
465
+ const colRest = fullColumnFieldData[groupField] || {}
466
+ const ctParams = {
467
+ $table,
468
+ groupField,
469
+ groupColumn: (colRest ? colRest.column : null) as VxeTableDefines.ColumnInfo,
470
+ column,
471
+ groupValue: groupContent,
472
+ childList,
473
+ childCount,
474
+ aggValue: null as any,
475
+
476
+ /**
477
+ * 已废弃
478
+ * @deprecated
479
+ */
480
+ children: childList,
481
+ /**
482
+ * 已废弃
483
+ * @deprecated
484
+ */
485
+ totalValue: childCount
486
+ }
487
+ if (mode === 'column' ? field === aggRow.groupField : rowGroupNode) {
488
+ cellValue = groupContent
489
+ if (contentMethod) {
490
+ cellValue = `${contentMethod(ctParams)}`
491
+ }
492
+ if (showTotal) {
493
+ cellValue = getI18n('vxe.table.rowGroupContentTotal', [cellValue, totalMethod ? totalMethod(ctParams) : childCount, childCount])
494
+ }
495
+ if (gcSlot) {
496
+ return renderCellBaseVNs(params, $table.callSlot(gcSlot, Object.assign({ groupField, groupContent, childList, childCount }, params)))
497
+ }
498
+ } else if ($table.getPivotTableAggregateCellAggValue) {
499
+ cellValue = $table.getPivotTableAggregateCellAggValue(params)
500
+ ctParams.aggValue = cellValue
501
+ if (gvSlot) {
502
+ return renderCellBaseVNs(params, $table.callSlot(gvSlot, Object.assign({ groupField, groupContent, childList, childCount }, params, ctParams)))
503
+ }
504
+ } else if (aggFunc === true || (countFields && countFields.includes(field))) {
505
+ cellValue = currAggData ? currAggData.value : childCount
506
+ ctParams.aggValue = cellValue
507
+ if (formatValuesMethod) {
508
+ cellValue = formatValuesMethod(ctParams)
509
+ }
510
+ if (gvSlot) {
511
+ return renderCellBaseVNs(params, $table.callSlot(gvSlot, Object.assign({ groupField, groupContent, childList, childCount }, params, ctParams)))
512
+ }
513
+ }
514
+ } else {
515
+ if (defaultSlot) {
516
+ return renderCellBaseVNs(params, $table.callSlot(defaultSlot, params))
517
+ }
518
+ const { computeRendererOpts } = $table.getComputeMaps()
519
+ const rendererOpts = computeRendererOpts.value
520
+ // 如果是编辑模式-查看:slot default > formatter > cellRender.renderTableDefault > editRender.renderTableCell > editRender.renderTableDefault > cellRender.tableCellFormatter > editRender.tableCellFormatter > field
521
+ // 如果是查看表格:slot default > formatter > cellRender.renderTableDefault > cellRender.tableCellFormatter > field
522
+ const cellCompConf = cellRenderOpts && cellRenderOpts.name ? rendererOpts[cellRenderOpts.name] || renderer.get(cellRenderOpts.name) : null
523
+ if (cellRenderOpts) {
524
+ const cellDefaultRenderFn = cellCompConf ? cellCompConf.renderTableDefault || cellCompConf.renderDefault : null
525
+ if (cellDefaultRenderFn && cellRenderOpts) {
526
+ return renderCellBaseVNs(params, getSlotVNs(cellDefaultRenderFn(cellRenderOpts, Object.assign({ $type: editRenderOpts ? 'edit' : 'cell' }, params))))
527
+ }
528
+ }
529
+ if (editRenderOpts) {
530
+ const editCompConf = editRenderOpts && editRenderOpts.name ? rendererOpts[editRenderOpts.name] || renderer.get(editRenderOpts.name) : null
531
+ const editCellRenderFn = editCompConf ? editCompConf.renderTableCell || editCompConf.renderCell || editCompConf.renderTableDefault || editCompConf.renderDefault : null
532
+ if (editCellRenderFn) {
533
+ return renderCellBaseVNs(params, getSlotVNs(editCellRenderFn(editRenderOpts, Object.assign({ $type: editRenderOpts ? 'edit' : 'cell' }, params))))
534
+ }
535
+ }
536
+
537
+ // 如果是编辑模式-查看:cellRender.tableCellFormatter > editRender.tableCellFormatter > field
538
+ // 如果是查看表格:cellRender.tableCellFormatter > field
539
+ cellValue = $table.getCellLabel(row, column)
540
+ }
541
+ const cellPlaceholder = editRenderOpts ? editRenderOpts.placeholder : ''
542
+ return renderCellBaseVNs(params, [
543
+ h(
544
+ 'span',
545
+ {
546
+ class: 'vxe-cell--label'
547
+ },
548
+ [
549
+ // 如果设置占位符
550
+ editRenderOpts && eqEmptyValue(cellValue)
551
+ ? h(
552
+ 'span',
553
+ {
554
+ class: 'vxe-cell--placeholder'
555
+ },
556
+ formatText(getFuncText(cellPlaceholder), 1)
557
+ )
558
+ : h('span', formatText(cellValue, 1))
559
+ ]
560
+ )
561
+ ])
562
+ },
563
+ renderDeepCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
564
+ return Cell.renderDeepNodeBtn(params, Cell.renderDefaultCell(params) as VNode[])
565
+ },
566
+ renderDefaultFooter(params: VxeTableDefines.CellRenderFooterParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
567
+ return getFooterContent(params)
568
+ },
569
+
570
+ /**
571
+ * 行分组
572
+ */
573
+ renderRowGroupBtn(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, cellVNodes: VxeComponentSlotType[]) {
574
+ const { $table } = params
575
+ const tableReactData = $table.reactData
576
+ const tableInternalData = $table.internalData
577
+ const { row, level } = params
578
+ const { computeAggregateOpts } = $table.getComputeMaps()
579
+ const { rowGroupExpandedFlag } = tableReactData
580
+ const { rowGroupExpandedMaps } = tableInternalData
581
+ const aggregateOpts = computeAggregateOpts.value
582
+ const { mode, padding, indent, showIcon, iconOpen, iconClose } = aggregateOpts
583
+ const rowid = getRowid($table, row)
584
+ const isExpand = !!rowGroupExpandedFlag && !!rowGroupExpandedMaps[rowid]
585
+ return h(
586
+ 'div',
587
+ {
588
+ class: [
589
+ 'vxe-row-group--tree-node',
590
+ {
591
+ 'is--expanded': isExpand
592
+ }
593
+ ],
594
+ style:
595
+ mode !== 'column' && padding && indent
596
+ ? {
597
+ paddingLeft: `${level * indent}px`
598
+ }
599
+ : undefined
600
+ },
601
+ [
602
+ showIcon && row.isAggregate
603
+ ? h(
604
+ 'span',
605
+ {
606
+ class: 'vxe-row-group--node-btn',
607
+ onClick(evnt: MouseEvent) {
608
+ $table.triggerRowGroupExpandEvent(evnt, params)
609
+ }
610
+ },
611
+ [
612
+ h('i', {
613
+ class: isExpand ? iconOpen || getIcon().TABLE_ROW_GROUP_OPEN : iconClose || getIcon().TABLE_ROW_GROUP_CLOSE
614
+ })
615
+ ]
616
+ )
617
+ : renderEmptyElement($table),
618
+ h(
619
+ 'div',
620
+ {
621
+ class: 'vxe-row-group-cell'
622
+ },
623
+ cellVNodes
624
+ )
625
+ ]
626
+ )
627
+ },
628
+ /**
629
+ * 树
630
+ */
631
+ renderTreeNodeBtn(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, cellVNodes: VxeComponentSlotType[]) {
632
+ const { $table, isHidden } = params
633
+ const tableReactData = $table.reactData
634
+ const tableInternalData = $table.internalData
635
+ const { row, column, level } = params
636
+ const { slots } = column
637
+ const iconSlot = slots ? slots.icon : null
638
+ if (iconSlot) {
639
+ return $table.callSlot(iconSlot, params)
640
+ }
641
+ const { computeTreeOpts } = $table.getComputeMaps()
642
+ const { treeExpandedFlag } = tableReactData
643
+ const { fullAllDataRowIdData, treeExpandedMaps, treeExpandLazyLoadedMaps } = tableInternalData
644
+ const treeOpts = computeTreeOpts.value
645
+ const { padding, indent, lazy, trigger, visibleMethod, iconLoaded, showIcon, iconOpen, iconClose } = treeOpts
646
+ const childrenField = treeOpts.children || treeOpts.childrenField
647
+ const hasChildField = treeOpts.hasChild || treeOpts.hasChildField
648
+ const rowChilds = row[childrenField]
649
+ const hasChild = rowChilds && rowChilds.length
650
+ let hasLazyChilds = false
651
+ let isActive = false
652
+ let isLazyLoading = false
653
+ let isLazyLoaded = false
654
+ const ons: Record<string, any> = {}
655
+ if (!isHidden) {
656
+ const rowid = getRowid($table, row)
657
+ isActive = !!treeExpandedFlag && !!treeExpandedMaps[rowid]
658
+ if (lazy) {
659
+ const rest = fullAllDataRowIdData[rowid]
660
+ isLazyLoading = !!treeExpandLazyLoadedMaps[rowid]
661
+ hasLazyChilds = row[hasChildField]
662
+ isLazyLoaded = !!rest.treeLoaded
663
+ }
664
+ }
665
+ if (!trigger || trigger === 'default') {
666
+ ons.onClick = (evnt: MouseEvent) => {
667
+ $table.triggerTreeExpandEvent(evnt, params)
668
+ }
669
+ }
670
+ return h(
671
+ 'div',
672
+ {
673
+ class: [
674
+ 'vxe-cell--tree-node',
675
+ {
676
+ 'is--active': isActive
677
+ }
678
+ ],
679
+ style:
680
+ padding && indent
681
+ ? {
682
+ paddingLeft: `${level * indent}px`
683
+ }
684
+ : undefined
685
+ },
686
+ [
687
+ showIcon && (lazy ? (isLazyLoaded ? hasChild : hasChild || hasLazyChilds) : hasChild) && (!visibleMethod || visibleMethod(params))
688
+ ? [
689
+ h(
690
+ 'div',
691
+ {
692
+ class: 'vxe-cell--tree-btn',
693
+ ...ons
694
+ },
695
+ [
696
+ h('i', {
697
+ class: isLazyLoading ? iconLoaded || getIcon().TABLE_TREE_LOADED : isActive ? iconOpen || getIcon().TABLE_TREE_OPEN : iconClose || getIcon().TABLE_TREE_CLOSE
698
+ })
699
+ ]
700
+ )
701
+ ]
702
+ : null,
703
+ h(
704
+ 'div',
705
+ {
706
+ class: 'vxe-tree-cell'
707
+ },
708
+ cellVNodes
709
+ )
710
+ ]
711
+ )
712
+ },
713
+ /**
714
+ * 层级节点。
715
+ * 行分组、树结构
716
+ */
717
+ renderDeepNodeBtn(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, cellVNodes: VxeComponentSlotType[]) {
718
+ const { $table, row, column } = params
719
+ const { rowGroupNode } = column
720
+ const tableReactData = $table.reactData
721
+ const { rowGroupList } = tableReactData
722
+ if (rowGroupList.length) {
723
+ const { computeAggregateOpts } = $table.getComputeMaps()
724
+ const aggregateOpts = computeAggregateOpts.value
725
+ const { mode } = aggregateOpts
726
+ if (mode === 'column') {
727
+ if (row.groupField && column.field === row.groupField) {
728
+ return [Cell.renderRowGroupBtn(params, cellVNodes)]
729
+ }
730
+ return cellVNodes
731
+ } else if (rowGroupNode) {
732
+ return [Cell.renderRowGroupBtn(params, cellVNodes)]
733
+ }
734
+ }
735
+ return [Cell.renderTreeNodeBtn(params, cellVNodes)]
736
+ },
737
+
738
+ /**
739
+ * 序号
740
+ */
741
+ renderSeqHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
742
+ const { $table, column } = params
743
+
744
+ // 兼容已废弃方式
745
+ if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
746
+ const { slots } = column
747
+ const headerSlot = slots ? slots.header : null
748
+ return renderHeaderCellBaseVNs(params, renderTitleContent(params, headerSlot ? $table.callSlot(headerSlot, params) : $table.getHeaderCellLabel(column)))
749
+ }
750
+
751
+ return renderHeaderCellBaseVNs(params, renderTitleContent(params, $table.getHeaderCellLabel(column)))
752
+ },
753
+ renderSeqCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
754
+ const { $table, column } = params
755
+ const tableProps = $table.props
756
+ const { treeConfig } = tableProps
757
+ const { computeSeqOpts } = $table.getComputeMaps()
758
+ const seqOpts = computeSeqOpts.value
759
+ const { slots } = column
760
+ const defaultSlot = slots ? slots.default : null
761
+ if (defaultSlot) {
762
+ return renderCellBaseVNs(params, $table.callSlot(defaultSlot, params))
763
+ }
764
+ const { seq } = params
765
+ const seqMd = seqOpts.seqMethod
766
+ return renderCellBaseVNs(params, [h('span', `${formatText(seqMd ? seqMd(params) : treeConfig ? seq : (seqOpts.startIndex || 0) + (seq as number), 1)}`)])
767
+ },
768
+ renderDeepIndexCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
769
+ return Cell.renderDeepNodeBtn(params, Cell.renderSeqCell(params) as VNode[])
770
+ },
771
+
772
+ /**
773
+ * 单选
774
+ */
775
+ renderRadioHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
776
+ const { $table, column } = params
777
+ const { slots } = column
778
+ const titleSlot = slots ? slots.title : null
779
+
780
+ // 兼容已废弃方式
781
+ if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
782
+ const headerSlot = slots ? slots.header : null
783
+ return renderHeaderCellBaseVNs(
784
+ params,
785
+ renderTitleContent(
786
+ params,
787
+ headerSlot
788
+ ? $table.callSlot(headerSlot, params)
789
+ : [
790
+ h(
791
+ 'span',
792
+ {
793
+ class: 'vxe-radio--label'
794
+ },
795
+ titleSlot ? $table.callSlot(titleSlot, params) : $table.getHeaderCellLabel(column)
796
+ )
797
+ ]
798
+ )
799
+ )
800
+ }
801
+
802
+ return renderHeaderCellBaseVNs(
803
+ params,
804
+ renderTitleContent(params, [
805
+ h(
806
+ 'span',
807
+ {
808
+ class: 'vxe-radio--label'
809
+ },
810
+ titleSlot ? $table.callSlot(titleSlot, params) : $table.getHeaderCellLabel(column)
811
+ )
812
+ ])
813
+ )
814
+ },
815
+ renderRadioCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
816
+ const { $table, column, isHidden } = params
817
+ const tableReactData = $table.reactData
818
+ const { computeRadioOpts } = $table.getComputeMaps()
819
+ const { selectRadioRow } = tableReactData
820
+ const radioOpts = computeRadioOpts.value
821
+ const { slots } = column
822
+ const { labelField, checkMethod, visibleMethod } = radioOpts
823
+ const { row } = params
824
+ const defaultSlot = slots ? slots.default : null
825
+ const radioSlot = slots ? slots.radio : null
826
+ const isChecked = $table.eqRow(row, selectRadioRow)
827
+ const isVisible = !visibleMethod || visibleMethod({ $table, row })
828
+ let isDisabled = !!checkMethod
829
+ let ons
830
+ if (!isHidden) {
831
+ ons = {
832
+ onClick(evnt: Event) {
833
+ if (!isDisabled && isVisible) {
834
+ $table.triggerRadioRowEvent(evnt, params)
835
+ }
836
+ }
837
+ }
838
+ if (checkMethod) {
839
+ isDisabled = !checkMethod({ $table, row })
840
+ }
841
+ }
842
+ const radioParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible }
843
+ if (radioSlot) {
844
+ return renderCellBaseVNs(params, $table.callSlot(radioSlot, radioParams))
845
+ }
846
+ const radioVNs: VNode[] = []
847
+ if (isVisible) {
848
+ radioVNs.push(
849
+ h('span', {
850
+ class: ['vxe-radio--icon', isChecked ? getIcon().TABLE_RADIO_CHECKED : isDisabled ? getIcon().TABLE_RADIO_DISABLED_UNCHECKED : getIcon().TABLE_RADIO_UNCHECKED]
851
+ })
852
+ )
853
+ }
854
+ if (defaultSlot || labelField) {
855
+ radioVNs.push(
856
+ h(
857
+ 'span',
858
+ {
859
+ class: 'vxe-radio--label'
860
+ },
861
+ defaultSlot ? $table.callSlot(defaultSlot, radioParams) : XEUtils.get(row, labelField as string)
862
+ )
863
+ )
864
+ }
865
+ return renderCellBaseVNs(params, [
866
+ h(
867
+ 'span',
868
+ {
869
+ class: [
870
+ 'vxe-cell--radio',
871
+ {
872
+ 'is--checked': isChecked,
873
+ 'is--disabled': isDisabled
874
+ }
875
+ ],
876
+ ...ons
877
+ },
878
+ radioVNs
879
+ )
880
+ ])
881
+ },
882
+ renderDeepRadioCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
883
+ return Cell.renderDeepNodeBtn(params, Cell.renderRadioCell(params))
884
+ },
885
+
886
+ /**
887
+ * 多选
888
+ */
889
+ renderCheckboxHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
890
+ const { $table, column, isHidden } = params
891
+ const tableReactData = $table.reactData
892
+ const { computeIsAllCheckboxDisabled, computeCheckboxOpts } = $table.getComputeMaps()
893
+ const { isAllSelected: isAllCheckboxSelected, isIndeterminate: isAllCheckboxIndeterminate } = tableReactData
894
+ const isAllCheckboxDisabled = computeIsAllCheckboxDisabled.value
895
+ const { slots } = column
896
+ const titleSlot = slots ? slots.title : null
897
+ const checkboxOpts = computeCheckboxOpts.value
898
+ const { checkStrictly, showHeader, headerTitle } = checkboxOpts
899
+ const colTitle = $table.getHeaderCellLabel(column)
900
+ const ons: Record<string, any> = {}
901
+ if (!isHidden) {
902
+ ons.onClick = (evnt: MouseEvent) => {
903
+ if (!isAllCheckboxDisabled) {
904
+ $table.triggerCheckAllEvent(evnt, !isAllCheckboxSelected)
905
+ }
906
+ }
907
+ }
908
+ const checkboxParams = { ...params, checked: isAllCheckboxSelected, disabled: isAllCheckboxDisabled, indeterminate: isAllCheckboxIndeterminate }
909
+
910
+ // 兼容已废弃方式
911
+ if (getConfig().tableHeadeSlotToTitleSlot === 'obsolete') {
912
+ const headerSlot = slots ? slots.header : null
913
+ if (headerSlot) {
914
+ return renderHeaderCellBaseVNs(params, renderTitleContent(checkboxParams, $table.callSlot(headerSlot, checkboxParams)))
915
+ }
916
+ }
917
+
918
+ if (checkStrictly ? !showHeader : showHeader === false) {
919
+ return renderHeaderCellBaseVNs(
920
+ params,
921
+ renderTitleContent(checkboxParams, [
922
+ h(
923
+ 'span',
924
+ {
925
+ class: 'vxe-checkbox--label'
926
+ },
927
+ titleSlot ? $table.callSlot(titleSlot, checkboxParams) : colTitle
928
+ )
929
+ ])
930
+ )
931
+ }
932
+ return renderHeaderCellBaseVNs(
933
+ params,
934
+ renderTitleContent(checkboxParams, [
935
+ h(
936
+ 'span',
937
+ {
938
+ class: [
939
+ 'vxe-cell--checkbox',
940
+ {
941
+ 'is--checked': isAllCheckboxSelected,
942
+ 'is--disabled': isAllCheckboxDisabled,
943
+ 'is--indeterminate': isAllCheckboxIndeterminate
944
+ }
945
+ ],
946
+ title: XEUtils.eqNull(headerTitle) ? getI18n('vxe.table.allTitle') : `${headerTitle || ''}`,
947
+ ...ons
948
+ },
949
+ [
950
+ h('span', {
951
+ class: ['vxe-checkbox--icon', isAllCheckboxIndeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isAllCheckboxSelected ? getIcon().TABLE_CHECKBOX_CHECKED : isAllCheckboxDisabled ? getIcon().TABLE_CHECKBOX_DISABLED_UNCHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
952
+ })
953
+ ].concat(
954
+ titleSlot || colTitle
955
+ ? [
956
+ h(
957
+ 'span',
958
+ {
959
+ class: 'vxe-checkbox--label'
960
+ },
961
+ titleSlot ? $table.callSlot(titleSlot, checkboxParams) : colTitle
962
+ )
963
+ ]
964
+ : []
965
+ )
966
+ )
967
+ ])
968
+ )
969
+ },
970
+ renderCheckboxCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
971
+ const { $table, row, column, isHidden } = params
972
+ const tableProps = $table.props
973
+ const tableReactData = $table.reactData
974
+ const tableInternalData = $table.internalData
975
+ const { treeConfig } = tableProps
976
+ const { updateCheckboxFlag, isRowGroupStatus } = tableReactData
977
+ const { selectCheckboxMaps, treeIndeterminateRowMaps } = tableInternalData
978
+ const { computeCheckboxOpts, computeAggregateOpts } = $table.getComputeMaps()
979
+ const aggregateOpts = computeAggregateOpts.value
980
+ const { mapChildrenField } = aggregateOpts
981
+ const checkboxOpts = computeCheckboxOpts.value
982
+ const { labelField, checkMethod, visibleMethod } = checkboxOpts
983
+ const { slots } = column
984
+ const defaultSlot = slots ? slots.default : null
985
+ const checkboxSlot = slots ? slots.checkbox : null
986
+ let indeterminate = false
987
+ let isChecked = false
988
+ let isVisible = true
989
+ let isDisabled = false
990
+ const ons: Record<string, any> = {}
991
+ if (!isHidden) {
992
+ const rowid = getRowid($table, row)
993
+ isChecked = !!updateCheckboxFlag && !!selectCheckboxMaps[rowid]
994
+ if (checkMethod && isRowGroupStatus && $table.isAggregateRecord(row)) {
995
+ const childList: any[] = row[mapChildrenField || '']
996
+ if (!childList || !childList.length || childList.every((item) => !checkMethod({ $table, row: item }))) {
997
+ isDisabled = true
998
+ }
999
+ } else {
1000
+ isVisible = !visibleMethod || visibleMethod({ $table, row })
1001
+ isDisabled = checkMethod ? !checkMethod({ $table, row }) : !!checkMethod
1002
+ }
1003
+ if (treeConfig || isRowGroupStatus) {
1004
+ indeterminate = !!treeIndeterminateRowMaps[rowid]
1005
+ }
1006
+ ons.onClick = (evnt: MouseEvent) => {
1007
+ if (!isDisabled && isVisible) {
1008
+ $table.triggerCheckRowEvent(evnt, params, !isChecked)
1009
+ }
1010
+ }
1011
+ }
1012
+ const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible, indeterminate }
1013
+ if (checkboxSlot) {
1014
+ return renderCellBaseVNs(params, $table.callSlot(checkboxSlot, checkboxParams))
1015
+ }
1016
+ const checkVNs: VNode[] = []
1017
+ if (isVisible) {
1018
+ checkVNs.push(
1019
+ h('span', {
1020
+ class: ['vxe-checkbox--icon', indeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : isDisabled ? getIcon().TABLE_CHECKBOX_DISABLED_UNCHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
1021
+ })
1022
+ )
1023
+ }
1024
+ if (defaultSlot || labelField) {
1025
+ checkVNs.push(
1026
+ h(
1027
+ 'span',
1028
+ {
1029
+ class: 'vxe-checkbox--label'
1030
+ },
1031
+ defaultSlot ? $table.callSlot(defaultSlot, checkboxParams) : XEUtils.get(row, labelField as string)
1032
+ )
1033
+ )
1034
+ }
1035
+ return renderCellBaseVNs(params, [
1036
+ h(
1037
+ 'span',
1038
+ {
1039
+ class: [
1040
+ 'vxe-cell--checkbox',
1041
+ {
1042
+ 'is--checked': isChecked,
1043
+ 'is--disabled': isDisabled,
1044
+ 'is--indeterminate': indeterminate,
1045
+ 'is--hidden': !isVisible
1046
+ }
1047
+ ],
1048
+ ...ons
1049
+ },
1050
+ checkVNs
1051
+ )
1052
+ ])
1053
+ },
1054
+ renderDeepSelectionCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1055
+ return Cell.renderDeepNodeBtn(params, Cell.renderCheckboxCell(params))
1056
+ },
1057
+ renderCheckboxCellByProp(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1058
+ const { $table, row, column, isHidden } = params
1059
+ const tableProps = $table.props
1060
+ const tableReactData = $table.reactData
1061
+ const tableInternalData = $table.internalData
1062
+ const { treeConfig } = tableProps
1063
+ const { updateCheckboxFlag, isRowGroupStatus } = tableReactData
1064
+ const { treeIndeterminateRowMaps } = tableInternalData
1065
+ const { computeCheckboxOpts, computeAggregateOpts } = $table.getComputeMaps()
1066
+ const aggregateOpts = computeAggregateOpts.value
1067
+ const { mapChildrenField } = aggregateOpts
1068
+ const checkboxOpts = computeCheckboxOpts.value
1069
+ const { labelField, checkField, checkMethod, visibleMethod } = checkboxOpts
1070
+ const indeterminateField = checkboxOpts.indeterminateField || checkboxOpts.halfField
1071
+ const { slots } = column
1072
+ const defaultSlot = slots ? slots.default : null
1073
+ const checkboxSlot = slots ? slots.checkbox : null
1074
+ let indeterminate = false
1075
+ let isChecked = false
1076
+ let isVisible = true
1077
+ let isDisabled = false
1078
+ const ons: Record<string, any> = {}
1079
+ if (!isHidden) {
1080
+ const rowid = getRowid($table, row)
1081
+ isChecked = !!updateCheckboxFlag && XEUtils.get(row, checkField)
1082
+ if (checkMethod && isRowGroupStatus && $table.isAggregateRecord(row)) {
1083
+ const childList: any[] = row[mapChildrenField || '']
1084
+ if (!childList || !childList.length || childList.every((item) => !checkMethod({ $table, row: item }))) {
1085
+ isDisabled = true
1086
+ }
1087
+ } else {
1088
+ isVisible = !visibleMethod || visibleMethod({ $table, row })
1089
+ isDisabled = checkMethod ? !checkMethod({ $table, row }) : !!checkMethod
1090
+ }
1091
+ if (treeConfig || isRowGroupStatus) {
1092
+ indeterminate = !!treeIndeterminateRowMaps[rowid]
1093
+ }
1094
+ ons.onClick = (evnt: MouseEvent) => {
1095
+ if (!isDisabled && isVisible) {
1096
+ $table.triggerCheckRowEvent(evnt, params, !isChecked)
1097
+ }
1098
+ }
1099
+ }
1100
+ const checkboxParams = { ...params, checked: isChecked, disabled: isDisabled, visible: isVisible, indeterminate }
1101
+ if (checkboxSlot) {
1102
+ return renderCellBaseVNs(params, $table.callSlot(checkboxSlot, checkboxParams))
1103
+ }
1104
+ const checkVNs: VNode[] = []
1105
+ if (isVisible) {
1106
+ checkVNs.push(
1107
+ h('span', {
1108
+ class: ['vxe-checkbox--icon', indeterminate ? getIcon().TABLE_CHECKBOX_INDETERMINATE : isChecked ? getIcon().TABLE_CHECKBOX_CHECKED : isDisabled ? getIcon().TABLE_CHECKBOX_DISABLED_UNCHECKED : getIcon().TABLE_CHECKBOX_UNCHECKED]
1109
+ })
1110
+ )
1111
+ if (defaultSlot || labelField) {
1112
+ checkVNs.push(
1113
+ h(
1114
+ 'span',
1115
+ {
1116
+ class: 'vxe-checkbox--label'
1117
+ },
1118
+ defaultSlot ? $table.callSlot(defaultSlot, checkboxParams) : XEUtils.get(row, labelField as string)
1119
+ )
1120
+ )
1121
+ }
1122
+ }
1123
+ return renderCellBaseVNs(params, [
1124
+ h(
1125
+ 'span',
1126
+ {
1127
+ class: [
1128
+ 'vxe-cell--checkbox',
1129
+ {
1130
+ 'is--checked': isChecked,
1131
+ 'is--disabled': isDisabled,
1132
+ 'is--indeterminate': indeterminateField && !isChecked ? row[indeterminateField] : indeterminate,
1133
+ 'is--hidden': !isVisible
1134
+ }
1135
+ ],
1136
+ ...ons
1137
+ },
1138
+ checkVNs
1139
+ )
1140
+ ])
1141
+ },
1142
+ renderDeepSelectionCellByProp(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1143
+ return Cell.renderDeepNodeBtn(params, Cell.renderCheckboxCellByProp(params))
1144
+ },
1145
+
1146
+ /**
1147
+ * 展开行
1148
+ */
1149
+ renderExpandCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1150
+ const { $table, isHidden, row, column } = params
1151
+ const tableReactData = $table.reactData
1152
+ const tableInternalData = $table.internalData
1153
+ const { isRowGroupStatus } = tableReactData
1154
+ const { rowExpandedMaps, rowExpandLazyLoadedMaps } = tableInternalData
1155
+ const { computeExpandOpts } = $table.getComputeMaps()
1156
+ const expandOpts = computeExpandOpts.value
1157
+ const { lazy, labelField, iconLoaded, showIcon, iconOpen, iconClose, visibleMethod } = expandOpts
1158
+ const { slots } = column
1159
+ const defaultSlot = slots ? slots.default : null
1160
+ const iconSlot = slots ? slots.icon : null
1161
+ let isActive = false
1162
+ let isLazyLoading = false
1163
+ if (isRowGroupStatus && row.isAggregate) {
1164
+ return renderCellBaseVNs(params, [])
1165
+ }
1166
+ if (iconSlot) {
1167
+ return renderCellBaseVNs(params, $table.callSlot(iconSlot, params))
1168
+ }
1169
+ if (!isHidden) {
1170
+ const rowid = getRowid($table, row)
1171
+ isActive = !!rowExpandedMaps[rowid]
1172
+ if (lazy) {
1173
+ isLazyLoading = !!rowExpandLazyLoadedMaps[rowid]
1174
+ }
1175
+ }
1176
+ return renderCellBaseVNs(params, [
1177
+ showIcon && (!visibleMethod || visibleMethod(params))
1178
+ ? h(
1179
+ 'div',
1180
+ {
1181
+ class: [
1182
+ 'vxe-table--expanded',
1183
+ {
1184
+ 'is--active': isActive
1185
+ }
1186
+ ]
1187
+ },
1188
+ [
1189
+ h(
1190
+ 'span',
1191
+ {
1192
+ class: 'vxe-table--expand-btn',
1193
+ onMousedown(evnt) {
1194
+ evnt.stopPropagation()
1195
+ },
1196
+ onClick(evnt: MouseEvent) {
1197
+ $table.triggerRowExpandEvent(evnt, params)
1198
+ }
1199
+ },
1200
+ [
1201
+ h('i', {
1202
+ class: isLazyLoading ? iconLoaded || getIcon().TABLE_EXPAND_LOADED : isActive ? iconOpen || getIcon().TABLE_EXPAND_OPEN : iconClose || getIcon().TABLE_EXPAND_CLOSE
1203
+ })
1204
+ ]
1205
+ )
1206
+ ]
1207
+ )
1208
+ : renderEmptyElement($table),
1209
+ defaultSlot || labelField
1210
+ ? h(
1211
+ 'div',
1212
+ {
1213
+ class: 'vxe-table--expand-label'
1214
+ },
1215
+ defaultSlot ? $table.callSlot(defaultSlot, params) : XEUtils.get(row, labelField as string)
1216
+ )
1217
+ : renderEmptyElement($table)
1218
+ ])
1219
+ },
1220
+ renderExpandData(params: VxeTableDefines.CellRenderDataParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1221
+ const { $table, column } = params
1222
+ const { slots, contentRender } = column
1223
+ const contentSlot = slots ? slots.content : null
1224
+ if (contentSlot) {
1225
+ return $table.callSlot(contentSlot, params)
1226
+ }
1227
+ if (contentRender) {
1228
+ const { computeRendererOpts } = $table.getComputeMaps()
1229
+ const rendererOpts = computeRendererOpts.value
1230
+ const compConf = contentRender.name ? rendererOpts[contentRender.name] || renderer.get(contentRender.name) : null
1231
+ if (compConf) {
1232
+ const rtExpand = compConf.renderTableExpand || compConf.renderExpand
1233
+ if (rtExpand) {
1234
+ return getSlotVNs(rtExpand(contentRender, params))
1235
+ }
1236
+ }
1237
+ }
1238
+ return []
1239
+ },
1240
+
1241
+ /**
1242
+ * HTML 标签
1243
+ */
1244
+ renderHTMLCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1245
+ const { $table, column } = params
1246
+ const { slots } = column
1247
+ const defaultSlot = slots ? slots.default : null
1248
+ if (defaultSlot) {
1249
+ return renderCellBaseVNs(params, $table.callSlot(defaultSlot, params))
1250
+ }
1251
+ return renderCellBaseVNs(params, [
1252
+ h('span', {
1253
+ class: 'vxe-cell--html',
1254
+ innerHTML: getDefaultCellLabel(params)
1255
+ })
1256
+ ])
1257
+ },
1258
+ renderDeepHTMLCell(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1259
+ return Cell.renderDeepNodeBtn(params, Cell.renderHTMLCell(params))
1260
+ },
1261
+
1262
+ /**
1263
+ * 排序和筛选
1264
+ */
1265
+ renderSortAndFilterHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1266
+ return renderHeaderCellBaseVNs(params, Cell.renderHeaderTitle(params).concat(Cell.renderSortIcon(params).concat(Cell.renderFilterIcon(params))))
1267
+ },
1268
+
1269
+ /**
1270
+ * 排序
1271
+ */
1272
+ renderSortHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1273
+ return renderHeaderCellBaseVNs(params, Cell.renderHeaderTitle(params).concat(Cell.renderSortIcon(params)))
1274
+ },
1275
+ renderSortIcon(params: (VxeTableDefines.CellRenderHeaderParams | VxeTableDefines.CellRenderHeaderParams) & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1276
+ const { $table, column } = params
1277
+ const { computeSortOpts } = $table.getComputeMaps()
1278
+ const sortOpts = computeSortOpts.value
1279
+ const { showIcon, allowBtn, ascTitle, descTitle, iconLayout, iconAsc, iconDesc, iconVisibleMethod } = sortOpts
1280
+ const { order, slots } = column
1281
+ if (showIcon && (!iconVisibleMethod || iconVisibleMethod(params))) {
1282
+ const sortSlot = slots ? slots.sort : null
1283
+ return sortSlot
1284
+ ? (getSlotVNs($table.callSlot(sortSlot, params)) as VNode[])
1285
+ : [
1286
+ h(
1287
+ 'span',
1288
+ {
1289
+ class: ['vxe-cell--sort', `vxe-cell--sort-${iconLayout}-layout`]
1290
+ },
1291
+ [
1292
+ h('i', {
1293
+ class: [
1294
+ 'vxe-sort--asc-btn',
1295
+ iconAsc || getIcon().TABLE_SORT_ASC,
1296
+ {
1297
+ 'sort--active': order === 'asc'
1298
+ }
1299
+ ],
1300
+ title: XEUtils.eqNull(ascTitle) ? getI18n('vxe.table.sortAsc') : `${ascTitle || ''}`,
1301
+ onClick: allowBtn
1302
+ ? (evnt: Event) => {
1303
+ evnt.stopPropagation()
1304
+ $table.triggerSortEvent(evnt, column, 'asc')
1305
+ }
1306
+ : undefined
1307
+ }),
1308
+ h('i', {
1309
+ class: [
1310
+ 'vxe-sort--desc-btn',
1311
+ iconDesc || getIcon().TABLE_SORT_DESC,
1312
+ {
1313
+ 'sort--active': order === 'desc'
1314
+ }
1315
+ ],
1316
+ title: XEUtils.eqNull(descTitle) ? getI18n('vxe.table.sortDesc') : `${descTitle || ''}`,
1317
+ onClick: allowBtn
1318
+ ? (evnt: Event) => {
1319
+ evnt.stopPropagation()
1320
+ $table.triggerSortEvent(evnt, column, 'desc')
1321
+ }
1322
+ : undefined
1323
+ })
1324
+ ]
1325
+ )
1326
+ ]
1327
+ }
1328
+ return []
1329
+ },
1330
+
1331
+ /**
1332
+ * 筛选
1333
+ */
1334
+ renderFilterHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1335
+ return renderHeaderCellBaseVNs(params, Cell.renderHeaderTitle(params).concat(Cell.renderFilterIcon(params)))
1336
+ },
1337
+ renderFilterIcon(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1338
+ const { $table, column, hasFilter } = params
1339
+ const tableReactData = $table.reactData
1340
+ const { filterStore } = tableReactData
1341
+ const { computeFilterOpts } = $table.getComputeMaps()
1342
+ const filterOpts = computeFilterOpts.value
1343
+ const { showIcon, iconNone, iconMatch, iconVisibleMethod } = filterOpts
1344
+ if (showIcon && (!iconVisibleMethod || iconVisibleMethod(params))) {
1345
+ return [
1346
+ h(
1347
+ 'span',
1348
+ {
1349
+ class: [
1350
+ 'vxe-cell--filter',
1351
+ {
1352
+ 'is--active': filterStore.visible && filterStore.column === column
1353
+ }
1354
+ ],
1355
+ onClick(evnt) {
1356
+ if ($table.triggerFilterEvent) {
1357
+ $table.triggerFilterEvent(evnt, params.column, params)
1358
+ }
1359
+ }
1360
+ },
1361
+ [
1362
+ h('i', {
1363
+ class: ['vxe-filter--btn', hasFilter ? iconMatch || getIcon().TABLE_FILTER_MATCH : iconNone || getIcon().TABLE_FILTER_NONE],
1364
+ title: getI18n('vxe.table.filter')
1365
+ })
1366
+ ]
1367
+ )
1368
+ ]
1369
+ }
1370
+ return []
1371
+ },
1372
+
1373
+ /**
1374
+ * 可编辑
1375
+ */
1376
+ renderEditHeader(params: VxeTableDefines.CellRenderHeaderParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1377
+ const { $table, column } = params
1378
+ const tableProps = $table.props
1379
+ const { computeEditOpts } = $table.getComputeMaps()
1380
+ const { editConfig, editRules } = tableProps
1381
+ const editOpts = computeEditOpts.value
1382
+ const { sortable, filters, editRender } = column
1383
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
1384
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1385
+ let isRequired = false
1386
+ if (editRules) {
1387
+ const columnRules = column.rules ? column.rules : XEUtils.get(editRules, column.field)
1388
+ if (columnRules) {
1389
+ isRequired = columnRules.some((rule) => rule.required)
1390
+ }
1391
+ }
1392
+ let editIconVNs: VNode[] = []
1393
+ if (isEnableEdit) {
1394
+ const { showAsterisk, showIcon, icon } = editOpts
1395
+ editIconVNs = [
1396
+ isRequired && showAsterisk
1397
+ ? h(
1398
+ 'span',
1399
+ {
1400
+ class: 'vxe-cell--required-icon'
1401
+ },
1402
+ [h('i')]
1403
+ )
1404
+ : renderEmptyElement($table),
1405
+ editRenderOpts && showIcon
1406
+ ? h(
1407
+ 'span',
1408
+ {
1409
+ class: 'vxe-cell--edit-icon'
1410
+ },
1411
+ XEUtils.isFunction(icon)
1412
+ ? getSlotVNs(icon({}))
1413
+ : [
1414
+ h('i', {
1415
+ class: icon || getIcon().TABLE_EDIT
1416
+ })
1417
+ ]
1418
+ )
1419
+ : renderEmptyElement($table)
1420
+ ]
1421
+ }
1422
+ return renderHeaderCellBaseVNs(
1423
+ params,
1424
+ editIconVNs
1425
+ .concat(Cell.renderHeaderTitle(params))
1426
+ .concat(sortable ? Cell.renderSortIcon(params) : [])
1427
+ .concat(filters ? Cell.renderFilterIcon(params) : [])
1428
+ )
1429
+ },
1430
+ // 行格编辑模式
1431
+ renderRowEdit(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1432
+ const { $table, column } = params
1433
+ const tableProps = $table.props
1434
+ const { editConfig } = tableProps
1435
+ const tableReactData = $table.reactData
1436
+ const { editStore } = tableReactData
1437
+ const { actived } = editStore
1438
+ const { editRender } = column
1439
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
1440
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1441
+ return Cell.runRenderer(params, !!(editRenderOpts && actived && actived.row === params.row))
1442
+ },
1443
+ renderDeepRowEdit(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1444
+ return Cell.renderDeepNodeBtn(params, Cell.renderRowEdit(params) as VNode[])
1445
+ },
1446
+ // 单元格编辑模式
1447
+ renderCellEdit(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1448
+ const { $table, column } = params
1449
+ const tableProps = $table.props
1450
+ const { editConfig } = tableProps
1451
+ const tableReactData = $table.reactData
1452
+ const { editStore } = tableReactData
1453
+ const { actived } = editStore
1454
+ const { editRender } = column
1455
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
1456
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1457
+ return Cell.runRenderer(params, !!(editRenderOpts && actived && actived.row === params.row && actived.column === params.column))
1458
+ },
1459
+ renderDeepCellEdit(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1460
+ return Cell.renderDeepNodeBtn(params, Cell.renderCellEdit(params) as VNode[])
1461
+ },
1462
+ runRenderer(params: VxeTableDefines.CellRenderBodyParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }, isEdit: boolean) {
1463
+ const { $table, row, column } = params
1464
+ const tableProps = $table.props
1465
+ const { editConfig } = tableProps
1466
+ const tableReactData = $table.reactData
1467
+ const { isRowGroupStatus } = tableReactData
1468
+ const { slots, field, editRender, formatter } = column
1469
+ const isEnableEdit = editConfig && isEnableConf(editConfig)
1470
+ const editRenderOpts = isEnableEdit && isEnableConf(editRender) ? editRender : null
1471
+ const defaultSlot = slots ? slots.default : null
1472
+ const gcSlot = slots ? slots.groupContent || slots['group-content'] : null
1473
+ const editSlot = slots ? slots.edit : null
1474
+ const cellParams = Object.assign({ $type: '', isEdit }, params)
1475
+ if (isEdit && editRenderOpts) {
1476
+ cellParams.$type = 'edit'
1477
+ if (editSlot) {
1478
+ return $table.callSlot(editSlot, cellParams)
1479
+ }
1480
+ const { computeRendererOpts } = $table.getComputeMaps()
1481
+ const rendererOpts = computeRendererOpts.value
1482
+ const compConf = editRenderOpts.name ? rendererOpts[editRenderOpts.name] || renderer.get(editRenderOpts.name) : null
1483
+ const rtEdit = compConf ? compConf.renderTableEdit || compConf.renderEdit : null
1484
+ if (rtEdit) {
1485
+ return getSlotVNs(rtEdit(editRenderOpts, cellParams))
1486
+ }
1487
+ return []
1488
+ }
1489
+
1490
+ if (isRowGroupStatus && field && row.isAggregate) {
1491
+ const aggRow: VxeTableDefines.AggregateRowInfo = row
1492
+ const { computeAggregateOpts } = $table.getComputeMaps()
1493
+ const aggregateOpts = computeAggregateOpts.value
1494
+ const { mapChildrenField } = aggregateOpts
1495
+ const groupField = aggRow.groupField
1496
+ const groupContent = aggRow.groupContent
1497
+ const childList = mapChildrenField ? aggRow[mapChildrenField] || [] : []
1498
+ const childCount = aggRow.childCount
1499
+ if (gcSlot) {
1500
+ return renderCellBaseVNs(params, $table.callSlot(gcSlot, Object.assign({ groupField, groupContent, childList, childCount }, params)))
1501
+ }
1502
+ } else {
1503
+ if (defaultSlot) {
1504
+ return renderCellBaseVNs(params, $table.callSlot(defaultSlot, cellParams))
1505
+ }
1506
+ }
1507
+
1508
+ // slot default > formatter
1509
+ if (formatter) {
1510
+ return renderCellBaseVNs(params, [
1511
+ h(
1512
+ 'span',
1513
+ {
1514
+ class: 'vxe-cell--label'
1515
+ },
1516
+ getDefaultCellLabel(cellParams)
1517
+ )
1518
+ ])
1519
+ }
1520
+ return Cell.renderDefaultCell(cellParams)
1521
+ }
1522
+ }
1523
+
1524
+ export default Cell