@vxe-ui/plugin-render-element 4.0.7 → 4.0.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.
@@ -1,604 +1,605 @@
1
- import { h, resolveComponent, ComponentOptions } from 'vue'
2
- import XEUtils from 'xe-utils'
3
- import dayjs from 'dayjs'
4
-
5
- import type { VxeUIExport, VxeTableDefines, VxeColumnPropTypes, VxeGlobalRendererHandles } from 'vxe-pc-ui'
6
-
7
- /**
8
- * 表格 - 渲染器
9
- */
10
- export function defineTableRender (VxeUI: VxeUIExport) {
11
- function isEmptyValue (cellValue: any) {
12
- return cellValue === null || cellValue === undefined || cellValue === ''
13
- }
14
-
15
- function getOnName (type: string) {
16
- return 'on' + type.substring(0, 1).toLocaleUpperCase() + type.substring(1)
17
- }
18
-
19
- function getModelProp (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
20
- return 'modelValue'
21
- }
22
-
23
- function getModelEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
24
- return 'update:modelValue'
25
- }
26
-
27
- function getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
28
- let type = 'change'
29
- switch (renderOpts.name) {
30
- case 'ElAutocomplete':
31
- type = 'select'
32
- break
33
- case 'ElInput':
34
- case 'ElInputNumber':
35
- type = 'input'
36
- break
37
- }
38
- return type
39
- }
40
-
41
- function toDayStringDate (value: any, format: string) {
42
- return dayjs(value, format).toDate()
43
- }
44
-
45
- function toDayDateString (date: any, format: string) {
46
- return dayjs(date).format(format)
47
- }
48
-
49
- function parseDate (value: any, props: { [key: string]: any }) {
50
- return value && props.valueFormat ? toDayStringDate(value, props.valueFormat) : value
51
- }
52
-
53
- function getFormatDate (value: any, props: { [key: string]: any }, defaultFormat: string) {
54
- return value ? toDayDateString(parseDate(value, props), props.format || props.valueFormat || defaultFormat) : value
55
- }
56
-
57
- function getFormatDates (values: any[], props: { [key: string]: any }, separator: string, defaultFormat: string) {
58
- return XEUtils.map(values, (date: any) => getFormatDate(date, props, defaultFormat)).join(separator)
59
- }
60
-
61
- function equalDateRange (cellValue: any, data: any, props: { [key: string]: any }, defaultFormat: string) {
62
- cellValue = getFormatDate(cellValue, props, defaultFormat)
63
- return cellValue >= getFormatDate(data[0], props, defaultFormat) && cellValue <= getFormatDate(data[1], props, defaultFormat)
64
- }
65
-
66
- function getCellEditFilterProps (renderOpts: any, params: VxeGlobalRendererHandles.RenderEditParams | VxeGlobalRendererHandles.RenderFilterParams, value: any, defaultProps?: { [prop: string]: any }) {
67
- return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
68
- }
69
-
70
- function formatText (cellValue: any) {
71
- return '' + (isEmptyValue(cellValue) ? '' : cellValue)
72
- }
73
-
74
- function getCellLabelVNs (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams, cellLabel: any) {
75
- const { placeholder } = renderOpts
76
- return [
77
- h('span', {
78
- class: 'vxe-cell--label'
79
- }, placeholder && isEmptyValue(cellLabel)
80
- ? [
81
- h('span', {
82
- class: 'vxe-cell--placeholder'
83
- }, formatText(VxeUI.getI18n(placeholder)))
84
- ]
85
- : formatText(cellLabel))
86
- ]
87
- }
88
-
89
- function getOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderParams, inputFunc?: Function, changeFunc?: Function) {
90
- const { events } = renderOpts
91
- const modelEvent = getModelEvent(renderOpts)
92
- const changeEvent = getChangeEvent(renderOpts)
93
- const isSameEvent = changeEvent === modelEvent
94
- const ons: { [type: string]: Function } = {}
95
- XEUtils.objectEach(events, (func: Function, key: string) => {
96
- ons[getOnName(key)] = function (...args: any[]) {
97
- func(params, ...args)
98
- }
99
- })
100
- if (inputFunc) {
101
- ons[getOnName(modelEvent)] = function (targetEvnt: any) {
102
- inputFunc(targetEvnt)
103
- if (events && events[modelEvent]) {
104
- events[modelEvent](params, targetEvnt)
105
- }
106
- if (isSameEvent && changeFunc) {
107
- changeFunc(targetEvnt)
108
- }
109
- }
110
- }
111
- if (!isSameEvent && changeFunc) {
112
- ons[getOnName(changeEvent)] = function (...args: any[]) {
113
- changeFunc(...args)
114
- if (events && events[changeEvent]) {
115
- events[changeEvent](params, ...args)
116
- }
117
- }
118
- }
119
- return ons
120
- }
121
-
122
- function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderEditParams) {
123
- const { $table, row, column } = params
124
- return getOns(renderOpts, params, (value: any) => {
125
- // 处理 model 值双向绑定
126
- XEUtils.set(row, column.field, value)
127
- }, () => {
128
- // 处理 change 事件相关逻辑
129
- $table.updateStatus(params)
130
- })
131
- }
132
-
133
- function getFilterOns (renderOpts: any, params: VxeGlobalRendererHandles.RenderFilterParams, option: VxeTableDefines.FilterOption, changeFunc: Function) {
134
- return getOns(renderOpts, params, (value: any) => {
135
- // 处理 model 值双向绑定
136
- option.data = value
137
- }, changeFunc)
138
- }
139
-
140
- function matchCascaderData (index: number, list: any[], values: any[], labels: any[]) {
141
- const val = values[index]
142
- if (list && values.length > index) {
143
- XEUtils.each(list, (item) => {
144
- if (item.value === val) {
145
- labels.push(item.label)
146
- matchCascaderData(++index, item.children, values, labels)
147
- }
148
- })
149
- }
150
- }
151
-
152
- function getSelectCellValue (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
153
- const { options = [], optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
154
- const { $table, rowid, row, column } = params
155
- const { filterable, multiple } = props
156
- const labelProp = optionProps.label || 'label'
157
- const valueProp = optionProps.value || 'value'
158
- const groupOptions = optionGroupProps.options || 'options'
159
- const cellValue = XEUtils.get(row, column.field)
160
- const colid = column.id
161
- let cellData: any
162
- if (filterable) {
163
- const { internalData } = $table
164
- const { fullAllDataRowIdData } = internalData
165
- const rest: any = fullAllDataRowIdData[rowid]
166
- if (rest) {
167
- cellData = rest.cellData
168
- if (!cellData) {
169
- cellData = rest.cellData = {}
170
- }
171
- }
172
- if (rest && cellData[colid] && cellData[colid].value === cellValue) {
173
- return cellData[colid].label
174
- }
175
- }
176
- if (!isEmptyValue(cellValue)) {
177
- const selectlabel = XEUtils.map(multiple ? cellValue : [cellValue], optionGroups
178
- ? (value) => {
179
- let selectItem: any
180
- for (let index = 0; index < optionGroups.length; index++) {
181
- selectItem = XEUtils.find(optionGroups[index][groupOptions], (item) => item[valueProp] === value)
182
- if (selectItem) {
183
- break
184
- }
185
- }
186
- return selectItem ? selectItem[labelProp] : value
187
- }
188
- : (value) => {
189
- const selectItem = XEUtils.find(options, (item) => item[valueProp] === value)
190
- return selectItem ? selectItem[labelProp] : value
191
- }).join(', ')
192
- if (cellData && options && options.length) {
193
- cellData[colid] = { value: cellValue, label: selectlabel }
194
- }
195
- return selectlabel
196
- }
197
- return ''
198
- }
199
-
200
- function getCascaderCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams) {
201
- const { props = {} } = renderOpts
202
- const { row, column } = params
203
- const cellValue = XEUtils.get(row, column.field)
204
- const values: any[] = cellValue || []
205
- const labels: any[] = []
206
- matchCascaderData(0, props.options, values, labels)
207
- return (props.showAllLevels === false ? labels.slice(labels.length - 1, labels.length) : labels).join(` ${props.separator || '/'} `)
208
- }
209
-
210
- function getDatePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.ExportMethodParams) {
211
- const { props = {} } = renderOpts
212
- const { row, column } = params
213
- const { rangeSeparator = '-' } = props
214
- let cellValue = XEUtils.get(row, column.field)
215
- switch (props.type) {
216
- case 'week':
217
- cellValue = getFormatDate(cellValue, props, 'YYYYwWW')
218
- break
219
- case 'month':
220
- cellValue = getFormatDate(cellValue, props, 'YYYY-MM')
221
- break
222
- case 'year':
223
- cellValue = getFormatDate(cellValue, props, 'YYYY')
224
- break
225
- case 'dates':
226
- cellValue = getFormatDates(cellValue, props, ', ', 'YYYY-MM-DD')
227
- break
228
- case 'daterange':
229
- cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD')
230
- break
231
- case 'datetimerange':
232
- cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD HH:ss:mm')
233
- break
234
- case 'monthrange':
235
- cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM')
236
- break
237
- default:
238
- cellValue = getFormatDate(cellValue, props, 'YYYY-MM-DD')
239
- }
240
- return cellValue
241
- }
242
-
243
- function getTimePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.RenderEditParams) {
244
- const { props = {} } = renderOpts
245
- const { row, column } = params
246
- const { isRange, format = 'HH:mm:ss', rangeSeparator = '-' } = props
247
- let cellValue = XEUtils.get(row, column.field)
248
- if (cellValue && isRange) {
249
- cellValue = XEUtils.map(cellValue, (date) => toDayDateString(parseDate(date, props), format)).join(` ${rangeSeparator} `)
250
- }
251
- return toDayDateString(parseDate(cellValue, props), format)
252
- }
253
-
254
- function createEditRender (defaultProps?: { [key: string]: any }) {
255
- return function (renderOpts: VxeColumnPropTypes.EditRender & { name: string }, params: VxeGlobalRendererHandles.RenderEditParams) {
256
- const { row, column } = params
257
- const { name, attrs } = renderOpts
258
- const cellValue = XEUtils.get(row, column.field)
259
- return [
260
- h(resolveComponent(name), {
261
- ...attrs,
262
- ...getCellEditFilterProps(renderOpts, params, cellValue, defaultProps),
263
- ...getEditOns(renderOpts, params)
264
- })
265
- ]
266
- }
267
- }
268
-
269
- function defaultButtonEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
270
- const { attrs } = renderOpts
271
- return [
272
- h(resolveComponent('el-button'), {
273
- ...attrs,
274
- ...getCellEditFilterProps(renderOpts, params, null),
275
- ...getOns(renderOpts, params)
276
- }, cellText(renderOpts.content))
277
- ]
278
- }
279
-
280
- function defaultButtonsEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
281
- const { children } = renderOpts
282
- if (children) {
283
- return children.map((childRenderOpts: VxeColumnPropTypes.EditRender) => defaultButtonEditRender(childRenderOpts, params)[0])
284
- }
285
- return []
286
- }
287
-
288
- function createFilterRender (defaultProps?: { [key: string]: any }) {
289
- return function (renderOpts: VxeColumnPropTypes.FilterRender & { name: string }, params: VxeGlobalRendererHandles.RenderFilterParams) {
290
- const { column } = params
291
- const { name, attrs } = renderOpts
292
- return [
293
- h('div', {
294
- class: 'vxe-table--filter-element-wrapper'
295
- }, column.filters.map((option, oIndex) => {
296
- const optionValue = option.data
297
- return h(resolveComponent(name), {
298
- key: oIndex,
299
- ...attrs,
300
- ...getCellEditFilterProps(renderOpts, params, optionValue, defaultProps),
301
- ...getFilterOns(renderOpts, params, option, () => {
302
- // 处理 change 事件相关逻辑
303
- handleConfirmFilter(params, !!option.data, option)
304
- })
305
- })
306
- }))
307
- ]
308
- }
309
- }
310
-
311
- function handleConfirmFilter (params: VxeGlobalRendererHandles.RenderFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
312
- const { $panel } = params
313
- $panel.changeOption(null, checked, option)
314
- }
315
-
316
- /**
317
- * 模糊匹配
318
- * @param params
319
- */
320
- function defaultFuzzyFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
321
- const { option, row, column } = params
322
- const { data } = option
323
- const cellValue = XEUtils.get(row, column.field)
324
- return XEUtils.toValueString(cellValue).indexOf(data) > -1
325
- }
326
-
327
- /**
328
- * 精确匹配
329
- * @param params
330
- */
331
- function defaultExactFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
332
- const { option, row, column } = params
333
- const { data } = option
334
- const cellValue = XEUtils.get(row, column.field)
335
- /* eslint-disable eqeqeq */
336
- return cellValue === data
337
- }
338
-
339
- function renderOptions (options: any[], optionProps: VxeGlobalRendererHandles.RenderOptionProps) {
340
- const labelProp = optionProps.label || 'label'
341
- const valueProp = optionProps.value || 'value'
342
- return XEUtils.map(options, (item, oIndex) => {
343
- return h(resolveComponent('el-option'), {
344
- key: oIndex,
345
- value: item[valueProp],
346
- label: item[labelProp],
347
- disabled: item.disabled
348
- })
349
- })
350
- }
351
-
352
- function cellText (cellValue: any): string[] {
353
- return [formatText(cellValue)]
354
- }
355
-
356
- function createExportMethod (getExportCellValue: Function) {
357
- return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
358
- const { row, column, options } = params
359
- return options && options.original ? XEUtils.get(row, column.field) : getExportCellValue(column.editRender || column.cellRender, params)
360
- }
361
- }
362
-
363
- VxeUI.renderer.mixin({
364
- ElAutocomplete: {
365
- tableAutoFocus: 'input',
366
- renderTableDefault: createEditRender(),
367
- renderTableEdit: createEditRender(),
368
- renderTableFilter: createFilterRender(),
369
- tableFilterDefaultMethod: defaultExactFilterMethod
370
- },
371
- ElInput: {
372
- tableAutoFocus: 'input',
373
- renderTableDefault: createEditRender(),
374
- renderTableEdit: createEditRender(),
375
- renderTableFilter: createFilterRender(),
376
- tableFilterDefaultMethod: defaultFuzzyFilterMethod
377
- },
378
- ElInputNumber: {
379
- tableAutoFocus: 'input',
380
- renderTableDefault: createEditRender(),
381
- renderTableEdit: createEditRender(),
382
- renderTableFilter: createFilterRender(),
383
- tableFilterDefaultMethod: defaultFuzzyFilterMethod
384
- },
385
- ElSelect: {
386
- renderTableEdit (renderOpts, params) {
387
- const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
388
- const { row, column } = params
389
- const { attrs } = renderOpts
390
- const cellValue = XEUtils.get(row, column.field)
391
- const props = getCellEditFilterProps(renderOpts, params, cellValue)
392
- const ons = getEditOns(renderOpts, params)
393
- if (optionGroups) {
394
- const groupOptions = optionGroupProps.options || 'options'
395
- const groupLabel = optionGroupProps.label || 'label'
396
- return [
397
- h(resolveComponent('el-select') as ComponentOptions, {
398
- ...attrs,
399
- ...props,
400
- ...ons
401
- }, {
402
- default: () => {
403
- return XEUtils.map(optionGroups, (group, gIndex) => {
404
- return h(resolveComponent('el-option-group') as ComponentOptions, {
405
- key: gIndex,
406
- label: group[groupLabel]
407
- }, {
408
- default: () => renderOptions(group[groupOptions], optionProps)
409
- })
410
- })
411
- }
412
- })
413
- ]
414
- }
415
- return [
416
- h(resolveComponent('el-select') as ComponentOptions, {
417
- ...props,
418
- ...attrs,
419
- ...ons
420
- }, {
421
- default: () => renderOptions(options, optionProps)
422
- })
423
- ]
424
- },
425
- renderTableCell (renderOpts, params) {
426
- return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
427
- },
428
- renderTableFilter (renderOpts, params) {
429
- const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
430
- const groupOptions = optionGroupProps.options || 'options'
431
- const groupLabel = optionGroupProps.label || 'label'
432
- const { column } = params
433
- const { attrs } = renderOpts
434
- return [
435
- h('div', {
436
- class: 'vxe-table--filter-element-wrapper'
437
- }, optionGroups
438
- ? column.filters.map((option, oIndex) => {
439
- const optionValue = option.data
440
- const props = getCellEditFilterProps(renderOpts, params, optionValue)
441
- return h(resolveComponent('el-select') as ComponentOptions, {
442
- key: oIndex,
443
- ...attrs,
444
- ...props,
445
- ...getFilterOns(renderOpts, params, option, () => {
446
- // 处理 change 事件相关逻辑
447
- handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
448
- })
449
- }, {
450
- default: () => {
451
- return XEUtils.map(optionGroups, (group, gIndex) => {
452
- return h(resolveComponent('el-option-group') as ComponentOptions, {
453
- key: gIndex,
454
- label: group[groupLabel]
455
- }, {
456
- default: () => renderOptions(group[groupOptions], optionProps)
457
- })
458
- })
459
- }
460
- })
461
- })
462
- : column.filters.map((option, oIndex) => {
463
- const optionValue = option.data
464
- const props = getCellEditFilterProps(renderOpts, params, optionValue)
465
- return h(resolveComponent('el-select') as ComponentOptions, {
466
- key: oIndex,
467
- ...attrs,
468
- ...props,
469
- ...getFilterOns(renderOpts, params, option, () => {
470
- // 处理 change 事件相关逻辑
471
- handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
472
- })
473
- }, {
474
- default: () => renderOptions(options, optionProps)
475
- })
476
- }))
477
- ]
478
- },
479
- tableFilterDefaultMethod (params) {
480
- const { option, row, column } = params
481
- const { data } = option
482
- const { field, filterRender: renderOpts } = column
483
- const { props = {} } = renderOpts
484
- const cellValue = XEUtils.get(row, field)
485
- if (props.multiple) {
486
- if (XEUtils.isArray(cellValue)) {
487
- return XEUtils.includeArrays(cellValue, data)
488
- }
489
- return data.indexOf(cellValue) > -1
490
- }
491
- /* eslint-disable eqeqeq */
492
- return cellValue == data
493
- },
494
- tableExportMethod: createExportMethod(getSelectCellValue)
495
- },
496
- ElCascader: {
497
- renderTableEdit: createEditRender(),
498
- renderTableCell (renderOpts, params) {
499
- return getCellLabelVNs(renderOpts, params, getCascaderCellValue(renderOpts, params))
500
- },
501
- tableExportMethod: createExportMethod(getCascaderCellValue)
502
- },
503
- ElDatePicker: {
504
- renderTableEdit: createEditRender(),
505
- renderTableCell (renderOpts, params) {
506
- return getCellLabelVNs(renderOpts, params, getDatePickerCellValue(renderOpts, params))
507
- },
508
- renderTableFilter (renderOpts, params) {
509
- const { column } = params
510
- const { name, attrs } = renderOpts
511
- return [
512
- h('div', {
513
- class: 'vxe-table--filter-element-wrapper'
514
- }, column.filters.map((option, oIndex) => {
515
- const optionValue = option.data
516
- return h(resolveComponent(name as string), {
517
- key: oIndex,
518
- ...attrs,
519
- ...getCellEditFilterProps(renderOpts, params, optionValue),
520
- ...getFilterOns(renderOpts, params, option, () => {
521
- // 处理 change 事件相关逻辑
522
- handleConfirmFilter(params, !!option.data, option)
523
- })
524
- })
525
- }))
526
- ]
527
- },
528
- tableFilterDefaultMethod (params) {
529
- const { option, row, column } = params
530
- const { data } = option
531
- const { filterRender: renderOpts } = column
532
- const { props = {} } = renderOpts
533
- const cellValue = XEUtils.get(row, column.field)
534
- if (data) {
535
- switch (props.type) {
536
- case 'daterange':
537
- return equalDateRange(cellValue, data, props, 'YYYY-MM-DD')
538
- case 'datetimerange':
539
- return equalDateRange(cellValue, data, props, 'YYYY-MM-DD HH:ss:mm')
540
- case 'monthrange':
541
- return equalDateRange(cellValue, data, props, 'YYYY-MM')
542
- default:
543
- return cellValue === data
544
- }
545
- }
546
- return false
547
- },
548
- tableExportMethod: createExportMethod(getDatePickerCellValue)
549
- },
550
- ElTimePicker: {
551
- renderTableEdit: createEditRender(),
552
- renderTableCell (renderOpts, params) {
553
- return getCellLabelVNs(renderOpts, params, getTimePickerCellValue(renderOpts, params))
554
- },
555
- tableExportMethod: createExportMethod(getTimePickerCellValue)
556
- },
557
- ElTimeSelect: {
558
- renderTableEdit: createEditRender()
559
- },
560
- ElRate: {
561
- renderTableDefault: createEditRender(),
562
- renderTableEdit: createEditRender(),
563
- renderTableFilter: createFilterRender(),
564
- tableFilterDefaultMethod: defaultExactFilterMethod
565
- },
566
- ElSwitch: {
567
- renderTableDefault: createEditRender(),
568
- renderTableEdit: createEditRender(),
569
- renderTableFilter (renderOpts, params) {
570
- const { column } = params
571
- const { name, attrs } = renderOpts
572
- return [
573
- h('div', {
574
- class: 'vxe-table--filter-element-wrapper'
575
- }, column.filters.map((option, oIndex) => {
576
- const optionValue = option.data
577
- return h(resolveComponent(name as string), {
578
- key: oIndex,
579
- ...attrs,
580
- ...getCellEditFilterProps(renderOpts, params, optionValue),
581
- ...getFilterOns(renderOpts, params, option, () => {
582
- // 处理 change 事件相关逻辑
583
- handleConfirmFilter(params, XEUtils.isBoolean(option.data), option)
584
- })
585
- })
586
- }))
587
- ]
588
- },
589
- tableFilterDefaultMethod: defaultExactFilterMethod
590
- },
591
- ElSlider: {
592
- renderTableDefault: createEditRender(),
593
- renderTableEdit: createEditRender(),
594
- renderTableFilter: createFilterRender(),
595
- tableFilterDefaultMethod: defaultExactFilterMethod
596
- },
597
- ElButton: {
598
- renderTableDefault: defaultButtonEditRender
599
- },
600
- ElButtons: {
601
- renderTableDefault: defaultButtonsEditRender
602
- }
603
- })
604
- }
1
+ import { h, resolveComponent, ComponentOptions } from 'vue'
2
+ import XEUtils from 'xe-utils'
3
+ import dayjs from 'dayjs'
4
+
5
+ import type { VxeUIExport, VxeGlobalRendererHandles } from 'vxe-pc-ui'
6
+ import type { VxeTableDefines, VxeColumnPropTypes } from 'vxe-table'
7
+
8
+ /**
9
+ * 表格 - 渲染器
10
+ */
11
+ export function defineTableRender (VxeUI: VxeUIExport) {
12
+ function isEmptyValue (cellValue: any) {
13
+ return cellValue === null || cellValue === undefined || cellValue === ''
14
+ }
15
+
16
+ function getOnName (type: string) {
17
+ return 'on' + type.substring(0, 1).toLocaleUpperCase() + type.substring(1)
18
+ }
19
+
20
+ function getModelProp (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
21
+ return 'modelValue'
22
+ }
23
+
24
+ function getModelEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
25
+ return 'update:modelValue'
26
+ }
27
+
28
+ function getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
29
+ let type = 'change'
30
+ switch (renderOpts.name) {
31
+ case 'ElAutocomplete':
32
+ type = 'select'
33
+ break
34
+ case 'ElInput':
35
+ case 'ElInputNumber':
36
+ type = 'input'
37
+ break
38
+ }
39
+ return type
40
+ }
41
+
42
+ function toDayStringDate (value: any, format: string) {
43
+ return dayjs(value, format).toDate()
44
+ }
45
+
46
+ function toDayDateString (date: any, format: string) {
47
+ return dayjs(date).format(format)
48
+ }
49
+
50
+ function parseDate (value: any, props: { [key: string]: any }) {
51
+ return value && props.valueFormat ? toDayStringDate(value, props.valueFormat) : value
52
+ }
53
+
54
+ function getFormatDate (value: any, props: { [key: string]: any }, defaultFormat: string) {
55
+ return value ? toDayDateString(parseDate(value, props), props.format || props.valueFormat || defaultFormat) : value
56
+ }
57
+
58
+ function getFormatDates (values: any[], props: { [key: string]: any }, separator: string, defaultFormat: string) {
59
+ return XEUtils.map(values, (date: any) => getFormatDate(date, props, defaultFormat)).join(separator)
60
+ }
61
+
62
+ function equalDateRange (cellValue: any, data: any, props: { [key: string]: any }, defaultFormat: string) {
63
+ cellValue = getFormatDate(cellValue, props, defaultFormat)
64
+ return cellValue >= getFormatDate(data[0], props, defaultFormat) && cellValue <= getFormatDate(data[1], props, defaultFormat)
65
+ }
66
+
67
+ function getCellEditFilterProps (renderOpts: any, params: VxeGlobalRendererHandles.RenderEditParams | VxeGlobalRendererHandles.RenderFilterParams, value: any, defaultProps?: { [prop: string]: any }) {
68
+ return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
69
+ }
70
+
71
+ function formatText (cellValue: any) {
72
+ return '' + (isEmptyValue(cellValue) ? '' : cellValue)
73
+ }
74
+
75
+ function getCellLabelVNs (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams, cellLabel: any) {
76
+ const { placeholder } = renderOpts
77
+ return [
78
+ h('span', {
79
+ class: 'vxe-cell--label'
80
+ }, placeholder && isEmptyValue(cellLabel)
81
+ ? [
82
+ h('span', {
83
+ class: 'vxe-cell--placeholder'
84
+ }, formatText(VxeUI.getI18n(placeholder)))
85
+ ]
86
+ : formatText(cellLabel))
87
+ ]
88
+ }
89
+
90
+ function getOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderParams, inputFunc?: Function, changeFunc?: Function) {
91
+ const { events } = renderOpts
92
+ const modelEvent = getModelEvent(renderOpts)
93
+ const changeEvent = getChangeEvent(renderOpts)
94
+ const isSameEvent = changeEvent === modelEvent
95
+ const ons: { [type: string]: Function } = {}
96
+ XEUtils.objectEach(events, (func: Function, key: string) => {
97
+ ons[getOnName(key)] = function (...args: any[]) {
98
+ func(params, ...args)
99
+ }
100
+ })
101
+ if (inputFunc) {
102
+ ons[getOnName(modelEvent)] = function (targetEvnt: any) {
103
+ inputFunc(targetEvnt)
104
+ if (events && events[modelEvent]) {
105
+ events[modelEvent](params, targetEvnt)
106
+ }
107
+ if (isSameEvent && changeFunc) {
108
+ changeFunc(targetEvnt)
109
+ }
110
+ }
111
+ }
112
+ if (!isSameEvent && changeFunc) {
113
+ ons[getOnName(changeEvent)] = function (...args: any[]) {
114
+ changeFunc(...args)
115
+ if (events && events[changeEvent]) {
116
+ events[changeEvent](params, ...args)
117
+ }
118
+ }
119
+ }
120
+ return ons
121
+ }
122
+
123
+ function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderEditParams) {
124
+ const { $table, row, column } = params
125
+ return getOns(renderOpts, params, (value: any) => {
126
+ // 处理 model 值双向绑定
127
+ XEUtils.set(row, column.field, value)
128
+ }, () => {
129
+ // 处理 change 事件相关逻辑
130
+ $table.updateStatus(params)
131
+ })
132
+ }
133
+
134
+ function getFilterOns (renderOpts: any, params: VxeGlobalRendererHandles.RenderFilterParams, option: VxeTableDefines.FilterOption, changeFunc: Function) {
135
+ return getOns(renderOpts, params, (value: any) => {
136
+ // 处理 model 值双向绑定
137
+ option.data = value
138
+ }, changeFunc)
139
+ }
140
+
141
+ function matchCascaderData (index: number, list: any[], values: any[], labels: any[]) {
142
+ const val = values[index]
143
+ if (list && values.length > index) {
144
+ XEUtils.each(list, (item) => {
145
+ if (item.value === val) {
146
+ labels.push(item.label)
147
+ matchCascaderData(++index, item.children, values, labels)
148
+ }
149
+ })
150
+ }
151
+ }
152
+
153
+ function getSelectCellValue (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
154
+ const { options = [], optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
155
+ const { $table, rowid, row, column } = params
156
+ const { filterable, multiple } = props
157
+ const labelProp = optionProps.label || 'label'
158
+ const valueProp = optionProps.value || 'value'
159
+ const groupOptions = optionGroupProps.options || 'options'
160
+ const cellValue = XEUtils.get(row, column.field)
161
+ const colid = column.id
162
+ let cellData: any
163
+ if (filterable) {
164
+ const { internalData } = $table
165
+ const { fullAllDataRowIdData } = internalData
166
+ const rest: any = fullAllDataRowIdData[rowid]
167
+ if (rest) {
168
+ cellData = rest.cellData
169
+ if (!cellData) {
170
+ cellData = rest.cellData = {}
171
+ }
172
+ }
173
+ if (rest && cellData[colid] && cellData[colid].value === cellValue) {
174
+ return cellData[colid].label
175
+ }
176
+ }
177
+ if (!isEmptyValue(cellValue)) {
178
+ const selectlabel = XEUtils.map(multiple ? cellValue : [cellValue], optionGroups
179
+ ? (value) => {
180
+ let selectItem: any
181
+ for (let index = 0; index < optionGroups.length; index++) {
182
+ selectItem = XEUtils.find(optionGroups[index][groupOptions], (item) => item[valueProp] === value)
183
+ if (selectItem) {
184
+ break
185
+ }
186
+ }
187
+ return selectItem ? selectItem[labelProp] : value
188
+ }
189
+ : (value) => {
190
+ const selectItem = XEUtils.find(options, (item) => item[valueProp] === value)
191
+ return selectItem ? selectItem[labelProp] : value
192
+ }).join(', ')
193
+ if (cellData && options && options.length) {
194
+ cellData[colid] = { value: cellValue, label: selectlabel }
195
+ }
196
+ return selectlabel
197
+ }
198
+ return ''
199
+ }
200
+
201
+ function getCascaderCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams) {
202
+ const { props = {} } = renderOpts
203
+ const { row, column } = params
204
+ const cellValue = XEUtils.get(row, column.field)
205
+ const values: any[] = cellValue || []
206
+ const labels: any[] = []
207
+ matchCascaderData(0, props.options, values, labels)
208
+ return (props.showAllLevels === false ? labels.slice(labels.length - 1, labels.length) : labels).join(` ${props.separator || '/'} `)
209
+ }
210
+
211
+ function getDatePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.ExportMethodParams) {
212
+ const { props = {} } = renderOpts
213
+ const { row, column } = params
214
+ const { rangeSeparator = '-' } = props
215
+ let cellValue = XEUtils.get(row, column.field)
216
+ switch (props.type) {
217
+ case 'week':
218
+ cellValue = getFormatDate(cellValue, props, 'YYYYwWW')
219
+ break
220
+ case 'month':
221
+ cellValue = getFormatDate(cellValue, props, 'YYYY-MM')
222
+ break
223
+ case 'year':
224
+ cellValue = getFormatDate(cellValue, props, 'YYYY')
225
+ break
226
+ case 'dates':
227
+ cellValue = getFormatDates(cellValue, props, ', ', 'YYYY-MM-DD')
228
+ break
229
+ case 'daterange':
230
+ cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD')
231
+ break
232
+ case 'datetimerange':
233
+ cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD HH:ss:mm')
234
+ break
235
+ case 'monthrange':
236
+ cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM')
237
+ break
238
+ default:
239
+ cellValue = getFormatDate(cellValue, props, 'YYYY-MM-DD')
240
+ }
241
+ return cellValue
242
+ }
243
+
244
+ function getTimePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.RenderEditParams) {
245
+ const { props = {} } = renderOpts
246
+ const { row, column } = params
247
+ const { isRange, format = 'HH:mm:ss', rangeSeparator = '-' } = props
248
+ let cellValue = XEUtils.get(row, column.field)
249
+ if (cellValue && isRange) {
250
+ cellValue = XEUtils.map(cellValue, (date) => toDayDateString(parseDate(date, props), format)).join(` ${rangeSeparator} `)
251
+ }
252
+ return toDayDateString(parseDate(cellValue, props), format)
253
+ }
254
+
255
+ function createEditRender (defaultProps?: { [key: string]: any }) {
256
+ return function (renderOpts: VxeColumnPropTypes.EditRender & { name: string }, params: VxeGlobalRendererHandles.RenderEditParams) {
257
+ const { row, column } = params
258
+ const { name, attrs } = renderOpts
259
+ const cellValue = XEUtils.get(row, column.field)
260
+ return [
261
+ h(resolveComponent(name), {
262
+ ...attrs,
263
+ ...getCellEditFilterProps(renderOpts, params, cellValue, defaultProps),
264
+ ...getEditOns(renderOpts, params)
265
+ })
266
+ ]
267
+ }
268
+ }
269
+
270
+ function defaultButtonEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
271
+ const { attrs } = renderOpts
272
+ return [
273
+ h(resolveComponent('el-button'), {
274
+ ...attrs,
275
+ ...getCellEditFilterProps(renderOpts, params, null),
276
+ ...getOns(renderOpts, params)
277
+ }, cellText(renderOpts.content))
278
+ ]
279
+ }
280
+
281
+ function defaultButtonsEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
282
+ const { children } = renderOpts
283
+ if (children) {
284
+ return children.map((childRenderOpts: VxeColumnPropTypes.EditRender) => defaultButtonEditRender(childRenderOpts, params)[0])
285
+ }
286
+ return []
287
+ }
288
+
289
+ function createFilterRender (defaultProps?: { [key: string]: any }) {
290
+ return function (renderOpts: VxeColumnPropTypes.FilterRender & { name: string }, params: VxeGlobalRendererHandles.RenderFilterParams) {
291
+ const { column } = params
292
+ const { name, attrs } = renderOpts
293
+ return [
294
+ h('div', {
295
+ class: 'vxe-table--filter-element-wrapper'
296
+ }, column.filters.map((option, oIndex) => {
297
+ const optionValue = option.data
298
+ return h(resolveComponent(name), {
299
+ key: oIndex,
300
+ ...attrs,
301
+ ...getCellEditFilterProps(renderOpts, params, optionValue, defaultProps),
302
+ ...getFilterOns(renderOpts, params, option, () => {
303
+ // 处理 change 事件相关逻辑
304
+ handleConfirmFilter(params, !!option.data, option)
305
+ })
306
+ })
307
+ }))
308
+ ]
309
+ }
310
+ }
311
+
312
+ function handleConfirmFilter (params: VxeGlobalRendererHandles.RenderFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
313
+ const { $panel } = params
314
+ $panel.changeOption(null, checked, option)
315
+ }
316
+
317
+ /**
318
+ * 模糊匹配
319
+ * @param params
320
+ */
321
+ function defaultFuzzyFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
322
+ const { option, row, column } = params
323
+ const { data } = option
324
+ const cellValue = XEUtils.get(row, column.field)
325
+ return XEUtils.toValueString(cellValue).indexOf(data) > -1
326
+ }
327
+
328
+ /**
329
+ * 精确匹配
330
+ * @param params
331
+ */
332
+ function defaultExactFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
333
+ const { option, row, column } = params
334
+ const { data } = option
335
+ const cellValue = XEUtils.get(row, column.field)
336
+ /* eslint-disable eqeqeq */
337
+ return cellValue === data
338
+ }
339
+
340
+ function renderOptions (options: any[], optionProps: VxeGlobalRendererHandles.RenderOptionProps) {
341
+ const labelProp = optionProps.label || 'label'
342
+ const valueProp = optionProps.value || 'value'
343
+ return XEUtils.map(options, (item, oIndex) => {
344
+ return h(resolveComponent('el-option'), {
345
+ key: oIndex,
346
+ value: item[valueProp],
347
+ label: item[labelProp],
348
+ disabled: item.disabled
349
+ })
350
+ })
351
+ }
352
+
353
+ function cellText (cellValue: any): string[] {
354
+ return [formatText(cellValue)]
355
+ }
356
+
357
+ function createExportMethod (getExportCellValue: Function) {
358
+ return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
359
+ const { row, column, options } = params
360
+ return options && options.original ? XEUtils.get(row, column.field) : getExportCellValue(column.editRender || column.cellRender, params)
361
+ }
362
+ }
363
+
364
+ VxeUI.renderer.mixin({
365
+ ElAutocomplete: {
366
+ tableAutoFocus: 'input',
367
+ renderTableDefault: createEditRender(),
368
+ renderTableEdit: createEditRender(),
369
+ renderTableFilter: createFilterRender(),
370
+ tableFilterDefaultMethod: defaultExactFilterMethod
371
+ },
372
+ ElInput: {
373
+ tableAutoFocus: 'input',
374
+ renderTableDefault: createEditRender(),
375
+ renderTableEdit: createEditRender(),
376
+ renderTableFilter: createFilterRender(),
377
+ tableFilterDefaultMethod: defaultFuzzyFilterMethod
378
+ },
379
+ ElInputNumber: {
380
+ tableAutoFocus: 'input',
381
+ renderTableDefault: createEditRender(),
382
+ renderTableEdit: createEditRender(),
383
+ renderTableFilter: createFilterRender(),
384
+ tableFilterDefaultMethod: defaultFuzzyFilterMethod
385
+ },
386
+ ElSelect: {
387
+ renderTableEdit (renderOpts, params) {
388
+ const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
389
+ const { row, column } = params
390
+ const { attrs } = renderOpts
391
+ const cellValue = XEUtils.get(row, column.field)
392
+ const props = getCellEditFilterProps(renderOpts, params, cellValue)
393
+ const ons = getEditOns(renderOpts, params)
394
+ if (optionGroups) {
395
+ const groupOptions = optionGroupProps.options || 'options'
396
+ const groupLabel = optionGroupProps.label || 'label'
397
+ return [
398
+ h(resolveComponent('el-select') as ComponentOptions, {
399
+ ...attrs,
400
+ ...props,
401
+ ...ons
402
+ }, {
403
+ default: () => {
404
+ return XEUtils.map(optionGroups, (group, gIndex) => {
405
+ return h(resolveComponent('el-option-group') as ComponentOptions, {
406
+ key: gIndex,
407
+ label: group[groupLabel]
408
+ }, {
409
+ default: () => renderOptions(group[groupOptions], optionProps)
410
+ })
411
+ })
412
+ }
413
+ })
414
+ ]
415
+ }
416
+ return [
417
+ h(resolveComponent('el-select') as ComponentOptions, {
418
+ ...props,
419
+ ...attrs,
420
+ ...ons
421
+ }, {
422
+ default: () => renderOptions(options, optionProps)
423
+ })
424
+ ]
425
+ },
426
+ renderTableCell (renderOpts, params) {
427
+ return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
428
+ },
429
+ renderTableFilter (renderOpts, params) {
430
+ const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
431
+ const groupOptions = optionGroupProps.options || 'options'
432
+ const groupLabel = optionGroupProps.label || 'label'
433
+ const { column } = params
434
+ const { attrs } = renderOpts
435
+ return [
436
+ h('div', {
437
+ class: 'vxe-table--filter-element-wrapper'
438
+ }, optionGroups
439
+ ? column.filters.map((option, oIndex) => {
440
+ const optionValue = option.data
441
+ const props = getCellEditFilterProps(renderOpts, params, optionValue)
442
+ return h(resolveComponent('el-select') as ComponentOptions, {
443
+ key: oIndex,
444
+ ...attrs,
445
+ ...props,
446
+ ...getFilterOns(renderOpts, params, option, () => {
447
+ // 处理 change 事件相关逻辑
448
+ handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
449
+ })
450
+ }, {
451
+ default: () => {
452
+ return XEUtils.map(optionGroups, (group, gIndex) => {
453
+ return h(resolveComponent('el-option-group') as ComponentOptions, {
454
+ key: gIndex,
455
+ label: group[groupLabel]
456
+ }, {
457
+ default: () => renderOptions(group[groupOptions], optionProps)
458
+ })
459
+ })
460
+ }
461
+ })
462
+ })
463
+ : column.filters.map((option, oIndex) => {
464
+ const optionValue = option.data
465
+ const props = getCellEditFilterProps(renderOpts, params, optionValue)
466
+ return h(resolveComponent('el-select') as ComponentOptions, {
467
+ key: oIndex,
468
+ ...attrs,
469
+ ...props,
470
+ ...getFilterOns(renderOpts, params, option, () => {
471
+ // 处理 change 事件相关逻辑
472
+ handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
473
+ })
474
+ }, {
475
+ default: () => renderOptions(options, optionProps)
476
+ })
477
+ }))
478
+ ]
479
+ },
480
+ tableFilterDefaultMethod (params) {
481
+ const { option, row, column } = params
482
+ const { data } = option
483
+ const { field, filterRender: renderOpts } = column
484
+ const { props = {} } = renderOpts
485
+ const cellValue = XEUtils.get(row, field)
486
+ if (props.multiple) {
487
+ if (XEUtils.isArray(cellValue)) {
488
+ return XEUtils.includeArrays(cellValue, data)
489
+ }
490
+ return data.indexOf(cellValue) > -1
491
+ }
492
+ /* eslint-disable eqeqeq */
493
+ return cellValue == data
494
+ },
495
+ tableExportMethod: createExportMethod(getSelectCellValue)
496
+ },
497
+ ElCascader: {
498
+ renderTableEdit: createEditRender(),
499
+ renderTableCell (renderOpts, params) {
500
+ return getCellLabelVNs(renderOpts, params, getCascaderCellValue(renderOpts, params))
501
+ },
502
+ tableExportMethod: createExportMethod(getCascaderCellValue)
503
+ },
504
+ ElDatePicker: {
505
+ renderTableEdit: createEditRender(),
506
+ renderTableCell (renderOpts, params) {
507
+ return getCellLabelVNs(renderOpts, params, getDatePickerCellValue(renderOpts, params))
508
+ },
509
+ renderTableFilter (renderOpts, params) {
510
+ const { column } = params
511
+ const { name, attrs } = renderOpts
512
+ return [
513
+ h('div', {
514
+ class: 'vxe-table--filter-element-wrapper'
515
+ }, column.filters.map((option, oIndex) => {
516
+ const optionValue = option.data
517
+ return h(resolveComponent(name as string), {
518
+ key: oIndex,
519
+ ...attrs,
520
+ ...getCellEditFilterProps(renderOpts, params, optionValue),
521
+ ...getFilterOns(renderOpts, params, option, () => {
522
+ // 处理 change 事件相关逻辑
523
+ handleConfirmFilter(params, !!option.data, option)
524
+ })
525
+ })
526
+ }))
527
+ ]
528
+ },
529
+ tableFilterDefaultMethod (params) {
530
+ const { option, row, column } = params
531
+ const { data } = option
532
+ const { filterRender: renderOpts } = column
533
+ const { props = {} } = renderOpts
534
+ const cellValue = XEUtils.get(row, column.field)
535
+ if (data) {
536
+ switch (props.type) {
537
+ case 'daterange':
538
+ return equalDateRange(cellValue, data, props, 'YYYY-MM-DD')
539
+ case 'datetimerange':
540
+ return equalDateRange(cellValue, data, props, 'YYYY-MM-DD HH:ss:mm')
541
+ case 'monthrange':
542
+ return equalDateRange(cellValue, data, props, 'YYYY-MM')
543
+ default:
544
+ return cellValue === data
545
+ }
546
+ }
547
+ return false
548
+ },
549
+ tableExportMethod: createExportMethod(getDatePickerCellValue)
550
+ },
551
+ ElTimePicker: {
552
+ renderTableEdit: createEditRender(),
553
+ renderTableCell (renderOpts, params) {
554
+ return getCellLabelVNs(renderOpts, params, getTimePickerCellValue(renderOpts, params))
555
+ },
556
+ tableExportMethod: createExportMethod(getTimePickerCellValue)
557
+ },
558
+ ElTimeSelect: {
559
+ renderTableEdit: createEditRender()
560
+ },
561
+ ElRate: {
562
+ renderTableDefault: createEditRender(),
563
+ renderTableEdit: createEditRender(),
564
+ renderTableFilter: createFilterRender(),
565
+ tableFilterDefaultMethod: defaultExactFilterMethod
566
+ },
567
+ ElSwitch: {
568
+ renderTableDefault: createEditRender(),
569
+ renderTableEdit: createEditRender(),
570
+ renderTableFilter (renderOpts, params) {
571
+ const { column } = params
572
+ const { name, attrs } = renderOpts
573
+ return [
574
+ h('div', {
575
+ class: 'vxe-table--filter-element-wrapper'
576
+ }, column.filters.map((option, oIndex) => {
577
+ const optionValue = option.data
578
+ return h(resolveComponent(name as string), {
579
+ key: oIndex,
580
+ ...attrs,
581
+ ...getCellEditFilterProps(renderOpts, params, optionValue),
582
+ ...getFilterOns(renderOpts, params, option, () => {
583
+ // 处理 change 事件相关逻辑
584
+ handleConfirmFilter(params, XEUtils.isBoolean(option.data), option)
585
+ })
586
+ })
587
+ }))
588
+ ]
589
+ },
590
+ tableFilterDefaultMethod: defaultExactFilterMethod
591
+ },
592
+ ElSlider: {
593
+ renderTableDefault: createEditRender(),
594
+ renderTableEdit: createEditRender(),
595
+ renderTableFilter: createFilterRender(),
596
+ tableFilterDefaultMethod: defaultExactFilterMethod
597
+ },
598
+ ElButton: {
599
+ renderTableDefault: defaultButtonEditRender
600
+ },
601
+ ElButtons: {
602
+ renderTableDefault: defaultButtonsEditRender
603
+ }
604
+ })
605
+ }