vxe-table 3.20.7 → 3.20.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (144) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +106 -106
  3. package/es/index.esm.js +2 -1
  4. package/es/style.css +1 -1
  5. package/es/table/src/methods.js +81 -84
  6. package/es/table/src/table.js +20 -1
  7. package/es/table/src/util.js +6 -0
  8. package/es/table/style.css +18 -48
  9. package/es/ui/index.js +1 -1
  10. package/es/ui/src/dom.js +19 -20
  11. package/es/ui/src/log.js +1 -1
  12. package/es/vxe-table/style.css +18 -48
  13. package/lib/index.common.js +2 -1
  14. package/lib/index.umd.js +1985 -3291
  15. package/lib/index.umd.min.js +1 -1
  16. package/lib/style.css +1 -1
  17. package/lib/table/src/methods.js +17 -15
  18. package/lib/table/src/methods.min.js +1 -1
  19. package/lib/table/src/table.js +19 -1
  20. package/lib/table/src/table.min.js +1 -1
  21. package/lib/table/src/util.js +6 -0
  22. package/lib/table/src/util.min.js +1 -1
  23. package/lib/table/style/style.css +18 -48
  24. package/lib/ui/index.js +1 -1
  25. package/lib/ui/index.min.js +1 -1
  26. package/lib/ui/src/dom.js +21 -20
  27. package/lib/ui/src/dom.min.js +1 -1
  28. package/lib/ui/src/log.js +1 -1
  29. package/lib/ui/src/log.min.js +1 -1
  30. package/lib/v-x-e-table/index.js +2 -1
  31. package/lib/v-x-e-table/index.min.js +1 -1
  32. package/lib/vxe-colgroup/index.js +2 -1
  33. package/lib/vxe-colgroup/index.min.js +1 -1
  34. package/lib/vxe-column/index.js +2 -1
  35. package/lib/vxe-column/index.min.js +1 -1
  36. package/lib/vxe-grid/index.js +2 -1
  37. package/lib/vxe-grid/index.min.js +1 -1
  38. package/lib/vxe-table/index.js +2 -1
  39. package/lib/vxe-table/index.min.js +1 -1
  40. package/lib/vxe-table/style/style.css +18 -48
  41. package/lib/vxe-toolbar/index.js +2 -1
  42. package/lib/vxe-toolbar/index.min.js +1 -1
  43. package/lib/vxe-ui/index.js +2 -1
  44. package/lib/vxe-ui/index.min.js +1 -1
  45. package/lib/vxe-v-x-e-table/index.js +2 -1
  46. package/lib/vxe-v-x-e-table/index.min.js +1 -1
  47. package/package.json +93 -93
  48. package/packages/colgroup/index.ts +22 -22
  49. package/packages/column/index.ts +22 -22
  50. package/packages/components.ts +42 -42
  51. package/packages/grid/index.ts +22 -22
  52. package/packages/grid/src/grid.ts +1935 -1935
  53. package/packages/index.ts +4 -4
  54. package/packages/locale/lang/ar-EG.ts +832 -832
  55. package/packages/locale/lang/de-DE.ts +832 -832
  56. package/packages/locale/lang/en-US.ts +832 -832
  57. package/packages/locale/lang/es-ES.ts +832 -832
  58. package/packages/locale/lang/fr-FR.ts +832 -832
  59. package/packages/locale/lang/hu-HU.ts +832 -832
  60. package/packages/locale/lang/hy-AM.ts +832 -832
  61. package/packages/locale/lang/id-ID.ts +832 -832
  62. package/packages/locale/lang/it-IT.ts +832 -832
  63. package/packages/locale/lang/ja-JP.ts +832 -832
  64. package/packages/locale/lang/ko-KR.ts +832 -832
  65. package/packages/locale/lang/ms-MY.ts +832 -832
  66. package/packages/locale/lang/nb-NO.ts +832 -832
  67. package/packages/locale/lang/pt-BR.ts +832 -832
  68. package/packages/locale/lang/ru-RU.ts +832 -832
  69. package/packages/locale/lang/th-TH.ts +832 -832
  70. package/packages/locale/lang/ug-CN.ts +832 -832
  71. package/packages/locale/lang/uk-UA.ts +832 -832
  72. package/packages/locale/lang/uz-UZ.ts +832 -832
  73. package/packages/locale/lang/vi-VN.ts +832 -832
  74. package/packages/locale/lang/zh-CHT.ts +832 -832
  75. package/packages/locale/lang/zh-CN.ts +832 -832
  76. package/packages/locale/lang/zh-HK.ts +3 -3
  77. package/packages/locale/lang/zh-MO.ts +3 -3
  78. package/packages/locale/lang/zh-TC.ts +3 -3
  79. package/packages/locale/lang/zh-TW.ts +3 -3
  80. package/packages/table/index.ts +49 -49
  81. package/packages/table/module/custom/mixin.ts +369 -369
  82. package/packages/table/module/custom/panel.ts +1461 -1461
  83. package/packages/table/module/edit/mixin.ts +1123 -1123
  84. package/packages/table/module/export/export-panel.ts +658 -658
  85. package/packages/table/module/export/import-panel.ts +319 -319
  86. package/packages/table/module/export/mixin.ts +1693 -1693
  87. package/packages/table/module/export/util.ts +24 -24
  88. package/packages/table/module/filter/mixin.ts +507 -507
  89. package/packages/table/module/filter/panel.ts +329 -329
  90. package/packages/table/module/keyboard/mixin.ts +513 -513
  91. package/packages/table/module/menu/mixin.ts +329 -329
  92. package/packages/table/module/menu/panel.ts +212 -212
  93. package/packages/table/module/validator/mixin.ts +626 -626
  94. package/packages/table/render/index.ts +1456 -1456
  95. package/packages/table/src/body.ts +969 -969
  96. package/packages/table/src/cell.ts +1285 -1285
  97. package/packages/table/src/column.ts +205 -205
  98. package/packages/table/src/columnInfo.ts +228 -228
  99. package/packages/table/src/footer.ts +388 -388
  100. package/packages/table/src/group.ts +51 -51
  101. package/packages/table/src/header.ts +602 -602
  102. package/packages/table/src/methods.ts +12936 -12939
  103. package/packages/table/src/props.ts +311 -311
  104. package/packages/table/src/store.ts +15 -15
  105. package/packages/table/src/table.ts +2523 -2505
  106. package/packages/table/src/util.ts +1018 -1012
  107. package/packages/toolbar/index.ts +18 -18
  108. package/packages/toolbar/src/toolbar.ts +856 -856
  109. package/packages/ui/index.ts +530 -530
  110. package/packages/ui/src/anime.ts +52 -52
  111. package/packages/ui/src/comp.ts +3 -3
  112. package/packages/ui/src/dom.ts +237 -236
  113. package/packages/ui/src/log.ts +8 -8
  114. package/packages/ui/src/utils.ts +56 -56
  115. package/packages/ui/src/vn.ts +65 -65
  116. package/packages/v-x-e-table/index.ts +4 -4
  117. package/styles/all.scss +7 -7
  118. package/styles/base.scss +16 -16
  119. package/styles/components/grid.scss +89 -89
  120. package/styles/components/icon.scss +225 -225
  121. package/styles/components/old-icon.scss +715 -715
  122. package/styles/components/table-module/all.scss +6 -6
  123. package/styles/components/table-module/custom.scss +527 -527
  124. package/styles/components/table-module/export.scss +130 -130
  125. package/styles/components/table-module/filter.scss +130 -130
  126. package/styles/components/table-module/menu.scss +81 -81
  127. package/styles/components/table.scss +2679 -2679
  128. package/styles/components/toolbar.scss +119 -119
  129. package/styles/default.scss +2 -2
  130. package/styles/helpers/baseMixin.scss +95 -95
  131. package/styles/index.scss +3 -3
  132. package/styles/modules.scss +5 -5
  133. package/styles/theme/base.scss +93 -93
  134. package/styles/theme/dark.scss +49 -49
  135. package/styles/theme/light.scss +44 -44
  136. package/styles/variable.scss +43 -43
  137. package/types/all.d.ts +53 -53
  138. package/types/index.d.ts +4 -4
  139. /package/es/{iconfont.1773991883171.ttf → iconfont.1774420912543.ttf} +0 -0
  140. /package/es/{iconfont.1773991883171.woff → iconfont.1774420912543.woff} +0 -0
  141. /package/es/{iconfont.1773991883171.woff2 → iconfont.1774420912543.woff2} +0 -0
  142. /package/lib/{iconfont.1773991883171.ttf → iconfont.1774420912543.ttf} +0 -0
  143. /package/lib/{iconfont.1773991883171.woff → iconfont.1774420912543.woff} +0 -0
  144. /package/lib/{iconfont.1773991883171.woff2 → iconfont.1774420912543.woff2} +0 -0
