-
Notifications
You must be signed in to change notification settings - Fork 27
/
index.ts
805 lines (758 loc) · 29.4 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
import { h, resolveComponent, ComponentOptions } from 'vue'
import XEUtils from 'xe-utils'
import { VXETableCore, VxeTableDefines, VxeColumnPropTypes, VxeGlobalRendererHandles, VxeGlobalInterceptorHandles } from 'vxe-table'
import dayjs from 'dayjs'
let vxetable: VXETableCore
function isEmptyValue (cellValue: any) {
return cellValue === null || cellValue === undefined || cellValue === ''
}
function getOnName (type: string) {
return 'on' + type.substring(0, 1).toLocaleUpperCase() + type.substring(1)
}
function getModelProp (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
return 'modelValue'
}
function getModelEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
return 'update:modelValue'
}
function getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
let type = 'change'
switch (renderOpts.name) {
case 'ElAutocomplete':
type = 'select'
break
case 'ElInput':
case 'ElInputNumber':
type = 'input'
break
}
return type
}
function toDayStringDate (value: any, format: string) {
return dayjs(value, format).date
}
function toDayDateString (date: any, format: string) {
return dayjs(date).format(format)
}
function parseDate (value: any, props: { [key: string]: any }) {
return value && props.valueFormat ? toDayStringDate(value, props.valueFormat) : value
}
function getFormatDate (value: any, props: { [key: string]: any }, defaultFormat: string) {
return value ? toDayDateString(parseDate(value, props), props.format || defaultFormat) : value
}
function getFormatDates (values: any[], props: { [key: string]: any }, separator: string, defaultFormat: string) {
return XEUtils.map(values, (date: any) => getFormatDate(date, props, defaultFormat)).join(separator)
}
function equalDaterange (cellValue: any, data: any, props: { [key: string]: any }, defaultFormat: string) {
cellValue = getFormatDate(cellValue, props, defaultFormat)
return cellValue >= getFormatDate(data[0], props, defaultFormat) && cellValue <= getFormatDate(data[1], props, defaultFormat)
}
function getCellEditFilterProps (renderOpts: any, params: VxeGlobalRendererHandles.RenderEditParams | VxeGlobalRendererHandles.RenderFilterParams, value: any, defaultProps?: { [prop: string]: any }) {
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
}
function getItemProps (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: any, value: any, defaultProps?: { [prop: string]: any }) {
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
}
function formatText (cellValue: any) {
return '' + (isEmptyValue(cellValue) ? '' : cellValue)
}
function getCellLabelVNs (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams, cellLabel: any) {
const { placeholder } = renderOpts
return [
h('span', {
class: 'vxe-cell--label'
}, placeholder && isEmptyValue(cellLabel)
? [
h('span', {
class: 'vxe-cell--placeholder'
}, formatText(vxetable._t(placeholder)))
]
: formatText(cellLabel))
]
}
function getOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderParams, inputFunc?: Function, changeFunc?: Function) {
const { events } = renderOpts
const modelEvent = getModelEvent(renderOpts)
const changeEvent = getChangeEvent(renderOpts)
const isSameEvent = changeEvent === modelEvent
const ons: { [type: string]: Function } = {}
XEUtils.objectEach(events, (func: Function, key: string) => {
ons[getOnName(key)] = function (...args: any[]) {
func(params, ...args)
}
})
if (inputFunc) {
ons[getOnName(modelEvent)] = function (targetEvnt: any) {
inputFunc(targetEvnt)
if (events && events[modelEvent]) {
events[modelEvent](params, targetEvnt)
}
if (isSameEvent && changeFunc) {
changeFunc(targetEvnt)
}
}
}
if (!isSameEvent && changeFunc) {
ons[getOnName(changeEvent)] = function (...args: any[]) {
changeFunc(...args)
if (events && events[changeEvent]) {
events[changeEvent](params, ...args)
}
}
}
return ons
}
function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderEditParams) {
const { $table, row, column } = params
return getOns(renderOpts, params, (value: any) => {
// 处理 model 值双向绑定
XEUtils.set(row, column.field, value)
}, () => {
// 处理 change 事件相关逻辑
$table.updateStatus(params)
})
}
function getFilterOns (renderOpts: any, params: VxeGlobalRendererHandles.RenderFilterParams, option: VxeTableDefines.FilterOption, changeFunc: Function) {
return getOns(renderOpts, params, (value: any) => {
// 处理 model 值双向绑定
option.data = value
}, changeFunc)
}
function getItemOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: any) {
const { $form, data, field } = params
return getOns(renderOpts, params, (value: any) => {
// 处理 model 值双向绑定
XEUtils.set(data, field, value)
}, () => {
// 处理 change 事件相关逻辑
$form.updateStatus(params)
})
}
function matchCascaderData (index: number, list: any[], values: any[], labels: any[]) {
const val = values[index]
if (list && values.length > index) {
XEUtils.each(list, (item) => {
if (item.value === val) {
labels.push(item.label)
matchCascaderData(++index, item.children, values, labels)
}
})
}
}
function getSelectCellValue (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
const { options = [], optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
const { $table, rowid, row, column } = params
const { filterable, multiple } = props
const labelProp = optionProps.label || 'label'
const valueProp = optionProps.value || 'value'
const groupOptions = optionGroupProps.options || 'options'
const cellValue = XEUtils.get(row, column.field)
const colid = column.id
let cellData: any
if (filterable) {
const { internalData } = $table
const { fullAllDataRowIdData } = internalData
const rest: any = fullAllDataRowIdData[rowid]
if (rest) {
cellData = rest.cellData
if (!cellData) {
cellData = rest.cellData = {}
}
}
if (rest && cellData[colid] && cellData[colid].value === cellValue) {
return cellData[colid].label
}
}
if (!isEmptyValue(cellValue)) {
const selectlabel = XEUtils.map(multiple ? cellValue : [cellValue], optionGroups
? (value) => {
let selectItem: any
for (let index = 0; index < optionGroups.length; index++) {
selectItem = XEUtils.find(optionGroups[index][groupOptions], (item) => item[valueProp] === value)
if (selectItem) {
break
}
}
return selectItem ? selectItem[labelProp] : value
}
: (value) => {
const selectItem = XEUtils.find(options, (item) => item[valueProp] === value)
return selectItem ? selectItem[labelProp] : value
}).join(', ')
if (cellData && options && options.length) {
cellData[colid] = { value: cellValue, label: selectlabel }
}
return selectlabel
}
return ''
}
function getCascaderCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams) {
const { props = {} } = renderOpts
const { row, column } = params
const cellValue = XEUtils.get(row, column.field)
const values: any[] = cellValue || []
const labels: any[] = []
matchCascaderData(0, props.options, values, labels)
return (props.showAllLevels === false ? labels.slice(labels.length - 1, labels.length) : labels).join(` ${props.separator || '/'} `)
}
function getDatePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.ExportMethodParams) {
const { props = {} } = renderOpts
const { row, column } = params
const { rangeSeparator = '-' } = props
let cellValue = XEUtils.get(row, column.field)
switch (props.type) {
case 'week':
cellValue = getFormatDate(cellValue, props, 'YYYYwWW')
break
case 'month':
cellValue = getFormatDate(cellValue, props, 'YYYY-MM')
break
case 'year':
cellValue = getFormatDate(cellValue, props, 'YYYY')
break
case 'dates':
cellValue = getFormatDates(cellValue, props, ', ', 'YYYY-MM-DD')
break
case 'daterange':
cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD')
break
case 'datetimerange':
cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD HH:ss:mm')
break
case 'monthrange':
cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM')
break
default:
cellValue = getFormatDate(cellValue, props, 'YYYY-MM-DD')
}
return cellValue
}
function getTimePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.RenderEditParams) {
const { props = {} } = renderOpts
const { row, column } = params
const { isRange, format = 'hh:mm:ss', rangeSeparator = '-' } = props
let cellValue = XEUtils.get(row, column.field)
if (cellValue && isRange) {
cellValue = XEUtils.map(cellValue, (date) => toDayDateString(parseDate(date, props), format)).join(` ${rangeSeparator} `)
}
return toDayDateString(parseDate(cellValue, props), format)
}
function createEditRender (defaultProps?: { [key: string]: any }) {
return function (renderOpts: VxeColumnPropTypes.EditRender & { name: string }, params: VxeGlobalRendererHandles.RenderEditParams) {
const { row, column } = params
const { name, attrs } = renderOpts
const cellValue = XEUtils.get(row, column.field)
return [
h(resolveComponent(name), {
...attrs,
...getCellEditFilterProps(renderOpts, params, cellValue, defaultProps),
...getEditOns(renderOpts, params)
})
]
}
}
function defaultButtonEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
const { attrs } = renderOpts
return [
h(resolveComponent('el-button'), {
...attrs,
...getCellEditFilterProps(renderOpts, params, null),
...getOns(renderOpts, params)
}, cellText(renderOpts.content))
]
}
function defaultButtonsEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
const { children } = renderOpts
if (children) {
return children.map((childRenderOpts: VxeColumnPropTypes.EditRender) => defaultButtonEditRender(childRenderOpts, params)[0])
}
return []
}
function createFilterRender (defaultProps?: { [key: string]: any }) {
return function (renderOpts: VxeColumnPropTypes.FilterRender & { name: string }, params: VxeGlobalRendererHandles.RenderFilterParams) {
const { column } = params
const { name, attrs } = renderOpts
return [
h('div', {
class: 'vxe-table--filter-element-wrapper'
}, column.filters.map((option, oIndex) => {
const optionValue = option.data
return h(resolveComponent(name), {
key: oIndex,
...attrs,
...getCellEditFilterProps(renderOpts, params, optionValue, defaultProps),
...getFilterOns(renderOpts, params, option, () => {
// 处理 change 事件相关逻辑
handleConfirmFilter(params, !!option.data, option)
})
})
}))
]
}
}
function handleConfirmFilter (params: VxeGlobalRendererHandles.RenderFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
const { $panel } = params
$panel.changeOption(null, checked, option)
}
/**
* 模糊匹配
* @param params
*/
function defaultFuzzyFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
const { option, row, column } = params
const { data } = option
const cellValue = XEUtils.get(row, column.field)
return XEUtils.toValueString(cellValue).indexOf(data) > -1
}
/**
* 精确匹配
* @param params
*/
function defaultExactFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
const { option, row, column } = params
const { data } = option
const cellValue = XEUtils.get(row, column.field)
/* eslint-disable eqeqeq */
return cellValue === data
}
function renderOptions (options: any[], optionProps: VxeGlobalRendererHandles.RenderOptionProps) {
const labelProp = optionProps.label || 'label'
const valueProp = optionProps.value || 'value'
return XEUtils.map(options, (item, oIndex) => {
return h(resolveComponent('el-option'), {
key: oIndex,
value: item[valueProp],
label: item[labelProp],
disabled: item.disabled
})
})
}
function cellText (cellValue: any): string[] {
return [formatText(cellValue)]
}
function createFormItemRender (defaultProps?: { [key: string]: any }) {
return function (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: any) {
const { data, field } = params
const { name } = renderOpts
const { attrs } = renderOpts
const itemValue = XEUtils.get(data, field)
return [
h(resolveComponent(name), {
...attrs,
...getItemProps(renderOpts, params, itemValue, defaultProps),
...getItemOns(renderOpts, params)
})
]
}
}
function defaultButtonItemRender (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: any) {
const { attrs } = renderOpts
const props = getItemProps(renderOpts, params, null)
return [
h(resolveComponent('el-button') as ComponentOptions, {
...attrs,
...props,
...getOns(renderOpts, params)
}, {
default: () => cellText(renderOpts.content || props.content)
})
]
}
function defaultButtonsItemRender (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: any) {
const { children } = renderOpts
if (children) {
return children.map((childRenderOpts: VxeGlobalRendererHandles.RenderItemContentOptions) => defaultButtonItemRender(childRenderOpts, params)[0])
}
return []
}
function createExportMethod (getExportCellValue: Function) {
return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
const { row, column, options } = params
return options && options.original ? XEUtils.get(row, column.field) : getExportCellValue(column.editRender || column.cellRender, params)
}
}
function createFormItemRadioAndCheckboxRender () {
return function (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: any) {
const { name, options = [], optionProps = {}, attrs } = renderOpts
const { data, field } = params
const labelProp = optionProps.label || 'label'
const valueProp = optionProps.value || 'value'
const itemValue = XEUtils.get(data, field)
return [
h(resolveComponent(`${name}Group`) as ComponentOptions, {
...attrs,
...getItemProps(renderOpts, params, itemValue),
...getItemOns(renderOpts, params)
}, {
default: () => {
return options.map((option, oIndex) => {
return h(resolveComponent(name) as ComponentOptions, {
key: oIndex,
label: option[valueProp],
disabled: option.disabled
}, {
default: () => cellText(option[labelProp])
})
})
}
})
]
}
}
/**
* 检查触发源是否属于目标节点
*/
function getEventTargetNode (evnt: any, container: HTMLElement, className: string) {
let targetElem
let target = evnt.target
while (target && target.nodeType && target !== document) {
if (className && target.className && target.className.split && target.className.split(' ').indexOf(className) > -1) {
targetElem = target
} else if (target === container) {
return { flag: className ? !!targetElem : true, container, targetElem: targetElem }
}
target = target.parentNode
}
return { flag: false }
}
/**
* 事件兼容性处理
*/
function handleClearEvent (params: VxeGlobalInterceptorHandles.InterceptorClearFilterParams | VxeGlobalInterceptorHandles.InterceptorClearEditParams | VxeGlobalInterceptorHandles.InterceptorClearAreasParams) {
const { $event } = params
const bodyElem = document.body
if (
// 远程搜索
getEventTargetNode($event, bodyElem, 'el-autocomplete-suggestion').flag ||
// 下拉框
getEventTargetNode($event, bodyElem, 'el-select-dropdown').flag ||
// 级联
getEventTargetNode($event, bodyElem, 'el-cascader__dropdown').flag ||
getEventTargetNode($event, bodyElem, 'el-cascader-menus').flag ||
// 日期
getEventTargetNode($event, bodyElem, 'el-time-panel').flag ||
getEventTargetNode($event, bodyElem, 'el-picker-panel').flag ||
// 颜色
getEventTargetNode($event, bodyElem, 'el-color-dropdown').flag
) {
return false
}
}
/**
* 基于 vxe-table 的表格适配插件,用于兼容 element-ui 组件库
*/
export const VXETablePluginElement = {
install (vxetable: VXETableCore) {
// 检查版本
if (!/^(4)\./.test(vxetable.version) && !/v4/i.test((vxetable as any).v)) {
console.error('[vxe-table-plugin-element 4.x] Version vxe-table 4.x is required')
}
vxetable.renderer.mixin({
ElAutocomplete: {
autofocus: 'input.el-input__inner',
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
defaultFilterMethod: defaultExactFilterMethod,
renderItemContent: createFormItemRender()
},
ElInput: {
autofocus: 'input.el-input__inner',
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
defaultFilterMethod: defaultFuzzyFilterMethod,
renderItemContent: createFormItemRender()
},
ElInputNumber: {
autofocus: 'input.el-input__inner',
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
defaultFilterMethod: defaultFuzzyFilterMethod,
renderItemContent: createFormItemRender()
},
ElSelect: {
renderEdit (renderOpts, params) {
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
const { row, column } = params
const { attrs } = renderOpts
const cellValue = XEUtils.get(row, column.field)
const props = getCellEditFilterProps(renderOpts, params, cellValue)
const ons = getEditOns(renderOpts, params)
if (optionGroups) {
const groupOptions = optionGroupProps.options || 'options'
const groupLabel = optionGroupProps.label || 'label'
return [
h(resolveComponent('el-select') as ComponentOptions, {
...attrs,
...props,
...ons
}, {
default: () => {
return XEUtils.map(optionGroups, (group, gIndex) => {
return h(resolveComponent('el-option-group') as ComponentOptions, {
key: gIndex,
label: group[groupLabel]
}, {
default: () => renderOptions(group[groupOptions], optionProps)
})
})
}
})
]
}
return [
h(resolveComponent('el-select') as ComponentOptions, {
...props,
...attrs,
...ons
}, {
default: () => renderOptions(options, optionProps)
})
]
},
renderCell (renderOpts, params) {
return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
},
renderFilter (renderOpts, params) {
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
const groupOptions = optionGroupProps.options || 'options'
const groupLabel = optionGroupProps.label || 'label'
const { column } = params
const { attrs } = renderOpts
return [
h('div', {
class: 'vxe-table--filter-element-wrapper'
}, optionGroups
? column.filters.map((option, oIndex) => {
const optionValue = option.data
const props = getCellEditFilterProps(renderOpts, params, optionValue)
return h(resolveComponent('el-select') as ComponentOptions, {
key: oIndex,
...attrs,
...props,
...getFilterOns(renderOpts, params, option, () => {
// 处理 change 事件相关逻辑
handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
})
}, {
default: () => {
return XEUtils.map(optionGroups, (group, gIndex) => {
return h(resolveComponent('el-option-group') as ComponentOptions, {
key: gIndex,
label: group[groupLabel]
}, {
default: () => renderOptions(group[groupOptions], optionProps)
})
})
}
})
})
: column.filters.map((option, oIndex) => {
const optionValue = option.data
const props = getCellEditFilterProps(renderOpts, params, optionValue)
return h(resolveComponent('el-select') as ComponentOptions, {
key: oIndex,
...attrs,
...props,
...getFilterOns(renderOpts, params, option, () => {
// 处理 change 事件相关逻辑
handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
})
}, {
default: () => renderOptions(options, optionProps)
})
}))
]
},
defaultFilterMethod (params) {
const { option, row, column } = params
const { data } = option
const { field, filterRender: renderOpts } = column
const { props = {} } = renderOpts
const cellValue = XEUtils.get(row, field)
if (props.multiple) {
if (XEUtils.isArray(cellValue)) {
return XEUtils.includeArrays(cellValue, data)
}
return data.indexOf(cellValue) > -1
}
/* eslint-disable eqeqeq */
return cellValue == data
},
renderItemContent (renderOpts, params) {
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
const { data, field } = params
const { attrs } = renderOpts
const itemValue = XEUtils.get(data, field)
const props = getItemProps(renderOpts, params, itemValue)
const ons = getItemOns(renderOpts, params)
if (optionGroups) {
const groupOptions = optionGroupProps.options || 'options'
const groupLabel = optionGroupProps.label || 'label'
return [
h(resolveComponent('el-select') as ComponentOptions, {
...attrs,
...props,
...ons
}, {
default: () => {
return XEUtils.map(optionGroups, (group, gIndex) => {
return h(resolveComponent('el-option-group') as ComponentOptions, {
label: group[groupLabel],
key: gIndex
}, {
default: () => renderOptions(group[groupOptions], optionProps)
})
})
}
})
]
}
return [
h(resolveComponent('el-select') as ComponentOptions, {
...attrs,
...props,
...ons
}, {
default: () => renderOptions(options, optionProps)
})
]
},
exportMethod: createExportMethod(getSelectCellValue)
},
ElCascader: {
renderEdit: createEditRender(),
renderCell (renderOpts, params) {
return getCellLabelVNs(renderOpts, params, getCascaderCellValue(renderOpts, params))
},
renderItemContent: createFormItemRender(),
exportMethod: createExportMethod(getCascaderCellValue)
},
ElDatePicker: {
renderEdit: createEditRender(),
renderCell (renderOpts, params) {
return getCellLabelVNs(renderOpts, params, getDatePickerCellValue(renderOpts, params))
},
renderFilter (renderOpts, params) {
const { column } = params
const { name, attrs } = renderOpts
return [
h('div', {
class: 'vxe-table--filter-element-wrapper'
}, column.filters.map((option, oIndex) => {
const optionValue = option.data
return h(resolveComponent(name as string), {
key: oIndex,
...attrs,
...getCellEditFilterProps(renderOpts, params, optionValue),
...getFilterOns(renderOpts, params, option, () => {
// 处理 change 事件相关逻辑
handleConfirmFilter(params, !!option.data, option)
})
})
}))
]
},
defaultFilterMethod (params) {
const { option, row, column } = params
const { data } = option
const { filterRender: renderOpts } = column
const { props = {} } = renderOpts
const cellValue = XEUtils.get(row, column.field)
if (data) {
switch (props.type) {
case 'daterange':
return equalDaterange(cellValue, data, props, 'YYYY-MM-DD')
case 'datetimerange':
return equalDaterange(cellValue, data, props, 'YYYY-MM-DD HH:ss:mm')
case 'monthrange':
return equalDaterange(cellValue, data, props, 'YYYY-MM')
default:
return cellValue === data
}
}
return false
},
renderItemContent: createFormItemRender(),
exportMethod: createExportMethod(getDatePickerCellValue)
},
ElTimePicker: {
renderEdit: createEditRender(),
renderCell (renderOpts, params) {
return getCellLabelVNs(renderOpts, params, getTimePickerCellValue(renderOpts, params))
},
renderItemContent: createFormItemRender(),
exportMethod: createExportMethod(getTimePickerCellValue)
},
ElTimeSelect: {
renderEdit: createEditRender(),
renderItemContent: createFormItemRender()
},
ElRate: {
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
defaultFilterMethod: defaultExactFilterMethod,
renderItemContent: createFormItemRender()
},
ElSwitch: {
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter (renderOpts, params) {
const { column } = params
const { name, attrs } = renderOpts
return [
h('div', {
class: 'vxe-table--filter-element-wrapper'
}, column.filters.map((option, oIndex) => {
const optionValue = option.data
return h(resolveComponent(name as string), {
key: oIndex,
...attrs,
...getCellEditFilterProps(renderOpts, params, optionValue),
...getFilterOns(renderOpts, params, option, () => {
// 处理 change 事件相关逻辑
handleConfirmFilter(params, XEUtils.isBoolean(option.data), option)
})
})
}))
]
},
defaultFilterMethod: defaultExactFilterMethod,
renderItemContent: createFormItemRender()
},
ElSlider: {
renderDefault: createEditRender(),
renderEdit: createEditRender(),
renderFilter: createFilterRender(),
defaultFilterMethod: defaultExactFilterMethod,
renderItemContent: createFormItemRender()
},
ElRadio: {
renderItemContent: createFormItemRadioAndCheckboxRender()
},
ElCheckbox: {
renderItemContent: createFormItemRadioAndCheckboxRender()
},
ElButton: {
renderDefault: defaultButtonEditRender,
renderItemContent: defaultButtonItemRender
},
ElButtons: {
renderDefault: defaultButtonsEditRender,
renderItemContent: defaultButtonsItemRender
}
})
vxetable.interceptor.add('event.clearFilter', handleClearEvent)
vxetable.interceptor.add('event.clearEdit', handleClearEvent)
vxetable.interceptor.add('event.clearAreas', handleClearEvent)
// 兼容老版本
vxetable.interceptor.add('event.clearActived', handleClearEvent)
}
}
if (typeof window !== 'undefined' && window.VXETable && window.VXETable.use) {
window.VXETable.use(VXETablePluginElement)
}
export default VXETablePluginElement