vxe-table 4.23.8 → 4.23.10

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 (126) hide show
  1. package/dist/all.esm.js +5683 -3798
  2. package/es/components.d.ts +1 -0
  3. package/es/components.js +2 -7
  4. package/es/grid/src/emits.js +1 -15
  5. package/es/grid/src/grid.js +397 -120
  6. package/es/index.esm.js +5 -3
  7. package/es/index.js +5 -3
  8. package/es/table/module/custom/hook.js +49 -42
  9. package/es/table/module/custom/panel.js +777 -527
  10. package/es/table/module/edit/hook.js +140 -62
  11. package/es/table/module/export/export-panel.js +399 -316
  12. package/es/table/module/export/hook.js +395 -337
  13. package/es/table/module/export/import-panel.js +152 -123
  14. package/es/table/module/filter/hook.js +16 -2
  15. package/es/table/module/filter/panel.js +146 -84
  16. package/es/table/module/keyboard/hook.js +8 -4
  17. package/es/table/module/menu/panel.js +197 -126
  18. package/es/table/render/index.js +151 -98
  19. package/es/table/src/body.js +355 -233
  20. package/es/table/src/cell.js +426 -269
  21. package/es/table/src/columnInfo.js +1 -0
  22. package/es/table/src/footer.js +144 -99
  23. package/es/table/src/group.js +7 -3
  24. package/es/table/src/header.js +229 -172
  25. package/es/table/src/table.js +1503 -1030
  26. package/es/table/src/util.js +15 -19
  27. package/es/toolbar/src/toolbar.js +132 -75
  28. package/es/ui/index.js +1 -1
  29. package/es/ui/src/dom.js +9 -6
  30. package/es/ui/src/log.js +1 -1
  31. package/es/ui/src/utils.d.ts +1 -1
  32. package/lib/components.js +2 -7
  33. package/lib/grid/src/emits.js +1 -15
  34. package/lib/grid/src/grid.js +397 -120
  35. package/lib/index.common.js +5 -3
  36. package/lib/index.js +5 -3
  37. package/lib/index.umd.js +5652 -3797
  38. package/lib/index.umd.min.js +3 -3
  39. package/lib/table/module/custom/hook.js +49 -42
  40. package/lib/table/module/custom/panel.js +777 -527
  41. package/lib/table/module/edit/hook.js +140 -62
  42. package/lib/table/module/export/export-panel.js +399 -316
  43. package/lib/table/module/export/hook.js +395 -337
  44. package/lib/table/module/export/import-panel.js +152 -123
  45. package/lib/table/module/filter/hook.js +16 -2
  46. package/lib/table/module/filter/panel.js +146 -84
  47. package/lib/table/module/keyboard/hook.js +8 -4
  48. package/lib/table/module/menu/panel.js +197 -126
  49. package/lib/table/render/index.js +151 -98
  50. package/lib/table/src/body.js +355 -233
  51. package/lib/table/src/cell.js +426 -269
  52. package/lib/table/src/columnInfo.js +1 -0
  53. package/lib/table/src/footer.js +144 -99
  54. package/lib/table/src/group.js +7 -3
  55. package/lib/table/src/header.js +229 -172
  56. package/lib/table/src/table.js +1471 -1029
  57. package/lib/table/src/util.js +15 -19
  58. package/lib/toolbar/src/toolbar.js +132 -75
  59. package/lib/ui/index.js +1 -1
  60. package/lib/ui/src/dom.js +9 -6
  61. package/lib/ui/src/log.js +1 -1
  62. package/package.json +2 -2
  63. package/packages/colgroup/index.ts +22 -22
  64. package/packages/column/index.ts +22 -22
  65. package/packages/components.ts +42 -44
  66. package/packages/grid/index.ts +18 -18
  67. package/packages/grid/src/emits.ts +5 -19
  68. package/packages/grid/src/grid.ts +2229 -1925
  69. package/packages/grid/src/props.ts +22 -23
  70. package/packages/index.ts +13 -11
  71. package/packages/locale/lang/fr-FR.ts +15 -15
  72. package/packages/locale/lang/it-IT.ts +4 -4
  73. package/packages/locale/lang/uk-UA.ts +1 -1
  74. package/packages/locale/lang/uz-UZ.ts +13 -13
  75. package/packages/locale/lang/zh-CN.ts +907 -907
  76. package/packages/table/index.ts +26 -26
  77. package/packages/table/module/custom/hook.ts +510 -503
  78. package/packages/table/module/custom/panel.ts +2002 -1743
  79. package/packages/table/module/edit/hook.ts +1224 -1131
  80. package/packages/table/module/export/export-panel.ts +697 -611
  81. package/packages/table/module/export/hook.ts +2160 -2059
  82. package/packages/table/module/export/import-panel.ts +319 -279
  83. package/packages/table/module/export/util.ts +25 -24
  84. package/packages/table/module/filter/hook.ts +519 -501
  85. package/packages/table/module/filter/panel.ts +368 -304
  86. package/packages/table/module/keyboard/hook.ts +498 -494
  87. package/packages/table/module/menu/hook.ts +330 -330
  88. package/packages/table/module/menu/panel.ts +272 -201
  89. package/packages/table/module/validator/hook.ts +653 -635
  90. package/packages/table/render/index.ts +1819 -1744
  91. package/packages/table/src/body.ts +1078 -955
  92. package/packages/table/src/cell.ts +1524 -1359
  93. package/packages/table/src/column.ts +192 -192
  94. package/packages/table/src/columnInfo.ts +232 -232
  95. package/packages/table/src/emits.ts +134 -134
  96. package/packages/table/src/footer.ts +425 -380
  97. package/packages/table/src/group.ts +67 -63
  98. package/packages/table/src/header.ts +642 -581
  99. package/packages/table/src/props.ts +336 -336
  100. package/packages/table/src/store.ts +14 -14
  101. package/packages/table/src/table.ts +16011 -15454
  102. package/packages/table/src/use/cell-view.ts +41 -44
  103. package/packages/table/src/use/index.ts +1 -1
  104. package/packages/table/src/util.ts +1206 -1216
  105. package/packages/toolbar/index.ts +18 -18
  106. package/packages/toolbar/src/toolbar.ts +768 -706
  107. package/packages/ui/index.ts +519 -520
  108. package/packages/ui/src/anime.ts +51 -52
  109. package/packages/ui/src/comp.ts +3 -3
  110. package/packages/ui/src/dom.ts +466 -463
  111. package/packages/ui/src/log.ts +19 -19
  112. package/packages/ui/src/utils.ts +66 -66
  113. package/packages/ui/src/vn.ts +55 -55
  114. package/packages/v-x-e-table/index.d.ts +3 -3
  115. package/packages/v-x-e-table/index.ts +3 -3
  116. package/types/all.d.ts +76 -76
  117. package/types/index.d.ts +4 -4
  118. /package/dist/{iconfont.1793007753347.ttf → iconfont.1793015256719.ttf} +0 -0
  119. /package/dist/{iconfont.1793007753347.woff → iconfont.1793015256719.woff} +0 -0
  120. /package/dist/{iconfont.1793007753347.woff2 → iconfont.1793015256719.woff2} +0 -0
  121. /package/es/{iconfont.1793007753347.ttf → iconfont.1793015256719.ttf} +0 -0
  122. /package/es/{iconfont.1793007753347.woff → iconfont.1793015256719.woff} +0 -0
  123. /package/es/{iconfont.1793007753347.woff2 → iconfont.1793015256719.woff2} +0 -0
  124. /package/lib/{iconfont.1793007753347.ttf → iconfont.1793015256719.ttf} +0 -0
  125. /package/lib/{iconfont.1793007753347.woff → iconfont.1793015256719.woff} +0 -0
  126. /package/lib/{iconfont.1793007753347.woff2 → iconfont.1793015256719.woff2} +0 -0