@@ -1,1456 +1,1456 @@
1
- import { CreateElement } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import { VxeUI } from '../../ui'
4
- import { getCellValue, setCellValue } from '../src/util'
5
- import { getFuncText, formatText, isEmptyValue } from '../../ui/src/utils'
6
- import { getOnName, getModelEvent, getChangeEvent, hasInputType } from '../../ui/src/vn'
7
- import { errLog } from '../../ui/src/log'
8
-
9
- import type { VxeGlobalRendererHandles, VxeColumnPropTypes, VxeTableConstructor, VxeTablePrivateMethods, VxeTableDefines } from '../../../types'
10
-
11
- const { getConfig, renderer, getI18n, getComponent } = VxeUI
12
-
13
- const componentDefaultModelProp = 'value'
14
-
15
- const defaultCompProps = {}
16
-
17
- function handleDefaultValue (value: any, defaultVal: any, initVal: any) {
18
- return XEUtils.eqNull(value) ? (XEUtils.eqNull(defaultVal) ? initVal : defaultVal) : value
19
- }
20
-
21
- function parseDate (value: any, props: any) {
22
- return value && props.valueFormat ? XEUtils.toStringDate(value, props.valueFormat) : value
23
- }
24
-
25
- function getFormatDate (value: any, props: any, defaultFormat: string) {
26
- const { dateConfig = {} } = props
27
- return XEUtils.toDateString(parseDate(value, props), dateConfig.labelFormat || defaultFormat)
28
- }
29
-
30
- function getLabelFormatDate (value: any, props: any) {
31
- return getFormatDate(value, props, getI18n(`vxe.input.date.labelFormat.${props.type || 'date'}`))
32
- }
33
-
34
- /**
35
- * 已废弃
36
- * @deprecated
37
- */
38
- function getOldComponentName (name: string) {
39
- return `vxe-${name.replace('$', '')}`
40
- }
41
-
42
- /**
43
- * 已废弃
44
- * @deprecated
45
- */
46
- function getOldComponent ({ name }: any) {
47
- return getOldComponentName(name)
48
- }
49
-
50
- function getDefaultComponent ({ name }: any) {
51
- return getComponent(name) || name
52
- }
53
-
54
- function updateFilterChangeOption (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
55
- const { $table } = params
56
- $table.updateFilterOptionStatus(option, checked)
57
- }
58
-
59
- function saveFilterEvent (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
60
- const { $table, column } = params
61
- $table.saveFilterByEvent(new Event('change'), column)
62
- }
63
-
64
- function getNativeAttrs (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
65
- let { name, attrs } = renderOpts
66
- if (name === 'input') {
67
- attrs = Object.assign({ type: 'text' }, attrs)
68
- }
69
- return attrs
70
- }
71
-
72
- function getInputImmediateModel (renderOpts: VxeColumnPropTypes.EditRender) {
73
- const { name, immediate, props } = renderOpts
74
- if (!immediate) {
75
- if (name === 'VxeInput' || name === '$input') {
76
- const { type } = props || {}
77
- return !(!type || type === 'text' || type === 'number' || type === 'integer' || type === 'float')
78
- }
79
- if (name === 'input' || name === 'textarea' || name === '$textarea') {
80
- return false
81
- }
82
- return true
83
- }
84
- return immediate
85
- }
86
-
87
- function getCellEditProps (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams, value: any, defaultProps?: any) {
88
- return XEUtils.assign({ immediate: getInputImmediateModel(renderOpts) }, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
89
- }
90
-
91
- function getCellEditFilterProps (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, value: any, defaultProps?: any) {
92
- return XEUtils.assign({}, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
93
- }
94
-
95
- function isImmediateCell (renderOpts: VxeColumnPropTypes.EditRender, params: any) {
96
- return params.$type === 'cell' || getInputImmediateModel(renderOpts)
97
- }
98
-
99
- function getCellLabelVNs (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, cellLabel: any, opts?: {
100
- class?: string
101
- }) {
102
- const { placeholder } = renderOpts
103
- return [
104
- h('span', {
105
- class: ['vxe-cell--label', opts ? opts.class : '']
106
- }, placeholder && isEmptyValue(cellLabel)
107
- ? [
108
- h('span', {
109
- class: 'vxe-cell--placeholder'
110
- }, formatText(getFuncText(placeholder), 1))
111
- ]
112
- : formatText(cellLabel, 1))
113
- ]
114
- }
115
-
116
- /**
117
- * 原生事件处理
118
- * @param renderOpts
119
- * @param params
120
- * @param modelFunc
121
- * @param changeFunc
122
- */
123
- function getNativeElementOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
124
- model: (evnt: Event) => void
125
- change?: (evnt: Event) => void
126
- blur?: (evnt: Event) => void
127
- }) {
128
- const { events } = renderOpts
129
- const modelEvent = getModelEvent(renderOpts)
130
- const changeEvent = getChangeEvent(renderOpts)
131
- const { model: modelFunc, change: changeFunc, blur: blurFunc } = eFns || {}
132
- const isSameEvent = changeEvent === modelEvent
133
- const ons: any = {}
134
- if (events) {
135
- XEUtils.objectEach(events, (func, key: any) => {
136
- ons[getOnName(key)] = function (...args: any[]) {
137
- func(params, ...args)
138
- }
139
- })
140
- }
141
- if (modelFunc) {
142
- ons[getOnName(modelEvent)] = function (targetEvnt: any) {
143
- modelFunc(targetEvnt)
144
- if (isSameEvent && changeFunc) {
145
- changeFunc(targetEvnt)
146
- }
147
- if (events && events[modelEvent]) {
148
- events[modelEvent](params, targetEvnt)
149
- }
150
- }
151
- }
152
- if (!isSameEvent && changeFunc) {
153
- ons[getOnName(changeEvent)] = function (evnt: Event) {
154
- changeFunc(evnt)
155
- if (events && events[changeEvent]) {
156
- events[changeEvent](params, evnt)
157
- }
158
- }
159
- }
160
- if (blurFunc) {
161
- ons[getOnName(blurEvent)] = function (evnt: Event) {
162
- blurFunc(evnt)
163
- if (events && events[blurEvent]) {
164
- events[blurEvent](params, evnt)
165
- }
166
- }
167
- }
168
- return ons
169
- }
170
-
171
- const blurEvent = 'blur'
172
- const clearEvent = 'clear'
173
-
174
- /**
175
- * 组件事件处理
176
- * @param renderOpts
177
- * @param params
178
- * @param modelFunc
179
- * @param changeFunc
180
- */
181
- function getComponentOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
182
- model: (cellValue: any) => void
183
- change?: (...args: any[]) => void
184
- blur?: (...args: any[]) => void
185
- clear?: (...args: any[]) => void
186
- }, eventOns?: Record<string, any>) {
187
- const { events } = renderOpts
188
- const modelEvent = getModelEvent(renderOpts)
189
- const changeEvent = getChangeEvent(renderOpts)
190
- const { model: modelFunc, change: changeFunc, blur: blurFunc, clear: clearFunc } = eFns || {}
191
- const ons: any = {}
192
- XEUtils.objectEach(events, (func, key: any) => {
193
- ons[getOnName(key)] = function (...args: any[]) {
194
- if (!XEUtils.isFunction(func)) {
195
- errLog('vxe.error.errFunc', [func])
196
- }
197
- func(params, ...args)
198
- }
199
- })
200
- if (modelFunc) {
201
- ons[getOnName(modelEvent)] = function (targetEvnt: any) {
202
- modelFunc(targetEvnt)
203
- if (events && events[modelEvent]) {
204
- events[modelEvent](params, targetEvnt)
205
- }
206
- }
207
- }
208
- if (changeFunc) {
209
- ons[getOnName(changeEvent)] = function (...args: any[]) {
210
- changeFunc(...args)
211
- if (events && events[changeEvent]) {
212
- events[changeEvent](params, ...args)
213
- }
214
- }
215
- }
216
- if (blurFunc) {
217
- ons[getOnName(blurEvent)] = function (...args: any[]) {
218
- blurFunc(...args)
219
- if (events && events[blurEvent]) {
220
- events[blurEvent](params, ...args)
221
- }
222
- }
223
- }
224
- if (clearFunc) {
225
- ons[getOnName(clearEvent)] = function (...args: any[]) {
226
- clearFunc(...args)
227
- if (events && events[clearEvent]) {
228
- events[clearEvent](params, ...args)
229
- }
230
- }
231
- }
232
- return eventOns ? Object.assign(ons, eventOns) : ons
233
- }
234
-
235
- function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
236
- const { $table, row, column } = params
237
- const { name } = renderOpts
238
- const { model } = column
239
- const isImmediate = isImmediateCell(renderOpts, params)
240
- return getComponentOns(renderOpts, params, {
241
- model (cellValue) {
242
- // 处理 model 值双向绑定
243
- model.update = true
244
- model.value = cellValue
245
- if (isImmediate) {
246
- setCellValue(row, column, cellValue)
247
- }
248
- },
249
- change (eventParams) {
250
- // 处理 change 事件相关逻辑
251
- if (!isImmediate && name && (['VxeInput', 'VxeNumberInput', 'VxeTextarea', '$input', '$textarea'].includes(name))) {
252
- const cellValue = eventParams.value
253
- model.update = true
254
- model.value = cellValue
255
- $table.updateStatus(params, cellValue)
256
- } else {
257
- $table.updateStatus(params)
258
- }
259
- },
260
- blur () {
261
- if (isImmediate) {
262
- $table.handleCellRuleUpdateStatus('blur', params)
263
- } else {
264
- $table.handleCellRuleUpdateStatus('blur', params, model.value)
265
- }
266
- }
267
- })
268
- }
269
-
270
- function getFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams, option: VxeTableDefines.FilterOption) {
271
- return getComponentOns(renderOpts, params, {
272
- model (value) {
273
- // 处理 model 值双向绑定
274
- option.data = value
275
- },
276
- change () {
277
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
278
- },
279
- blur () {
280
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
281
- }
282
- })
283
- }
284
-
285
- function getFloatingFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams, option: VxeTableDefines.FilterOption) {
286
- const { $table, column } = params
287
- if (hasInputType(renderOpts)) {
288
- return getComponentOns(renderOpts, params, {
289
- model (value: any) {
290
- // 处理 model 值双向绑定
291
- option.data = value
292
- },
293
- change () {
294
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
295
- },
296
- clear () {
297
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
298
- saveFilterEvent(params)
299
- },
300
- blur () {
301
- $table.saveFilterByEvent(new Event('change'), column)
302
- }
303
- }, renderOpts.name === 'VxeNumberInput'
304
- ? {
305
- [getOnName('plus-number')] () {
306
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
307
- saveFilterEvent(params)
308
- },
309
- [getOnName('minus-number')] () {
310
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
311
- saveFilterEvent(params)
312
- }
313
- }
314
- : {})
315
- }
316
- return getComponentOns(renderOpts, params, {
317
- model (value: any) {
318
- // 处理 model 值双向绑定
319
- option.data = value
320
- },
321
- clear () {
322
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
323
- $table.saveFilterByEvent(new Event('change'), column)
324
- },
325
- change () {
326
- updateFilterChangeOption(params, !isEmptyValue(option.data), option)
327
- $table.saveFilterByEvent(new Event('change'), column)
328
- }
329
- })
330
- }
331
-
332
- function getNativeEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
333
- const { $table, row, column } = params
334
- const { model } = column
335
- return getNativeElementOns(renderOpts, params, {
336
- model (evnt) {
337
- // 处理 model 值双向绑定
338
- const targetEl = evnt.target as HTMLInputElement
339
- if (targetEl) {
340
- const cellValue = targetEl.value
341
- if (isImmediateCell(renderOpts, params)) {
342
- setCellValue(row, column, cellValue)
343
- } else {
344
- model.update = true
345
- model.value = cellValue
346
- }
347
- }
348
- },
349
- change (evnt) {
350
- // 处理 change 事件相关逻辑
351
- const targetEl = evnt.target as HTMLInputElement
352
- if (targetEl) {
353
- const cellValue = targetEl.value
354
- $table.updateStatus(params, cellValue)
355
- }
356
- },
357
- blur (evnt) {
358
- const targetEl = evnt.target as HTMLInputElement
359
- if (targetEl) {
360
- const cellValue = targetEl.value
361
- $table.updateStatus(params, cellValue)
362
- }
363
- }
364
- })
365
- }
366
-
367
- function getNativeFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, option: any) {
368
- return getNativeElementOns(renderOpts, params, {
369
- model (evnt) {
370
- // 处理 model 值双向绑定
371
- const targetEl = evnt.target as HTMLInputElement
372
- if (targetEl) {
373
- option.data = targetEl.value
374
- }
375
- },
376
- change () {
377
- updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
378
- },
379
- blur () {
380
- updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
381
- }
382
- })
383
- }
384
-
385
- /**
386
- * 单元格可编辑渲染-原生的标签
387
- * input、textarea、select
388
- */
389
- function nativeEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
390
- const { row, column } = params
391
- const { name } = renderOpts
392
- const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
393
- return [
394
- h(`${name}`, {
395
- class: `vxe-default-${name}`,
396
- attrs: getNativeAttrs(renderOpts),
397
- domProps: {
398
- value: cellValue
399
- },
400
- on: getNativeEditOns(renderOpts, params)
401
- })
402
- ]
403
- }
404
-
405
- function buttonCellRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any) {
406
- return [
407
- h(getDefaultComponent(renderOpts), {
408
- props: getCellEditProps(renderOpts, params, null),
409
- on: getComponentOns(renderOpts, params)
410
- })
411
- ]
412
- }
413
-
414
- function defaultEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
415
- const { row, column } = params
416
- const cellValue = getCellValue(row, column)
417
- return [
418
- h(getDefaultComponent(renderOpts), {
419
- props: getCellEditProps(renderOpts, params, cellValue),
420
- on: getEditOns(renderOpts, params)
421
- })
422
- ]
423
- }
424
-
425
- function checkboxEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
426
- const { row, column } = params
427
- const cellValue = getCellValue(row, column)
428
- return [
429
- h(getDefaultComponent(renderOpts), {
430
- props: getCellEditProps(renderOpts, params, cellValue),
431
- on: getEditOns(renderOpts, params)
432
- })
433
- ]
434
- }
435
-
436
- function radioAndCheckboxGroupEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
437
- const { options } = renderOpts
438
- const { row, column } = params
439
- const cellValue = getCellValue(row, column)
440
- return [
441
- h(getDefaultComponent(renderOpts), {
442
- props: {
443
- options,
444
- ...getCellEditProps(renderOpts, params, cellValue)
445
- },
446
- on: getEditOns(renderOpts, params)
447
- })
448
- ]
449
- }
450
-
451
- /**
452
- * 已废弃
453
- * @deprecated
454
- */
455
- function oldEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
456
- const { row, column } = params
457
- const cellValue = getCellValue(row, column)
458
- return [
459
- h(getOldComponent(renderOpts), {
460
- props: getCellEditProps(renderOpts, params, cellValue),
461
- on: getEditOns(renderOpts, params)
462
- })
463
- ]
464
- }
465
-
466
- /**
467
- * 已废弃
468
- * @deprecated
469
- */
470
- function oldButtonEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
471
- return [
472
- h('vxe-button', {
473
- props: getCellEditProps(renderOpts, params, null),
474
- on: getComponentOns(renderOpts, params)
475
- })
476
- ]
477
- }
478
-
479
- /**
480
- * 已废弃
481
- * @deprecated
482
- */
483
- function oldButtonsEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: any) {
484
- const { children } = renderOpts
485
- return children ? children.map((childRenderOpts: any) => oldButtonEditRender(h, childRenderOpts, params)[0]) : []
486
- }
487
-
488
- function renderNativeOptgroups (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any, renderOptionsMethods: any) {
489
- const { optionGroups, optionGroupProps = {} } = renderOpts
490
- const groupOptions = optionGroupProps.options || 'options'
491
- const groupLabel = optionGroupProps.label || 'label'
492
- if (optionGroups) {
493
- return optionGroups.map((group: any, gIndex: any) => {
494
- return h('optgroup', {
495
- key: gIndex,
496
- attrs: {
497
- label: group[groupLabel]
498
- }
499
- }, renderOptionsMethods(h, group[groupOptions], renderOpts, params))
500
- })
501
- }
502
- return []
503
- }
504
-
505
- /**
506
- * 渲染原生的 option 标签
507
- */
508
- function renderNativeOptions (h: CreateElement, options: any, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: any) {
509
- const { optionProps = {} } = renderOpts
510
- const { row, column } = params
511
- const labelProp = optionProps.label || 'label'
512
- const valueProp = optionProps.value || 'value'
513
- const disabledProp = optionProps.disabled || 'disabled'
514
- const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
515
- if (options) {
516
- return options.map((option: any, oIndex: any) => {
517
- return h('option', {
518
- key: oIndex,
519
- attrs: {
520
- value: option[valueProp],
521
- disabled: option[disabledProp]
522
- },
523
- domProps: {
524
- /* eslint-disable eqeqeq */
525
- selected: option[valueProp] == cellValue
526
- }
527
- }, option[labelProp])
528
- })
529
- }
530
- return []
531
- }
532
-
533
- function nativeFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
534
- const { column } = params
535
- const { name } = renderOpts
536
- const attrs = getNativeAttrs(renderOpts)
537
- return column.filters.map((option, oIndex) => {
538
- return h(`${name}`, {
539
- key: oIndex,
540
- class: `vxe-default-${name}`,
541
- attrs,
542
- domProps: {
543
- value: option.data
544
- },
545
- on: getNativeFilterOns(renderOpts, params, option)
546
- })
547
- })
548
- }
549
-
550
- function defaultFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
551
- const { column } = params
552
- return column.filters.map((option, oIndex) => {
553
- const optionValue = option.data
554
- return h(getDefaultComponent(renderOpts), {
555
- key: oIndex,
556
- props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
557
- on: getFilterOns(renderOpts, params, option)
558
- })
559
- })
560
- }
561
-
562
- function defaultFloatingFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFloatingFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
563
- const { option } = params
564
- const optionValue = option.data
565
- return [
566
- h(getDefaultComponent(renderOpts), {
567
- props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
568
- on: getFloatingFilterOns(renderOpts, params, option)
569
- })
570
- ]
571
- }
572
-
573
- function defaultFilterOptions () {
574
- return [
575
- { data: null }
576
- ]
577
- }
578
-
579
- /**
580
- * 已废弃
581
- * @deprecated
582
- */
583
- function oldFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any) {
584
- const { column } = params
585
- return column.filters.map((option: any, oIndex: any) => {
586
- const optionValue = option.data
587
- return h(getOldComponent(renderOpts), {
588
- key: oIndex,
589
- props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
590
- on: getFilterOns(renderOpts, params, option)
591
- })
592
- })
593
- }
594
-
595
- function handleFilterMethod ({ option, row, column }: any) {
596
- const { data } = option
597
- const cellValue = XEUtils.get(row, column.field)
598
- /* eslint-disable eqeqeq */
599
- return cellValue == data
600
- }
601
-
602
- function handleInputFilterMethod ({ option, row, column }: any) {
603
- const { data } = option
604
- const cellValue = XEUtils.get(row, column.field)
605
- /* eslint-disable eqeqeq */
606
- return XEUtils.toValueString(cellValue).indexOf(data) > -1
607
- }
608
-
609
- function nativeSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
610
- return [
611
- h('select', {
612
- class: 'vxe-default-select',
613
- attrs: getNativeAttrs(renderOpts),
614
- on: getNativeEditOns(renderOpts, params)
615
- },
616
- renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params))
617
- ]
618
- }
619
-
620
- function defaultSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
621
- const { row, column } = params
622
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
623
- const cellValue = getCellValue(row, column)
624
- return [
625
- h(getDefaultComponent(renderOpts), {
626
- props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
627
- on: getEditOns(renderOpts, params)
628
- })
629
- ]
630
- }
631
-
632
- function defaultTableOrTreeSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
633
- const { row, column } = params
634
- const { options, optionProps } = renderOpts
635
- const cellValue = getCellValue(row, column)
636
- return [
637
- h(getDefaultComponent(renderOpts), {
638
- props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps }),
639
- on: getEditOns(renderOpts, params)
640
- })
641
- ]
642
- }
643
-
644
- /**
645
- * 已废弃
646
- * @deprecated
647
- */
648
- function oldSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
649
- const { row, column } = params
650
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
651
- const cellValue = getCellValue(row, column)
652
- return [
653
- h(getOldComponent(renderOpts), {
654
- props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
655
- on: getEditOns(renderOpts, params)
656
- })
657
- ]
658
- }
659
-
660
- function handleSelectCellValue (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
661
- const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props = {} } = renderOpts
662
- let selectItem: any
663
- const labelProp = optionProps.label || 'label'
664
- const valueProp = optionProps.value || 'value'
665
- if (!(cellValue === null || cellValue === undefined)) {
666
- let vals = []
667
- if (XEUtils.isArray(cellValue)) {
668
- vals = cellValue
669
- } else {
670
- if (props.multiple && `${cellValue}`.indexOf(',') > -1) {
671
- vals = `${cellValue}`.split(',')
672
- } else {
673
- vals = [cellValue]
674
- }
675
- }
676
- return XEUtils.map(vals, optionGroups
677
- ? (value) => {
678
- const groupOptions = optionGroupProps.options || 'options'
679
- for (let index = 0; index < optionGroups.length; index++) {
680
- /* eslint-disable eqeqeq */
681
- selectItem = XEUtils.find(optionGroups[index][groupOptions], item => item[valueProp] == value)
682
- if (selectItem) {
683
- break
684
- }
685
- }
686
- return selectItem ? selectItem[labelProp] : value
687
- }
688
- : (value) => {
689
- /* eslint-disable eqeqeq */
690
- selectItem = XEUtils.find(options, item => item[valueProp] == value)
691
- return selectItem ? selectItem[labelProp] : value
692
- }
693
- ).join(', ')
694
- }
695
- return ''
696
- }
697
-
698
- function getSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, { row, column }: any) {
699
- const cellValue = XEUtils.get(row, column.field)
700
- return handleSelectCellValue(cellValue, renderOpts)
701
- }
702
-
703
- function handleExportSelectMethod (params: any) {
704
- const { row, column, options } = params
705
- return options.original ? getCellValue(row, column) : getSelectCellValue(column.editRender || column.cellRender, params)
706
- }
707
-
708
- function handleTreeSelectCellValue (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions) {
709
- const { options, optionProps = {} } = renderOpts
710
- const labelProp = optionProps.label || 'label'
711
- const valueProp = optionProps.value || 'value'
712
- const childrenProp = optionProps.children || 'children'
713
- if (!(cellValue === null || cellValue === undefined)) {
714
- const keyMaps: Record<string, any> = {}
715
- XEUtils.eachTree(options, item => {
716
- keyMaps[XEUtils.get(item, valueProp)] = item
717
- }, { children: childrenProp })
718
- return XEUtils.map(XEUtils.isArray(cellValue) ? cellValue : [cellValue], (value) => {
719
- const item = keyMaps[value]
720
- return item ? XEUtils.get(item, labelProp) : item
721
- }
722
- ).join(', ')
723
- }
724
- return ''
725
- }
726
-
727
- function getTreeSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, { row, column }: any) {
728
- const cellValue = XEUtils.get(row, column.field)
729
- return handleTreeSelectCellValue(cellValue, renderOpts)
730
- }
731
-
732
- function handleExportTreeSelectMethod (params: any) {
733
- const { row, column, options } = params
734
- return options.original ? getCellValue(row, column) : getTreeSelectCellValue(column.editRender || column.cellRender, params)
735
- }
736
-
737
- function handleNumberCell (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.RenderTableDefaultParams) {
738
- const { props = {}, showNegativeStatus } = renderOpts
739
- const { row, column } = params
740
- const { type } = props
741
- let cellValue = XEUtils.get(row, column.field)
742
- let isNegative = false
743
- if (!isEmptyValue(cellValue)) {
744
- const numberInputConfig = getConfig().numberInput || {}
745
- if (type === 'float') {
746
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
747
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
748
- cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
749
- if (!autoFill) {
750
- cellValue = XEUtils.toNumber(cellValue)
751
- }
752
- if (showNegativeStatus) {
753
- if (cellValue < 0) {
754
- isNegative = true
755
- }
756
- }
757
- } else if (type === 'amount') {
758
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
759
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
760
- const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
761
- cellValue = XEUtils.toNumber(cellValue)
762
- if (showNegativeStatus) {
763
- if (cellValue < 0) {
764
- isNegative = true
765
- }
766
- }
767
- cellValue = XEUtils.commafy(cellValue, { digits })
768
- if (!autoFill) {
769
- const [iStr, dStr] = cellValue.split('.')
770
- if (dStr) {
771
- const dRest = dStr.replace(/0+$/, '')
772
- cellValue = dRest ? [iStr, '.', dRest].join('') : iStr
773
- }
774
- }
775
- if (showCurrency) {
776
- cellValue = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${cellValue}`
777
- }
778
- } else {
779
- if (type === 'integer') {
780
- cellValue = XEUtils.toInteger(cellValue)
781
- }
782
- if (showNegativeStatus) {
783
- if (XEUtils.toNumber(cellValue) < 0) {
784
- isNegative = true
785
- }
786
- }
787
- }
788
- }
789
- return getCellLabelVNs(h, renderOpts, params, cellValue, isNegative
790
- ? {
791
- class: 'is--negative'
792
- }
793
- : {})
794
- }
795
-
796
- function handleFormatDatePicker (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams) {
797
- const { props = {} } = renderOpts
798
- const { cellValue } = params
799
- if (cellValue) {
800
- if (props.type !== 'time') {
801
- return getLabelFormatDate(cellValue, props)
802
- }
803
- }
804
- return cellValue
805
- }
806
-
807
- function handleFormatSelect (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
808
- const { cellValue } = params
809
- return handleSelectCellValue(cellValue, renderOpts)
810
- }
811
-
812
- function handleSetSelectValue (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
813
- const { row, column, cellValue } = params
814
- const { field } = column
815
- if (field) {
816
- const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props } = renderOpts
817
- if (isEmptyValue(cellValue)) {
818
- XEUtils.set(row, field, props && props.multiple ? [] : null)
819
- return
820
- }
821
- const isMultiVal = XEUtils.indexOf(`${cellValue}`, ',') > -1
822
- const labelProp = optionProps.label || 'label'
823
- const valueProp = optionProps.value || 'value'
824
- const labelMpas: Record<string, any> = {}
825
- if (optionGroups && optionGroups.length) {
826
- const groupOptions = optionGroupProps.options || 'options'
827
- for (let i = 0; i < optionGroups.length; i++) {
828
- const opts = optionGroups[i][groupOptions] || {}
829
- for (let j = 0; j < opts.length; j++) {
830
- const item = opts[j]
831
- if (isMultiVal) {
832
- labelMpas[item[labelProp]] = item
833
- /* eslint-disable eqeqeq */
834
- } else if (item[labelProp] == cellValue) {
835
- XEUtils.set(row, field, item[valueProp])
836
- return
837
- }
838
- }
839
- }
840
- } else {
841
- if (options) {
842
- for (let i = 0; i < options.length; i++) {
843
- const item = options[i]
844
- if (isMultiVal) {
845
- labelMpas[item[labelProp]] = item
846
- /* eslint-disable eqeqeq */
847
- } else if (item[labelProp] == cellValue) {
848
- XEUtils.set(row, field, item[valueProp])
849
- return
850
- }
851
- }
852
- }
853
- }
854
- if (isMultiVal) {
855
- XEUtils.set(row, field, (isMultiVal
856
- ? cellValue.split(',')
857
- : [cellValue]).map((label: any) => {
858
- const item = labelMpas[label]
859
- return item ? item[valueProp] : label
860
- }))
861
- } else {
862
- XEUtils.set(row, field, cellValue)
863
- }
864
- }
865
- }
866
-
867
- function handleFormatTreeSelect (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
868
- const { cellValue } = params
869
- return handleTreeSelectCellValue(cellValue, renderOpts)
870
- }
871
-
872
- function handleSetTreeSelectValue (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
873
- const { row, column, cellValue } = params
874
- const { field } = column
875
- if (field) {
876
- const { options, optionProps = {} } = renderOpts
877
- const labelProp = optionProps.label || 'label'
878
- const valueProp = optionProps.value || 'value'
879
- const childrenProp = optionProps.children || 'children'
880
- const matchRest = XEUtils.findTree(options || [], item => XEUtils.get(item, labelProp) === cellValue, { children: childrenProp })
881
- if (matchRest) {
882
- const selectItem = matchRest.item
883
- if (selectItem) {
884
- XEUtils.set(row, field, selectItem[valueProp])
885
- return
886
- }
887
- }
888
- XEUtils.set(row, field, cellValue)
889
- }
890
- }
891
-
892
- /**
893
- * 表格 - 渲染器
894
- */
895
- renderer.mixin({
896
- input: {
897
- tableAutoFocus: 'input',
898
- renderTableEdit: nativeEditRender,
899
- renderTableDefault: nativeEditRender,
900
- renderTableFilter: nativeFilterRender,
901
- tableFilterDefaultMethod: handleInputFilterMethod
902
- },
903
- textarea: {
904
- tableAutoFocus: 'textarea',
905
- renderTableEdit: nativeEditRender
906
- },
907
- select: {
908
- renderTableEdit: nativeSelectEditRender,
909
- renderTableDefault: nativeSelectEditRender,
910
- renderTableCell (h, renderOpts, params) {
911
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
912
- },
913
- renderTableFilter (h, renderOpts, params) {
914
- const { column } = params
915
- return column.filters.map((option, oIndex) => {
916
- return h('select', {
917
- key: oIndex,
918
- class: 'vxe-default-select',
919
- attrs: getNativeAttrs(renderOpts),
920
- on: getNativeFilterOns(renderOpts, params, option)
921
- },
922
- renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params))
923
- })
924
- },
925
- tableCellFormatter: handleFormatSelect,
926
- tableCellCopyMethod: handleFormatSelect,
927
- tableCellPasteMethod: handleSetSelectValue,
928
- tableFilterDefaultMethod: handleFilterMethod,
929
- tableExportMethod: handleExportSelectMethod
930
- },
931
- VxeInput: {
932
- tableAutoFocus: 'input',
933
- renderTableEdit: defaultEditRender,
934
- renderTableCell (h, renderOpts, params) {
935
- const { props = {} } = renderOpts
936
- const { row, column } = params
937
- const inputConfig = getConfig().input || {}
938
- const digits = props.digits || inputConfig.digits || 2
939
- let cellValue = XEUtils.get(row, column.field)
940
- if (cellValue) {
941
- switch (props.type) {
942
- case 'date':
943
- case 'week':
944
- case 'month':
945
- case 'quarter':
946
- case 'year':
947
- cellValue = getLabelFormatDate(cellValue, props)
948
- break
949
- case 'float':
950
- cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
951
- break
952
- }
953
- }
954
- return getCellLabelVNs(h, renderOpts, params, cellValue)
955
- },
956
- renderTableDefault: defaultEditRender,
957
- createTableFilterOptions: defaultFilterOptions,
958
- renderTableFilter: defaultFilterRender,
959
- renderTableFloatingFilter: defaultFloatingFilterRender,
960
- tableFilterDefaultMethod: handleInputFilterMethod
961
- },
962
- FormatNumberInput: {
963
- renderTableDefault: handleNumberCell,
964
- tableFilterDefaultMethod: handleInputFilterMethod,
965
- tableExportMethod (params) {
966
- const { row, column } = params
967
- const cellValue = XEUtils.get(row, column.field)
968
- return cellValue
969
- }
970
- },
971
- VxeNumberInput: {
972
- tableAutoFocus: 'input',
973
- renderTableEdit: defaultEditRender,
974
- renderTableCell: handleNumberCell,
975
- renderTableFooter (h, renderOpts, params) {
976
- const { props = {} } = renderOpts
977
- const { row, column, _columnIndex } = params
978
- const { type } = props
979
- // 兼容老模式
980
- const itemValue = XEUtils.isArray(row) ? row[_columnIndex] : XEUtils.get(row, column.field)
981
- if (XEUtils.isNumber(itemValue)) {
982
- const numberInputConfig = getConfig().numberInput || {}
983
- if (type === 'float') {
984
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
985
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
986
- let amountLabel = XEUtils.toFixed(XEUtils.floor(itemValue, digits), digits)
987
- if (!autoFill) {
988
- amountLabel = XEUtils.toNumber(amountLabel)
989
- }
990
- return amountLabel
991
- } else if (type === 'amount') {
992
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
993
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
994
- const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
995
- let amountLabel = XEUtils.commafy(XEUtils.toNumber(itemValue), { digits })
996
- if (!autoFill) {
997
- const [iStr, dStr] = amountLabel.split('.')
998
- if (dStr) {
999
- const dRest = dStr.replace(/0+$/, '')
1000
- amountLabel = dRest ? [iStr, '.', dRest].join('') : iStr
1001
- }
1002
- }
1003
- if (showCurrency) {
1004
- amountLabel = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${amountLabel}`
1005
- }
1006
- return amountLabel
1007
- }
1008
- }
1009
- return getFuncText(itemValue, 1)
1010
- },
1011
- renderTableDefault: defaultEditRender,
1012
- createTableFilterOptions: defaultFilterOptions,
1013
- renderTableFilter: defaultFilterRender,
1014
- renderTableFloatingFilter: defaultFloatingFilterRender,
1015
- tableFilterDefaultMethod: handleInputFilterMethod,
1016
- tableExportMethod (params) {
1017
- const { row, column } = params
1018
- const cellValue = XEUtils.get(row, column.field)
1019
- return cellValue
1020
- }
1021
- },
1022
- VxeDatePicker: {
1023
- tableAutoFocus: 'input',
1024
- renderTableEdit: defaultEditRender,
1025
- renderTableCell (h, renderOpts, params) {
1026
- const { props = {} } = renderOpts
1027
- const { row, column } = params
1028
- let cellValue = XEUtils.get(row, column.field)
1029
- if (cellValue) {
1030
- if (props.type !== 'time') {
1031
- cellValue = getLabelFormatDate(cellValue, props)
1032
- }
1033
- }
1034
- return getCellLabelVNs(h, renderOpts, params, cellValue)
1035
- },
1036
- tableCellFormatter: handleFormatDatePicker,
1037
- renderTableDefault: defaultEditRender,
1038
- createTableFilterOptions: defaultFilterOptions,
1039
- renderTableFilter: defaultFilterRender,
1040
- renderTableFloatingFilter: defaultFloatingFilterRender,
1041
- tableFilterDefaultMethod: handleFilterMethod
1042
- },
1043
- VxeDateRangePicker: {
1044
- tableAutoFocus: 'input',
1045
- renderTableEdit (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1046
- const { startField, endField } = renderOpts
1047
- const { $table, row, column } = params
1048
- const { model } = column
1049
- const cellValue = getCellValue(row, column)
1050
- const seProps: Record<string, any> = {}
1051
- const seOs: Record<string, any> = {}
1052
- if (startField && endField) {
1053
- seProps.startValue = XEUtils.get(row, startField)
1054
- seProps.endValue = XEUtils.get(row, endField)
1055
- seOs['update:startValue'] = (value: any) => {
1056
- if (startField) {
1057
- XEUtils.set(row, startField, value)
1058
- }
1059
- }
1060
- seOs['update:endValue'] = (value: any) => {
1061
- if (endField) {
1062
- XEUtils.set(row, endField, value)
1063
- }
1064
- }
1065
- }
1066
- return [
1067
- h(getDefaultComponent(renderOpts), {
1068
- props: getCellEditProps(renderOpts, params, cellValue, seProps),
1069
- on: getComponentOns(renderOpts, params, {
1070
- model (cellValue) {
1071
- model.update = true
1072
- model.value = cellValue
1073
- setCellValue(row, column, cellValue)
1074
- },
1075
- change () {
1076
- $table.updateStatus(params)
1077
- },
1078
- blur () {
1079
- $table.handleCellRuleUpdateStatus('blur', params)
1080
- }
1081
- }, seOs)
1082
- })
1083
- ]
1084
- },
1085
- renderTableCell (h, renderOpts, params) {
1086
- const { startField, endField } = renderOpts
1087
- const { row, column } = params
1088
- let startValue = ''
1089
- let endValue = ''
1090
- if (startField && endField) {
1091
- startValue = XEUtils.get(row, startField)
1092
- endValue = XEUtils.get(row, endField)
1093
- } else {
1094
- const cellValue = XEUtils.get(row, column.field)
1095
- if (cellValue) {
1096
- if (XEUtils.isArray(cellValue)) {
1097
- startValue = cellValue[0]
1098
- endValue = cellValue[1]
1099
- } else {
1100
- const strs = `${cellValue}`.split(',')
1101
- startValue = strs[0]
1102
- endValue = strs[1]
1103
- }
1104
- }
1105
- }
1106
- let cellLabel = ''
1107
- if (startValue && endValue) {
1108
- cellLabel = `${startValue} ~ ${endValue}`
1109
- }
1110
- return getCellLabelVNs(h, renderOpts, params, cellLabel)
1111
- }
1112
- },
1113
- VxeTextarea: {
1114
- tableAutoFocus: 'textarea',
1115
- renderTableEdit: defaultEditRender
1116
- },
1117
- VxeButton: {
1118
- renderTableDefault: buttonCellRender
1119
- },
1120
- VxeButtonGroup: {
1121
- renderTableDefault (h, renderOpts, params) {
1122
- const { options } = renderOpts
1123
- return [
1124
- h(getDefaultComponent(renderOpts), {
1125
- props: {
1126
- options,
1127
- ...getCellEditProps(renderOpts, params, null)
1128
- },
1129
- on: getComponentOns(renderOpts, params)
1130
- })
1131
- ]
1132
- }
1133
- },
1134
- VxeSelect: {
1135
- tableAutoFocus: 'input',
1136
- renderTableEdit: defaultSelectEditRender,
1137
- renderTableDefault: defaultSelectEditRender,
1138
- renderTableCell (h, renderOpts, params) {
1139
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1140
- },
1141
- createTableFilterOptions: defaultFilterOptions,
1142
- renderTableFilter (h, renderOpts, params) {
1143
- const { column } = params
1144
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1145
- return column.filters.map((option, oIndex) => {
1146
- const optionValue = option.data
1147
- return h(getDefaultComponent(renderOpts), {
1148
- key: oIndex,
1149
- props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1150
- on: getFilterOns(renderOpts, params, option)
1151
- })
1152
- })
1153
- },
1154
- renderTableFloatingFilter (h, renderOpts, params) {
1155
- const { option } = params
1156
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1157
- const optionValue = option.data
1158
- return h(getDefaultComponent(renderOpts), {
1159
- props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1160
- on: getFloatingFilterOns(renderOpts, params, option)
1161
- })
1162
- },
1163
- tableCellFormatter: handleFormatSelect,
1164
- tableCellCopyMethod: handleFormatSelect,
1165
- tableCellPasteMethod: handleSetSelectValue,
1166
- tableFilterDefaultMethod: handleFilterMethod,
1167
- tableExportMethod: handleExportSelectMethod
1168
- },
1169
- VxeText: {
1170
- renderTableDefault (h, renderOpts, params) {
1171
- const { $table, row, column } = params
1172
- const { props } = renderOpts
1173
- const cellLabel = $table.getCellLabel(row, column)
1174
- return [
1175
- h(getDefaultComponent(renderOpts), {
1176
- props: {
1177
- ...(props || {}),
1178
- content: cellLabel
1179
- },
1180
- on: getComponentOns(renderOpts, params)
1181
- })
1182
- ]
1183
- }
1184
- },
1185
- VxeLink: {
1186
- renderTableDefault (h, renderOpts, params) {
1187
- const { $table, row, column } = params
1188
- const { props } = renderOpts
1189
- const { href } = props || {}
1190
- const cellLabel = $table.getCellLabel(row, column)
1191
- return [
1192
- h(getDefaultComponent(renderOpts), {
1193
- props: {
1194
- ...(props || {}),
1195
- content: cellLabel,
1196
- href: XEUtils.toFormatString(href, params)
1197
- },
1198
- on: getComponentOns(renderOpts, params)
1199
- })
1200
- ]
1201
- }
1202
- },
1203
- /**
1204
- * 已废弃,被 FormatSelect 替换
1205
- * @deprecated
1206
- */
1207
- formatOption: {
1208
- renderTableDefault (h, renderOpts, params) {
1209
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1210
- }
1211
- },
1212
- FormatSelect: {
1213
- renderTableDefault (h, renderOpts, params) {
1214
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1215
- },
1216
- tableCellFormatter: handleFormatSelect,
1217
- tableCellCopyMethod: handleFormatSelect,
1218
- tableCellPasteMethod: handleSetSelectValue,
1219
- tableFilterDefaultMethod: handleFilterMethod,
1220
- tableExportMethod: handleExportSelectMethod
1221
- },
1222
- VxeTreeSelect: {
1223
- tableAutoFocus: 'input',
1224
- renderTableEdit: defaultTableOrTreeSelectEditRender,
1225
- renderTableCell (h, renderOpts, params) {
1226
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1227
- },
1228
- tableCellFormatter: handleFormatTreeSelect,
1229
- tableCellCopyMethod: handleFormatTreeSelect,
1230
- tableCellPasteMethod: handleSetTreeSelectValue,
1231
- tableExportMethod: handleExportTreeSelectMethod
1232
- },
1233
- VxeTableSelect: {
1234
- tableAutoFocus: 'input',
1235
- renderTableEdit: defaultTableOrTreeSelectEditRender,
1236
- renderTableCell (h, renderOpts, params) {
1237
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1238
- },
1239
- tableCellFormatter: handleFormatTreeSelect,
1240
- tableCellCopyMethod: handleFormatTreeSelect,
1241
- tableCellPasteMethod: handleSetTreeSelectValue,
1242
- tableExportMethod: handleExportTreeSelectMethod
1243
- },
1244
- /**
1245
- * 已废弃,被 FormatTreeSelect 替换
1246
- * @deprecated
1247
- */
1248
- formatTree: {
1249
- renderTableDefault (h, renderOpts, params) {
1250
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1251
- }
1252
- },
1253
- FormatTreeSelect: {
1254
- renderTableDefault (h, renderOpts, params) {
1255
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1256
- },
1257
- tableCellFormatter: handleFormatTreeSelect,
1258
- tableCellCopyMethod: handleFormatTreeSelect,
1259
- tableCellPasteMethod: handleSetTreeSelectValue,
1260
- tableExportMethod: handleExportTreeSelectMethod
1261
- },
1262
- VxeColorPicker: {
1263
- tableAutoFocus: 'input',
1264
- renderTableEdit (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1265
- const { row, column } = params
1266
- const { options } = renderOpts
1267
- const cellValue = getCellValue(row, column)
1268
- return [
1269
- h(getDefaultComponent(renderOpts), {
1270
- props: getCellEditProps(renderOpts, params, cellValue, { colors: options }),
1271
- on: getEditOns(renderOpts, params)
1272
- })
1273
- ]
1274
- },
1275
- renderTableCell (h, renderOpts, params) {
1276
- const { row, column } = params
1277
- const cellValue = XEUtils.get(row, column.field)
1278
- return h('span', {
1279
- class: 'vxe-color-picker--readonly'
1280
- }, [
1281
- h('div', {
1282
- class: 'vxe-color-picker--readonly-color',
1283
- style: {
1284
- backgroundColor: cellValue
1285
- }
1286
- })
1287
- ])
1288
- }
1289
- },
1290
- VxeIconPicker: {
1291
- tableAutoFocus: 'input',
1292
- renderTableEdit (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1293
- const { row, column } = params
1294
- const { options } = renderOpts
1295
- const cellValue = getCellValue(row, column)
1296
- return [
1297
- h(getDefaultComponent(renderOpts), {
1298
- props: getCellEditProps(renderOpts, params, cellValue, { icons: options }),
1299
- on: getEditOns(renderOpts, params)
1300
- })
1301
- ]
1302
- },
1303
- renderTableCell (h, renderOpts, params) {
1304
- const { row, column } = params
1305
- const cellValue = XEUtils.get(row, column.field)
1306
- return h('i', {
1307
- class: cellValue
1308
- })
1309
- }
1310
- },
1311
- VxeRadioGroup: {
1312
- renderTableDefault: radioAndCheckboxGroupEditRender
1313
- },
1314
- VxeCheckbox: {
1315
- renderTableDefault: checkboxEditRender
1316
- },
1317
- VxeCheckboxGroup: {
1318
- renderTableDefault: radioAndCheckboxGroupEditRender
1319
- },
1320
- VxeSwitch: {
1321
- tableAutoFocus: 'button',
1322
- renderTableEdit: defaultEditRender,
1323
- renderTableDefault: defaultEditRender
1324
- },
1325
- VxeUpload: {
1326
- renderTableEdit: defaultEditRender,
1327
- renderTableCell: defaultEditRender,
1328
- renderTableDefault: defaultEditRender
1329
- },
1330
- VxeImage: {
1331
- renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1332
- const { row, column } = params
1333
- const { props } = renderOpts
1334
- const cellValue = getCellValue(row, column)
1335
- return [
1336
- h(getDefaultComponent(renderOpts), {
1337
- props: {
1338
- ...props,
1339
- src: cellValue
1340
- },
1341
- on: getEditOns(renderOpts, params)
1342
- })
1343
- ]
1344
- }
1345
- },
1346
- VxeImageGroup: {
1347
- renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1348
- const { row, column } = params
1349
- const { props } = renderOpts
1350
- const cellValue = getCellValue(row, column)
1351
- return [
1352
- h(getDefaultComponent(renderOpts), {
1353
- props: {
1354
- ...props,
1355
- urlList: cellValue
1356
- },
1357
- on: getEditOns(renderOpts, params)
1358
- })
1359
- ]
1360
- }
1361
- },
1362
- VxeTextEllipsis: {
1363
- renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1364
- const { row, column } = params
1365
- const { props } = renderOpts
1366
- const cellValue = getCellValue(row, column)
1367
- return [
1368
- h(getDefaultComponent(renderOpts), {
1369
- props: {
1370
- ...props,
1371
- content: cellValue
1372
- },
1373
- on: getEditOns(renderOpts, params)
1374
- })
1375
- ]
1376
- }
1377
- },
1378
- VxeRate: {
1379
- renderTableDefault: defaultEditRender
1380
- },
1381
- VxeSlider: {
1382
- renderTableDefault: defaultEditRender
1383
- },
1384
-
1385
- // 以下已废弃
1386
- $input: {
1387
- tableAutoFocus: '.vxe-input--inner',
1388
- renderTableEdit: oldEditRender,
1389
- renderTableCell (h, renderOpts, params) {
1390
- const { props = {} } = renderOpts
1391
- const { row, column } = params
1392
- const digits = props.digits || getConfig().input?.digits || 2
1393
- let cellValue = XEUtils.get(row, column.field)
1394
- if (cellValue) {
1395
- switch (props.type) {
1396
- case 'date':
1397
- case 'week':
1398
- case 'month':
1399
- case 'year':
1400
- cellValue = getLabelFormatDate(cellValue, props)
1401
- break
1402
- case 'float':
1403
- cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
1404
- break
1405
- }
1406
- }
1407
- return getCellLabelVNs(h, renderOpts, params, cellValue)
1408
- },
1409
- renderTableDefault: oldEditRender,
1410
- renderTableFilter: oldFilterRender,
1411
- tableFilterDefaultMethod: handleInputFilterMethod
1412
- },
1413
- $textarea: {
1414
- tableAutoFocus: '.vxe-textarea--inner'
1415
- },
1416
- $button: {
1417
- renderTableDefault: oldButtonEditRender
1418
- },
1419
- $buttons: {
1420
- renderTableDefault: oldButtonsEditRender
1421
- },
1422
- $select: {
1423
- tableAutoFocus: '.vxe-input--inner',
1424
- renderTableEdit: oldSelectEditRender,
1425
- renderTableDefault: oldSelectEditRender,
1426
- renderTableCell (h, renderOpts, params) {
1427
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1428
- },
1429
- renderTableFilter (h, renderOpts, params) {
1430
- const { column } = params
1431
- const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1432
- return column.filters.map((option, oIndex) => {
1433
- const optionValue = option.data
1434
- return h(getOldComponent(renderOpts), {
1435
- key: oIndex,
1436
- props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1437
- on: getFilterOns(renderOpts, params, option)
1438
- })
1439
- })
1440
- },
1441
- tableFilterDefaultMethod: handleFilterMethod,
1442
- tableExportMethod: handleExportSelectMethod
1443
- },
1444
- $radio: {
1445
- tableAutoFocus: '.vxe-radio--input'
1446
- },
1447
- $checkbox: {
1448
- tableAutoFocus: '.vxe-checkbox--input'
1449
- },
1450
- $switch: {
1451
- tableAutoFocus: '.vxe-switch--button',
1452
- renderTableEdit: oldEditRender,
1453
- renderTableDefault: oldEditRender
1454
- }
1455
- // 以上已废弃
1456
- })
1
+ import { CreateElement } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import { VxeUI } from '../../ui'
4
+ import { getCellValue, setCellValue } from '../src/util'
5
+ import { getFuncText, formatText, isEmptyValue } from '../../ui/src/utils'
6
+ import { getOnName, getModelEvent, getChangeEvent, hasInputType } from '../../ui/src/vn'
7
+ import { errLog } from '../../ui/src/log'
8
+
9
+ import type { VxeGlobalRendererHandles, VxeColumnPropTypes, VxeTableConstructor, VxeTablePrivateMethods, VxeTableDefines } from '../../../types'
10
+
11
+ const { getConfig, renderer, getI18n, getComponent } = VxeUI
12
+
13
+ const componentDefaultModelProp = 'value'
14
+
15
+ const defaultCompProps = {}
16
+
17
+ function handleDefaultValue (value: any, defaultVal: any, initVal: any) {
18
+ return XEUtils.eqNull(value) ? (XEUtils.eqNull(defaultVal) ? initVal : defaultVal) : value
19
+ }
20
+
21
+ function parseDate (value: any, props: any) {
22
+ return value && props.valueFormat ? XEUtils.toStringDate(value, props.valueFormat) : value
23
+ }
24
+
25
+ function getFormatDate (value: any, props: any, defaultFormat: string) {
26
+ const { dateConfig = {} } = props
27
+ return XEUtils.toDateString(parseDate(value, props), dateConfig.labelFormat || defaultFormat)
28
+ }
29
+
30
+ function getLabelFormatDate (value: any, props: any) {
31
+ return getFormatDate(value, props, getI18n(`vxe.input.date.labelFormat.${props.type || 'date'}`))
32
+ }
33
+
34
+ /**
35
+ * 已废弃
36
+ * @deprecated
37
+ */
38
+ function getOldComponentName (name: string) {
39
+ return `vxe-${name.replace('$', '')}`
40
+ }
41
+
42
+ /**
43
+ * 已废弃
44
+ * @deprecated
45
+ */
46
+ function getOldComponent ({ name }: any) {
47
+ return getOldComponentName(name)
48
+ }
49
+
50
+ function getDefaultComponent ({ name }: any) {
51
+ return getComponent(name) || name
52
+ }
53
+
54
+ function updateFilterChangeOption (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
55
+ const { $table } = params
56
+ $table.updateFilterOptionStatus(option, checked)
57
+ }
58
+
59
+ function saveFilterEvent (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
60
+ const { $table, column } = params
61
+ $table.saveFilterByEvent(new Event('change'), column)
62
+ }
63
+
64
+ function getNativeAttrs (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
65
+ let { name, attrs } = renderOpts
66
+ if (name === 'input') {
67
+ attrs = Object.assign({ type: 'text' }, attrs)
68
+ }
69
+ return attrs
70
+ }
71
+
72
+ function getInputImmediateModel (renderOpts: VxeColumnPropTypes.EditRender) {
73
+ const { name, immediate, props } = renderOpts
74
+ if (!immediate) {
75
+ if (name === 'VxeInput' || name === '$input') {
76
+ const { type } = props || {}
77
+ return !(!type || type === 'text' || type === 'number' || type === 'integer' || type === 'float')
78
+ }
79
+ if (name === 'input' || name === 'textarea' || name === '$textarea') {
80
+ return false
81
+ }
82
+ return true
83
+ }
84
+ return immediate
85
+ }
86
+
87
+ function getCellEditProps (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams, value: any, defaultProps?: any) {
88
+ return XEUtils.assign({ immediate: getInputImmediateModel(renderOpts) }, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
89
+ }
90
+
91
+ function getCellEditFilterProps (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, value: any, defaultProps?: any) {
92
+ return XEUtils.assign({}, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
93
+ }
94
+
95
+ function isImmediateCell (renderOpts: VxeColumnPropTypes.EditRender, params: any) {
96
+ return params.$type === 'cell' || getInputImmediateModel(renderOpts)
97
+ }
98
+
99
+ function getCellLabelVNs (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, cellLabel: any, opts?: {
100
+ class?: string
101
+ }) {
102
+ const { placeholder } = renderOpts
103
+ return [
104
+ h('span', {
105
+ class: ['vxe-cell--label', opts ? opts.class : '']
106
+ }, placeholder && isEmptyValue(cellLabel)
107
+ ? [
108
+ h('span', {
109
+ class: 'vxe-cell--placeholder'
110
+ }, formatText(getFuncText(placeholder), 1))
111
+ ]
112
+ : formatText(cellLabel, 1))
113
+ ]
114
+ }
115
+
116
+ /**
117
+ * 原生事件处理
118
+ * @param renderOpts
119
+ * @param params
120
+ * @param modelFunc
121
+ * @param changeFunc
122
+ */
123
+ function getNativeElementOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
124
+ model: (evnt: Event) => void
125
+ change?: (evnt: Event) => void
126
+ blur?: (evnt: Event) => void
127
+ }) {
128
+ const { events } = renderOpts
129
+ const modelEvent = getModelEvent(renderOpts)
130
+ const changeEvent = getChangeEvent(renderOpts)
131
+ const { model: modelFunc, change: changeFunc, blur: blurFunc } = eFns || {}
132
+ const isSameEvent = changeEvent === modelEvent
133
+ const ons: any = {}
134
+ if (events) {
135
+ XEUtils.objectEach(events, (func, key: any) => {
136
+ ons[getOnName(key)] = function (...args: any[]) {
137
+ func(params, ...args)
138
+ }
139
+ })
140
+ }
141
+ if (modelFunc) {
142
+ ons[getOnName(modelEvent)] = function (targetEvnt: any) {
143
+ modelFunc(targetEvnt)
144
+ if (isSameEvent && changeFunc) {
145
+ changeFunc(targetEvnt)
146
+ }
147
+ if (events && events[modelEvent]) {
148
+ events[modelEvent](params, targetEvnt)
149
+ }
150
+ }
151
+ }
152
+ if (!isSameEvent && changeFunc) {
153
+ ons[getOnName(changeEvent)] = function (evnt: Event) {
154
+ changeFunc(evnt)
155
+ if (events && events[changeEvent]) {
156
+ events[changeEvent](params, evnt)
157
+ }
158
+ }
159
+ }
160
+ if (blurFunc) {
161
+ ons[getOnName(blurEvent)] = function (evnt: Event) {
162
+ blurFunc(evnt)
163
+ if (events && events[blurEvent]) {
164
+ events[blurEvent](params, evnt)
165
+ }
166
+ }
167
+ }
168
+ return ons
169
+ }
170
+
171
+ const blurEvent = 'blur'
172
+ const clearEvent = 'clear'
173
+
174
+ /**
175
+ * 组件事件处理
176
+ * @param renderOpts
177
+ * @param params
178
+ * @param modelFunc
179
+ * @param changeFunc
180
+ */
181
+ function getComponentOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
182
+ model: (cellValue: any) => void
183
+ change?: (...args: any[]) => void
184
+ blur?: (...args: any[]) => void
185
+ clear?: (...args: any[]) => void
186
+ }, eventOns?: Record<string, any>) {
187
+ const { events } = renderOpts
188
+ const modelEvent = getModelEvent(renderOpts)
189
+ const changeEvent = getChangeEvent(renderOpts)
190
+ const { model: modelFunc, change: changeFunc, blur: blurFunc, clear: clearFunc } = eFns || {}
191
+ const ons: any = {}
192
+ XEUtils.objectEach(events, (func, key: any) => {
193
+ ons[getOnName(key)] = function (...args: any[]) {
194
+ if (!XEUtils.isFunction(func)) {
195
+ errLog('vxe.error.errFunc', [func])
196
+ }
197
+ func(params, ...args)
198
+ }
199
+ })
200
+ if (modelFunc) {
201
+ ons[getOnName(modelEvent)] = function (targetEvnt: any) {
202
+ modelFunc(targetEvnt)
203
+ if (events && events[modelEvent]) {
204
+ events[modelEvent](params, targetEvnt)
205
+ }
206
+ }
207
+ }
208
+ if (changeFunc) {
209
+ ons[getOnName(changeEvent)] = function (...args: any[]) {
210
+ changeFunc(...args)
211
+ if (events && events[changeEvent]) {
212
+ events[changeEvent](params, ...args)
213
+ }
214
+ }
215
+ }
216
+ if (blurFunc) {
217
+ ons[getOnName(blurEvent)] = function (...args: any[]) {
218
+ blurFunc(...args)
219
+ if (events && events[blurEvent]) {
220
+ events[blurEvent](params, ...args)
221
+ }
222
+ }
223
+ }
224
+ if (clearFunc) {
225
+ ons[getOnName(clearEvent)] = function (...args: any[]) {
226
+ clearFunc(...args)
227
+ if (events && events[clearEvent]) {
228
+ events[clearEvent](params, ...args)
229
+ }
230
+ }
231
+ }
232
+ return eventOns ? Object.assign(ons, eventOns) : ons
233
+ }
234
+
235
+ function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
236
+ const { $table, row, column } = params
237
+ const { name } = renderOpts
238
+ const { model } = column
239
+ const isImmediate = isImmediateCell(renderOpts, params)
240
+ return getComponentOns(renderOpts, params, {
241
+ model (cellValue) {
242
+ // 处理 model 值双向绑定
243
+ model.update = true
244
+ model.value = cellValue
245
+ if (isImmediate) {
246
+ setCellValue(row, column, cellValue)
247
+ }
248
+ },
249
+ change (eventParams) {
250
+ // 处理 change 事件相关逻辑
251
+ if (!isImmediate && name && (['VxeInput', 'VxeNumberInput', 'VxeTextarea', '$input', '$textarea'].includes(name))) {
252
+ const cellValue = eventParams.value
253
+ model.update = true
254
+ model.value = cellValue
255
+ $table.updateStatus(params, cellValue)
256
+ } else {
257
+ $table.updateStatus(params)
258
+ }
259
+ },
260
+ blur () {
261
+ if (isImmediate) {
262
+ $table.handleCellRuleUpdateStatus('blur', params)
263
+ } else {
264
+ $table.handleCellRuleUpdateStatus('blur', params, model.value)
265
+ }
266
+ }
267
+ })
268
+ }
269
+
270
+ function getFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams, option: VxeTableDefines.FilterOption) {
271
+ return getComponentOns(renderOpts, params, {
272
+ model (value) {
273
+ // 处理 model 值双向绑定
274
+ option.data = value
275
+ },
276
+ change () {
277
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
278
+ },
279
+ blur () {
280
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
281
+ }
282
+ })
283
+ }
284
+
285
+ function getFloatingFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams, option: VxeTableDefines.FilterOption) {
286
+ const { $table, column } = params
287
+ if (hasInputType(renderOpts)) {
288
+ return getComponentOns(renderOpts, params, {
289
+ model (value: any) {
290
+ // 处理 model 值双向绑定
291
+ option.data = value
292
+ },
293
+ change () {
294
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
295
+ },
296
+ clear () {
297
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
298
+ saveFilterEvent(params)
299
+ },
300
+ blur () {
301
+ $table.saveFilterByEvent(new Event('change'), column)
302
+ }
303
+ }, renderOpts.name === 'VxeNumberInput'
304
+ ? {
305
+ [getOnName('plus-number')] () {
306
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
307
+ saveFilterEvent(params)
308
+ },
309
+ [getOnName('minus-number')] () {
310
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
311
+ saveFilterEvent(params)
312
+ }
313
+ }
314
+ : {})
315
+ }
316
+ return getComponentOns(renderOpts, params, {
317
+ model (value: any) {
318
+ // 处理 model 值双向绑定
319
+ option.data = value
320
+ },
321
+ clear () {
322
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
323
+ $table.saveFilterByEvent(new Event('change'), column)
324
+ },
325
+ change () {
326
+ updateFilterChangeOption(params, !isEmptyValue(option.data), option)
327
+ $table.saveFilterByEvent(new Event('change'), column)
328
+ }
329
+ })
330
+ }
331
+
332
+ function getNativeEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
333
+ const { $table, row, column } = params
334
+ const { model } = column
335
+ return getNativeElementOns(renderOpts, params, {
336
+ model (evnt) {
337
+ // 处理 model 值双向绑定
338
+ const targetEl = evnt.target as HTMLInputElement
339
+ if (targetEl) {
340
+ const cellValue = targetEl.value
341
+ if (isImmediateCell(renderOpts, params)) {
342
+ setCellValue(row, column, cellValue)
343
+ } else {
344
+ model.update = true
345
+ model.value = cellValue
346
+ }
347
+ }
348
+ },
349
+ change (evnt) {
350
+ // 处理 change 事件相关逻辑
351
+ const targetEl = evnt.target as HTMLInputElement
352
+ if (targetEl) {
353
+ const cellValue = targetEl.value
354
+ $table.updateStatus(params, cellValue)
355
+ }
356
+ },
357
+ blur (evnt) {
358
+ const targetEl = evnt.target as HTMLInputElement
359
+ if (targetEl) {
360
+ const cellValue = targetEl.value
361
+ $table.updateStatus(params, cellValue)
362
+ }
363
+ }
364
+ })
365
+ }
366
+
367
+ function getNativeFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, option: any) {
368
+ return getNativeElementOns(renderOpts, params, {
369
+ model (evnt) {
370
+ // 处理 model 值双向绑定
371
+ const targetEl = evnt.target as HTMLInputElement
372
+ if (targetEl) {
373
+ option.data = targetEl.value
374
+ }
375
+ },
376
+ change () {
377
+ updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
378
+ },
379
+ blur () {
380
+ updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
381
+ }
382
+ })
383
+ }
384
+
385
+ /**
386
+ * 单元格可编辑渲染-原生的标签
387
+ * input、textarea、select
388
+ */
389
+ function nativeEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
390
+ const { row, column } = params
391
+ const { name } = renderOpts
392
+ const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
393
+ return [
394
+ h(`${name}`, {
395
+ class: `vxe-default-${name}`,
396
+ attrs: getNativeAttrs(renderOpts),
397
+ domProps: {
398
+ value: cellValue
399
+ },
400
+ on: getNativeEditOns(renderOpts, params)
401
+ })
402
+ ]
403
+ }
404
+
405
+ function buttonCellRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any) {
406
+ return [
407
+ h(getDefaultComponent(renderOpts), {
408
+ props: getCellEditProps(renderOpts, params, null),
409
+ on: getComponentOns(renderOpts, params)
410
+ })
411
+ ]
412
+ }
413
+
414
+ function defaultEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
415
+ const { row, column } = params
416
+ const cellValue = getCellValue(row, column)
417
+ return [
418
+ h(getDefaultComponent(renderOpts), {
419
+ props: getCellEditProps(renderOpts, params, cellValue),
420
+ on: getEditOns(renderOpts, params)
421
+ })
422
+ ]
423
+ }
424
+
425
+ function checkboxEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
426
+ const { row, column } = params
427
+ const cellValue = getCellValue(row, column)
428
+ return [
429
+ h(getDefaultComponent(renderOpts), {
430
+ props: getCellEditProps(renderOpts, params, cellValue),
431
+ on: getEditOns(renderOpts, params)
432
+ })
433
+ ]
434
+ }
435
+
436
+ function radioAndCheckboxGroupEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
437
+ const { options } = renderOpts
438
+ const { row, column } = params
439
+ const cellValue = getCellValue(row, column)
440
+ return [
441
+ h(getDefaultComponent(renderOpts), {
442
+ props: {
443
+ options,
444
+ ...getCellEditProps(renderOpts, params, cellValue)
445
+ },
446
+ on: getEditOns(renderOpts, params)
447
+ })
448
+ ]
449
+ }
450
+
451
+ /**
452
+ * 已废弃
453
+ * @deprecated
454
+ */
455
+ function oldEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
456
+ const { row, column } = params
457
+ const cellValue = getCellValue(row, column)
458
+ return [
459
+ h(getOldComponent(renderOpts), {
460
+ props: getCellEditProps(renderOpts, params, cellValue),
461
+ on: getEditOns(renderOpts, params)
462
+ })
463
+ ]
464
+ }
465
+
466
+ /**
467
+ * 已废弃
468
+ * @deprecated
469
+ */
470
+ function oldButtonEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
471
+ return [
472
+ h('vxe-button', {
473
+ props: getCellEditProps(renderOpts, params, null),
474
+ on: getComponentOns(renderOpts, params)
475
+ })
476
+ ]
477
+ }
478
+
479
+ /**
480
+ * 已废弃
481
+ * @deprecated
482
+ */
483
+ function oldButtonsEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: any) {
484
+ const { children } = renderOpts
485
+ return children ? children.map((childRenderOpts: any) => oldButtonEditRender(h, childRenderOpts, params)[0]) : []
486
+ }
487
+
488
+ function renderNativeOptgroups (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any, renderOptionsMethods: any) {
489
+ const { optionGroups, optionGroupProps = {} } = renderOpts
490
+ const groupOptions = optionGroupProps.options || 'options'
491
+ const groupLabel = optionGroupProps.label || 'label'
492
+ if (optionGroups) {
493
+ return optionGroups.map((group: any, gIndex: any) => {
494
+ return h('optgroup', {
495
+ key: gIndex,
496
+ attrs: {
497
+ label: group[groupLabel]
498
+ }
499
+ }, renderOptionsMethods(h, group[groupOptions], renderOpts, params))
500
+ })
501
+ }
502
+ return []
503
+ }
504
+
505
+ /**
506
+ * 渲染原生的 option 标签
507
+ */
508
+ function renderNativeOptions (h: CreateElement, options: any, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: any) {
509
+ const { optionProps = {} } = renderOpts
510
+ const { row, column } = params
511
+ const labelProp = optionProps.label || 'label'
512
+ const valueProp = optionProps.value || 'value'
513
+ const disabledProp = optionProps.disabled || 'disabled'
514
+ const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
515
+ if (options) {
516
+ return options.map((option: any, oIndex: any) => {
517
+ return h('option', {
518
+ key: oIndex,
519
+ attrs: {
520
+ value: option[valueProp],
521
+ disabled: option[disabledProp]
522
+ },
523
+ domProps: {
524
+ /* eslint-disable eqeqeq */
525
+ selected: option[valueProp] == cellValue
526
+ }
527
+ }, option[labelProp])
528
+ })
529
+ }
530
+ return []
531
+ }
532
+
533
+ function nativeFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
534
+ const { column } = params
535
+ const { name } = renderOpts
536
+ const attrs = getNativeAttrs(renderOpts)
537
+ return column.filters.map((option, oIndex) => {
538
+ return h(`${name}`, {
539
+ key: oIndex,
540
+ class: `vxe-default-${name}`,
541
+ attrs,
542
+ domProps: {
543
+ value: option.data
544
+ },
545
+ on: getNativeFilterOns(renderOpts, params, option)
546
+ })
547
+ })
548
+ }
549
+
550
+ function defaultFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
551
+ const { column } = params
552
+ return column.filters.map((option, oIndex) => {
553
+ const optionValue = option.data
554
+ return h(getDefaultComponent(renderOpts), {
555
+ key: oIndex,
556
+ props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
557
+ on: getFilterOns(renderOpts, params, option)
558
+ })
559
+ })
560
+ }
561
+
562
+ function defaultFloatingFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFloatingFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
563
+ const { option } = params
564
+ const optionValue = option.data
565
+ return [
566
+ h(getDefaultComponent(renderOpts), {
567
+ props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
568
+ on: getFloatingFilterOns(renderOpts, params, option)
569
+ })
570
+ ]
571
+ }
572
+
573
+ function defaultFilterOptions () {
574
+ return [
575
+ { data: null }
576
+ ]
577
+ }
578
+
579
+ /**
580
+ * 已废弃
581
+ * @deprecated
582
+ */
583
+ function oldFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any) {
584
+ const { column } = params
585
+ return column.filters.map((option: any, oIndex: any) => {
586
+ const optionValue = option.data
587
+ return h(getOldComponent(renderOpts), {
588
+ key: oIndex,
589
+ props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
590
+ on: getFilterOns(renderOpts, params, option)
591
+ })
592
+ })
593
+ }
594
+
595
+ function handleFilterMethod ({ option, row, column }: any) {
596
+ const { data } = option
597
+ const cellValue = XEUtils.get(row, column.field)
598
+ /* eslint-disable eqeqeq */
599
+ return cellValue == data
600
+ }
601
+
602
+ function handleInputFilterMethod ({ option, row, column }: any) {
603
+ const { data } = option
604
+ const cellValue = XEUtils.get(row, column.field)
605
+ /* eslint-disable eqeqeq */
606
+ return XEUtils.toValueString(cellValue).indexOf(data) > -1
607
+ }
608
+
609
+ function nativeSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
610
+ return [
611
+ h('select', {
612
+ class: 'vxe-default-select',
613
+ attrs: getNativeAttrs(renderOpts),
614
+ on: getNativeEditOns(renderOpts, params)
615
+ },
616
+ renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params))
617
+ ]
618
+ }
619
+
620
+ function defaultSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
621
+ const { row, column } = params
622
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
623
+ const cellValue = getCellValue(row, column)
624
+ return [
625
+ h(getDefaultComponent(renderOpts), {
626
+ props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
627
+ on: getEditOns(renderOpts, params)
628
+ })
629
+ ]
630
+ }
631
+
632
+ function defaultTableOrTreeSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
633
+ const { row, column } = params
634
+ const { options, optionProps } = renderOpts
635
+ const cellValue = getCellValue(row, column)
636
+ return [
637
+ h(getDefaultComponent(renderOpts), {
638
+ props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps }),
639
+ on: getEditOns(renderOpts, params)
640
+ })
641
+ ]
642
+ }
643
+
644
+ /**
645
+ * 已废弃
646
+ * @deprecated
647
+ */
648
+ function oldSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
649
+ const { row, column } = params
650
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
651
+ const cellValue = getCellValue(row, column)
652
+ return [
653
+ h(getOldComponent(renderOpts), {
654
+ props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
655
+ on: getEditOns(renderOpts, params)
656
+ })
657
+ ]
658
+ }
659
+
660
+ function handleSelectCellValue (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
661
+ const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props = {} } = renderOpts
662
+ let selectItem: any
663
+ const labelProp = optionProps.label || 'label'
664
+ const valueProp = optionProps.value || 'value'
665
+ if (!(cellValue === null || cellValue === undefined)) {
666
+ let vals = []
667
+ if (XEUtils.isArray(cellValue)) {
668
+ vals = cellValue
669
+ } else {
670
+ if (props.multiple && `${cellValue}`.indexOf(',') > -1) {
671
+ vals = `${cellValue}`.split(',')
672
+ } else {
673
+ vals = [cellValue]
674
+ }
675
+ }
676
+ return XEUtils.map(vals, optionGroups
677
+ ? (value) => {
678
+ const groupOptions = optionGroupProps.options || 'options'
679
+ for (let index = 0; index < optionGroups.length; index++) {
680
+ /* eslint-disable eqeqeq */
681
+ selectItem = XEUtils.find(optionGroups[index][groupOptions], item => item[valueProp] == value)
682
+ if (selectItem) {
683
+ break
684
+ }
685
+ }
686
+ return selectItem ? selectItem[labelProp] : value
687
+ }
688
+ : (value) => {
689
+ /* eslint-disable eqeqeq */
690
+ selectItem = XEUtils.find(options, item => item[valueProp] == value)
691
+ return selectItem ? selectItem[labelProp] : value
692
+ }
693
+ ).join(', ')
694
+ }
695
+ return ''
696
+ }
697
+
698
+ function getSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, { row, column }: any) {
699
+ const cellValue = XEUtils.get(row, column.field)
700
+ return handleSelectCellValue(cellValue, renderOpts)
701
+ }
702
+
703
+ function handleExportSelectMethod (params: any) {
704
+ const { row, column, options } = params
705
+ return options.original ? getCellValue(row, column) : getSelectCellValue(column.editRender || column.cellRender, params)
706
+ }
707
+
708
+ function handleTreeSelectCellValue (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions) {
709
+ const { options, optionProps = {} } = renderOpts
710
+ const labelProp = optionProps.label || 'label'
711
+ const valueProp = optionProps.value || 'value'
712
+ const childrenProp = optionProps.children || 'children'
713
+ if (!(cellValue === null || cellValue === undefined)) {
714
+ const keyMaps: Record<string, any> = {}
715
+ XEUtils.eachTree(options, item => {
716
+ keyMaps[XEUtils.get(item, valueProp)] = item
717
+ }, { children: childrenProp })
718
+ return XEUtils.map(XEUtils.isArray(cellValue) ? cellValue : [cellValue], (value) => {
719
+ const item = keyMaps[value]
720
+ return item ? XEUtils.get(item, labelProp) : item
721
+ }
722
+ ).join(', ')
723
+ }
724
+ return ''
725
+ }
726
+
727
+ function getTreeSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, { row, column }: any) {
728
+ const cellValue = XEUtils.get(row, column.field)
729
+ return handleTreeSelectCellValue(cellValue, renderOpts)
730
+ }
731
+
732
+ function handleExportTreeSelectMethod (params: any) {
733
+ const { row, column, options } = params
734
+ return options.original ? getCellValue(row, column) : getTreeSelectCellValue(column.editRender || column.cellRender, params)
735
+ }
736
+
737
+ function handleNumberCell (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.RenderTableDefaultParams) {
738
+ const { props = {}, showNegativeStatus } = renderOpts
739
+ const { row, column } = params
740
+ const { type } = props
741
+ let cellValue = XEUtils.get(row, column.field)
742
+ let isNegative = false
743
+ if (!isEmptyValue(cellValue)) {
744
+ const numberInputConfig = getConfig().numberInput || {}
745
+ if (type === 'float') {
746
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
747
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
748
+ cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
749
+ if (!autoFill) {
750
+ cellValue = XEUtils.toNumber(cellValue)
751
+ }
752
+ if (showNegativeStatus) {
753
+ if (cellValue < 0) {
754
+ isNegative = true
755
+ }
756
+ }
757
+ } else if (type === 'amount') {
758
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
759
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
760
+ const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
761
+ cellValue = XEUtils.toNumber(cellValue)
762
+ if (showNegativeStatus) {
763
+ if (cellValue < 0) {
764
+ isNegative = true
765
+ }
766
+ }
767
+ cellValue = XEUtils.commafy(cellValue, { digits })
768
+ if (!autoFill) {
769
+ const [iStr, dStr] = cellValue.split('.')
770
+ if (dStr) {
771
+ const dRest = dStr.replace(/0+$/, '')
772
+ cellValue = dRest ? [iStr, '.', dRest].join('') : iStr
773
+ }
774
+ }
775
+ if (showCurrency) {
776
+ cellValue = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${cellValue}`
777
+ }
778
+ } else {
779
+ if (type === 'integer') {
780
+ cellValue = XEUtils.toInteger(cellValue)
781
+ }
782
+ if (showNegativeStatus) {
783
+ if (XEUtils.toNumber(cellValue) < 0) {
784
+ isNegative = true
785
+ }
786
+ }
787
+ }
788
+ }
789
+ return getCellLabelVNs(h, renderOpts, params, cellValue, isNegative
790
+ ? {
791
+ class: 'is--negative'
792
+ }
793
+ : {})
794
+ }
795
+
796
+ function handleFormatDatePicker (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams) {
797
+ const { props = {} } = renderOpts
798
+ const { cellValue } = params
799
+ if (cellValue) {
800
+ if (props.type !== 'time') {
801
+ return getLabelFormatDate(cellValue, props)
802
+ }
803
+ }
804
+ return cellValue
805
+ }
806
+
807
+ function handleFormatSelect (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
808
+ const { cellValue } = params
809
+ return handleSelectCellValue(cellValue, renderOpts)
810
+ }
811
+
812
+ function handleSetSelectValue (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
813
+ const { row, column, cellValue } = params
814
+ const { field } = column
815
+ if (field) {
816
+ const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props } = renderOpts
817
+ if (isEmptyValue(cellValue)) {
818
+ XEUtils.set(row, field, props && props.multiple ? [] : null)
819
+ return
820
+ }
821
+ const isMultiVal = XEUtils.indexOf(`${cellValue}`, ',') > -1
822
+ const labelProp = optionProps.label || 'label'
823
+ const valueProp = optionProps.value || 'value'
824
+ const labelMpas: Record<string, any> = {}
825
+ if (optionGroups && optionGroups.length) {
826
+ const groupOptions = optionGroupProps.options || 'options'
827
+ for (let i = 0; i < optionGroups.length; i++) {
828
+ const opts = optionGroups[i][groupOptions] || {}
829
+ for (let j = 0; j < opts.length; j++) {
830
+ const item = opts[j]
831
+ if (isMultiVal) {
832
+ labelMpas[item[labelProp]] = item
833
+ /* eslint-disable eqeqeq */
834
+ } else if (item[labelProp] == cellValue) {
835
+ XEUtils.set(row, field, item[valueProp])
836
+ return
837
+ }
838
+ }
839
+ }
840
+ } else {
841
+ if (options) {
842
+ for (let i = 0; i < options.length; i++) {
843
+ const item = options[i]
844
+ if (isMultiVal) {
845
+ labelMpas[item[labelProp]] = item
846
+ /* eslint-disable eqeqeq */
847
+ } else if (item[labelProp] == cellValue) {
848
+ XEUtils.set(row, field, item[valueProp])
849
+ return
850
+ }
851
+ }
852
+ }
853
+ }
854
+ if (isMultiVal) {
855
+ XEUtils.set(row, field, (isMultiVal
856
+ ? cellValue.split(',')
857
+ : [cellValue]).map((label: any) => {
858
+ const item = labelMpas[label]
859
+ return item ? item[valueProp] : label
860
+ }))
861
+ } else {
862
+ XEUtils.set(row, field, cellValue)
863
+ }
864
+ }
865
+ }
866
+
867
+ function handleFormatTreeSelect (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
868
+ const { cellValue } = params
869
+ return handleTreeSelectCellValue(cellValue, renderOpts)
870
+ }
871
+
872
+ function handleSetTreeSelectValue (renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.TableCellFormatterParams | VxeGlobalRendererHandles.TableCellCopyMethodParams) {
873
+ const { row, column, cellValue } = params
874
+ const { field } = column
875
+ if (field) {
876
+ const { options, optionProps = {} } = renderOpts
877
+ const labelProp = optionProps.label || 'label'
878
+ const valueProp = optionProps.value || 'value'
879
+ const childrenProp = optionProps.children || 'children'
880
+ const matchRest = XEUtils.findTree(options || [], item => XEUtils.get(item, labelProp) === cellValue, { children: childrenProp })
881
+ if (matchRest) {
882
+ const selectItem = matchRest.item
883
+ if (selectItem) {
884
+ XEUtils.set(row, field, selectItem[valueProp])
885
+ return
886
+ }
887
+ }
888
+ XEUtils.set(row, field, cellValue)
889
+ }
890
+ }
891
+
892
+ /**
893
+ * 表格 - 渲染器
894
+ */
895
+ renderer.mixin({
896
+ input: {
897
+ tableAutoFocus: 'input',
898
+ renderTableEdit: nativeEditRender,
899
+ renderTableDefault: nativeEditRender,
900
+ renderTableFilter: nativeFilterRender,
901
+ tableFilterDefaultMethod: handleInputFilterMethod
902
+ },
903
+ textarea: {
904
+ tableAutoFocus: 'textarea',
905
+ renderTableEdit: nativeEditRender
906
+ },
907
+ select: {
908
+ renderTableEdit: nativeSelectEditRender,
909
+ renderTableDefault: nativeSelectEditRender,
910
+ renderTableCell (h, renderOpts, params) {
911
+ return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
912
+ },
913
+ renderTableFilter (h, renderOpts, params) {
914
+ const { column } = params
915
+ return column.filters.map((option, oIndex) => {
916
+ return h('select', {
917
+ key: oIndex,
918
+ class: 'vxe-default-select',
919
+ attrs: getNativeAttrs(renderOpts),
920
+ on: getNativeFilterOns(renderOpts, params, option)
921
+ },
922
+ renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params))
923
+ })
924
+ },
925
+ tableCellFormatter: handleFormatSelect,
926
+ tableCellCopyMethod: handleFormatSelect,
927
+ tableCellPasteMethod: handleSetSelectValue,
928
+ tableFilterDefaultMethod: handleFilterMethod,
929
+ tableExportMethod: handleExportSelectMethod
930
+ },
931
+ VxeInput: {
932
+ tableAutoFocus: 'input',
933
+ renderTableEdit: defaultEditRender,
934
+ renderTableCell (h, renderOpts, params) {
935
+ const { props = {} } = renderOpts
936
+ const { row, column } = params
937
+ const inputConfig = getConfig().input || {}
938
+ const digits = props.digits || inputConfig.digits || 2
939
+ let cellValue = XEUtils.get(row, column.field)
940
+ if (cellValue) {
941
+ switch (props.type) {
942
+ case 'date':
943
+ case 'week':
944
+ case 'month':
945
+ case 'quarter':
946
+ case 'year':
947
+ cellValue = getLabelFormatDate(cellValue, props)
948
+ break
949
+ case 'float':
950
+ cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
951
+ break
952
+ }
953
+ }
954
+ return getCellLabelVNs(h, renderOpts, params, cellValue)
955
+ },
956
+ renderTableDefault: defaultEditRender,
957
+ createTableFilterOptions: defaultFilterOptions,
958
+ renderTableFilter: defaultFilterRender,
959
+ renderTableFloatingFilter: defaultFloatingFilterRender,
960
+ tableFilterDefaultMethod: handleInputFilterMethod
961
+ },
962
+ FormatNumberInput: {
963
+ renderTableDefault: handleNumberCell,
964
+ tableFilterDefaultMethod: handleInputFilterMethod,
965
+ tableExportMethod (params) {
966
+ const { row, column } = params
967
+ const cellValue = XEUtils.get(row, column.field)
968
+ return cellValue
969
+ }
970
+ },
971
+ VxeNumberInput: {
972
+ tableAutoFocus: 'input',
973
+ renderTableEdit: defaultEditRender,
974
+ renderTableCell: handleNumberCell,
975
+ renderTableFooter (h, renderOpts, params) {
976
+ const { props = {} } = renderOpts
977
+ const { row, column, _columnIndex } = params
978
+ const { type } = props
979
+ // 兼容老模式
980
+ const itemValue = XEUtils.isArray(row) ? row[_columnIndex] : XEUtils.get(row, column.field)
981
+ if (XEUtils.isNumber(itemValue)) {
982
+ const numberInputConfig = getConfig().numberInput || {}
983
+ if (type === 'float') {
984
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
985
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
986
+ let amountLabel = XEUtils.toFixed(XEUtils.floor(itemValue, digits), digits)
987
+ if (!autoFill) {
988
+ amountLabel = XEUtils.toNumber(amountLabel)
989
+ }
990
+ return amountLabel
991
+ } else if (type === 'amount') {
992
+ const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
993
+ const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
994
+ const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
995
+ let amountLabel = XEUtils.commafy(XEUtils.toNumber(itemValue), { digits })
996
+ if (!autoFill) {
997
+ const [iStr, dStr] = amountLabel.split('.')
998
+ if (dStr) {
999
+ const dRest = dStr.replace(/0+$/, '')
1000
+ amountLabel = dRest ? [iStr, '.', dRest].join('') : iStr
1001
+ }
1002
+ }
1003
+ if (showCurrency) {
1004
+ amountLabel = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${amountLabel}`
1005
+ }
1006
+ return amountLabel
1007
+ }
1008
+ }
1009
+ return getFuncText(itemValue, 1)
1010
+ },
1011
+ renderTableDefault: defaultEditRender,
1012
+ createTableFilterOptions: defaultFilterOptions,
1013
+ renderTableFilter: defaultFilterRender,
1014
+ renderTableFloatingFilter: defaultFloatingFilterRender,
1015
+ tableFilterDefaultMethod: handleInputFilterMethod,
1016
+ tableExportMethod (params) {
1017
+ const { row, column } = params
1018
+ const cellValue = XEUtils.get(row, column.field)
1019
+ return cellValue
1020
+ }
1021
+ },
1022
+ VxeDatePicker: {
1023
+ tableAutoFocus: 'input',
1024
+ renderTableEdit: defaultEditRender,
1025
+ renderTableCell (h, renderOpts, params) {
1026
+ const { props = {} } = renderOpts
1027
+ const { row, column } = params
1028
+ let cellValue = XEUtils.get(row, column.field)
1029
+ if (cellValue) {
1030
+ if (props.type !== 'time') {
1031
+ cellValue = getLabelFormatDate(cellValue, props)
1032
+ }
1033
+ }
1034
+ return getCellLabelVNs(h, renderOpts, params, cellValue)
1035
+ },
1036
+ tableCellFormatter: handleFormatDatePicker,
1037
+ renderTableDefault: defaultEditRender,
1038
+ createTableFilterOptions: defaultFilterOptions,
1039
+ renderTableFilter: defaultFilterRender,
1040
+ renderTableFloatingFilter: defaultFloatingFilterRender,
1041
+ tableFilterDefaultMethod: handleFilterMethod
1042
+ },
1043
+ VxeDateRangePicker: {
1044
+ tableAutoFocus: 'input',
1045
+ renderTableEdit (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1046
+ const { startField, endField } = renderOpts
1047
+ const { $table, row, column } = params
1048
+ const { model } = column
1049
+ const cellValue = getCellValue(row, column)
1050
+ const seProps: Record<string, any> = {}
1051
+ const seOs: Record<string, any> = {}
1052
+ if (startField && endField) {
1053
+ seProps.startValue = XEUtils.get(row, startField)
1054
+ seProps.endValue = XEUtils.get(row, endField)
1055
+ seOs['update:startValue'] = (value: any) => {
1056
+ if (startField) {
1057
+ XEUtils.set(row, startField, value)
1058
+ }
1059
+ }
1060
+ seOs['update:endValue'] = (value: any) => {
1061
+ if (endField) {
1062
+ XEUtils.set(row, endField, value)
1063
+ }
1064
+ }
1065
+ }
1066
+ return [
1067
+ h(getDefaultComponent(renderOpts), {
1068
+ props: getCellEditProps(renderOpts, params, cellValue, seProps),
1069
+ on: getComponentOns(renderOpts, params, {
1070
+ model (cellValue) {
1071
+ model.update = true
1072
+ model.value = cellValue
1073
+ setCellValue(row, column, cellValue)
1074
+ },
1075
+ change () {
1076
+ $table.updateStatus(params)
1077
+ },
1078
+ blur () {
1079
+ $table.handleCellRuleUpdateStatus('blur', params)
1080
+ }
1081
+ }, seOs)
1082
+ })
1083
+ ]
1084
+ },
1085
+ renderTableCell (h, renderOpts, params) {
1086
+ const { startField, endField } = renderOpts
1087
+ const { row, column } = params
1088
+ let startValue = ''
1089
+ let endValue = ''
1090
+ if (startField && endField) {
1091
+ startValue = XEUtils.get(row, startField)
1092
+ endValue = XEUtils.get(row, endField)
1093
+ } else {
1094
+ const cellValue = XEUtils.get(row, column.field)
1095
+ if (cellValue) {
1096
+ if (XEUtils.isArray(cellValue)) {
1097
+ startValue = cellValue[0]
1098
+ endValue = cellValue[1]
1099
+ } else {
1100
+ const strs = `${cellValue}`.split(',')
1101
+ startValue = strs[0]
1102
+ endValue = strs[1]
1103
+ }
1104
+ }
1105
+ }
1106
+ let cellLabel = ''
1107
+ if (startValue && endValue) {
1108
+ cellLabel = `${startValue} ~ ${endValue}`
1109
+ }
1110
+ return getCellLabelVNs(h, renderOpts, params, cellLabel)
1111
+ }
1112
+ },
1113
+ VxeTextarea: {
1114
+ tableAutoFocus: 'textarea',
1115
+ renderTableEdit: defaultEditRender
1116
+ },
1117
+ VxeButton: {
1118
+ renderTableDefault: buttonCellRender
1119
+ },
1120
+ VxeButtonGroup: {
1121
+ renderTableDefault (h, renderOpts, params) {
1122
+ const { options } = renderOpts
1123
+ return [
1124
+ h(getDefaultComponent(renderOpts), {
1125
+ props: {
1126
+ options,
1127
+ ...getCellEditProps(renderOpts, params, null)
1128
+ },
1129
+ on: getComponentOns(renderOpts, params)
1130
+ })
1131
+ ]
1132
+ }
1133
+ },
1134
+ VxeSelect: {
1135
+ tableAutoFocus: 'input',
1136
+ renderTableEdit: defaultSelectEditRender,
1137
+ renderTableDefault: defaultSelectEditRender,
1138
+ renderTableCell (h, renderOpts, params) {
1139
+ return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1140
+ },
1141
+ createTableFilterOptions: defaultFilterOptions,
1142
+ renderTableFilter (h, renderOpts, params) {
1143
+ const { column } = params
1144
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1145
+ return column.filters.map((option, oIndex) => {
1146
+ const optionValue = option.data
1147
+ return h(getDefaultComponent(renderOpts), {
1148
+ key: oIndex,
1149
+ props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1150
+ on: getFilterOns(renderOpts, params, option)
1151
+ })
1152
+ })
1153
+ },
1154
+ renderTableFloatingFilter (h, renderOpts, params) {
1155
+ const { option } = params
1156
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1157
+ const optionValue = option.data
1158
+ return h(getDefaultComponent(renderOpts), {
1159
+ props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1160
+ on: getFloatingFilterOns(renderOpts, params, option)
1161
+ })
1162
+ },
1163
+ tableCellFormatter: handleFormatSelect,
1164
+ tableCellCopyMethod: handleFormatSelect,
1165
+ tableCellPasteMethod: handleSetSelectValue,
1166
+ tableFilterDefaultMethod: handleFilterMethod,
1167
+ tableExportMethod: handleExportSelectMethod
1168
+ },
1169
+ VxeText: {
1170
+ renderTableDefault (h, renderOpts, params) {
1171
+ const { $table, row, column } = params
1172
+ const { props } = renderOpts
1173
+ const cellLabel = $table.getCellLabel(row, column)
1174
+ return [
1175
+ h(getDefaultComponent(renderOpts), {
1176
+ props: {
1177
+ ...(props || {}),
1178
+ content: cellLabel
1179
+ },
1180
+ on: getComponentOns(renderOpts, params)
1181
+ })
1182
+ ]
1183
+ }
1184
+ },
1185
+ VxeLink: {
1186
+ renderTableDefault (h, renderOpts, params) {
1187
+ const { $table, row, column } = params
1188
+ const { props } = renderOpts
1189
+ const { href } = props || {}
1190
+ const cellLabel = $table.getCellLabel(row, column)
1191
+ return [
1192
+ h(getDefaultComponent(renderOpts), {
1193
+ props: {
1194
+ ...(props || {}),
1195
+ content: cellLabel,
1196
+ href: XEUtils.toFormatString(href, params)
1197
+ },
1198
+ on: getComponentOns(renderOpts, params)
1199
+ })
1200
+ ]
1201
+ }
1202
+ },
1203
+ /**
1204
+ * 已废弃,被 FormatSelect 替换
1205
+ * @deprecated
1206
+ */
1207
+ formatOption: {
1208
+ renderTableDefault (h, renderOpts, params) {
1209
+ return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1210
+ }
1211
+ },
1212
+ FormatSelect: {
1213
+ renderTableDefault (h, renderOpts, params) {
1214
+ return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1215
+ },
1216
+ tableCellFormatter: handleFormatSelect,
1217
+ tableCellCopyMethod: handleFormatSelect,
1218
+ tableCellPasteMethod: handleSetSelectValue,
1219
+ tableFilterDefaultMethod: handleFilterMethod,
1220
+ tableExportMethod: handleExportSelectMethod
1221
+ },
1222
+ VxeTreeSelect: {
1223
+ tableAutoFocus: 'input',
1224
+ renderTableEdit: defaultTableOrTreeSelectEditRender,
1225
+ renderTableCell (h, renderOpts, params) {
1226
+ return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1227
+ },
1228
+ tableCellFormatter: handleFormatTreeSelect,
1229
+ tableCellCopyMethod: handleFormatTreeSelect,
1230
+ tableCellPasteMethod: handleSetTreeSelectValue,
1231
+ tableExportMethod: handleExportTreeSelectMethod
1232
+ },
1233
+ VxeTableSelect: {
1234
+ tableAutoFocus: 'input',
1235
+ renderTableEdit: defaultTableOrTreeSelectEditRender,
1236
+ renderTableCell (h, renderOpts, params) {
1237
+ return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1238
+ },
1239
+ tableCellFormatter: handleFormatTreeSelect,
1240
+ tableCellCopyMethod: handleFormatTreeSelect,
1241
+ tableCellPasteMethod: handleSetTreeSelectValue,
1242
+ tableExportMethod: handleExportTreeSelectMethod
1243
+ },
1244
+ /**
1245
+ * 已废弃,被 FormatTreeSelect 替换
1246
+ * @deprecated
1247
+ */
1248
+ formatTree: {
1249
+ renderTableDefault (h, renderOpts, params) {
1250
+ return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1251
+ }
1252
+ },
1253
+ FormatTreeSelect: {
1254
+ renderTableDefault (h, renderOpts, params) {
1255
+ return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
1256
+ },
1257
+ tableCellFormatter: handleFormatTreeSelect,
1258
+ tableCellCopyMethod: handleFormatTreeSelect,
1259
+ tableCellPasteMethod: handleSetTreeSelectValue,
1260
+ tableExportMethod: handleExportTreeSelectMethod
1261
+ },
1262
+ VxeColorPicker: {
1263
+ tableAutoFocus: 'input',
1264
+ renderTableEdit (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1265
+ const { row, column } = params
1266
+ const { options } = renderOpts
1267
+ const cellValue = getCellValue(row, column)
1268
+ return [
1269
+ h(getDefaultComponent(renderOpts), {
1270
+ props: getCellEditProps(renderOpts, params, cellValue, { colors: options }),
1271
+ on: getEditOns(renderOpts, params)
1272
+ })
1273
+ ]
1274
+ },
1275
+ renderTableCell (h, renderOpts, params) {
1276
+ const { row, column } = params
1277
+ const cellValue = XEUtils.get(row, column.field)
1278
+ return h('span', {
1279
+ class: 'vxe-color-picker--readonly'
1280
+ }, [
1281
+ h('div', {
1282
+ class: 'vxe-color-picker--readonly-color',
1283
+ style: {
1284
+ backgroundColor: cellValue
1285
+ }
1286
+ })
1287
+ ])
1288
+ }
1289
+ },
1290
+ VxeIconPicker: {
1291
+ tableAutoFocus: 'input',
1292
+ renderTableEdit (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1293
+ const { row, column } = params
1294
+ const { options } = renderOpts
1295
+ const cellValue = getCellValue(row, column)
1296
+ return [
1297
+ h(getDefaultComponent(renderOpts), {
1298
+ props: getCellEditProps(renderOpts, params, cellValue, { icons: options }),
1299
+ on: getEditOns(renderOpts, params)
1300
+ })
1301
+ ]
1302
+ },
1303
+ renderTableCell (h, renderOpts, params) {
1304
+ const { row, column } = params
1305
+ const cellValue = XEUtils.get(row, column.field)
1306
+ return h('i', {
1307
+ class: cellValue
1308
+ })
1309
+ }
1310
+ },
1311
+ VxeRadioGroup: {
1312
+ renderTableDefault: radioAndCheckboxGroupEditRender
1313
+ },
1314
+ VxeCheckbox: {
1315
+ renderTableDefault: checkboxEditRender
1316
+ },
1317
+ VxeCheckboxGroup: {
1318
+ renderTableDefault: radioAndCheckboxGroupEditRender
1319
+ },
1320
+ VxeSwitch: {
1321
+ tableAutoFocus: 'button',
1322
+ renderTableEdit: defaultEditRender,
1323
+ renderTableDefault: defaultEditRender
1324
+ },
1325
+ VxeUpload: {
1326
+ renderTableEdit: defaultEditRender,
1327
+ renderTableCell: defaultEditRender,
1328
+ renderTableDefault: defaultEditRender
1329
+ },
1330
+ VxeImage: {
1331
+ renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1332
+ const { row, column } = params
1333
+ const { props } = renderOpts
1334
+ const cellValue = getCellValue(row, column)
1335
+ return [
1336
+ h(getDefaultComponent(renderOpts), {
1337
+ props: {
1338
+ ...props,
1339
+ src: cellValue
1340
+ },
1341
+ on: getEditOns(renderOpts, params)
1342
+ })
1343
+ ]
1344
+ }
1345
+ },
1346
+ VxeImageGroup: {
1347
+ renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1348
+ const { row, column } = params
1349
+ const { props } = renderOpts
1350
+ const cellValue = getCellValue(row, column)
1351
+ return [
1352
+ h(getDefaultComponent(renderOpts), {
1353
+ props: {
1354
+ ...props,
1355
+ urlList: cellValue
1356
+ },
1357
+ on: getEditOns(renderOpts, params)
1358
+ })
1359
+ ]
1360
+ }
1361
+ },
1362
+ VxeTextEllipsis: {
1363
+ renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
1364
+ const { row, column } = params
1365
+ const { props } = renderOpts
1366
+ const cellValue = getCellValue(row, column)
1367
+ return [
1368
+ h(getDefaultComponent(renderOpts), {
1369
+ props: {
1370
+ ...props,
1371
+ content: cellValue
1372
+ },
1373
+ on: getEditOns(renderOpts, params)
1374
+ })
1375
+ ]
1376
+ }
1377
+ },
1378
+ VxeRate: {
1379
+ renderTableDefault: defaultEditRender
1380
+ },
1381
+ VxeSlider: {
1382
+ renderTableDefault: defaultEditRender
1383
+ },
1384
+
1385
+ // 以下已废弃
1386
+ $input: {
1387
+ tableAutoFocus: '.vxe-input--inner',
1388
+ renderTableEdit: oldEditRender,
1389
+ renderTableCell (h, renderOpts, params) {
1390
+ const { props = {} } = renderOpts
1391
+ const { row, column } = params
1392
+ const digits = props.digits || getConfig().input?.digits || 2
1393
+ let cellValue = XEUtils.get(row, column.field)
1394
+ if (cellValue) {
1395
+ switch (props.type) {
1396
+ case 'date':
1397
+ case 'week':
1398
+ case 'month':
1399
+ case 'year':
1400
+ cellValue = getLabelFormatDate(cellValue, props)
1401
+ break
1402
+ case 'float':
1403
+ cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
1404
+ break
1405
+ }
1406
+ }
1407
+ return getCellLabelVNs(h, renderOpts, params, cellValue)
1408
+ },
1409
+ renderTableDefault: oldEditRender,
1410
+ renderTableFilter: oldFilterRender,
1411
+ tableFilterDefaultMethod: handleInputFilterMethod
1412
+ },
1413
+ $textarea: {
1414
+ tableAutoFocus: '.vxe-textarea--inner'
1415
+ },
1416
+ $button: {
1417
+ renderTableDefault: oldButtonEditRender
1418
+ },
1419
+ $buttons: {
1420
+ renderTableDefault: oldButtonsEditRender
1421
+ },
1422
+ $select: {
1423
+ tableAutoFocus: '.vxe-input--inner',
1424
+ renderTableEdit: oldSelectEditRender,
1425
+ renderTableDefault: oldSelectEditRender,
1426
+ renderTableCell (h, renderOpts, params) {
1427
+ return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
1428
+ },
1429
+ renderTableFilter (h, renderOpts, params) {
1430
+ const { column } = params
1431
+ const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
1432
+ return column.filters.map((option, oIndex) => {
1433
+ const optionValue = option.data
1434
+ return h(getOldComponent(renderOpts), {
1435
+ key: oIndex,
1436
+ props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
1437
+ on: getFilterOns(renderOpts, params, option)
1438
+ })
1439
+ })
1440
+ },
1441
+ tableFilterDefaultMethod: handleFilterMethod,
1442
+ tableExportMethod: handleExportSelectMethod
1443
+ },
1444
+ $radio: {
1445
+ tableAutoFocus: '.vxe-radio--input'
1446
+ },
1447
+ $checkbox: {
1448
+ tableAutoFocus: '.vxe-checkbox--input'
1449
+ },
1450
+ $switch: {
1451
+ tableAutoFocus: '.vxe-switch--button',
1452
+ renderTableEdit: oldEditRender,
1453
+ renderTableDefault: oldEditRender
1454
+ }
1455
+ // 以上已废弃
1456
+ })