vxe-table 4.23.19 → 4.23.21

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 (127) hide show
  1. package/dist/all.esm.js +289 -253
  2. package/dist/all.esm.min.js +3 -3
  3. package/dist/style.css +4 -1
  4. package/dist/style.mini.css +1 -1
  5. package/es/components.d.ts +1 -3
  6. package/es/components.js +1 -2
  7. package/es/esm.index.d.ts +7 -0
  8. package/es/esm.index.js +8 -0
  9. package/es/style.css +4 -1
  10. package/es/style.mini.css +1 -1
  11. package/es/table/src/table.js +6 -2
  12. package/es/table/style.css +4 -1
  13. package/es/table/style.mini.css +1 -1
  14. package/es/ui/abandon.d.ts +82 -0
  15. package/es/ui/abandon.js +90 -0
  16. package/es/ui/index.d.ts +1 -83
  17. package/es/ui/index.js +2 -89
  18. package/es/ui/src/log.js +1 -1
  19. package/es/vxe-table/style.css +4 -1
  20. package/es/vxe-table/style.mini.css +1 -1
  21. package/lib/components.d.ts +1 -3
  22. package/lib/components.js +1 -2
  23. package/lib/esm.index.d.ts +7 -0
  24. package/lib/esm.index.js +39 -0
  25. package/lib/index.umd.js +254 -249
  26. package/lib/index.umd.min.js +3 -3
  27. package/lib/style.css +4 -1
  28. package/lib/style.mini.css +1 -1
  29. package/lib/table/src/table.js +6 -2
  30. package/lib/table/style/style.css +4 -1
  31. package/lib/table/style/style.mini.css +1 -1
  32. package/lib/ui/abandon.d.ts +82 -0
  33. package/lib/ui/abandon.js +110 -0
  34. package/lib/ui/index.d.ts +1 -83
  35. package/lib/ui/index.js +3 -89
  36. package/lib/ui/src/log.js +1 -1
  37. package/lib/vxe-table/style/style.css +4 -1
  38. package/lib/vxe-table/style/style.mini.css +1 -1
  39. package/package.json +1 -1
  40. package/packages/colgroup/index.ts +22 -22
  41. package/packages/column/index.ts +22 -22
  42. package/packages/components.ts +42 -45
  43. package/packages/esm.index.ts +10 -0
  44. package/packages/grid/index.ts +18 -18
  45. package/packages/grid/src/emits.ts +5 -5
  46. package/packages/grid/src/grid.ts +2220 -2220
  47. package/packages/grid/src/props.ts +22 -22
  48. package/packages/index.ts +13 -13
  49. package/packages/locale/lang/ar-EG.ts +914 -914
  50. package/packages/locale/lang/de-DE.ts +914 -914
  51. package/packages/locale/lang/en-US.ts +914 -914
  52. package/packages/locale/lang/es-ES.ts +914 -914
  53. package/packages/locale/lang/fr-FR.ts +914 -914
  54. package/packages/locale/lang/hu-HU.ts +914 -914
  55. package/packages/locale/lang/hy-AM.ts +914 -914
  56. package/packages/locale/lang/id-ID.ts +914 -914
  57. package/packages/locale/lang/it-IT.ts +914 -914
  58. package/packages/locale/lang/ja-JP.ts +914 -914
  59. package/packages/locale/lang/ko-KR.ts +914 -914
  60. package/packages/locale/lang/ms-MY.ts +914 -914
  61. package/packages/locale/lang/nb-NO.ts +914 -914
  62. package/packages/locale/lang/pt-BR.ts +914 -914
  63. package/packages/locale/lang/ru-RU.ts +914 -914
  64. package/packages/locale/lang/th-TH.ts +914 -914
  65. package/packages/locale/lang/ug-CN.ts +914 -914
  66. package/packages/locale/lang/uk-UA.ts +914 -914
  67. package/packages/locale/lang/uz-UZ.ts +914 -914
  68. package/packages/locale/lang/vi-VN.ts +914 -914
  69. package/packages/locale/lang/zh-CHT.ts +914 -914
  70. package/packages/locale/lang/zh-CN.ts +914 -914
  71. package/packages/locale/lang/zh-HK.ts +914 -914
  72. package/packages/locale/lang/zh-MO.ts +914 -914
  73. package/packages/locale/lang/zh-TC.ts +914 -914
  74. package/packages/locale/lang/zh-TW.ts +914 -914
  75. package/packages/table/index.ts +26 -26
  76. package/packages/table/module/custom/hook.ts +510 -510
  77. package/packages/table/module/custom/panel.ts +2002 -2002
  78. package/packages/table/module/edit/hook.ts +1232 -1232
  79. package/packages/table/module/export/export-panel.ts +697 -697
  80. package/packages/table/module/export/hook.ts +2158 -2158
  81. package/packages/table/module/export/import-panel.ts +319 -319
  82. package/packages/table/module/export/util.ts +25 -25
  83. package/packages/table/module/filter/hook.ts +505 -505
  84. package/packages/table/module/filter/panel.ts +368 -368
  85. package/packages/table/module/keyboard/hook.ts +498 -498
  86. package/packages/table/module/menu/hook.ts +330 -330
  87. package/packages/table/module/menu/panel.ts +272 -272
  88. package/packages/table/module/validator/hook.ts +653 -653
  89. package/packages/table/render/index.ts +1819 -1819
  90. package/packages/table/src/body.ts +1078 -1078
  91. package/packages/table/src/cell.ts +1524 -1524
  92. package/packages/table/src/column.ts +192 -192
  93. package/packages/table/src/columnInfo.ts +232 -232
  94. package/packages/table/src/emits.ts +134 -134
  95. package/packages/table/src/footer.ts +425 -425
  96. package/packages/table/src/group.ts +67 -67
  97. package/packages/table/src/header.ts +661 -661
  98. package/packages/table/src/props.ts +336 -336
  99. package/packages/table/src/store.ts +14 -14
  100. package/packages/table/src/table.ts +8 -3
  101. package/packages/table/src/use/cell-view.ts +41 -41
  102. package/packages/table/src/use/index.ts +1 -1
  103. package/packages/table/src/util.ts +1206 -1206
  104. package/packages/toolbar/index.ts +18 -18
  105. package/packages/toolbar/src/toolbar.ts +768 -768
  106. package/packages/ui/abandon.ts +136 -0
  107. package/packages/ui/index.ts +404 -524
  108. package/packages/ui/src/anime.ts +51 -51
  109. package/packages/ui/src/comp.ts +3 -3
  110. package/packages/ui/src/dom.ts +466 -466
  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/styles/components/table.scss +2 -1
  117. package/types/all.d.ts +76 -76
  118. package/types/index.d.ts +4 -4
  119. /package/dist/{iconfont.1794474448348.ttf → iconfont.1794983806256.ttf} +0 -0
  120. /package/dist/{iconfont.1794474448348.woff → iconfont.1794983806256.woff} +0 -0
  121. /package/dist/{iconfont.1794474448348.woff2 → iconfont.1794983806256.woff2} +0 -0
  122. /package/es/{iconfont.1794474448348.ttf → iconfont.1794983806256.ttf} +0 -0
  123. /package/es/{iconfont.1794474448348.woff → iconfont.1794983806256.woff} +0 -0
  124. /package/es/{iconfont.1794474448348.woff2 → iconfont.1794983806256.woff2} +0 -0
  125. /package/lib/{iconfont.1794474448348.ttf → iconfont.1794983806256.ttf} +0 -0
  126. /package/lib/{iconfont.1794474448348.woff → iconfont.1794983806256.woff} +0 -0
  127. /package/lib/{iconfont.1794474448348.woff2 → iconfont.1794983806256.woff2} +0 -0
@@ -1,1819 +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(
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
- })
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
+ })