@vxe-ui/plugin-render-element 3.0.0 → 3.0.1

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