@@ -1,1744 +1,1819 @@
1
- import { h, VNode, resolveComponent, ComponentOptions } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import { VxeUI } from '@vxe-ui/core'
4
- import { getCellValue, setCellValue } from '../../table/src/util'
5
- import { getFuncText, formatText, isEmptyValue, hasEnableConf } from '../../ui/src/utils'
6
- import { getOnName, getModelEvent, getChangeEvent, hasInputType } from '../../ui/src/vn'
7
- import { createComponentLog } from '../../ui/src/log'
8
-
9
- import type { VxeGlobalRendererHandles, VxeColumnPropTypes, VxeTableConstructor, VxeTablePrivateMethods, VxeTableDefines } from '../../../types'
10
-
11
- const { errLog } = createComponentLog('table')
12
-
13
- const { getConfig, renderer, getI18n, getComponent } = VxeUI
14
-
15
- const componentDefaultModelProp = 'modelValue'
16
-
17
- const defaultCompProps = {}
18
-
19
- function handleDefaultValue (value: any, defaultVal: any, initVal: any) {
20
- return XEUtils.eqNull(value) ? (XEUtils.eqNull(defaultVal) ? initVal : defaultVal) : value
21
- }
22
-
23
- function parseDate (value: any, props: any) {
24
- return value && props.valueFormat ? XEUtils.toStringDate(value, props.valueFormat) : value
25
- }
26
-
27
- function getFormatDate (value: any, props: any, defaultFormat: string) {
28
- const { dateConfig = {} } = props
29
- return XEUtils.toDateString(parseDate(value, props), dateConfig.labelFormat || defaultFormat)
30
- }
31
-
32
- function getLabelFormatDate (value: any, props: any) {
33
- return getFormatDate(value, props, getI18n(`vxe.input.date.labelFormat.${props.type || 'date'}`))
34
- }
35
-
36
- /**
37
- * 已废弃
38
- * @deprecated
39
- */
40
- function getOldComponentName (name: string) {
41
- return `vxe-${name.replace('$', '')}`
42
- }
43
-
44
- function getDefaultComponent ({ name }: any) {
45
- return getComponent(name)
46
- }
47
-
48
- /**
49
- * 已废弃
50
- * @deprecated
51
- */
52
- function getOldComponent ({ name }: any) {
53
- return resolveComponent(getOldComponentName(name)) as ComponentOptions
54
- }
55
-
56
- function updateFilterChangeOption (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
57
- const { $table } = params
58
- $table.updateFilterOptionStatus(option, checked)
59
- }
60
-
61
- function saveFilterEvent (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
62
- const { $table, column } = params
63
- $table.saveFilterByEvent(new Event('change'), column)
64
- }
65
-
66
- function getNativeAttrs (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
67
- let { name, attrs } = renderOpts
68
- if (name === 'input') {
69
- attrs = Object.assign({ type: 'text' }, attrs)
70
- }
71
- return attrs
72
- }
73
-
74
- function getInputImmediateModel (renderOpts: VxeColumnPropTypes.EditRender) {
75
- const { name, immediate, props } = renderOpts
76
- if (!immediate) {
77
- if (name === 'VxeInput' || name === '$input') {
78
- const { type } = props || {}
79
- return !(!type || type === 'text' || type === 'number' || type === 'integer' || type === 'float')
80
- }
81
- if (name === 'input' || name === 'textarea' || name === '$textarea') {
82
- return false
83
- }
84
- return true
85
- }
86
- return immediate
87
- }
88
-
89
- function getCellEditProps (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams, value: any, defaultProps?: any) {
90
- return XEUtils.assign({ immediate: getInputImmediateModel(renderOpts) }, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
91
- }
92
-
93
- function getCellEditFilterProps (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, value: any, defaultProps?: any) {
94
- return XEUtils.assign({}, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
95
- }
96
-
97
- function isImmediateCell (renderOpts: VxeColumnPropTypes.EditRender, params: any) {
98
- return params.$type === 'cell' || getInputImmediateModel(renderOpts)
99
- }
100
-
101
- function getCellLabelVNs (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, cellLabel: any, opts?: {
102
- class?: string
103
- }) {
104
- const { placeholder } = renderOpts
105
- return [
106
- h('span', {
107
- key: 1,
108
- class: ['vxe-cell--label', opts ? opts.class : '']
109
- }, placeholder && isEmptyValue(cellLabel)
110
- ? [
111
- h('span', {
112
- class: 'vxe-cell--placeholder'
113
- }, formatText(getFuncText(placeholder), 1))
114
- ]
115
- : formatText(cellLabel, 1))
116
- ]
117
- }
118
-
119
- /**
120
- * 原生事件处理
121
- * @param renderOpts
122
- * @param params
123
- * @param modelFunc
124
- * @param changeFunc
125
- */
126
- function getNativeElementOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
127
- model: (evnt: Event) => void
128
- change?: (evnt: Event) => void
129
- blur?: (evnt: Event) => void
130
- }) {
131
- const { events } = renderOpts
132
- const modelEvent = getModelEvent(renderOpts)
133
- const changeEvent = getChangeEvent(renderOpts)
134
- const { model: modelFunc, change: changeFunc, blur: blurFunc } = eFns || {}
135
- const isSameEvent = changeEvent === modelEvent
136
- const ons: any = {}
137
- if (events) {
138
- XEUtils.objectEach(events, (func, key: any) => {
139
- ons[getOnName(key)] = function (...args: any[]) {
140
- func(params, ...args)
141
- }
142
- })
143
- }
144
- if (modelFunc) {
145
- ons[getOnName(modelEvent)] = function (targetEvnt: any) {
146
- modelFunc(targetEvnt)
147
- if (isSameEvent && changeFunc) {
148
- changeFunc(targetEvnt)
149
- }
150
- if (events && events[modelEvent]) {
151
- events[modelEvent](params, targetEvnt)
152
- }
153
- }
154
- }
155
- if (!isSameEvent && changeFunc) {
156
- ons[getOnName(changeEvent)] = function (evnt: Event) {
157
- changeFunc(evnt)
158
- if (events && events[changeEvent]) {
159
- events[changeEvent](params, evnt)
160
- }
161
- }
162
- }
163
- if (blurFunc) {
164
- ons[getOnName(blurEvent)] = function (evnt: Event) {
165
- blurFunc(evnt)
166
- if (events && events[blurEvent]) {
167
- events[blurEvent](params, evnt)
168
- }
169
- }
170
- }
171
- return ons
172
- }
173
-
174
- const blurEvent = 'blur'
175
- const clearEvent = 'clear'
176
-
177
- /**
178
- * 组件事件处理
179
- * @param renderOpts
180
- * @param params
181
- * @param modelFunc
182
- * @param changeFunc
183
- */
184
- function getComponentOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
185
- model: (cellValue: any) => void
186
- change?: (...args: any[]) => void
187
- blur?: (...args: any[]) => void
188
- clear?: (...args: any[]) => void
189
- }, eventOns?: Record<string, any>) {
190
- const { events } = renderOpts
191
- const modelEvent = getModelEvent(renderOpts)
192
- const changeEvent = getChangeEvent(renderOpts)
193
- const { model: modelFunc, change: changeFunc, blur: blurFunc, clear: clearFunc } = eFns || {}
194
- const ons: any = {}
195
- XEUtils.objectEach(events, (func, key: any) => {
196
- ons[getOnName(key)] = function (...args: any[]) {
197
- if (!XEUtils.isFunction(func)) {
198
- errLog('vxe.error.errFunc', [func])
199
- }
200
- func(params, ...args)
201
- }
202
- })
203
- if (modelFunc) {
204
- ons[getOnName(modelEvent)] = function (targetEvnt: any) {
205
- modelFunc(targetEvnt)
206
- if (events && events[modelEvent]) {
207
- events[modelEvent](params, targetEvnt)
208
- }
209
- }
210
- }
211
- if (changeFunc) {
212
- ons[getOnName(changeEvent)] = function (...args: any[]) {
213
- changeFunc(...args)
214
- if (events && events[changeEvent]) {
215
- events[changeEvent](params, ...args)
216
- }
217
- }
218
- }
219
- if (blurFunc) {
220
- ons[getOnName(blurEvent)] = function (...args: any[]) {
221
- blurFunc(...args)
222
- if (events && events[blurEvent]) {
223
- events[blurEvent](params, ...args)
224
- }
225
- }
226
- }
227
- if (clearFunc) {
228
- ons[getOnName(clearEvent)] = function (...args: any[]) {
229
- clearFunc(...args)
230
- if (events && events[clearEvent]) {
231
- events[clearEvent](params, ...args)
232
- }
233
- }
234
- }
235
- return eventOns ? Object.assign(ons, eventOns) : ons
236
- }
237
-
238
- function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
239
- const { $table, row, column } = params
240
- const { name } = renderOpts
241
- const { model } = column
242
- const isImmediate = isImmediateCell(renderOpts, params)
243
- return getComponentOns(renderOpts, params, {
244
- model (cellValue) {
245
- // 处理 model 值双向绑定
246
- model.update = true
247
- model.value = cellValue
248
- if (isImmediate) {
249
- setCellValue(row, column, cellValue)
250
- }
251
- },
252
- change (eventParams) {
253
- // 处理 change 事件相关逻辑
254
- if (!isImmediate && name && (['VxeInput', 'VxeNumberInput', 'VxeTextarea', '$input', '$textarea'].includes(name))) {
255
- const cellValue = eventParams.value
256
- model.update = true
257
- model.value = cellValue
258
- $table.updateStatus(params, cellValue)
259
- } else {
260
- $table.updateStatus(params)
261
- }
262
- },
263
- blur () {
264
- if (isImmediate) {
265
- $table.handleCellRuleUpdateStatus('blur', params)
266
- } else {
267
- $table.handleCellRuleUpdateStatus('blur', params, model.value)
268
- }
269
- }
270
- })
271
- }
272
-
273
- function getFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams, option: VxeTableDefines.FilterOption) {
274
- return getComponentOns(renderOpts, params, {
275
- model (value: any) {
276
- // 处理 model 值双向绑定
277
- option.data = value
278
- },
279
- change () {
280
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
281
- },
282
- blur () {
283
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
284
- }
285
- })
286
- }
287
-
288
- function getFloatingFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams, option: VxeTableDefines.FilterOption) {
289
- const { $table, column } = params
290
- if (hasInputType(renderOpts)) {
291
- return getComponentOns(renderOpts, params, {
292
- model (value: any) {
293
- // 处理 model 值双向绑定
294
- option.data = value
295
- },
296
- change () {
297
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
298
- },
299
- clear () {
300
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
301
- saveFilterEvent(params)
302
- },
303
- blur () {
304
- $table.saveFilterByEvent(new Event('change'), column)
305
- }
306
- }, renderOpts.name === 'VxeNumberInput'
307
- ? {
308
- [getOnName('plus-number')] () {
309
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
310
- saveFilterEvent(params)
311
- },
312
- [getOnName('minus-number')] () {
313
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
314
- saveFilterEvent(params)
315
- }
316
- }
317
- : {})
318
- }
319
- return getComponentOns(renderOpts, params, {
320
- model (value: any) {
321
- // 处理 model 值双向绑定
322
- option.data = value
323
- },
324
- clear () {
325
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
326
- $table.saveFilterByEvent(new Event('change'), column)
327
- },
328
- change () {
329
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
330
- $table.saveFilterByEvent(new Event('change'), column)
331
- }
332
- })
333
- }
334
-
335
- function getNativeEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
336
- const { $table, row, column } = params
337
- const { model } = column
338
- return getNativeElementOns(renderOpts, params, {
339
- model (evnt) {
340
- // 处理 model 值双向绑定
341
- const targetEl = evnt.target as HTMLInputElement
342
- if (targetEl) {
343
- const cellValue = targetEl.value
344
- if (isImmediateCell(renderOpts, params)) {
345
- setCellValue(row, column, cellValue)
346
- } else {
347
- model.update = true
348
- model.value = cellValue
349
- }
350
- }
351
- },
352
- change (evnt) {
353
- // 处理 change 事件相关逻辑
354
- const targetEl = evnt.target as HTMLInputElement
355
- if (targetEl) {
356
- const cellValue = targetEl.value
357
- $table.updateStatus(params, cellValue)
358
- }
359
- },
360
- blur (evnt) {
361
- const targetEl = evnt.target as HTMLInputElement
362
- if (targetEl) {
363
- const cellValue = targetEl.value
364
- $table.updateStatus(params, cellValue)
365
- }
366
- }
367
- })
368
- }
369
-
370
- function getNativeFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, option: any) {
371
- return getNativeElementOns(renderOpts, params, {
372
- model (evnt) {
373
- // 处理 model 值双向绑定
374
- const targetEl = evnt.target as HTMLInputElement
375
- if (targetEl) {
376
- option.data = targetEl.value
377
- }
378
- },
379
- change () {
380
- updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
381
- },
382
- blur () {
383
- updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
384
- }
385
- })
386
- }
387
-
388
- function nativeInputCellRender (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
389
- const { row, column } = renderParams
390
- const cellValue = XEUtils.get(row, column.field)
391
- const cellVNs = [
392
- h('span', {
393
- key: 1
394
- }, cellValue)
395
- ]
396
- return getNativeInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
397
- }
398
-
399
- /**
400
- * 单元格可编辑渲染-原生的标签
401
- * input、textarea
402
- */
403
- function nativeInputEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams) {
404
- const { row, column } = renderParams
405
- const { name } = renderOpts
406
- const cellValue = isImmediateCell(renderOpts, renderParams) ? getCellValue(row, column) : column.model.value
407
- return [
408
- h('' + name, {
409
- key: 2,
410
- class: `vxe-default-${name}`,
411
- ...getNativeAttrs(renderOpts),
412
- value: cellValue,
413
- ...getNativeEditOns(renderOpts, renderParams)
414
- })
415
- ]
416
- }
417
-
418
- function buttonCellRender (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any) {
419
- return [
420
- h(getDefaultComponent(renderOpts), {
421
- ...getCellEditProps(renderOpts, params, null),
422
- ...getComponentOns(renderOpts, params)
423
- })
424
- ]
425
- }
426
-
427
- function defaultInputEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
428
- const { row, column } = params
429
- const cellValue = getCellValue(row, column)
430
- return [
431
- h(getDefaultComponent(renderOpts), {
432
- key: 2,
433
- ...getCellEditProps(renderOpts, params, cellValue),
434
- ...getEditOns(renderOpts, params)
435
- })
436
- ]
437
- }
438
-
439
- function defaultEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
440
- const { row, column } = params
441
- const cellValue = getCellValue(row, column)
442
- return [
443
- h(getDefaultComponent(renderOpts), {
444
- ...getCellEditProps(renderOpts, params, cellValue),
445
- ...getEditOns(renderOpts, params)
446
- })
447
- ]
448
- }
449
-
450
- function checkboxEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
451
- const { row, column } = params
452
- const cellValue = getCellValue(row, column)
453
- return [
454
- h(getDefaultComponent(renderOpts), {
455
- ...getCellEditProps(renderOpts, params, cellValue),
456
- ...getEditOns(renderOpts, params)
457
- })
458
- ]
459
- }
460
-
461
- function radioAndCheckboxGroupEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
462
- const { options } = renderOpts
463
- const { row, column } = params
464
- const cellValue = getCellValue(row, column)
465
- return [
466
- h(getDefaultComponent(renderOpts), {
467
- options,
468
- ...getCellEditProps(renderOpts, params, cellValue),
469
- ...getEditOns(renderOpts, params)
470
- })
471
- ]
472
- }
473
-
474
- /**
475
- * 已废弃
476
- * @deprecated
477
- */
478
- function oldEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
479
- const { row, column } = params
480
- const cellValue = getCellValue(row, column)
481
- return [
482
- h(getOldComponent(renderOpts), {
483
- ...getCellEditProps(renderOpts, params, cellValue),
484
- ...getEditOns(renderOpts, params)
485
- })
486
- ]
487
- }
488
-
489
- /**
490
- * 已废弃
491
- * @deprecated
492
- */
493
- function oldButtonEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
494
- return [
495
- h(getComponent('vxe-button'), {
496
- ...getCellEditProps(renderOpts, params, null),
497
- ...getComponentOns(renderOpts, params)
498
- })
499
- ]
500
- }
501
-
502
- /**
503
- * 已废弃
504
- * @deprecated
505
- */
506
- function oldButtonsEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
507
- const { children } = renderOpts
508
- return children ? children.map((childRenderOpts: any) => oldButtonEditRender(childRenderOpts, params)[0]) : []
509
- }
510
-
511
- function renderNativeOptgroups (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, renderOptionsMethods: any) {
512
- const { optionGroups, optionGroupProps = {} } = renderOpts
513
- const groupOptions = optionGroupProps.options || 'options'
514
- const groupLabel = optionGroupProps.label || 'label'
515
- if (optionGroups) {
516
- return optionGroups.map((group: any, gIndex: any) => {
517
- return h('optgroup', {
518
- key: gIndex,
519
- label: group[groupLabel]
520
- }, renderOptionsMethods(group[groupOptions], renderOpts, params))
521
- })
522
- }
523
- return []
524
- }
525
-
526
- /**
527
- * 渲染原生的 option 标签
528
- */
529
- function renderNativeOptions (options: any, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
530
- const { optionProps = {} } = renderOpts
531
- const { row, column } = params
532
- const labelProp = optionProps.label || 'label'
533
- const valueProp = optionProps.value || 'value'
534
- const disabledProp = optionProps.disabled || 'disabled'
535
- const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
536
- if (options) {
537
- return options.map((option: any, oIndex: any) => {
538
- return h('option', {
539
- key: oIndex,
540
- value: option[valueProp],
541
- disabled: option[disabledProp],
542
- /* eslint-disable eqeqeq */
543
- selected: option[valueProp] == cellValue
544
- }, option[labelProp])
545
- })
546
- }
547
- return []
548
- }
549
-
550
- function nativeFilterRender (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
551
- const { column } = params
552
- const { name } = renderOpts
553
- const attrs = getNativeAttrs(renderOpts)
554
- return column.filters.map((option, oIndex) => {
555
- return h(`${name}`, {
556
- key: oIndex,
557
- class: `vxe-default-${name}`,
558
- ...attrs,
559
- value: option.data,
560
- ...getNativeFilterOns(renderOpts, params, option)
561
- })
562
- })
563
- }
564
-
565
- function defaultFilterRender (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
566
- const { column } = params
567
- return column.filters.map((option, oIndex) => {
568
- const optionValue = option.data
569
- return h(getDefaultComponent(renderOpts), {
570
- key: oIndex,
571
- ...getCellEditFilterProps(renderOpts, renderOpts, optionValue),
572
- ...getFilterOns(renderOpts, params, option)
573
- })
574
- })
575
- }
576
-
577
- function defaultFloatingFilterRender (renderOpts: VxeGlobalRendererHandles.RenderTableFloatingFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
578
- const { option } = params
579
- const optionValue = option.data
580
- return [
581
- h(getDefaultComponent(renderOpts), {
582
- ...getCellEditFilterProps(renderOpts, renderOpts, optionValue),
583
- ...getFloatingFilterOns(renderOpts, params, option)
584
- })
585
- ]
586
- }
587
-
588
- function defaultFilterOptions () {
589
- return [
590
- { data: null }
591
- ]
592
- }
593
-
594
- /**
595
- * 已废弃
596
- * @deprecated
597
- */
598
- function oldFilterRender (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any) {
599
- const { column } = params
600
- return column.filters.map((option: any, oIndex: any) => {
601
- const optionValue = option.data
602
- return h(getOldComponent(renderOpts), {
603
- key: oIndex,
604
- ...getCellEditFilterProps(renderOpts, renderOpts, optionValue),
605
- ...getFilterOns(renderOpts, params, option)
606
- })
607
- })
608
- }
609
-
610
- function handleFilterMethod ({ option, row, column }: any) {
611
- const { data } = option
612
- const cellValue = XEUtils.get(row, column.field)
613
- /* eslint-disable eqeqeq */
614
- return cellValue == data
615
- }
616
-
617
- function handleInputFilterMethod ({ option, row, column }: any) {
618
- const { data } = option
619
- const cellValue = XEUtils.get(row, column.field)
620
- /* eslint-disable eqeqeq */
621
- return XEUtils.toValueString(cellValue).indexOf(data) > -1
622
- }
623
-
624
- function nativeSelectEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
625
- return [
626
- h('select', {
627
- class: 'vxe-default-select',
628
- ...getNativeAttrs(renderOpts),
629
- ...getNativeEditOns(renderOpts, params)
630
- },
631
- renderOpts.optionGroups ? renderNativeOptgroups(renderOpts, params, renderNativeOptions) : renderNativeOptions(renderOpts.options, renderOpts, params))
632
- ]
633
- }
634
-
635
- function defaultSelectEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
636
- const { row, column } = params
637
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
638
- const cellValue = getCellValue(row, column)
639
- return [
640
- h(getDefaultComponent(renderOpts), {
641
- ...getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
642
- ...getEditOns(renderOpts, params)
643
- })
644
- ]
645
- }
646
-
647
- function defaultTableOrTreeSelectEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
648
- const { row, column } = params
649
- const { options, optionProps } = renderOpts
650
- const cellValue = getCellValue(row, column)
651
- return [
652
- h(getDefaultComponent(renderOpts), {
653
- ...getCellEditProps(renderOpts, params, cellValue, { options, optionProps }),
654
- ...getEditOns(renderOpts, params)
655
- })
656
- ]
657
- }
658
-
659
- /**
660
- * 已废弃
661
- * @deprecated
662
- */
663
- function oldSelectEditRender (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
664
- const { row, column } = params
665
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
666
- const cellValue = getCellValue(row, column)
667
- return [
668
- h(getOldComponent(renderOpts), {
669
- ...getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
670
- ...getEditOns(renderOpts, params)
671
- })
672
- ]
673
- }
674
-
675
- function handleSelectCellValue (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
676
- const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props = {} } = renderOpts
677
- let selectItem: any
678
- const labelProp = optionProps.label || 'label'
679
- const valueProp = optionProps.value || 'value'
680
- if (!(cellValue === null || cellValue === undefined)) {
681
- let vals = []
682
- if (XEUtils.isArray(cellValue)) {
683
- vals = cellValue
684
- } else {
685
- if (props.multiple && `${cellValue}`.indexOf(',') > -1) {
686
- vals = `${cellValue}`.split(',')
687
- } else {
688
- vals = [cellValue]
689
- }
690
- }
691
- return XEUtils.map(vals, optionGroups
692
- ? (value) => {
693
- const groupOptions = optionGroupProps.options || 'options'
694
- for (let index = 0; index < optionGroups.length; index++) {
695
- /* eslint-disable eqeqeq */
696
- selectItem = XEUtils.find(optionGroups[index][groupOptions], item => item[valueProp] == value)
697
- if (selectItem) {
698
- break
699
- }
700
- }
701
- return selectItem ? selectItem[labelProp] : value
702
- }
703
- : (value) => {
704
- /* eslint-disable eqeqeq */
705
- selectItem = XEUtils.find(options, item => item[valueProp] == value)
706
- return selectItem ? selectItem[labelProp] : value
707
- }
708
- ).join(', ')
709
- }
710
- return ''
711
- }
712
-
713
- function getSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, { row, column }: any) {
714
- const cellValue = XEUtils.get(row, column.field)
715
- return handleSelectCellValue(cellValue, renderOpts)
716
- }
717
-
718
- function handleExportSelectMethod (params: any) {
719
- const { row, column, options } = params
720
- return options.original ? getCellValue(row, column) : getSelectCellValue(column.editRender || column.cellRender, params)
721
- }
722
-
723
- function handleTreeSelectCellValue (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions) {
724
- const { options, optionProps = {} } = renderOpts
725
- const labelProp = optionProps.label || 'label'
726
- const valueProp = optionProps.value || 'value'
727
- const childrenProp = optionProps.children || 'children'
728
- if (!(cellValue === null || cellValue === undefined)) {
729
- const keyMaps: Record<string, any> = {}
730
- XEUtils.eachTree(options, item => {
731
- keyMaps[XEUtils.get(item, valueProp)] = item
732
- }, { children: childrenProp })
733
- return XEUtils.map(XEUtils.isArray(cellValue) ? cellValue : [cellValue], (value) => {
734
- const item = keyMaps[value]
735
- return item ? XEUtils.get(item, labelProp) : item
736
- }
737
- ).join(', ')
738
- }
739
- return ''
740
- }
741
-
742
- function getTreeSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, { row, column }: any) {
743
- const cellValue = XEUtils.get(row, column.field)
744
- return handleTreeSelectCellValue(cellValue, renderOpts)
745
- }
746
-
747
- function handleExportTreeSelectMethod (params: any) {
748
- const { row, column, options } = params
749
- return options.original ? getCellValue(row, column) : getTreeSelectCellValue(column.editRender || column.cellRender, params)
750
- }
751
-
752
- function handleNumberCell (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.RenderTableDefaultParams) {
753
- const { props = {}, showNegativeStatus } = renderOpts
754
- const { type } = props
755
- let isNegative = false
756
- if (!isEmptyValue(cellValue)) {
757
- const numberInputConfig = getConfig().numberInput || {}
758
- if (type === 'float') {
759
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
760
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
761
- cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
762
- if (!autoFill) {
763
- cellValue = XEUtils.toNumber(cellValue)
764
- }
765
- if (showNegativeStatus) {
766
- if (cellValue < 0) {
767
- isNegative = true
768
- }
769
- }
770
- } else if (type === 'amount') {
771
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
772
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
773
- const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
774
- cellValue = XEUtils.toNumber(cellValue)
775
- if (showNegativeStatus) {
776
- if (cellValue < 0) {
777
- isNegative = true
778
- }
779
- }
780
- cellValue = XEUtils.commafy(cellValue, { digits })
781
- if (!autoFill) {
782
- const [iStr, dStr] = cellValue.split('.')
783
- if (dStr) {
784
- const dRest = dStr.replace(/0+$/, '')
785
- cellValue = dRest ? [iStr, '.', dRest].join('') : iStr
786
- }
787
- }
788
- if (showCurrency) {
789
- cellValue = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${cellValue}`
790
- }
791
- } else {
792
- if (type === 'integer') {
793
- cellValue = XEUtils.toInteger(cellValue)
794
- }
795
- if (showNegativeStatus) {
796
- if (XEUtils.toNumber(cellValue) < 0) {
797
- isNegative = true
798
- }
799
- }
800
- }
801
- }
802
- return getCellLabelVNs(renderOpts, params, cellValue, isNegative
803
- ? {
804
- class: 'is--negative'
805
- }
806
- : {})
807
- }
808
-
809
- function handleFormatDatePicker (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.TableCellFormatterParams) {
810
- const { props = {} } = renderOpts
811
- const { cellValue } = renderParams
812
- if (cellValue) {
813
- if (props.type !== 'time') {
814
- return getLabelFormatDate(cellValue, props)
815
- }
816
- }
817
- return cellValue
818
- }
819
-
820
- function handleFormatSelect (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
821
- const { cellValue } = renderParams
822
- return handleSelectCellValue(cellValue, renderOpts)
823
- }
824
-
825
- function handleSetSelectValue (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
826
- const { row, column, cellValue } = renderParams
827
- const { field } = column
828
- if (field) {
829
- const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props } = renderOpts
830
- if (isEmptyValue(cellValue)) {
831
- XEUtils.set(row, field, props && props.multiple ? [] : null)
832
- return
833
- }
834
- const isMultiVal = XEUtils.indexOf(`${cellValue}`, ',') > -1
835
- const labelProp = optionProps.label || 'label'
836
- const valueProp = optionProps.value || 'value'
837
- const labelMpas: Record<string, any> = {}
838
- if (optionGroups && optionGroups.length) {
839
- const groupOptions = optionGroupProps.options || 'options'
840
- for (let i = 0; i < optionGroups.length; i++) {
841
- const opts = optionGroups[i][groupOptions] || {}
842
- for (let j = 0; j < opts.length; j++) {
843
- const item = opts[j]
844
- if (isMultiVal) {
845
- labelMpas[item[labelProp]] = item
846
- /* eslint-disable eqeqeq */
847
- } else if (item[labelProp] == cellValue) {
848
- XEUtils.set(row, field, item[valueProp])
849
- return
850
- }
851
- }
852
- }
853
- } else {
854
- if (options) {
855
- for (let i = 0; i < options.length; i++) {
856
- const item = options[i]
857
- if (isMultiVal) {
858
- labelMpas[item[labelProp]] = item
859
- /* eslint-disable eqeqeq */
860
- } else if (item[labelProp] == cellValue) {
861
- XEUtils.set(row, field, item[valueProp])
862
- return
863
- }
864
- }
865
- }
866
- }
867
- if (isMultiVal) {
868
- XEUtils.set(row, field, (isMultiVal
869
- ? cellValue.split(',')
870
- : [cellValue]).map((label: any) => {
871
- const item = labelMpas[label]
872
- return item ? item[valueProp] : label
873
- }))
874
- } else {
875
- XEUtils.set(row, field, cellValue)
876
- }
877
- }
878
- }
879
-
880
- function handleFormatTreeSelect (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
881
- const { cellValue } = params
882
- return handleTreeSelectCellValue(cellValue, renderOpts)
883
- }
884
-
885
- function handleSetTreeSelectValue (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
886
- const { row, column, cellValue } = params
887
- const { field } = column
888
- if (field) {
889
- const { options, optionProps = {} } = renderOpts
890
- const labelProp = optionProps.label || 'label'
891
- const valueProp = optionProps.value || 'value'
892
- const childrenProp = optionProps.children || 'children'
893
- const matchRest = XEUtils.findTree(options || [], item => XEUtils.get(item, labelProp) === cellValue, { children: childrenProp })
894
- if (matchRest) {
895
- const selectItem = matchRest.item
896
- if (selectItem) {
897
- XEUtils.set(row, field, selectItem[valueProp])
898
- return
899
- }
900
- }
901
- XEUtils.set(row, field, cellValue)
902
- }
903
- }
904
-
905
- function getNativeInputRenderCellVNs (cellValue: any, labelVNs: VNode[], renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
906
- const { $table, row, column } = renderParams
907
- const { name } = renderOpts
908
- const tableProps = $table.props
909
- const { editConfig, mouseConfig } = tableProps
910
- const { computeMouseOpts } = $table.getComputeMaps()
911
- const mouseOpts = computeMouseOpts.value
912
- let isColSelected = false
913
- let isActiveCellArea = false
914
- if (editConfig && hasEnableConf(mouseConfig, mouseOpts)) {
915
- const tableReactData = $table.reactData
916
- const { editStore } = tableReactData
917
- const { selected } = editStore
918
- isColSelected = row === selected.row && column === selected.column
919
- if ($table.getActiveCellArea) {
920
- const activeCellArea = $table.getActiveCellArea()
921
- if (activeCellArea) {
922
- isActiveCellArea = row === activeCellArea.row && column === activeCellArea.column
923
- }
924
- }
925
- }
926
- const cellVNs = labelVNs
927
- if (isActiveCellArea || isColSelected) {
928
- cellVNs.push(
929
- h('' + name, {
930
- key: 2,
931
- class: `vxe-default-${name} vxe-reusekeep-control`,
932
- value: cellValue,
933
- ...getNativeAttrs(renderOpts),
934
- ...getNativeEditOns(renderOpts, renderParams)
935
- })
936
- )
937
- }
938
- return cellVNs
939
- }
940
-
941
- function getInputRenderCellVNs (cellValue: any, labelVNs: VNode[], renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
942
- const { $table, row, column } = renderParams
943
- const tableProps = $table.props
944
- const { editConfig, mouseConfig } = tableProps
945
- const { computeEditOpts, computeMouseOpts } = $table.getComputeMaps()
946
- const mouseOpts = computeMouseOpts.value
947
- let isColSelected = false
948
- let isActiveCellArea = false
949
- if (editConfig && hasEnableConf(mouseConfig, mouseOpts)) {
950
- const tableReactData = $table.reactData
951
- const { editStore } = tableReactData
952
- const editOpts = computeEditOpts.value
953
- if (editOpts.isReuseKeep) {
954
- const { selected } = editStore
955
- isColSelected = row === selected.row && column === selected.column
956
- if ($table.getActiveCellArea) {
957
- const activeCellArea = $table.getActiveCellArea()
958
- if (activeCellArea) {
959
- isActiveCellArea = row === activeCellArea.row && column === activeCellArea.column
960
- }
961
- }
962
- }
963
- }
964
- const cellVNs = labelVNs
965
- if (isActiveCellArea || isColSelected) {
966
- const compProps = getCellEditProps(renderOpts, renderParams, cellValue)
967
- const { className, inputClassName } = compProps
968
- cellVNs.push(
969
- h(getDefaultComponent(renderOpts), {
970
- key: 2,
971
- ...compProps,
972
- className: 'vxe-reusekeep-control' + (className ? (' ' + className) : ''),
973
- inputClassName: 'vxe-reusekeep-control' + (inputClassName ? (' ' + inputClassName) : ''),
974
- ...getEditOns(renderOpts, renderParams)
975
- })
976
- )
977
- }
978
- return cellVNs
979
- }
980
-
981
- /**
982
- * 表格 - 渲染器
983
- */
984
- renderer.mixin({
985
- input: {
986
- tableAutoFocus: true,
987
- renderTableEdit: nativeInputEditRender,
988
- renderTableCell: nativeInputCellRender,
989
- renderTableDefault: nativeInputEditRender,
990
- createTableFilterOptions: defaultFilterOptions,
991
- renderTableFilter: nativeFilterRender,
992
- tableFilterDefaultMethod: handleInputFilterMethod
993
- },
994
- textarea: {
995
- tableAutoFocus: true,
996
- renderTableEdit: nativeInputEditRender,
997
- renderTableCell: nativeInputCellRender,
998
- renderTableDefault: nativeInputEditRender
999
- },
1000
- select: {
1001
- renderTableEdit: nativeSelectEditRender,
1002
- renderTableDefault: nativeSelectEditRender,
1003
- renderTableCell (renderOpts, params) {
1004
- const { options, optionGroups } = renderOpts
1005
- const { $table, row, column } = params
1006
- const opSize = options ? options.length : null
1007
- const ogSize = optionGroups ? optionGroups.length : null
1008
- const { cellResult } = $table.effectCellData(row, column, {
1009
- key: 'render_table_cell',
1010
- isChanged ({ oldValue, cellValue }) {
1011
- return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1012
- },
1013
- setValue ({ cellValue }) {
1014
- return [cellValue, opSize, ogSize]
1015
- },
1016
- getResult ({ cellValue }) {
1017
- return handleSelectCellValue(cellValue, renderOpts)
1018
- }
1019
- })
1020
- // const cellResult = getSelectCellValue(renderOpts, params)
1021
- return getCellLabelVNs(renderOpts, params, cellResult)
1022
- },
1023
- createTableFilterOptions: defaultFilterOptions,
1024
- renderTableFilter (renderOpts, params) {
1025
- const { column } = params
1026
- return column.filters.map((option, oIndex) => {
1027
- return h('select', {
1028
- key: oIndex,
1029
- class: 'vxe-default-select',
1030
- ...getNativeAttrs(renderOpts),
1031
- ...getNativeFilterOns(renderOpts, params, option)
1032
- },
1033
- renderOpts.optionGroups ? renderNativeOptgroups(renderOpts, params, renderNativeOptions) : renderNativeOptions(renderOpts.options, renderOpts, params))
1034
- })
1035
- },
1036
- tableCellFormatter: handleFormatSelect,
1037
- tableCellCopyMethod: handleFormatSelect,
1038
- tableCellPasteMethod: handleSetSelectValue,
1039
- tableFilterDefaultMethod: handleFilterMethod,
1040
- tableExportMethod: handleExportSelectMethod
1041
- },
1042
- VxeInput: {
1043
- tableAutoFocus: true,
1044
- renderTableEdit: defaultInputEditRender,
1045
- renderTableCell (renderOpts, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1046
- const { props = {} } = renderOpts
1047
- const { row, column } = renderParams
1048
- const inputConfig = getConfig().input || {}
1049
- const digits = props.digits || inputConfig.digits || 2
1050
- let cellValue = XEUtils.get(row, column.field)
1051
- if (cellValue) {
1052
- switch (props.type) {
1053
- case 'date':
1054
- case 'week':
1055
- case 'month':
1056
- case 'quarter':
1057
- case 'year':
1058
- cellValue = getLabelFormatDate(cellValue, props)
1059
- break
1060
- case 'float':
1061
- cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
1062
- break
1063
- }
1064
- }
1065
- const cellVNs = getCellLabelVNs(renderOpts, renderParams, cellValue)
1066
- return getInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
1067
- },
1068
- renderTableDefault: defaultInputEditRender,
1069
- createTableFilterOptions: defaultFilterOptions,
1070
- renderTableFilter: defaultFilterRender,
1071
- renderTableFloatingFilter: defaultFloatingFilterRender,
1072
- tableFilterDefaultMethod: handleInputFilterMethod
1073
- },
1074
- FormatNumberInput: {
1075
- renderTableDefault (renderOpts, renderParams) {
1076
- const { row, column } = renderParams
1077
- const cellValue = XEUtils.get(row, column.field)
1078
- return handleNumberCell(cellValue, renderOpts, renderParams)
1079
- },
1080
- tableFilterDefaultMethod ({ option, row, column }) {
1081
- const { data } = option
1082
- const cellValue = XEUtils.get(row, column.field)
1083
- /* eslint-disable eqeqeq */
1084
- return cellValue == data
1085
- },
1086
- tableExportMethod (params) {
1087
- const { row, column } = params
1088
- const cellValue = XEUtils.get(row, column.field)
1089
- return cellValue
1090
- }
1091
- },
1092
- VxeNumberInput: {
1093
- tableAutoFocus: true,
1094
- renderTableEdit: defaultInputEditRender,
1095
- renderTableCell (renderOpts, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1096
- const { row, column } = renderParams
1097
- const cellValue = XEUtils.get(row, column.field)
1098
- const cellVNs = handleNumberCell(cellValue, renderOpts, renderParams)
1099
- return getInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
1100
- },
1101
- renderTableFooter (renderOpts, params) {
1102
- const { props = {} } = renderOpts
1103
- const { row, column, _columnIndex } = params
1104
- const { type } = props
1105
- // 兼容老模式
1106
- const itemValue = XEUtils.isArray(row) ? row[_columnIndex] : XEUtils.get(row, column.field)
1107
- if (XEUtils.isNumber(itemValue)) {
1108
- const numberInputConfig = getConfig().numberInput || {}
1109
- if (type === 'float') {
1110
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
1111
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
1112
- let amountLabel = XEUtils.toFixed(XEUtils.floor(itemValue, digits), digits)
1113
- if (!autoFill) {
1114
- amountLabel = '' + XEUtils.toNumber(amountLabel)
1115
- }
1116
- return amountLabel
1117
- } else if (type === 'amount') {
1118
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
1119
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
1120
- const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
1121
- let amountLabel = XEUtils.commafy(XEUtils.toNumber(itemValue), { digits })
1122
- if (!autoFill) {
1123
- const [iStr, dStr] = amountLabel.split('.')
1124
- if (dStr) {
1125
- const dRest = dStr.replace(/0+$/, '')
1126
- amountLabel = dRest ? [iStr, '.', dRest].join('') : iStr
1127
- }
1128
- }
1129
- if (showCurrency) {
1130
- amountLabel = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${amountLabel}`
1131
- }
1132
- return amountLabel
1133
- }
1134
- }
1135
- return getFuncText(itemValue, 1)
1136
- },
1137
- renderTableDefault: defaultInputEditRender,
1138
- createTableFilterOptions: defaultFilterOptions,
1139
- renderTableFilter: defaultFilterRender,
1140
- renderTableFloatingFilter: defaultFloatingFilterRender,
1141
- tableFilterDefaultMethod ({ option, row, column }) {
1142
- const { data } = option
1143
- const cellValue = XEUtils.get(row, column.field)
1144
- /* eslint-disable eqeqeq */
1145
- return cellValue == data
1146
- },
1147
- tableExportMethod (params) {
1148
- const { row, column } = params
1149
- const cellValue = XEUtils.get(row, column.field)
1150
- return cellValue
1151
- }
1152
- },
1153
- VxeDatePicker: {
1154
- tableAutoFocus: true,
1155
- renderTableEdit: defaultEditRender,
1156
- renderTableCell (renderOpts, params) {
1157
- const props = renderOpts.props || {}
1158
- const { $table, row, column } = params
1159
- const { cellResult } = $table.effectCellData(row, column, {
1160
- key: 'render_table_cell',
1161
- getResult ({ cellValue }) {
1162
- if (cellValue) {
1163
- if (props.type !== 'time') {
1164
- return getLabelFormatDate(cellValue, props)
1165
- }
1166
- }
1167
- return cellValue
1168
- }
1169
- })
1170
- return getCellLabelVNs(renderOpts, params, cellResult)
1171
- },
1172
- tableCellFormatter: handleFormatDatePicker,
1173
- renderTableDefault: defaultEditRender,
1174
- createTableFilterOptions: defaultFilterOptions,
1175
- renderTableFilter: defaultFilterRender,
1176
- renderTableFloatingFilter: defaultFloatingFilterRender,
1177
- tableFilterDefaultMethod: handleFilterMethod
1178
- },
1179
- VxeDateRangePicker: {
1180
- tableAutoFocus: true,
1181
- renderTableEdit (renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1182
- const { startField, endField } = renderOpts
1183
- const { $table, row, column } = params
1184
- const { model } = column
1185
- const cellValue = getCellValue(row, column)
1186
- const seProps: Record<string, any> = {}
1187
- const seOs: Record<string, any> = {}
1188
- if (startField && endField) {
1189
- seProps.startValue = XEUtils.get(row, startField)
1190
- seProps.endValue = XEUtils.get(row, endField)
1191
- seOs['onUpdate:startValue'] = (value: any) => {
1192
- if (startField) {
1193
- XEUtils.set(row, startField, value)
1194
- }
1195
- }
1196
- seOs['onUpdate:endValue'] = (value: any) => {
1197
- if (endField) {
1198
- XEUtils.set(row, endField, value)
1199
- }
1200
- }
1201
- }
1202
- return [
1203
- h(getDefaultComponent(renderOpts), {
1204
- ...getCellEditProps(renderOpts, params, cellValue, seProps),
1205
- ...getComponentOns(renderOpts, params, {
1206
- model (cellValue) {
1207
- model.update = true
1208
- model.value = cellValue
1209
- setCellValue(row, column, cellValue)
1210
- },
1211
- change () {
1212
- $table.updateStatus(params)
1213
- },
1214
- blur () {
1215
- $table.handleCellRuleUpdateStatus('blur', params)
1216
- }
1217
- }, seOs)
1218
- })
1219
- ]
1220
- },
1221
- renderTableDefault (renderOpts, params) {
1222
- const { startField, endField } = renderOpts
1223
- const { row, column } = params
1224
- const { model } = column
1225
- const cellValue = getCellValue(row, column)
1226
- const seProps: Record<string, any> = {}
1227
- const seOs: Record<string, any> = {}
1228
- if (startField && endField) {
1229
- seProps.startValue = XEUtils.get(row, startField)
1230
- seProps.endValue = XEUtils.get(row, endField)
1231
- seOs['onUpdate:startValue'] = (value: any) => {
1232
- if (startField) {
1233
- XEUtils.set(row, startField, value)
1234
- }
1235
- }
1236
- seOs['onUpdate:endValue'] = (value: any) => {
1237
- if (endField) {
1238
- XEUtils.set(row, endField, value)
1239
- }
1240
- }
1241
- }
1242
- return [
1243
- h(getDefaultComponent(renderOpts), {
1244
- ...getCellEditProps(renderOpts, params, cellValue, seProps),
1245
- ...getComponentOns(renderOpts, params, {
1246
- model (cellValue) {
1247
- model.update = true
1248
- model.value = cellValue
1249
- setCellValue(row, column, cellValue)
1250
- }
1251
- }, seOs)
1252
- })
1253
- ]
1254
- },
1255
- renderTableCell (renderOpts, params) {
1256
- const { startField, endField } = renderOpts
1257
- const { row, column } = params
1258
- let startValue = ''
1259
- let endValue = ''
1260
- if (startField && endField) {
1261
- startValue = XEUtils.get(row, startField)
1262
- endValue = XEUtils.get(row, endField)
1263
- } else {
1264
- const cellValue = XEUtils.get(row, column.field)
1265
- if (cellValue) {
1266
- if (XEUtils.isArray(cellValue)) {
1267
- startValue = cellValue[0]
1268
- endValue = cellValue[1]
1269
- } else {
1270
- const strs = `${cellValue}`.split(',')
1271
- startValue = strs[0]
1272
- endValue = strs[1]
1273
- }
1274
- }
1275
- }
1276
- let cellLabel = ''
1277
- if (startValue && endValue) {
1278
- cellLabel = `${startValue} ~ ${endValue}`
1279
- }
1280
- return getCellLabelVNs(renderOpts, params, cellLabel)
1281
- }
1282
- },
1283
- VxeTextarea: {
1284
- tableAutoFocus: true,
1285
- renderTableDefault: defaultInputEditRender,
1286
- renderTableCell (renderOpts, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1287
- const { row, column } = renderParams
1288
- const cellValue = XEUtils.get(row, column.field)
1289
- const cellVNs = getCellLabelVNs(renderOpts, renderParams, cellValue)
1290
- return getInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
1291
- },
1292
- renderTableEdit: defaultInputEditRender
1293
- },
1294
- VxeButton: {
1295
- renderTableDefault: buttonCellRender
1296
- },
1297
- VxeButtonGroup: {
1298
- renderTableDefault (renderOpts, params) {
1299
- const { options } = renderOpts
1300
- return [
1301
- h(getDefaultComponent(renderOpts), {
1302
- options,
1303
- ...getCellEditProps(renderOpts, params, null),
1304
- ...getComponentOns(renderOpts, params)
1305
- })
1306
- ]
1307
- }
1308
- },
1309
- VxeSelect: {
1310
- tableAutoFocus: true,
1311
- renderTableEdit: defaultSelectEditRender,
1312
- renderTableDefault: defaultSelectEditRender,
1313
- renderTableCell (renderOpts, params) {
1314
- const { options, optionGroups } = renderOpts
1315
- const { $table, row, column } = params
1316
- const opSize = options ? options.length : null
1317
- const ogSize = optionGroups ? optionGroups.length : null
1318
- const { cellResult } = $table.effectCellData(row, column, {
1319
- key: 'render_table_cell',
1320
- isChanged ({ oldValue, cellValue }) {
1321
- return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1322
- },
1323
- setValue ({ cellValue }) {
1324
- return [cellValue, opSize, ogSize]
1325
- },
1326
- getResult ({ cellValue }) {
1327
- return handleSelectCellValue(cellValue, renderOpts)
1328
- }
1329
- })
1330
- // const cellResult = getSelectCellValue(renderOpts, params)
1331
- return getCellLabelVNs(renderOpts, params, cellResult)
1332
- },
1333
- createTableFilterOptions: defaultFilterOptions,
1334
- renderTableFilter (renderOpts, params) {
1335
- const { column } = params
1336
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1337
- return column.filters.map((option, oIndex) => {
1338
- const optionValue = option.data
1339
- return h(getDefaultComponent(renderOpts), {
1340
- key: oIndex,
1341
- ...getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1342
- ...getFilterOns(renderOpts, params, option)
1343
- })
1344
- })
1345
- },
1346
- renderTableFloatingFilter (renderOpts, params) {
1347
- const { option } = params
1348
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1349
- const optionValue = option.data
1350
- return h(getDefaultComponent(renderOpts), {
1351
- ...getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1352
- ...getFloatingFilterOns(renderOpts, params, option)
1353
- })
1354
- },
1355
- tableCellFormatter: handleFormatSelect,
1356
- tableCellCopyMethod: handleFormatSelect,
1357
- tableCellPasteMethod: handleSetSelectValue,
1358
- tableFilterDefaultMethod: handleFilterMethod,
1359
- tableExportMethod: handleExportSelectMethod
1360
- },
1361
- VxeText: {
1362
- renderTableDefault (renderOpts, params) {
1363
- const { $table, row, column } = params
1364
- const { props } = renderOpts
1365
- const cellLabel = $table.getCellLabel(row, column)
1366
- return [
1367
- h(getDefaultComponent(renderOpts), {
1368
- ...(props || {}),
1369
- content: cellLabel,
1370
- ...getComponentOns(renderOpts, params)
1371
- })
1372
- ]
1373
- }
1374
- },
1375
- VxeLink: {
1376
- renderTableDefault (renderOpts, params) {
1377
- const { $table, row, column } = params
1378
- const { props } = renderOpts
1379
- const { href } = props || {}
1380
- const cellLabel = $table.getCellLabel(row, column)
1381
- return [
1382
- h(getDefaultComponent(renderOpts), {
1383
- ...(props || {}),
1384
- content: cellLabel,
1385
- href: XEUtils.toFormatString(href, params),
1386
- ...getComponentOns(renderOpts, params)
1387
- })
1388
- ]
1389
- }
1390
- },
1391
- /**
1392
- * 已废弃,被 FormatSelect 替换
1393
- * @deprecated
1394
- */
1395
- formatOption: {
1396
- renderTableDefault (renderOpts, params) {
1397
- return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
1398
- }
1399
- },
1400
- FormatSelect: {
1401
- renderTableDefault (renderOpts, params) {
1402
- const { options, optionGroups } = renderOpts
1403
- const { $table, row, column } = params
1404
- const opSize = options ? options.length : null
1405
- const ogSize = optionGroups ? optionGroups.length : null
1406
- const { cellResult } = $table.effectCellData(row, column, {
1407
- key: 'render_table_cell',
1408
- isChanged ({ oldValue, cellValue }) {
1409
- return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1410
- },
1411
- setValue ({ cellValue }) {
1412
- return [cellValue, opSize, ogSize]
1413
- },
1414
- getResult ({ cellValue }) {
1415
- return handleSelectCellValue(cellValue, renderOpts)
1416
- }
1417
- })
1418
- // const cellResult = getSelectCellValue(renderOpts, params)
1419
- return getCellLabelVNs(renderOpts, params, cellResult)
1420
- },
1421
- tableCellFormatter: handleFormatSelect,
1422
- tableCellCopyMethod: handleFormatSelect,
1423
- tableCellPasteMethod: handleSetSelectValue,
1424
- tableFilterDefaultMethod: handleFilterMethod,
1425
- tableExportMethod: handleExportSelectMethod
1426
- },
1427
- VxeTreeSelect: {
1428
- tableAutoFocus: true,
1429
- renderTableEdit: defaultTableOrTreeSelectEditRender,
1430
- renderTableCell (renderOpts, params) {
1431
- const { options, optionGroups } = renderOpts
1432
- const { $table, row, column } = params
1433
- const opSize = options ? options.length : null
1434
- const ogSize = optionGroups ? optionGroups.length : null
1435
- const { cellResult } = $table.effectCellData(row, column, {
1436
- key: 'render_table_cell',
1437
- isChanged ({ oldValue, cellValue }) {
1438
- return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1439
- },
1440
- setValue ({ cellValue }) {
1441
- return [cellValue, opSize, ogSize]
1442
- },
1443
- getResult ({ cellValue }) {
1444
- return handleTreeSelectCellValue(cellValue, renderOpts)
1445
- }
1446
- })
1447
- // const cellResult = getTreeSelectCellValue(renderOpts, params)
1448
- return getCellLabelVNs(renderOpts, params, cellResult)
1449
- },
1450
- tableCellFormatter: handleFormatTreeSelect,
1451
- tableCellCopyMethod: handleFormatTreeSelect,
1452
- tableCellPasteMethod: handleSetTreeSelectValue,
1453
- tableExportMethod: handleExportTreeSelectMethod
1454
- },
1455
- /**
1456
- * 已废弃,被 FormatTreeSelect 替换
1457
- * @deprecated
1458
- */
1459
- formatTree: {
1460
- renderTableDefault (renderOpts, params) {
1461
- return getCellLabelVNs(renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1462
- }
1463
- },
1464
- FormatTreeSelect: {
1465
- renderTableDefault (renderOpts, params) {
1466
- const { options, optionGroups } = renderOpts
1467
- const { $table, row, column } = params
1468
- const opSize = options ? options.length : null
1469
- const ogSize = optionGroups ? optionGroups.length : null
1470
- const { cellResult } = $table.effectCellData(row, column, {
1471
- key: 'render_table_cell',
1472
- isChanged ({ oldValue, cellValue }) {
1473
- return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1474
- },
1475
- setValue ({ cellValue }) {
1476
- return [cellValue, opSize, ogSize]
1477
- },
1478
- getResult ({ cellValue }) {
1479
- return handleTreeSelectCellValue(cellValue, renderOpts)
1480
- }
1481
- })
1482
- // const cellResult = getTreeSelectCellValue(renderOpts, params)
1483
- return getCellLabelVNs(renderOpts, params, cellResult)
1484
- },
1485
- tableCellFormatter: handleFormatTreeSelect,
1486
- tableCellCopyMethod: handleFormatTreeSelect,
1487
- tableCellPasteMethod: handleSetTreeSelectValue,
1488
- tableExportMethod: handleExportTreeSelectMethod
1489
- },
1490
- VxeCascader: {
1491
- tableAutoFocus: true,
1492
- renderTableEdit: defaultTableOrTreeSelectEditRender,
1493
- renderTableCell (renderOpts, params) {
1494
- const { options, optionGroups } = renderOpts
1495
- const { $table, row, column } = params
1496
- const opSize = options ? options.length : null
1497
- const ogSize = optionGroups ? optionGroups.length : null
1498
- const { cellResult } = $table.effectCellData(row, column, {
1499
- key: 'render_table_cell',
1500
- isChanged ({ oldValue, cellValue }) {
1501
- return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1502
- },
1503
- setValue ({ cellValue }) {
1504
- return [cellValue, opSize, ogSize]
1505
- },
1506
- getResult ({ cellValue }) {
1507
- return handleTreeSelectCellValue(cellValue, renderOpts)
1508
- }
1509
- })
1510
- // const cellResult = getTreeSelectCellValue(renderOpts, params)
1511
- return getCellLabelVNs(renderOpts, params, cellResult)
1512
- },
1513
- tableCellFormatter: handleFormatTreeSelect,
1514
- tableCellCopyMethod: handleFormatTreeSelect,
1515
- tableCellPasteMethod: handleSetTreeSelectValue,
1516
- tableExportMethod: handleExportTreeSelectMethod
1517
- },
1518
- VxeTableSelect: {
1519
- tableAutoFocus: true,
1520
- renderTableEdit: defaultTableOrTreeSelectEditRender,
1521
- renderTableCell (renderOpts, params) {
1522
- const { options, optionGroups } = renderOpts
1523
- const { $table, row, column } = params
1524
- const opSize = options ? options.length : null
1525
- const ogSize = optionGroups ? optionGroups.length : null
1526
- const { cellResult } = $table.effectCellData(row, column, {
1527
- key: 'render_table_cell',
1528
- isChanged ({ oldValue, cellValue }) {
1529
- return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1530
- },
1531
- setValue ({ cellValue }) {
1532
- return [cellValue, opSize, ogSize]
1533
- },
1534
- getResult ({ cellValue }) {
1535
- return handleTreeSelectCellValue(cellValue, renderOpts)
1536
- }
1537
- })
1538
- // const cellResult = getTreeSelectCellValue(renderOpts, params)
1539
- return getCellLabelVNs(renderOpts, params, cellResult)
1540
- },
1541
- tableCellFormatter: handleFormatTreeSelect,
1542
- tableCellCopyMethod: handleFormatTreeSelect,
1543
- tableCellPasteMethod: handleSetTreeSelectValue,
1544
- tableExportMethod: handleExportTreeSelectMethod
1545
- },
1546
- VxeColorPicker: {
1547
- tableAutoFocus: true,
1548
- renderTableEdit (renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1549
- const { row, column } = params
1550
- const { options } = renderOpts
1551
- const cellValue = getCellValue(row, column)
1552
- return [
1553
- h(getDefaultComponent(renderOpts), {
1554
- ...getCellEditProps(renderOpts, params, cellValue, { colors: options }),
1555
- ...getEditOns(renderOpts, params)
1556
- })
1557
- ]
1558
- },
1559
- renderTableCell (renderOpts, params) {
1560
- const { $table, row, column } = params
1561
- const { props } = renderOpts
1562
- const { computeSize } = $table.getComputeMaps()
1563
- const customSize = props ? props.size : null
1564
- const vSize = customSize || computeSize.value
1565
- const cellValue = XEUtils.get(row, column.field)
1566
- return h('span', {
1567
- class: ['vxe-color-picker--readonly', {
1568
- [`size--${vSize}`]: vSize
1569
- }]
1570
- }, [
1571
- h('div', {
1572
- class: ['vxe-color-picker--readonly-color', {
1573
- 'is--empty': !cellValue
1574
- }],
1575
- style: cellValue
1576
- ? {
1577
- backgroundColor: cellValue
1578
- }
1579
- : undefined
1580
- })
1581
- ])
1582
- }
1583
- },
1584
- VxeIconPicker: {
1585
- tableAutoFocus: true,
1586
- renderTableEdit (renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1587
- const { row, column } = params
1588
- const { options } = renderOpts
1589
- const cellValue = getCellValue(row, column)
1590
- return [
1591
- h(getDefaultComponent(renderOpts), {
1592
- ...getCellEditProps(renderOpts, params, cellValue, { icons: options }),
1593
- ...getEditOns(renderOpts, params)
1594
- })
1595
- ]
1596
- },
1597
- renderTableCell (renderOpts, params) {
1598
- const { row, column } = params
1599
- const cellValue = XEUtils.get(row, column.field)
1600
- return h('i', {
1601
- class: cellValue
1602
- })
1603
- }
1604
- },
1605
- VxeRadioGroup: {
1606
- renderTableDefault: radioAndCheckboxGroupEditRender
1607
- },
1608
- VxeCheckbox: {
1609
- renderTableDefault: checkboxEditRender
1610
- },
1611
- VxeCheckboxGroup: {
1612
- renderTableDefault: radioAndCheckboxGroupEditRender
1613
- },
1614
- VxeSwitch: {
1615
- tableAutoFocus: 'button',
1616
- renderTableEdit: defaultEditRender,
1617
- renderTableDefault: defaultEditRender
1618
- },
1619
- VxeUpload: {
1620
- renderTableEdit: defaultEditRender,
1621
- renderTableCell: defaultEditRender,
1622
- renderTableDefault: defaultEditRender
1623
- },
1624
- VxeImage: {
1625
- renderTableDefault (renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1626
- const { row, column } = params
1627
- const { props } = renderOpts
1628
- const cellValue = getCellValue(row, column)
1629
- return [
1630
- h(getDefaultComponent(renderOpts), {
1631
- ...props,
1632
- src: cellValue,
1633
- ...getEditOns(renderOpts, params)
1634
- })
1635
- ]
1636
- }
1637
- },
1638
- VxeImageGroup: {
1639
- renderTableDefault (renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1640
- const { row, column } = params
1641
- const { props } = renderOpts
1642
- const cellValue = getCellValue(row, column)
1643
- return [
1644
- h(getDefaultComponent(renderOpts), {
1645
- ...props,
1646
- urlList: cellValue,
1647
- ...getEditOns(renderOpts, params)
1648
- })
1649
- ]
1650
- }
1651
- },
1652
- VxeTextEllipsis: {
1653
- renderTableDefault (renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1654
- const { row, column } = params
1655
- const { props } = renderOpts
1656
- const cellValue = getCellValue(row, column)
1657
- return [
1658
- h(getDefaultComponent(renderOpts), {
1659
- ...props,
1660
- content: cellValue,
1661
- ...getEditOns(renderOpts, params)
1662
- })
1663
- ]
1664
- }
1665
- },
1666
- VxeRate: {
1667
- renderTableDefault: defaultEditRender
1668
- },
1669
- VxeSlider: {
1670
- renderTableDefault: defaultEditRender
1671
- },
1672
-
1673
- // 以下已废弃
1674
- $input: {
1675
- tableAutoFocus: 'input',
1676
- renderTableEdit: oldEditRender,
1677
- renderTableCell (renderOpts, params) {
1678
- const { props = {} } = renderOpts
1679
- const { row, column } = params
1680
- const digits = props.digits || getConfig().input?.digits || 2
1681
- let cellValue = XEUtils.get(row, column.field)
1682
- if (cellValue) {
1683
- switch (props.type) {
1684
- case 'date':
1685
- case 'week':
1686
- case 'month':
1687
- case 'year':
1688
- cellValue = getLabelFormatDate(cellValue, props)
1689
- break
1690
- case 'float':
1691
- cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
1692
- break
1693
- }
1694
- }
1695
- return getCellLabelVNs(renderOpts, params, cellValue)
1696
- },
1697
- renderTableDefault: oldEditRender,
1698
- renderTableFilter: oldFilterRender,
1699
- tableFilterDefaultMethod: handleInputFilterMethod
1700
- },
1701
- $textarea: {
1702
- tableAutoFocus: 'textarea'
1703
- },
1704
- $button: {
1705
- renderTableDefault: oldButtonEditRender
1706
- },
1707
- $buttons: {
1708
- renderTableDefault: oldButtonsEditRender
1709
- },
1710
- $select: {
1711
- tableAutoFocus: 'input',
1712
- renderTableEdit: oldSelectEditRender,
1713
- renderTableDefault: oldSelectEditRender,
1714
- renderTableCell (renderOpts, params) {
1715
- return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
1716
- },
1717
- renderTableFilter (renderOpts, params) {
1718
- const { column } = params
1719
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1720
- return column.filters.map((option, oIndex) => {
1721
- const optionValue = option.data
1722
- return h(getOldComponent(renderOpts), {
1723
- key: oIndex,
1724
- ...getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1725
- ...getFilterOns(renderOpts, params, option)
1726
- })
1727
- })
1728
- },
1729
- tableFilterDefaultMethod: handleFilterMethod,
1730
- tableExportMethod: handleExportSelectMethod
1731
- },
1732
- $radio: {
1733
- tableAutoFocus: 'input'
1734
- },
1735
- $checkbox: {
1736
- tableAutoFocus: 'input'
1737
- },
1738
- $switch: {
1739
- tableAutoFocus: 'button',
1740
- renderTableEdit: oldEditRender,
1741
- renderTableDefault: oldEditRender
1742
- }
1743
- // 以上已废弃
1744
- })
1
+ import { h, VNode, resolveComponent, ComponentOptions } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import { VxeUI } from '@vxe-ui/core'
4
+ import { getCellValue, setCellValue } from '../../table/src/util'
5
+ import { getFuncText, formatText, isEmptyValue, hasEnableConf } from '../../ui/src/utils'
6
+ import { getOnName, getModelEvent, getChangeEvent, hasInputType } from '../../ui/src/vn'
7
+ import { createComponentLog } from '../../ui/src/log'
8
+
9
+ import type { VxeGlobalRendererHandles, VxeColumnPropTypes, VxeTableConstructor, VxeTablePrivateMethods, VxeTableDefines } from '../../../types'
10
+
11
+ const { errLog } = createComponentLog('table')
12
+
13
+ const { getConfig, renderer, getI18n, getComponent } = VxeUI
14
+
15
+ const componentDefaultModelProp = 'modelValue'
16
+
17
+ const defaultCompProps = {}
18
+
19
+ function handleDefaultValue(value: any, defaultVal: any, initVal: any) {
20
+ return XEUtils.eqNull(value) ? (XEUtils.eqNull(defaultVal) ? initVal : defaultVal) : value
21
+ }
22
+
23
+ function parseDate(value: any, props: any) {
24
+ return value && props.valueFormat ? XEUtils.toStringDate(value, props.valueFormat) : value
25
+ }
26
+
27
+ function getFormatDate(value: any, props: any, defaultFormat: string) {
28
+ const { dateConfig = {} } = props
29
+ return XEUtils.toDateString(parseDate(value, props), dateConfig.labelFormat || defaultFormat)
30
+ }
31
+
32
+ function getLabelFormatDate(value: any, props: any) {
33
+ return getFormatDate(value, props, getI18n(`vxe.input.date.labelFormat.${props.type || 'date'}`))
34
+ }
35
+
36
+ /**
37
+ * 已废弃
38
+ * @deprecated
39
+ */
40
+ function getOldComponentName(name: string) {
41
+ return `vxe-${name.replace('$', '')}`
42
+ }
43
+
44
+ function getDefaultComponent({ name }: any) {
45
+ return getComponent(name)
46
+ }
47
+
48
+ /**
49
+ * 已废弃
50
+ * @deprecated
51
+ */
52
+ function getOldComponent({ name }: any) {
53
+ return resolveComponent(getOldComponentName(name)) as ComponentOptions
54
+ }
55
+
56
+ function updateFilterChangeOption(params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
57
+ const { $table } = params
58
+ $table.updateFilterOptionStatus(option, checked)
59
+ }
60
+
61
+ function saveFilterEvent(params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
62
+ const { $table, column } = params
63
+ $table.saveFilterByEvent(new Event('change'), column)
64
+ }
65
+
66
+ function getNativeAttrs(renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
67
+ let { name, attrs } = renderOpts
68
+ if (name === 'input') {
69
+ attrs = Object.assign({ type: 'text' }, attrs)
70
+ }
71
+ return attrs
72
+ }
73
+
74
+ function getInputImmediateModel(renderOpts: VxeColumnPropTypes.EditRender) {
75
+ const { name, immediate, props } = renderOpts
76
+ if (!immediate) {
77
+ if (name === 'VxeInput' || name === '$input') {
78
+ const { type } = props || {}
79
+ return !(!type || type === 'text' || type === 'number' || type === 'integer' || type === 'float')
80
+ }
81
+ if (name === 'input' || name === 'textarea' || name === '$textarea') {
82
+ return false
83
+ }
84
+ return true
85
+ }
86
+ return immediate
87
+ }
88
+
89
+ function getCellEditProps(renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams, value: any, defaultProps?: any) {
90
+ return XEUtils.assign({ immediate: getInputImmediateModel(renderOpts) }, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
91
+ }
92
+
93
+ function getCellEditFilterProps(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, value: any, defaultProps?: any) {
94
+ return XEUtils.assign({}, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
95
+ }
96
+
97
+ function isImmediateCell(renderOpts: VxeColumnPropTypes.EditRender, params: any) {
98
+ return params.$type === 'cell' || getInputImmediateModel(renderOpts)
99
+ }
100
+
101
+ function getCellLabelVNs(
102
+ renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions,
103
+ params: any,
104
+ cellLabel: any,
105
+ opts?: {
106
+ class?: string
107
+ }
108
+ ) {
109
+ const { placeholder } = renderOpts
110
+ return [
111
+ h(
112
+ 'span',
113
+ {
114
+ key: 1,
115
+ class: ['vxe-cell--label', opts ? opts.class : '']
116
+ },
117
+ placeholder && isEmptyValue(cellLabel)
118
+ ? [
119
+ h(
120
+ 'span',
121
+ {
122
+ class: 'vxe-cell--placeholder'
123
+ },
124
+ formatText(getFuncText(placeholder), 1)
125
+ )
126
+ ]
127
+ : formatText(cellLabel, 1)
128
+ )
129
+ ]
130
+ }
131
+
132
+ /**
133
+ * 原生事件处理
134
+ * @param renderOpts
135
+ * @param params
136
+ * @param modelFunc
137
+ * @param changeFunc
138
+ */
139
+ function getNativeElementOns(
140
+ renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions,
141
+ params: any,
142
+ eFns?: {
143
+ model: (evnt: Event) => void
144
+ change?: (evnt: Event) => void
145
+ blur?: (evnt: Event) => void
146
+ }
147
+ ) {
148
+ const { events } = renderOpts
149
+ const modelEvent = getModelEvent(renderOpts)
150
+ const changeEvent = getChangeEvent(renderOpts)
151
+ const { model: modelFunc, change: changeFunc, blur: blurFunc } = eFns || {}
152
+ const isSameEvent = changeEvent === modelEvent
153
+ const ons: any = {}
154
+ if (events) {
155
+ XEUtils.objectEach(events, (func, key: any) => {
156
+ ons[getOnName(key)] = function (...args: any[]) {
157
+ func(params, ...args)
158
+ }
159
+ })
160
+ }
161
+ if (modelFunc) {
162
+ ons[getOnName(modelEvent)] = function (targetEvnt: any) {
163
+ modelFunc(targetEvnt)
164
+ if (isSameEvent && changeFunc) {
165
+ changeFunc(targetEvnt)
166
+ }
167
+ if (events && events[modelEvent]) {
168
+ events[modelEvent](params, targetEvnt)
169
+ }
170
+ }
171
+ }
172
+ if (!isSameEvent && changeFunc) {
173
+ ons[getOnName(changeEvent)] = function (evnt: Event) {
174
+ changeFunc(evnt)
175
+ if (events && events[changeEvent]) {
176
+ events[changeEvent](params, evnt)
177
+ }
178
+ }
179
+ }
180
+ if (blurFunc) {
181
+ ons[getOnName(blurEvent)] = function (evnt: Event) {
182
+ blurFunc(evnt)
183
+ if (events && events[blurEvent]) {
184
+ events[blurEvent](params, evnt)
185
+ }
186
+ }
187
+ }
188
+ return ons
189
+ }
190
+
191
+ const blurEvent = 'blur'
192
+ const clearEvent = 'clear'
193
+
194
+ /**
195
+ * 组件事件处理
196
+ * @param renderOpts
197
+ * @param params
198
+ * @param modelFunc
199
+ * @param changeFunc
200
+ */
201
+ function getComponentOns(
202
+ renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions,
203
+ params: any,
204
+ eFns?: {
205
+ model: (cellValue: any) => void
206
+ change?: (...args: any[]) => void
207
+ blur?: (...args: any[]) => void
208
+ clear?: (...args: any[]) => void
209
+ },
210
+ eventOns?: Record<string, any>
211
+ ) {
212
+ const { events } = renderOpts
213
+ const modelEvent = getModelEvent(renderOpts)
214
+ const changeEvent = getChangeEvent(renderOpts)
215
+ const { model: modelFunc, change: changeFunc, blur: blurFunc, clear: clearFunc } = eFns || {}
216
+ const ons: any = {}
217
+ XEUtils.objectEach(events, (func, key: any) => {
218
+ ons[getOnName(key)] = function (...args: any[]) {
219
+ if (!XEUtils.isFunction(func)) {
220
+ errLog('vxe.error.errFunc', [func])
221
+ }
222
+ func(params, ...args)
223
+ }
224
+ })
225
+ if (modelFunc) {
226
+ ons[getOnName(modelEvent)] = function (targetEvnt: any) {
227
+ modelFunc(targetEvnt)
228
+ if (events && events[modelEvent]) {
229
+ events[modelEvent](params, targetEvnt)
230
+ }
231
+ }
232
+ }
233
+ if (changeFunc) {
234
+ ons[getOnName(changeEvent)] = function (...args: any[]) {
235
+ changeFunc(...args)
236
+ if (events && events[changeEvent]) {
237
+ events[changeEvent](params, ...args)
238
+ }
239
+ }
240
+ }
241
+ if (blurFunc) {
242
+ ons[getOnName(blurEvent)] = function (...args: any[]) {
243
+ blurFunc(...args)
244
+ if (events && events[blurEvent]) {
245
+ events[blurEvent](params, ...args)
246
+ }
247
+ }
248
+ }
249
+ if (clearFunc) {
250
+ ons[getOnName(clearEvent)] = function (...args: any[]) {
251
+ clearFunc(...args)
252
+ if (events && events[clearEvent]) {
253
+ events[clearEvent](params, ...args)
254
+ }
255
+ }
256
+ }
257
+ return eventOns ? Object.assign(ons, eventOns) : ons
258
+ }
259
+
260
+ function getEditOns(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
261
+ const { $table, row, column } = params
262
+ const { name } = renderOpts
263
+ const { model } = column
264
+ const isImmediate = isImmediateCell(renderOpts, params)
265
+ return getComponentOns(renderOpts, params, {
266
+ model(cellValue) {
267
+ // 处理 model 值双向绑定
268
+ model.update = true
269
+ model.value = cellValue
270
+ if (isImmediate) {
271
+ setCellValue(row, column, cellValue)
272
+ }
273
+ },
274
+ change(eventParams) {
275
+ // 处理 change 事件相关逻辑
276
+ if (!isImmediate && name && ['VxeInput', 'VxeNumberInput', 'VxeTextarea', '$input', '$textarea'].includes(name)) {
277
+ const cellValue = eventParams.value
278
+ model.update = true
279
+ model.value = cellValue
280
+ $table.updateStatus(params, cellValue)
281
+ } else {
282
+ $table.updateStatus(params)
283
+ }
284
+ },
285
+ blur() {
286
+ if (isImmediate) {
287
+ $table.handleCellRuleUpdateStatus('blur', params)
288
+ } else {
289
+ $table.handleCellRuleUpdateStatus('blur', params, model.value)
290
+ }
291
+ }
292
+ })
293
+ }
294
+
295
+ function getFilterOns(renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams, option: VxeTableDefines.FilterOption) {
296
+ return getComponentOns(renderOpts, params, {
297
+ model(value: any) {
298
+ // 处理 model 值双向绑定
299
+ option.data = value
300
+ },
301
+ change() {
302
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
303
+ },
304
+ blur() {
305
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
306
+ }
307
+ })
308
+ }
309
+
310
+ function getFloatingFilterOns(renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams, option: VxeTableDefines.FilterOption) {
311
+ const { $table, column } = params
312
+ if (hasInputType(renderOpts)) {
313
+ return getComponentOns(
314
+ renderOpts,
315
+ params,
316
+ {
317
+ model(value: any) {
318
+ // 处理 model 值双向绑定
319
+ option.data = value
320
+ },
321
+ change() {
322
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
323
+ },
324
+ clear() {
325
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
326
+ saveFilterEvent(params)
327
+ },
328
+ blur() {
329
+ $table.saveFilterByEvent(new Event('change'), column)
330
+ }
331
+ },
332
+ renderOpts.name === 'VxeNumberInput'
333
+ ? {
334
+ [getOnName('plus-number')]() {
335
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
336
+ saveFilterEvent(params)
337
+ },
338
+ [getOnName('minus-number')]() {
339
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
340
+ saveFilterEvent(params)
341
+ }
342
+ }
343
+ : {}
344
+ )
345
+ }
346
+ return getComponentOns(renderOpts, params, {
347
+ model(value: any) {
348
+ // 处理 model 值双向绑定
349
+ option.data = value
350
+ },
351
+ clear() {
352
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
353
+ $table.saveFilterByEvent(new Event('change'), column)
354
+ },
355
+ change() {
356
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
357
+ $table.saveFilterByEvent(new Event('change'), column)
358
+ }
359
+ })
360
+ }
361
+
362
+ function getNativeEditOns(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
363
+ const { $table, row, column } = params
364
+ const { model } = column
365
+ return getNativeElementOns(renderOpts, params, {
366
+ model(evnt) {
367
+ // 处理 model 值双向绑定
368
+ const targetEl = evnt.target as HTMLInputElement
369
+ if (targetEl) {
370
+ const cellValue = targetEl.value
371
+ if (isImmediateCell(renderOpts, params)) {
372
+ setCellValue(row, column, cellValue)
373
+ } else {
374
+ model.update = true
375
+ model.value = cellValue
376
+ }
377
+ }
378
+ },
379
+ change(evnt) {
380
+ // 处理 change 事件相关逻辑
381
+ const targetEl = evnt.target as HTMLInputElement
382
+ if (targetEl) {
383
+ const cellValue = targetEl.value
384
+ $table.updateStatus(params, cellValue)
385
+ }
386
+ },
387
+ blur(evnt) {
388
+ const targetEl = evnt.target as HTMLInputElement
389
+ if (targetEl) {
390
+ const cellValue = targetEl.value
391
+ $table.updateStatus(params, cellValue)
392
+ }
393
+ }
394
+ })
395
+ }
396
+
397
+ function getNativeFilterOns(renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, option: any) {
398
+ return getNativeElementOns(renderOpts, params, {
399
+ model(evnt) {
400
+ // 处理 model 值双向绑定
401
+ const targetEl = evnt.target as HTMLInputElement
402
+ if (targetEl) {
403
+ option.data = targetEl.value
404
+ }
405
+ },
406
+ change() {
407
+ updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
408
+ },
409
+ blur() {
410
+ updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
411
+ }
412
+ })
413
+ }
414
+
415
+ function nativeInputCellRender(renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
416
+ const { row, column } = renderParams
417
+ const cellValue = XEUtils.get(row, column.field)
418
+ const cellVNs = [
419
+ h(
420
+ 'span',
421
+ {
422
+ key: 1
423
+ },
424
+ cellValue
425
+ )
426
+ ]
427
+ return getNativeInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
428
+ }
429
+
430
+ /**
431
+ * 单元格可编辑渲染-原生的标签
432
+ * input、textarea
433
+ */
434
+ function nativeInputEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams) {
435
+ const { row, column } = renderParams
436
+ const { name } = renderOpts
437
+ const cellValue = isImmediateCell(renderOpts, renderParams) ? getCellValue(row, column) : column.model.value
438
+ return [
439
+ h('' + name, {
440
+ key: 2,
441
+ class: `vxe-default-${name}`,
442
+ ...getNativeAttrs(renderOpts),
443
+ value: cellValue,
444
+ ...getNativeEditOns(renderOpts, renderParams)
445
+ })
446
+ ]
447
+ }
448
+
449
+ function buttonCellRender(renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any) {
450
+ return [
451
+ h(getDefaultComponent(renderOpts), {
452
+ ...getCellEditProps(renderOpts, params, null),
453
+ ...getComponentOns(renderOpts, params)
454
+ })
455
+ ]
456
+ }
457
+
458
+ function defaultInputEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
459
+ const { row, column } = params
460
+ const cellValue = getCellValue(row, column)
461
+ return [
462
+ h(getDefaultComponent(renderOpts), {
463
+ key: 2,
464
+ ...getCellEditProps(renderOpts, params, cellValue),
465
+ ...getEditOns(renderOpts, params)
466
+ })
467
+ ]
468
+ }
469
+
470
+ function defaultEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
471
+ const { row, column } = params
472
+ const cellValue = getCellValue(row, column)
473
+ return [
474
+ h(getDefaultComponent(renderOpts), {
475
+ ...getCellEditProps(renderOpts, params, cellValue),
476
+ ...getEditOns(renderOpts, params)
477
+ })
478
+ ]
479
+ }
480
+
481
+ function checkboxEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
482
+ const { row, column } = params
483
+ const cellValue = getCellValue(row, column)
484
+ return [
485
+ h(getDefaultComponent(renderOpts), {
486
+ ...getCellEditProps(renderOpts, params, cellValue),
487
+ ...getEditOns(renderOpts, params)
488
+ })
489
+ ]
490
+ }
491
+
492
+ function radioAndCheckboxGroupEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
493
+ const { options } = renderOpts
494
+ const { row, column } = params
495
+ const cellValue = getCellValue(row, column)
496
+ return [
497
+ h(getDefaultComponent(renderOpts), {
498
+ options,
499
+ ...getCellEditProps(renderOpts, params, cellValue),
500
+ ...getEditOns(renderOpts, params)
501
+ })
502
+ ]
503
+ }
504
+
505
+ /**
506
+ * 已废弃
507
+ * @deprecated
508
+ */
509
+ function oldEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
510
+ const { row, column } = params
511
+ const cellValue = getCellValue(row, column)
512
+ return [
513
+ h(getOldComponent(renderOpts), {
514
+ ...getCellEditProps(renderOpts, params, cellValue),
515
+ ...getEditOns(renderOpts, params)
516
+ })
517
+ ]
518
+ }
519
+
520
+ /**
521
+ * 已废弃
522
+ * @deprecated
523
+ */
524
+ function oldButtonEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
525
+ return [
526
+ h(getComponent('vxe-button'), {
527
+ ...getCellEditProps(renderOpts, params, null),
528
+ ...getComponentOns(renderOpts, params)
529
+ })
530
+ ]
531
+ }
532
+
533
+ /**
534
+ * 已废弃
535
+ * @deprecated
536
+ */
537
+ function oldButtonsEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
538
+ const { children } = renderOpts
539
+ return children ? children.map((childRenderOpts: any) => oldButtonEditRender(childRenderOpts, params)[0]) : []
540
+ }
541
+
542
+ function renderNativeOptgroups(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, renderOptionsMethods: any) {
543
+ const { optionGroups, optionGroupProps = {} } = renderOpts
544
+ const groupOptions = optionGroupProps.options || 'options'
545
+ const groupLabel = optionGroupProps.label || 'label'
546
+ if (optionGroups) {
547
+ return optionGroups.map((group: any, gIndex: any) => {
548
+ return h(
549
+ 'optgroup',
550
+ {
551
+ key: gIndex,
552
+ label: group[groupLabel]
553
+ },
554
+ renderOptionsMethods(group[groupOptions], renderOpts, params)
555
+ )
556
+ })
557
+ }
558
+ return []
559
+ }
560
+
561
+ /**
562
+ * 渲染原生的 option 标签
563
+ */
564
+ function renderNativeOptions(options: any, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
565
+ const { optionProps = {} } = renderOpts
566
+ const { row, column } = params
567
+ const labelProp = optionProps.label || 'label'
568
+ const valueProp = optionProps.value || 'value'
569
+ const disabledProp = optionProps.disabled || 'disabled'
570
+ const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
571
+ if (options) {
572
+ return options.map((option: any, oIndex: any) => {
573
+ return h(
574
+ 'option',
575
+ {
576
+ key: oIndex,
577
+ value: option[valueProp],
578
+ disabled: option[disabledProp],
579
+ /* eslint-disable eqeqeq */
580
+ selected: option[valueProp] == cellValue
581
+ },
582
+ option[labelProp]
583
+ )
584
+ })
585
+ }
586
+ return []
587
+ }
588
+
589
+ function nativeFilterRender(renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
590
+ const { column } = params
591
+ const { name } = renderOpts
592
+ const attrs = getNativeAttrs(renderOpts)
593
+ return column.filters.map((option, oIndex) => {
594
+ return h(`${name}`, {
595
+ key: oIndex,
596
+ class: `vxe-default-${name}`,
597
+ ...attrs,
598
+ value: option.data,
599
+ ...getNativeFilterOns(renderOpts, params, option)
600
+ })
601
+ })
602
+ }
603
+
604
+ function defaultFilterRender(renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
605
+ const { column } = params
606
+ return column.filters.map((option, oIndex) => {
607
+ const optionValue = option.data
608
+ return h(getDefaultComponent(renderOpts), {
609
+ key: oIndex,
610
+ ...getCellEditFilterProps(renderOpts, renderOpts, optionValue),
611
+ ...getFilterOns(renderOpts, params, option)
612
+ })
613
+ })
614
+ }
615
+
616
+ function defaultFloatingFilterRender(renderOpts: VxeGlobalRendererHandles.RenderTableFloatingFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
617
+ const { option } = params
618
+ const optionValue = option.data
619
+ return [
620
+ h(getDefaultComponent(renderOpts), {
621
+ ...getCellEditFilterProps(renderOpts, renderOpts, optionValue),
622
+ ...getFloatingFilterOns(renderOpts, params, option)
623
+ })
624
+ ]
625
+ }
626
+
627
+ function defaultFilterOptions() {
628
+ return [{ data: null }]
629
+ }
630
+
631
+ /**
632
+ * 已废弃
633
+ * @deprecated
634
+ */
635
+ function oldFilterRender(renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any) {
636
+ const { column } = params
637
+ return column.filters.map((option: any, oIndex: any) => {
638
+ const optionValue = option.data
639
+ return h(getOldComponent(renderOpts), {
640
+ key: oIndex,
641
+ ...getCellEditFilterProps(renderOpts, renderOpts, optionValue),
642
+ ...getFilterOns(renderOpts, params, option)
643
+ })
644
+ })
645
+ }
646
+
647
+ function handleFilterMethod({ option, row, column }: any) {
648
+ const { data } = option
649
+ const cellValue = XEUtils.get(row, column.field)
650
+ /* eslint-disable eqeqeq */
651
+ return cellValue == data
652
+ }
653
+
654
+ function handleInputFilterMethod({ option, row, column }: any) {
655
+ const { data } = option
656
+ const cellValue = XEUtils.get(row, column.field)
657
+ /* eslint-disable eqeqeq */
658
+ return XEUtils.toValueString(cellValue).indexOf(data) > -1
659
+ }
660
+
661
+ function nativeSelectEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
662
+ return [
663
+ h(
664
+ 'select',
665
+ {
666
+ class: 'vxe-default-select',
667
+ ...getNativeAttrs(renderOpts),
668
+ ...getNativeEditOns(renderOpts, params)
669
+ },
670
+ renderOpts.optionGroups ? renderNativeOptgroups(renderOpts, params, renderNativeOptions) : renderNativeOptions(renderOpts.options, renderOpts, params)
671
+ )
672
+ ]
673
+ }
674
+
675
+ function defaultSelectEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
676
+ const { row, column } = params
677
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
678
+ const cellValue = getCellValue(row, column)
679
+ return [
680
+ h(getDefaultComponent(renderOpts), {
681
+ ...getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
682
+ ...getEditOns(renderOpts, params)
683
+ })
684
+ ]
685
+ }
686
+
687
+ function defaultTableOrTreeSelectEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
688
+ const { row, column } = params
689
+ const { options, optionProps } = renderOpts
690
+ const cellValue = getCellValue(row, column)
691
+ return [
692
+ h(getDefaultComponent(renderOpts), {
693
+ ...getCellEditProps(renderOpts, params, cellValue, { options, optionProps }),
694
+ ...getEditOns(renderOpts, params)
695
+ })
696
+ ]
697
+ }
698
+
699
+ /**
700
+ * 已废弃
701
+ * @deprecated
702
+ */
703
+ function oldSelectEditRender(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
704
+ const { row, column } = params
705
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
706
+ const cellValue = getCellValue(row, column)
707
+ return [
708
+ h(getOldComponent(renderOpts), {
709
+ ...getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
710
+ ...getEditOns(renderOpts, params)
711
+ })
712
+ ]
713
+ }
714
+
715
+ function handleSelectCellValue(cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
716
+ const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props = {} } = renderOpts
717
+ let selectItem: any
718
+ const labelProp = optionProps.label || 'label'
719
+ const valueProp = optionProps.value || 'value'
720
+ if (!(cellValue === null || cellValue === undefined)) {
721
+ let vals = []
722
+ if (XEUtils.isArray(cellValue)) {
723
+ vals = cellValue
724
+ } else {
725
+ if (props.multiple && `${cellValue}`.indexOf(',') > -1) {
726
+ vals = `${cellValue}`.split(',')
727
+ } else {
728
+ vals = [cellValue]
729
+ }
730
+ }
731
+ return XEUtils.map(
732
+ vals,
733
+ optionGroups
734
+ ? (value) => {
735
+ const groupOptions = optionGroupProps.options || 'options'
736
+ for (let index = 0; index < optionGroups.length; index++) {
737
+ /* eslint-disable eqeqeq */
738
+ selectItem = XEUtils.find(optionGroups[index][groupOptions], (item) => item[valueProp] == value)
739
+ if (selectItem) {
740
+ break
741
+ }
742
+ }
743
+ return selectItem ? selectItem[labelProp] : value
744
+ }
745
+ : (value) => {
746
+ /* eslint-disable eqeqeq */
747
+ selectItem = XEUtils.find(options, (item) => item[valueProp] == value)
748
+ return selectItem ? selectItem[labelProp] : value
749
+ }
750
+ ).join(', ')
751
+ }
752
+ return ''
753
+ }
754
+
755
+ function getSelectCellValue(renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, { row, column }: any) {
756
+ const cellValue = XEUtils.get(row, column.field)
757
+ return handleSelectCellValue(cellValue, renderOpts)
758
+ }
759
+
760
+ function handleExportSelectMethod(params: any) {
761
+ const { row, column, options } = params
762
+ return options.original ? getCellValue(row, column) : getSelectCellValue(column.editRender || column.cellRender, params)
763
+ }
764
+
765
+ function handleTreeSelectCellValue(cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions) {
766
+ const { options, optionProps = {} } = renderOpts
767
+ const labelProp = optionProps.label || 'label'
768
+ const valueProp = optionProps.value || 'value'
769
+ const childrenProp = optionProps.children || 'children'
770
+ if (!(cellValue === null || cellValue === undefined)) {
771
+ const keyMaps: Record<string, any> = {}
772
+ XEUtils.eachTree(
773
+ options,
774
+ (item) => {
775
+ keyMaps[XEUtils.get(item, valueProp)] = item
776
+ },
777
+ { children: childrenProp }
778
+ )
779
+ return XEUtils.map(XEUtils.isArray(cellValue) ? cellValue : [cellValue], (value) => {
780
+ const item = keyMaps[value]
781
+ return item ? XEUtils.get(item, labelProp) : item
782
+ }).join(', ')
783
+ }
784
+ return ''
785
+ }
786
+
787
+ function getTreeSelectCellValue(renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, { row, column }: any) {
788
+ const cellValue = XEUtils.get(row, column.field)
789
+ return handleTreeSelectCellValue(cellValue, renderOpts)
790
+ }
791
+
792
+ function handleExportTreeSelectMethod(params: any) {
793
+ const { row, column, options } = params
794
+ return options.original ? getCellValue(row, column) : getTreeSelectCellValue(column.editRender || column.cellRender, params)
795
+ }
796
+
797
+ function handleNumberCell(cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.RenderTableDefaultParams) {
798
+ const { props = {}, showNegativeStatus } = renderOpts
799
+ const { type } = props
800
+ let isNegative = false
801
+ if (!isEmptyValue(cellValue)) {
802
+ const numberInputConfig = getConfig().numberInput || {}
803
+ if (type === 'float') {
804
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
805
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
806
+ cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
807
+ if (!autoFill) {
808
+ cellValue = XEUtils.toNumber(cellValue)
809
+ }
810
+ if (showNegativeStatus) {
811
+ if (cellValue < 0) {
812
+ isNegative = true
813
+ }
814
+ }
815
+ } else if (type === 'amount') {
816
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
817
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
818
+ const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
819
+ cellValue = XEUtils.toNumber(cellValue)
820
+ if (showNegativeStatus) {
821
+ if (cellValue < 0) {
822
+ isNegative = true
823
+ }
824
+ }
825
+ cellValue = XEUtils.commafy(cellValue, { digits })
826
+ if (!autoFill) {
827
+ const [iStr, dStr] = cellValue.split('.')
828
+ if (dStr) {
829
+ const dRest = dStr.replace(/0+$/, '')
830
+ cellValue = dRest ? [iStr, '.', dRest].join('') : iStr
831
+ }
832
+ }
833
+ if (showCurrency) {
834
+ cellValue = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${cellValue}`
835
+ }
836
+ } else {
837
+ if (type === 'integer') {
838
+ cellValue = XEUtils.toInteger(cellValue)
839
+ }
840
+ if (showNegativeStatus) {
841
+ if (XEUtils.toNumber(cellValue) < 0) {
842
+ isNegative = true
843
+ }
844
+ }
845
+ }
846
+ }
847
+ return getCellLabelVNs(
848
+ renderOpts,
849
+ params,
850
+ cellValue,
851
+ isNegative
852
+ ? {
853
+ class: 'is--negative'
854
+ }
855
+ : {}
856
+ )
857
+ }
858
+
859
+ function handleFormatDatePicker(renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.TableCellFormatterParams) {
860
+ const { props = {} } = renderOpts
861
+ const { cellValue } = renderParams
862
+ if (cellValue) {
863
+ if (props.type !== 'time') {
864
+ return getLabelFormatDate(cellValue, props)
865
+ }
866
+ }
867
+ return cellValue
868
+ }
869
+
870
+ function handleFormatSelect(renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
871
+ const { cellValue } = renderParams
872
+ return handleSelectCellValue(cellValue, renderOpts)
873
+ }
874
+
875
+ function handleSetSelectValue(renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
876
+ const { row, column, cellValue } = renderParams
877
+ const { field } = column
878
+ if (field) {
879
+ const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props } = renderOpts
880
+ if (isEmptyValue(cellValue)) {
881
+ XEUtils.set(row, field, props && props.multiple ? [] : null)
882
+ return
883
+ }
884
+ const isMultiVal = XEUtils.indexOf(`${cellValue}`, ',') > -1
885
+ const labelProp = optionProps.label || 'label'
886
+ const valueProp = optionProps.value || 'value'
887
+ const labelMpas: Record<string, any> = {}
888
+ if (optionGroups && optionGroups.length) {
889
+ const groupOptions = optionGroupProps.options || 'options'
890
+ for (let i = 0; i < optionGroups.length; i++) {
891
+ const opts = optionGroups[i][groupOptions] || {}
892
+ for (let j = 0; j < opts.length; j++) {
893
+ const item = opts[j]
894
+ if (isMultiVal) {
895
+ labelMpas[item[labelProp]] = item
896
+ /* eslint-disable eqeqeq */
897
+ } else if (item[labelProp] == cellValue) {
898
+ XEUtils.set(row, field, item[valueProp])
899
+ return
900
+ }
901
+ }
902
+ }
903
+ } else {
904
+ if (options) {
905
+ for (let i = 0; i < options.length; i++) {
906
+ const item = options[i]
907
+ if (isMultiVal) {
908
+ labelMpas[item[labelProp]] = item
909
+ /* eslint-disable eqeqeq */
910
+ } else if (item[labelProp] == cellValue) {
911
+ XEUtils.set(row, field, item[valueProp])
912
+ return
913
+ }
914
+ }
915
+ }
916
+ }
917
+ if (isMultiVal) {
918
+ XEUtils.set(
919
+ row,
920
+ field,
921
+ (isMultiVal ? cellValue.split(',') : [cellValue]).map((label: any) => {
922
+ const item = labelMpas[label]
923
+ return item ? item[valueProp] : label
924
+ })
925
+ )
926
+ } else {
927
+ XEUtils.set(row, field, cellValue)
928
+ }
929
+ }
930
+ }
931
+
932
+ function handleFormatTreeSelect(renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
933
+ const { cellValue } = params
934
+ return handleTreeSelectCellValue(cellValue, renderOpts)
935
+ }
936
+
937
+ function handleSetTreeSelectValue(renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
938
+ const { row, column, cellValue } = params
939
+ const { field } = column
940
+ if (field) {
941
+ const { options, optionProps = {} } = renderOpts
942
+ const labelProp = optionProps.label || 'label'
943
+ const valueProp = optionProps.value || 'value'
944
+ const childrenProp = optionProps.children || 'children'
945
+ const matchRest = XEUtils.findTree(options || [], (item) => XEUtils.get(item, labelProp) === cellValue, { children: childrenProp })
946
+ if (matchRest) {
947
+ const selectItem = matchRest.item
948
+ if (selectItem) {
949
+ XEUtils.set(row, field, selectItem[valueProp])
950
+ return
951
+ }
952
+ }
953
+ XEUtils.set(row, field, cellValue)
954
+ }
955
+ }
956
+
957
+ function getNativeInputRenderCellVNs(cellValue: any, labelVNs: VNode[], renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
958
+ const { $table, row, column } = renderParams
959
+ const { name } = renderOpts
960
+ const tableProps = $table.props
961
+ const { editConfig, mouseConfig } = tableProps
962
+ const { computeMouseOpts } = $table.getComputeMaps()
963
+ const mouseOpts = computeMouseOpts.value
964
+ let isColSelected = false
965
+ let isActiveCellArea = false
966
+ if (editConfig && hasEnableConf(mouseConfig, mouseOpts)) {
967
+ const tableReactData = $table.reactData
968
+ const { editStore } = tableReactData
969
+ const { selected } = editStore
970
+ isColSelected = row === selected.row && column === selected.column
971
+ if ($table.getActiveCellArea) {
972
+ const activeCellArea = $table.getActiveCellArea()
973
+ if (activeCellArea) {
974
+ isActiveCellArea = row === activeCellArea.row && column === activeCellArea.column
975
+ }
976
+ }
977
+ }
978
+ const cellVNs = labelVNs
979
+ if (isActiveCellArea || isColSelected) {
980
+ cellVNs.push(
981
+ h('' + name, {
982
+ key: 2,
983
+ class: `vxe-default-${name} vxe-reusekeep-control`,
984
+ value: cellValue,
985
+ ...getNativeAttrs(renderOpts),
986
+ ...getNativeEditOns(renderOpts, renderParams)
987
+ })
988
+ )
989
+ }
990
+ return cellVNs
991
+ }
992
+
993
+ function getInputRenderCellVNs(cellValue: any, labelVNs: VNode[], renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
994
+ const { $table, row, column } = renderParams
995
+ const tableProps = $table.props
996
+ const { editConfig, mouseConfig } = tableProps
997
+ const { computeEditOpts, computeMouseOpts } = $table.getComputeMaps()
998
+ const mouseOpts = computeMouseOpts.value
999
+ let isColSelected = false
1000
+ let isActiveCellArea = false
1001
+ if (editConfig && hasEnableConf(mouseConfig, mouseOpts)) {
1002
+ const tableReactData = $table.reactData
1003
+ const { editStore } = tableReactData
1004
+ const editOpts = computeEditOpts.value
1005
+ if (editOpts.isReuseKeep) {
1006
+ const { selected } = editStore
1007
+ isColSelected = row === selected.row && column === selected.column
1008
+ if ($table.getActiveCellArea) {
1009
+ const activeCellArea = $table.getActiveCellArea()
1010
+ if (activeCellArea) {
1011
+ isActiveCellArea = row === activeCellArea.row && column === activeCellArea.column
1012
+ }
1013
+ }
1014
+ }
1015
+ }
1016
+ const cellVNs = labelVNs
1017
+ if (isActiveCellArea || isColSelected) {
1018
+ const compProps = getCellEditProps(renderOpts, renderParams, cellValue)
1019
+ const { className, inputClassName } = compProps
1020
+ cellVNs.push(
1021
+ h(getDefaultComponent(renderOpts), {
1022
+ key: 2,
1023
+ ...compProps,
1024
+ className: 'vxe-reusekeep-control' + (className ? ' ' + className : ''),
1025
+ inputClassName: 'vxe-reusekeep-control' + (inputClassName ? ' ' + inputClassName : ''),
1026
+ ...getEditOns(renderOpts, renderParams)
1027
+ })
1028
+ )
1029
+ }
1030
+ return cellVNs
1031
+ }
1032
+
1033
+ /**
1034
+ * 表格 - 渲染器
1035
+ */
1036
+ renderer.mixin({
1037
+ input: {
1038
+ tableAutoFocus: true,
1039
+ renderTableEdit: nativeInputEditRender,
1040
+ renderTableCell: nativeInputCellRender,
1041
+ renderTableDefault: nativeInputEditRender,
1042
+ createTableFilterOptions: defaultFilterOptions,
1043
+ renderTableFilter: nativeFilterRender,
1044
+ tableFilterDefaultMethod: handleInputFilterMethod
1045
+ },
1046
+ textarea: {
1047
+ tableAutoFocus: true,
1048
+ renderTableEdit: nativeInputEditRender,
1049
+ renderTableCell: nativeInputCellRender,
1050
+ renderTableDefault: nativeInputEditRender
1051
+ },
1052
+ select: {
1053
+ renderTableEdit: nativeSelectEditRender,
1054
+ renderTableDefault: nativeSelectEditRender,
1055
+ renderTableCell(renderOpts, params) {
1056
+ const { options, optionGroups } = renderOpts
1057
+ const { $table, row, column } = params
1058
+ const opSize = options ? options.length : null
1059
+ const ogSize = optionGroups ? optionGroups.length : null
1060
+ const { cellResult } = $table.effectCellData(row, column, {
1061
+ key: 'render_table_cell',
1062
+ isChanged({ oldValue, cellValue }) {
1063
+ return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1064
+ },
1065
+ setValue({ cellValue }) {
1066
+ return [cellValue, opSize, ogSize]
1067
+ },
1068
+ getResult({ cellValue }) {
1069
+ return handleSelectCellValue(cellValue, renderOpts)
1070
+ }
1071
+ })
1072
+ // const cellResult = getSelectCellValue(renderOpts, params)
1073
+ return getCellLabelVNs(renderOpts, params, cellResult)
1074
+ },
1075
+ createTableFilterOptions: defaultFilterOptions,
1076
+ renderTableFilter(renderOpts, params) {
1077
+ const { column } = params
1078
+ return column.filters.map((option, oIndex) => {
1079
+ return h(
1080
+ 'select',
1081
+ {
1082
+ key: oIndex,
1083
+ class: 'vxe-default-select',
1084
+ ...getNativeAttrs(renderOpts),
1085
+ ...getNativeFilterOns(renderOpts, params, option)
1086
+ },
1087
+ renderOpts.optionGroups ? renderNativeOptgroups(renderOpts, params, renderNativeOptions) : renderNativeOptions(renderOpts.options, renderOpts, params)
1088
+ )
1089
+ })
1090
+ },
1091
+ tableCellFormatter: handleFormatSelect,
1092
+ tableCellCopyMethod: handleFormatSelect,
1093
+ tableCellPasteMethod: handleSetSelectValue,
1094
+ tableFilterDefaultMethod: handleFilterMethod,
1095
+ tableExportMethod: handleExportSelectMethod
1096
+ },
1097
+ VxeInput: {
1098
+ tableAutoFocus: true,
1099
+ renderTableEdit: defaultInputEditRender,
1100
+ renderTableCell(renderOpts, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1101
+ const { props = {} } = renderOpts
1102
+ const { row, column } = renderParams
1103
+ const inputConfig = getConfig().input || {}
1104
+ const digits = props.digits || inputConfig.digits || 2
1105
+ let cellValue = XEUtils.get(row, column.field)
1106
+ if (cellValue) {
1107
+ switch (props.type) {
1108
+ case 'date':
1109
+ case 'week':
1110
+ case 'month':
1111
+ case 'quarter':
1112
+ case 'year':
1113
+ cellValue = getLabelFormatDate(cellValue, props)
1114
+ break
1115
+ case 'float':
1116
+ cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
1117
+ break
1118
+ }
1119
+ }
1120
+ const cellVNs = getCellLabelVNs(renderOpts, renderParams, cellValue)
1121
+ return getInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
1122
+ },
1123
+ renderTableDefault: defaultInputEditRender,
1124
+ createTableFilterOptions: defaultFilterOptions,
1125
+ renderTableFilter: defaultFilterRender,
1126
+ renderTableFloatingFilter: defaultFloatingFilterRender,
1127
+ tableFilterDefaultMethod: handleInputFilterMethod
1128
+ },
1129
+ FormatNumberInput: {
1130
+ renderTableDefault(renderOpts, renderParams) {
1131
+ const { row, column } = renderParams
1132
+ const cellValue = XEUtils.get(row, column.field)
1133
+ return handleNumberCell(cellValue, renderOpts, renderParams)
1134
+ },
1135
+ tableFilterDefaultMethod({ option, row, column }) {
1136
+ const { data } = option
1137
+ const cellValue = XEUtils.get(row, column.field)
1138
+ /* eslint-disable eqeqeq */
1139
+ return cellValue == data
1140
+ },
1141
+ tableExportMethod(params) {
1142
+ const { row, column } = params
1143
+ const cellValue = XEUtils.get(row, column.field)
1144
+ return cellValue
1145
+ }
1146
+ },
1147
+ VxeNumberInput: {
1148
+ tableAutoFocus: true,
1149
+ renderTableEdit: defaultInputEditRender,
1150
+ renderTableCell(renderOpts, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1151
+ const { row, column } = renderParams
1152
+ const cellValue = XEUtils.get(row, column.field)
1153
+ const cellVNs = handleNumberCell(cellValue, renderOpts, renderParams)
1154
+ return getInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
1155
+ },
1156
+ renderTableFooter(renderOpts, params) {
1157
+ const { props = {} } = renderOpts
1158
+ const { row, column, _columnIndex } = params
1159
+ const { type } = props
1160
+ // 兼容老模式
1161
+ const itemValue = XEUtils.isArray(row) ? row[_columnIndex] : XEUtils.get(row, column.field)
1162
+ if (XEUtils.isNumber(itemValue)) {
1163
+ const numberInputConfig = getConfig().numberInput || {}
1164
+ if (type === 'float') {
1165
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
1166
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
1167
+ let amountLabel = XEUtils.toFixed(XEUtils.floor(itemValue, digits), digits)
1168
+ if (!autoFill) {
1169
+ amountLabel = '' + XEUtils.toNumber(amountLabel)
1170
+ }
1171
+ return amountLabel
1172
+ } else if (type === 'amount') {
1173
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
1174
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
1175
+ const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
1176
+ let amountLabel = XEUtils.commafy(XEUtils.toNumber(itemValue), { digits })
1177
+ if (!autoFill) {
1178
+ const [iStr, dStr] = amountLabel.split('.')
1179
+ if (dStr) {
1180
+ const dRest = dStr.replace(/0+$/, '')
1181
+ amountLabel = dRest ? [iStr, '.', dRest].join('') : iStr
1182
+ }
1183
+ }
1184
+ if (showCurrency) {
1185
+ amountLabel = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${amountLabel}`
1186
+ }
1187
+ return amountLabel
1188
+ }
1189
+ }
1190
+ return getFuncText(itemValue, 1)
1191
+ },
1192
+ renderTableDefault: defaultInputEditRender,
1193
+ createTableFilterOptions: defaultFilterOptions,
1194
+ renderTableFilter: defaultFilterRender,
1195
+ renderTableFloatingFilter: defaultFloatingFilterRender,
1196
+ tableFilterDefaultMethod({ option, row, column }) {
1197
+ const { data } = option
1198
+ const cellValue = XEUtils.get(row, column.field)
1199
+ /* eslint-disable eqeqeq */
1200
+ return cellValue == data
1201
+ },
1202
+ tableExportMethod(params) {
1203
+ const { row, column } = params
1204
+ const cellValue = XEUtils.get(row, column.field)
1205
+ return cellValue
1206
+ }
1207
+ },
1208
+ VxeDatePicker: {
1209
+ tableAutoFocus: true,
1210
+ renderTableEdit: defaultEditRender,
1211
+ renderTableCell(renderOpts, params) {
1212
+ const props = renderOpts.props || {}
1213
+ const { $table, row, column } = params
1214
+ const { cellResult } = $table.effectCellData(row, column, {
1215
+ key: 'render_table_cell',
1216
+ getResult({ cellValue }) {
1217
+ if (cellValue) {
1218
+ if (props.type !== 'time') {
1219
+ return getLabelFormatDate(cellValue, props)
1220
+ }
1221
+ }
1222
+ return cellValue
1223
+ }
1224
+ })
1225
+ return getCellLabelVNs(renderOpts, params, cellResult)
1226
+ },
1227
+ tableCellFormatter: handleFormatDatePicker,
1228
+ renderTableDefault: defaultEditRender,
1229
+ createTableFilterOptions: defaultFilterOptions,
1230
+ renderTableFilter: defaultFilterRender,
1231
+ renderTableFloatingFilter: defaultFloatingFilterRender,
1232
+ tableFilterDefaultMethod: handleFilterMethod
1233
+ },
1234
+ VxeDateRangePicker: {
1235
+ tableAutoFocus: true,
1236
+ renderTableEdit(renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1237
+ const { startField, endField } = renderOpts
1238
+ const { $table, row, column } = params
1239
+ const { model } = column
1240
+ const cellValue = getCellValue(row, column)
1241
+ const seProps: Record<string, any> = {}
1242
+ const seOs: Record<string, any> = {}
1243
+ if (startField && endField) {
1244
+ seProps.startValue = XEUtils.get(row, startField)
1245
+ seProps.endValue = XEUtils.get(row, endField)
1246
+ seOs['onUpdate:startValue'] = (value: any) => {
1247
+ if (startField) {
1248
+ XEUtils.set(row, startField, value)
1249
+ }
1250
+ }
1251
+ seOs['onUpdate:endValue'] = (value: any) => {
1252
+ if (endField) {
1253
+ XEUtils.set(row, endField, value)
1254
+ }
1255
+ }
1256
+ }
1257
+ return [
1258
+ h(getDefaultComponent(renderOpts), {
1259
+ ...getCellEditProps(renderOpts, params, cellValue, seProps),
1260
+ ...getComponentOns(
1261
+ renderOpts,
1262
+ params,
1263
+ {
1264
+ model(cellValue) {
1265
+ model.update = true
1266
+ model.value = cellValue
1267
+ setCellValue(row, column, cellValue)
1268
+ },
1269
+ change() {
1270
+ $table.updateStatus(params)
1271
+ },
1272
+ blur() {
1273
+ $table.handleCellRuleUpdateStatus('blur', params)
1274
+ }
1275
+ },
1276
+ seOs
1277
+ )
1278
+ })
1279
+ ]
1280
+ },
1281
+ renderTableDefault(renderOpts, params) {
1282
+ const { startField, endField } = renderOpts
1283
+ const { row, column } = params
1284
+ const { model } = column
1285
+ const cellValue = getCellValue(row, column)
1286
+ const seProps: Record<string, any> = {}
1287
+ const seOs: Record<string, any> = {}
1288
+ if (startField && endField) {
1289
+ seProps.startValue = XEUtils.get(row, startField)
1290
+ seProps.endValue = XEUtils.get(row, endField)
1291
+ seOs['onUpdate:startValue'] = (value: any) => {
1292
+ if (startField) {
1293
+ XEUtils.set(row, startField, value)
1294
+ }
1295
+ }
1296
+ seOs['onUpdate:endValue'] = (value: any) => {
1297
+ if (endField) {
1298
+ XEUtils.set(row, endField, value)
1299
+ }
1300
+ }
1301
+ }
1302
+ return [
1303
+ h(getDefaultComponent(renderOpts), {
1304
+ ...getCellEditProps(renderOpts, params, cellValue, seProps),
1305
+ ...getComponentOns(
1306
+ renderOpts,
1307
+ params,
1308
+ {
1309
+ model(cellValue) {
1310
+ model.update = true
1311
+ model.value = cellValue
1312
+ setCellValue(row, column, cellValue)
1313
+ }
1314
+ },
1315
+ seOs
1316
+ )
1317
+ })
1318
+ ]
1319
+ },
1320
+ renderTableCell(renderOpts, params) {
1321
+ const { startField, endField } = renderOpts
1322
+ const { row, column } = params
1323
+ let startValue = ''
1324
+ let endValue = ''
1325
+ if (startField && endField) {
1326
+ startValue = XEUtils.get(row, startField)
1327
+ endValue = XEUtils.get(row, endField)
1328
+ } else {
1329
+ const cellValue = XEUtils.get(row, column.field)
1330
+ if (cellValue) {
1331
+ if (XEUtils.isArray(cellValue)) {
1332
+ startValue = cellValue[0]
1333
+ endValue = cellValue[1]
1334
+ } else {
1335
+ const strs = `${cellValue}`.split(',')
1336
+ startValue = strs[0]
1337
+ endValue = strs[1]
1338
+ }
1339
+ }
1340
+ }
1341
+ let cellLabel = ''
1342
+ if (startValue && endValue) {
1343
+ cellLabel = `${startValue} ~ ${endValue}`
1344
+ }
1345
+ return getCellLabelVNs(renderOpts, params, cellLabel)
1346
+ }
1347
+ },
1348
+ VxeTextarea: {
1349
+ tableAutoFocus: true,
1350
+ renderTableDefault: defaultInputEditRender,
1351
+ renderTableCell(renderOpts, renderParams: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1352
+ const { row, column } = renderParams
1353
+ const cellValue = XEUtils.get(row, column.field)
1354
+ const cellVNs = getCellLabelVNs(renderOpts, renderParams, cellValue)
1355
+ return getInputRenderCellVNs(cellValue, cellVNs, renderOpts, renderParams)
1356
+ },
1357
+ renderTableEdit: defaultInputEditRender
1358
+ },
1359
+ VxeButton: {
1360
+ renderTableDefault: buttonCellRender
1361
+ },
1362
+ VxeButtonGroup: {
1363
+ renderTableDefault(renderOpts, params) {
1364
+ const { options } = renderOpts
1365
+ return [
1366
+ h(getDefaultComponent(renderOpts), {
1367
+ options,
1368
+ ...getCellEditProps(renderOpts, params, null),
1369
+ ...getComponentOns(renderOpts, params)
1370
+ })
1371
+ ]
1372
+ }
1373
+ },
1374
+ VxeSelect: {
1375
+ tableAutoFocus: true,
1376
+ renderTableEdit: defaultSelectEditRender,
1377
+ renderTableDefault: defaultSelectEditRender,
1378
+ renderTableCell(renderOpts, params) {
1379
+ const { options, optionGroups } = renderOpts
1380
+ const { $table, row, column } = params
1381
+ const opSize = options ? options.length : null
1382
+ const ogSize = optionGroups ? optionGroups.length : null
1383
+ const { cellResult } = $table.effectCellData(row, column, {
1384
+ key: 'render_table_cell',
1385
+ isChanged({ oldValue, cellValue }) {
1386
+ return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1387
+ },
1388
+ setValue({ cellValue }) {
1389
+ return [cellValue, opSize, ogSize]
1390
+ },
1391
+ getResult({ cellValue }) {
1392
+ return handleSelectCellValue(cellValue, renderOpts)
1393
+ }
1394
+ })
1395
+ // const cellResult = getSelectCellValue(renderOpts, params)
1396
+ return getCellLabelVNs(renderOpts, params, cellResult)
1397
+ },
1398
+ createTableFilterOptions: defaultFilterOptions,
1399
+ renderTableFilter(renderOpts, params) {
1400
+ const { column } = params
1401
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1402
+ return column.filters.map((option, oIndex) => {
1403
+ const optionValue = option.data
1404
+ return h(getDefaultComponent(renderOpts), {
1405
+ key: oIndex,
1406
+ ...getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1407
+ ...getFilterOns(renderOpts, params, option)
1408
+ })
1409
+ })
1410
+ },
1411
+ renderTableFloatingFilter(renderOpts, params) {
1412
+ const { option } = params
1413
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1414
+ const optionValue = option.data
1415
+ return h(getDefaultComponent(renderOpts), {
1416
+ ...getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1417
+ ...getFloatingFilterOns(renderOpts, params, option)
1418
+ })
1419
+ },
1420
+ tableCellFormatter: handleFormatSelect,
1421
+ tableCellCopyMethod: handleFormatSelect,
1422
+ tableCellPasteMethod: handleSetSelectValue,
1423
+ tableFilterDefaultMethod: handleFilterMethod,
1424
+ tableExportMethod: handleExportSelectMethod
1425
+ },
1426
+ VxeText: {
1427
+ renderTableDefault(renderOpts, params) {
1428
+ const { $table, row, column } = params
1429
+ const { props } = renderOpts
1430
+ const cellLabel = $table.getCellLabel(row, column)
1431
+ return [
1432
+ h(getDefaultComponent(renderOpts), {
1433
+ ...(props || {}),
1434
+ content: cellLabel,
1435
+ ...getComponentOns(renderOpts, params)
1436
+ })
1437
+ ]
1438
+ }
1439
+ },
1440
+ VxeLink: {
1441
+ renderTableDefault(renderOpts, params) {
1442
+ const { $table, row, column } = params
1443
+ const { props } = renderOpts
1444
+ const { href } = props || {}
1445
+ const cellLabel = $table.getCellLabel(row, column)
1446
+ return [
1447
+ h(getDefaultComponent(renderOpts), {
1448
+ ...(props || {}),
1449
+ content: cellLabel,
1450
+ href: XEUtils.toFormatString(href, params),
1451
+ ...getComponentOns(renderOpts, params)
1452
+ })
1453
+ ]
1454
+ }
1455
+ },
1456
+ /**
1457
+ * 已废弃,被 FormatSelect 替换
1458
+ * @deprecated
1459
+ */
1460
+ formatOption: {
1461
+ renderTableDefault(renderOpts, params) {
1462
+ return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
1463
+ }
1464
+ },
1465
+ FormatSelect: {
1466
+ renderTableDefault(renderOpts, params) {
1467
+ const { options, optionGroups } = renderOpts
1468
+ const { $table, row, column } = params
1469
+ const opSize = options ? options.length : null
1470
+ const ogSize = optionGroups ? optionGroups.length : null
1471
+ const { cellResult } = $table.effectCellData(row, column, {
1472
+ key: 'render_table_cell',
1473
+ isChanged({ oldValue, cellValue }) {
1474
+ return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1475
+ },
1476
+ setValue({ cellValue }) {
1477
+ return [cellValue, opSize, ogSize]
1478
+ },
1479
+ getResult({ cellValue }) {
1480
+ return handleSelectCellValue(cellValue, renderOpts)
1481
+ }
1482
+ })
1483
+ // const cellResult = getSelectCellValue(renderOpts, params)
1484
+ return getCellLabelVNs(renderOpts, params, cellResult)
1485
+ },
1486
+ tableCellFormatter: handleFormatSelect,
1487
+ tableCellCopyMethod: handleFormatSelect,
1488
+ tableCellPasteMethod: handleSetSelectValue,
1489
+ tableFilterDefaultMethod: handleFilterMethod,
1490
+ tableExportMethod: handleExportSelectMethod
1491
+ },
1492
+ VxeTreeSelect: {
1493
+ tableAutoFocus: true,
1494
+ renderTableEdit: defaultTableOrTreeSelectEditRender,
1495
+ renderTableCell(renderOpts, params) {
1496
+ const { options, optionGroups } = renderOpts
1497
+ const { $table, row, column } = params
1498
+ const opSize = options ? options.length : null
1499
+ const ogSize = optionGroups ? optionGroups.length : null
1500
+ const { cellResult } = $table.effectCellData(row, column, {
1501
+ key: 'render_table_cell',
1502
+ isChanged({ oldValue, cellValue }) {
1503
+ return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1504
+ },
1505
+ setValue({ cellValue }) {
1506
+ return [cellValue, opSize, ogSize]
1507
+ },
1508
+ getResult({ cellValue }) {
1509
+ return handleTreeSelectCellValue(cellValue, renderOpts)
1510
+ }
1511
+ })
1512
+ // const cellResult = getTreeSelectCellValue(renderOpts, params)
1513
+ return getCellLabelVNs(renderOpts, params, cellResult)
1514
+ },
1515
+ tableCellFormatter: handleFormatTreeSelect,
1516
+ tableCellCopyMethod: handleFormatTreeSelect,
1517
+ tableCellPasteMethod: handleSetTreeSelectValue,
1518
+ tableExportMethod: handleExportTreeSelectMethod
1519
+ },
1520
+ /**
1521
+ * 已废弃,被 FormatTreeSelect 替换
1522
+ * @deprecated
1523
+ */
1524
+ formatTree: {
1525
+ renderTableDefault(renderOpts, params) {
1526
+ return getCellLabelVNs(renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1527
+ }
1528
+ },
1529
+ FormatTreeSelect: {
1530
+ renderTableDefault(renderOpts, params) {
1531
+ const { options, optionGroups } = renderOpts
1532
+ const { $table, row, column } = params
1533
+ const opSize = options ? options.length : null
1534
+ const ogSize = optionGroups ? optionGroups.length : null
1535
+ const { cellResult } = $table.effectCellData(row, column, {
1536
+ key: 'render_table_cell',
1537
+ isChanged({ oldValue, cellValue }) {
1538
+ return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1539
+ },
1540
+ setValue({ cellValue }) {
1541
+ return [cellValue, opSize, ogSize]
1542
+ },
1543
+ getResult({ cellValue }) {
1544
+ return handleTreeSelectCellValue(cellValue, renderOpts)
1545
+ }
1546
+ })
1547
+ // const cellResult = getTreeSelectCellValue(renderOpts, params)
1548
+ return getCellLabelVNs(renderOpts, params, cellResult)
1549
+ },
1550
+ tableCellFormatter: handleFormatTreeSelect,
1551
+ tableCellCopyMethod: handleFormatTreeSelect,
1552
+ tableCellPasteMethod: handleSetTreeSelectValue,
1553
+ tableExportMethod: handleExportTreeSelectMethod
1554
+ },
1555
+ VxeCascader: {
1556
+ tableAutoFocus: true,
1557
+ renderTableEdit: defaultTableOrTreeSelectEditRender,
1558
+ renderTableCell(renderOpts, params) {
1559
+ const { options, optionGroups } = renderOpts
1560
+ const { $table, row, column } = params
1561
+ const opSize = options ? options.length : null
1562
+ const ogSize = optionGroups ? optionGroups.length : null
1563
+ const { cellResult } = $table.effectCellData(row, column, {
1564
+ key: 'render_table_cell',
1565
+ isChanged({ oldValue, cellValue }) {
1566
+ return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1567
+ },
1568
+ setValue({ cellValue }) {
1569
+ return [cellValue, opSize, ogSize]
1570
+ },
1571
+ getResult({ cellValue }) {
1572
+ return handleTreeSelectCellValue(cellValue, renderOpts)
1573
+ }
1574
+ })
1575
+ // const cellResult = getTreeSelectCellValue(renderOpts, params)
1576
+ return getCellLabelVNs(renderOpts, params, cellResult)
1577
+ },
1578
+ tableCellFormatter: handleFormatTreeSelect,
1579
+ tableCellCopyMethod: handleFormatTreeSelect,
1580
+ tableCellPasteMethod: handleSetTreeSelectValue,
1581
+ tableExportMethod: handleExportTreeSelectMethod
1582
+ },
1583
+ VxeTableSelect: {
1584
+ tableAutoFocus: true,
1585
+ renderTableEdit: defaultTableOrTreeSelectEditRender,
1586
+ renderTableCell(renderOpts, params) {
1587
+ const { options, optionGroups } = renderOpts
1588
+ const { $table, row, column } = params
1589
+ const opSize = options ? options.length : null
1590
+ const ogSize = optionGroups ? optionGroups.length : null
1591
+ const { cellResult } = $table.effectCellData(row, column, {
1592
+ key: 'render_table_cell',
1593
+ isChanged({ oldValue, cellValue }) {
1594
+ return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
1595
+ },
1596
+ setValue({ cellValue }) {
1597
+ return [cellValue, opSize, ogSize]
1598
+ },
1599
+ getResult({ cellValue }) {
1600
+ return handleTreeSelectCellValue(cellValue, renderOpts)
1601
+ }
1602
+ })
1603
+ // const cellResult = getTreeSelectCellValue(renderOpts, params)
1604
+ return getCellLabelVNs(renderOpts, params, cellResult)
1605
+ },
1606
+ tableCellFormatter: handleFormatTreeSelect,
1607
+ tableCellCopyMethod: handleFormatTreeSelect,
1608
+ tableCellPasteMethod: handleSetTreeSelectValue,
1609
+ tableExportMethod: handleExportTreeSelectMethod
1610
+ },
1611
+ VxeColorPicker: {
1612
+ tableAutoFocus: true,
1613
+ renderTableEdit(renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1614
+ const { row, column } = params
1615
+ const { options } = renderOpts
1616
+ const cellValue = getCellValue(row, column)
1617
+ return [
1618
+ h(getDefaultComponent(renderOpts), {
1619
+ ...getCellEditProps(renderOpts, params, cellValue, { colors: options }),
1620
+ ...getEditOns(renderOpts, params)
1621
+ })
1622
+ ]
1623
+ },
1624
+ renderTableCell(renderOpts, params) {
1625
+ const { $table, row, column } = params
1626
+ const { props } = renderOpts
1627
+ const { computeSize } = $table.getComputeMaps()
1628
+ const customSize = props ? props.size : null
1629
+ const vSize = customSize || computeSize.value
1630
+ const cellValue = XEUtils.get(row, column.field)
1631
+ return h(
1632
+ 'span',
1633
+ {
1634
+ class: [
1635
+ 'vxe-color-picker--readonly',
1636
+ {
1637
+ [`size--${vSize}`]: vSize
1638
+ }
1639
+ ]
1640
+ },
1641
+ [
1642
+ h('div', {
1643
+ class: [
1644
+ 'vxe-color-picker--readonly-color',
1645
+ {
1646
+ 'is--empty': !cellValue
1647
+ }
1648
+ ],
1649
+ style: cellValue
1650
+ ? {
1651
+ backgroundColor: cellValue
1652
+ }
1653
+ : undefined
1654
+ })
1655
+ ]
1656
+ )
1657
+ }
1658
+ },
1659
+ VxeIconPicker: {
1660
+ tableAutoFocus: true,
1661
+ renderTableEdit(renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1662
+ const { row, column } = params
1663
+ const { options } = renderOpts
1664
+ const cellValue = getCellValue(row, column)
1665
+ return [
1666
+ h(getDefaultComponent(renderOpts), {
1667
+ ...getCellEditProps(renderOpts, params, cellValue, { icons: options }),
1668
+ ...getEditOns(renderOpts, params)
1669
+ })
1670
+ ]
1671
+ },
1672
+ renderTableCell(renderOpts, params) {
1673
+ const { row, column } = params
1674
+ const cellValue = XEUtils.get(row, column.field)
1675
+ return h('i', {
1676
+ class: cellValue
1677
+ })
1678
+ }
1679
+ },
1680
+ VxeRadioGroup: {
1681
+ renderTableDefault: radioAndCheckboxGroupEditRender
1682
+ },
1683
+ VxeCheckbox: {
1684
+ renderTableDefault: checkboxEditRender
1685
+ },
1686
+ VxeCheckboxGroup: {
1687
+ renderTableDefault: radioAndCheckboxGroupEditRender
1688
+ },
1689
+ VxeSwitch: {
1690
+ tableAutoFocus: 'button',
1691
+ renderTableEdit: defaultEditRender,
1692
+ renderTableDefault: defaultEditRender
1693
+ },
1694
+ VxeUpload: {
1695
+ renderTableEdit: defaultEditRender,
1696
+ renderTableCell: defaultEditRender,
1697
+ renderTableDefault: defaultEditRender
1698
+ },
1699
+ VxeImage: {
1700
+ renderTableDefault(renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1701
+ const { row, column } = params
1702
+ const { props } = renderOpts
1703
+ const cellValue = getCellValue(row, column)
1704
+ return [
1705
+ h(getDefaultComponent(renderOpts), {
1706
+ ...props,
1707
+ src: cellValue,
1708
+ ...getEditOns(renderOpts, params)
1709
+ })
1710
+ ]
1711
+ }
1712
+ },
1713
+ VxeImageGroup: {
1714
+ renderTableDefault(renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1715
+ const { row, column } = params
1716
+ const { props } = renderOpts
1717
+ const cellValue = getCellValue(row, column)
1718
+ return [
1719
+ h(getDefaultComponent(renderOpts), {
1720
+ ...props,
1721
+ urlList: cellValue,
1722
+ ...getEditOns(renderOpts, params)
1723
+ })
1724
+ ]
1725
+ }
1726
+ },
1727
+ VxeTextEllipsis: {
1728
+ renderTableDefault(renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1729
+ const { row, column } = params
1730
+ const { props } = renderOpts
1731
+ const cellValue = getCellValue(row, column)
1732
+ return [
1733
+ h(getDefaultComponent(renderOpts), {
1734
+ ...props,
1735
+ content: cellValue,
1736
+ ...getEditOns(renderOpts, params)
1737
+ })
1738
+ ]
1739
+ }
1740
+ },
1741
+ VxeRate: {
1742
+ renderTableDefault: defaultEditRender
1743
+ },
1744
+ VxeSlider: {
1745
+ renderTableDefault: defaultEditRender
1746
+ },
1747
+
1748
+ // 以下已废弃
1749
+ $input: {
1750
+ tableAutoFocus: 'input',
1751
+ renderTableEdit: oldEditRender,
1752
+ renderTableCell(renderOpts, params) {
1753
+ const { props = {} } = renderOpts
1754
+ const { row, column } = params
1755
+ const digits = props.digits || getConfig().input?.digits || 2
1756
+ let cellValue = XEUtils.get(row, column.field)
1757
+ if (cellValue) {
1758
+ switch (props.type) {
1759
+ case 'date':
1760
+ case 'week':
1761
+ case 'month':
1762
+ case 'year':
1763
+ cellValue = getLabelFormatDate(cellValue, props)
1764
+ break
1765
+ case 'float':
1766
+ cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
1767
+ break
1768
+ }
1769
+ }
1770
+ return getCellLabelVNs(renderOpts, params, cellValue)
1771
+ },
1772
+ renderTableDefault: oldEditRender,
1773
+ renderTableFilter: oldFilterRender,
1774
+ tableFilterDefaultMethod: handleInputFilterMethod
1775
+ },
1776
+ $textarea: {
1777
+ tableAutoFocus: 'textarea'
1778
+ },
1779
+ $button: {
1780
+ renderTableDefault: oldButtonEditRender
1781
+ },
1782
+ $buttons: {
1783
+ renderTableDefault: oldButtonsEditRender
1784
+ },
1785
+ $select: {
1786
+ tableAutoFocus: 'input',
1787
+ renderTableEdit: oldSelectEditRender,
1788
+ renderTableDefault: oldSelectEditRender,
1789
+ renderTableCell(renderOpts, params) {
1790
+ return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
1791
+ },
1792
+ renderTableFilter(renderOpts, params) {
1793
+ const { column } = params
1794
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1795
+ return column.filters.map((option, oIndex) => {
1796
+ const optionValue = option.data
1797
+ return h(getOldComponent(renderOpts), {
1798
+ key: oIndex,
1799
+ ...getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1800
+ ...getFilterOns(renderOpts, params, option)
1801
+ })
1802
+ })
1803
+ },
1804
+ tableFilterDefaultMethod: handleFilterMethod,
1805
+ tableExportMethod: handleExportSelectMethod
1806
+ },
1807
+ $radio: {
1808
+ tableAutoFocus: 'input'
1809
+ },
1810
+ $checkbox: {
1811
+ tableAutoFocus: 'input'
1812
+ },
1813
+ $switch: {
1814
+ tableAutoFocus: 'button',
1815
+ renderTableEdit: oldEditRender,
1816
+ renderTableDefault: oldEditRender
1817
+ }
1818
+ // 以上已废弃
1819
+ })