@vxe-ui/plugin-render-element 4.3.1 → 4.4.0
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.
- package/LICENSE +20 -20
- package/README.md +176 -176
- package/dist/index.umd.js +48 -16
- package/dist/index.umd.min.js +1 -1
- package/es/index.esm.js +3 -3
- package/es/index.js +3 -3
- package/es/table/index.js +29 -5
- package/lib/index.common.js +3 -3
- package/lib/index.js +3 -3
- package/lib/index.umd.js +48 -16
- package/lib/index.umd.min.js +1 -1
- package/lib/table/index.js +40 -8
- package/package.json +78 -78
- package/src/form/index.ts +326 -326
- package/src/form-design/checkbox-widget.ts +167 -167
- package/src/form-design/date-picker-widget.ts +144 -144
- package/src/form-design/index.ts +101 -101
- package/src/form-design/input-widget.ts +145 -145
- package/src/form-design/number-input-widget.ts +144 -144
- package/src/form-design/radio-widget.ts +167 -167
- package/src/form-design/select-widget.ts +166 -166
- package/src/form-design/switch-widget.ts +140 -140
- package/src/form-design/textarea-widget.ts +149 -149
- package/src/form-design/use.ts +255 -255
- package/src/index.ts +124 -124
- package/src/store/index.ts +5 -5
- package/src/table/index.ts +754 -729
- package/src/util/comp.ts +21 -21
- package/types/index.d.ts +19 -19
package/src/table/index.ts
CHANGED
|
@@ -1,729 +1,754 @@
|
|
|
1
|
-
import { h, ComponentOptions } from 'vue'
|
|
2
|
-
import { getCurrComponent, hasInputType } from '../util/comp'
|
|
3
|
-
import XEUtils from 'xe-utils'
|
|
4
|
-
import dayjs from 'dayjs'
|
|
5
|
-
|
|
6
|
-
import type { VxeUIExport, VxeGlobalRendererHandles } from 'vxe-pc-ui'
|
|
7
|
-
import type { VxeTableDefines, VxeColumnPropTypes } from 'vxe-table'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* 表格 - 渲染器
|
|
11
|
-
*/
|
|
12
|
-
export function defineTableRender (VxeUI: VxeUIExport) {
|
|
13
|
-
function isEmptyValue (cellValue: any) {
|
|
14
|
-
return cellValue === null || cellValue === undefined || cellValue === ''
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function getOnName (type: string) {
|
|
18
|
-
return 'on' + type.substring(0, 1).toLocaleUpperCase() + type.substring(1)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function getModelProp (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
22
|
-
return 'modelValue'
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function getModelEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
26
|
-
return 'update:modelValue'
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
30
|
-
let type = 'change'
|
|
31
|
-
switch (renderOpts.name) {
|
|
32
|
-
case 'ElAutocomplete':
|
|
33
|
-
type = 'select'
|
|
34
|
-
break
|
|
35
|
-
case 'ElInput':
|
|
36
|
-
case 'ElInputNumber':
|
|
37
|
-
type = 'input'
|
|
38
|
-
break
|
|
39
|
-
}
|
|
40
|
-
return type
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function toDayStringDate (value: any, format: string) {
|
|
44
|
-
return dayjs(value, format).toDate()
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function toDayDateString (date: any, format: string) {
|
|
48
|
-
return dayjs(date).format(format)
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function parseDate (value: any, props: { [key: string]: any }) {
|
|
52
|
-
return value && props.valueFormat ? toDayStringDate(value, props.valueFormat) : value
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function getFormatDate (value: any, props: { [key: string]: any }, defaultFormat: string) {
|
|
56
|
-
return value ? toDayDateString(parseDate(value, props), props.format || props.valueFormat || defaultFormat) : value
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function getFormatDates (values: any[], props: { [key: string]: any }, separator: string, defaultFormat: string) {
|
|
60
|
-
return XEUtils.map(values, (date: any) => getFormatDate(date, props, defaultFormat)).join(separator)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function equalDateRange (cellValue: any, data: any, props: { [key: string]: any }, defaultFormat: string) {
|
|
64
|
-
cellValue = getFormatDate(cellValue, props, defaultFormat)
|
|
65
|
-
return cellValue >= getFormatDate(data[0], props, defaultFormat) && cellValue <= getFormatDate(data[1], props, defaultFormat)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function getCellEditFilterProps (renderOpts: any, params: VxeGlobalRendererHandles.RenderTableEditParams | VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, value: any, defaultProps?: { [prop: string]: any }) {
|
|
69
|
-
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function formatText (cellValue: any) {
|
|
73
|
-
return '' + (isEmptyValue(cellValue) ? '' : cellValue)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function updateFilterChangeOption (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
|
|
77
|
-
const { $table } = params
|
|
78
|
-
$table.updateFilterOptionStatus(option, checked)
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function saveFilterEvent (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
|
|
82
|
-
const { $table, column } = params
|
|
83
|
-
$table.saveFilterByEvent(new Event('change'), column)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getCellLabelVNs (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderTableCellParams, cellLabel: any) {
|
|
87
|
-
const { placeholder } = renderOpts
|
|
88
|
-
return [
|
|
89
|
-
h('span', {
|
|
90
|
-
class: 'vxe-cell--label'
|
|
91
|
-
}, placeholder && isEmptyValue(cellLabel)
|
|
92
|
-
? [
|
|
93
|
-
h('span', {
|
|
94
|
-
class: 'vxe-cell--placeholder'
|
|
95
|
-
}, formatText(VxeUI.getI18n(placeholder)))
|
|
96
|
-
]
|
|
97
|
-
: formatText(cellLabel))
|
|
98
|
-
]
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
const blurEvent = 'blur'
|
|
102
|
-
const clearEvent = 'clear'
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 组件事件处理
|
|
106
|
-
* @param renderOpts
|
|
107
|
-
* @param params
|
|
108
|
-
* @param modelFunc
|
|
109
|
-
* @param changeFunc
|
|
110
|
-
*/
|
|
111
|
-
function getComponentOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
|
|
112
|
-
model: (cellValue: any) => void
|
|
113
|
-
change?: (...args: any[]) => void
|
|
114
|
-
blur?: (...args: any[]) => void
|
|
115
|
-
clear?: (...args: any[]) => void
|
|
116
|
-
}, eventOns?: Record<string, any>) {
|
|
117
|
-
const { events } = renderOpts
|
|
118
|
-
const modelEvent = getModelEvent(renderOpts)
|
|
119
|
-
const changeEvent = getChangeEvent(renderOpts)
|
|
120
|
-
const { model: modelFunc, change: changeFunc, blur: blurFunc, clear: clearFunc } = eFns || {}
|
|
121
|
-
const ons: any = {}
|
|
122
|
-
XEUtils.objectEach(events, (func, key: any) => {
|
|
123
|
-
ons[getOnName(key)] = function (...args: any[]) {
|
|
124
|
-
if (!XEUtils.isFunction(func)) {
|
|
125
|
-
console.error(`Parameter "${func}" is not a method`)
|
|
126
|
-
}
|
|
127
|
-
func(params, ...args)
|
|
128
|
-
}
|
|
129
|
-
})
|
|
130
|
-
if (modelFunc) {
|
|
131
|
-
ons[getOnName(modelEvent)] = function (targetEvnt: any) {
|
|
132
|
-
modelFunc(targetEvnt)
|
|
133
|
-
if (events && events[modelEvent]) {
|
|
134
|
-
events[modelEvent](params, targetEvnt)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
if (changeFunc) {
|
|
139
|
-
ons[getOnName(changeEvent)] = function (...args: any[]) {
|
|
140
|
-
changeFunc(...args)
|
|
141
|
-
if (events && events[changeEvent]) {
|
|
142
|
-
events[changeEvent](params, ...args)
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (blurFunc) {
|
|
147
|
-
ons[getOnName(blurEvent)] = function (...args: any[]) {
|
|
148
|
-
blurFunc(...args)
|
|
149
|
-
if (events && events[blurEvent]) {
|
|
150
|
-
events[blurEvent](params, ...args)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (clearFunc) {
|
|
155
|
-
ons[getOnName(clearEvent)] = function (...args: any[]) {
|
|
156
|
-
clearFunc(...args)
|
|
157
|
-
if (events && events[clearEvent]) {
|
|
158
|
-
events[clearEvent](params, ...args)
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
return eventOns ? Object.assign(ons, eventOns) : ons
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderTableEditParams) {
|
|
166
|
-
const { $table, row, column } = params
|
|
167
|
-
return getComponentOns(renderOpts, params, {
|
|
168
|
-
model (value) {
|
|
169
|
-
// 处理 model 值双向绑定
|
|
170
|
-
XEUtils.set(row, column.field, value)
|
|
171
|
-
},
|
|
172
|
-
change () {
|
|
173
|
-
// 处理 change 事件相关逻辑
|
|
174
|
-
$table.updateStatus(params)
|
|
175
|
-
}
|
|
176
|
-
})
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function getFilterOns (renderOpts: any, params: VxeGlobalRendererHandles.RenderTableFilterParams, option: VxeTableDefines.FilterOption, changeFunc: ((...args: any[]) => void)) {
|
|
180
|
-
return getComponentOns(renderOpts, params, {
|
|
181
|
-
model (value: any) {
|
|
182
|
-
// 处理 model 值双向绑定
|
|
183
|
-
option.data = value
|
|
184
|
-
},
|
|
185
|
-
change: changeFunc
|
|
186
|
-
})
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function getFloatingFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams, option: VxeTableDefines.FilterOption) {
|
|
190
|
-
const { $table, column } = params
|
|
191
|
-
if (hasInputType(renderOpts)) {
|
|
192
|
-
return getComponentOns(renderOpts, params, {
|
|
193
|
-
model (value: any) {
|
|
194
|
-
// 处理 model 值双向绑定
|
|
195
|
-
option.data = value
|
|
196
|
-
},
|
|
197
|
-
change () {
|
|
198
|
-
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
199
|
-
},
|
|
200
|
-
clear () {
|
|
201
|
-
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
202
|
-
saveFilterEvent(params)
|
|
203
|
-
},
|
|
204
|
-
blur () {
|
|
205
|
-
$table.saveFilterByEvent(new Event('change'), column)
|
|
206
|
-
}
|
|
207
|
-
})
|
|
208
|
-
}
|
|
209
|
-
return getComponentOns(renderOpts, params, {
|
|
210
|
-
model (value: any) {
|
|
211
|
-
// 处理 model 值双向绑定
|
|
212
|
-
option.data = value
|
|
213
|
-
},
|
|
214
|
-
clear () {
|
|
215
|
-
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
216
|
-
$table.saveFilterByEvent(new Event('change'), column)
|
|
217
|
-
},
|
|
218
|
-
change () {
|
|
219
|
-
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
220
|
-
$table.saveFilterByEvent(new Event('change'), column)
|
|
221
|
-
}
|
|
222
|
-
})
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function matchCascaderData (index: number, list: any[], values: any[], labels: any[]) {
|
|
226
|
-
const val = values[index]
|
|
227
|
-
if (list && values.length > index) {
|
|
228
|
-
XEUtils.each(list, (item) => {
|
|
229
|
-
if (item.value === val) {
|
|
230
|
-
labels.push(item.label)
|
|
231
|
-
matchCascaderData(++index, item.children, values, labels)
|
|
232
|
-
}
|
|
233
|
-
})
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
function
|
|
238
|
-
const { options = [], optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
|
|
239
|
-
const { $table, rowid,
|
|
240
|
-
const { filterable, multiple } = props
|
|
241
|
-
const labelProp = optionProps.label || 'label'
|
|
242
|
-
const valueProp = optionProps.value || 'value'
|
|
243
|
-
const groupOptions = optionGroupProps.options || 'options'
|
|
244
|
-
const
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
const {
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
cellData
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
let
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
const
|
|
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
|
-
const
|
|
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
|
-
const
|
|
548
|
-
const
|
|
549
|
-
const
|
|
550
|
-
const
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
return
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const
|
|
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
|
-
const
|
|
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
|
-
tableFilterDefaultMethod: defaultExactFilterMethod
|
|
714
|
-
},
|
|
715
|
-
|
|
716
|
-
renderTableDefault: createEditRender(),
|
|
717
|
-
renderTableEdit: createEditRender(),
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
1
|
+
import { h, ComponentOptions } from 'vue'
|
|
2
|
+
import { getCurrComponent, hasInputType } from '../util/comp'
|
|
3
|
+
import XEUtils from 'xe-utils'
|
|
4
|
+
import dayjs from 'dayjs'
|
|
5
|
+
|
|
6
|
+
import type { VxeUIExport, VxeGlobalRendererHandles } from 'vxe-pc-ui'
|
|
7
|
+
import type { VxeTableDefines, VxeColumnPropTypes } from 'vxe-table'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 表格 - 渲染器
|
|
11
|
+
*/
|
|
12
|
+
export function defineTableRender (VxeUI: VxeUIExport) {
|
|
13
|
+
function isEmptyValue (cellValue: any) {
|
|
14
|
+
return cellValue === null || cellValue === undefined || cellValue === ''
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getOnName (type: string) {
|
|
18
|
+
return 'on' + type.substring(0, 1).toLocaleUpperCase() + type.substring(1)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getModelProp (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
22
|
+
return 'modelValue'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function getModelEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
26
|
+
return 'update:modelValue'
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
30
|
+
let type = 'change'
|
|
31
|
+
switch (renderOpts.name) {
|
|
32
|
+
case 'ElAutocomplete':
|
|
33
|
+
type = 'select'
|
|
34
|
+
break
|
|
35
|
+
case 'ElInput':
|
|
36
|
+
case 'ElInputNumber':
|
|
37
|
+
type = 'input'
|
|
38
|
+
break
|
|
39
|
+
}
|
|
40
|
+
return type
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function toDayStringDate (value: any, format: string) {
|
|
44
|
+
return dayjs(value, format).toDate()
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function toDayDateString (date: any, format: string) {
|
|
48
|
+
return dayjs(date).format(format)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function parseDate (value: any, props: { [key: string]: any }) {
|
|
52
|
+
return value && props.valueFormat ? toDayStringDate(value, props.valueFormat) : value
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function getFormatDate (value: any, props: { [key: string]: any }, defaultFormat: string) {
|
|
56
|
+
return value ? toDayDateString(parseDate(value, props), props.format || props.valueFormat || defaultFormat) : value
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function getFormatDates (values: any[], props: { [key: string]: any }, separator: string, defaultFormat: string) {
|
|
60
|
+
return XEUtils.map(values, (date: any) => getFormatDate(date, props, defaultFormat)).join(separator)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function equalDateRange (cellValue: any, data: any, props: { [key: string]: any }, defaultFormat: string) {
|
|
64
|
+
cellValue = getFormatDate(cellValue, props, defaultFormat)
|
|
65
|
+
return cellValue >= getFormatDate(data[0], props, defaultFormat) && cellValue <= getFormatDate(data[1], props, defaultFormat)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function getCellEditFilterProps (renderOpts: any, params: VxeGlobalRendererHandles.RenderTableEditParams | VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, value: any, defaultProps?: { [prop: string]: any }) {
|
|
69
|
+
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function formatText (cellValue: any) {
|
|
73
|
+
return '' + (isEmptyValue(cellValue) ? '' : cellValue)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function updateFilterChangeOption (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
|
|
77
|
+
const { $table } = params
|
|
78
|
+
$table.updateFilterOptionStatus(option, checked)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function saveFilterEvent (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
|
|
82
|
+
const { $table, column } = params
|
|
83
|
+
$table.saveFilterByEvent(new Event('change'), column)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function getCellLabelVNs (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderTableCellParams, cellLabel: any) {
|
|
87
|
+
const { placeholder } = renderOpts
|
|
88
|
+
return [
|
|
89
|
+
h('span', {
|
|
90
|
+
class: 'vxe-cell--label'
|
|
91
|
+
}, placeholder && isEmptyValue(cellLabel)
|
|
92
|
+
? [
|
|
93
|
+
h('span', {
|
|
94
|
+
class: 'vxe-cell--placeholder'
|
|
95
|
+
}, formatText(VxeUI.getI18n(placeholder)))
|
|
96
|
+
]
|
|
97
|
+
: formatText(cellLabel))
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const blurEvent = 'blur'
|
|
102
|
+
const clearEvent = 'clear'
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 组件事件处理
|
|
106
|
+
* @param renderOpts
|
|
107
|
+
* @param params
|
|
108
|
+
* @param modelFunc
|
|
109
|
+
* @param changeFunc
|
|
110
|
+
*/
|
|
111
|
+
function getComponentOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
|
|
112
|
+
model: (cellValue: any) => void
|
|
113
|
+
change?: (...args: any[]) => void
|
|
114
|
+
blur?: (...args: any[]) => void
|
|
115
|
+
clear?: (...args: any[]) => void
|
|
116
|
+
}, eventOns?: Record<string, any>) {
|
|
117
|
+
const { events } = renderOpts
|
|
118
|
+
const modelEvent = getModelEvent(renderOpts)
|
|
119
|
+
const changeEvent = getChangeEvent(renderOpts)
|
|
120
|
+
const { model: modelFunc, change: changeFunc, blur: blurFunc, clear: clearFunc } = eFns || {}
|
|
121
|
+
const ons: any = {}
|
|
122
|
+
XEUtils.objectEach(events, (func, key: any) => {
|
|
123
|
+
ons[getOnName(key)] = function (...args: any[]) {
|
|
124
|
+
if (!XEUtils.isFunction(func)) {
|
|
125
|
+
console.error(`Parameter "${func}" is not a method`)
|
|
126
|
+
}
|
|
127
|
+
func(params, ...args)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
if (modelFunc) {
|
|
131
|
+
ons[getOnName(modelEvent)] = function (targetEvnt: any) {
|
|
132
|
+
modelFunc(targetEvnt)
|
|
133
|
+
if (events && events[modelEvent]) {
|
|
134
|
+
events[modelEvent](params, targetEvnt)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (changeFunc) {
|
|
139
|
+
ons[getOnName(changeEvent)] = function (...args: any[]) {
|
|
140
|
+
changeFunc(...args)
|
|
141
|
+
if (events && events[changeEvent]) {
|
|
142
|
+
events[changeEvent](params, ...args)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (blurFunc) {
|
|
147
|
+
ons[getOnName(blurEvent)] = function (...args: any[]) {
|
|
148
|
+
blurFunc(...args)
|
|
149
|
+
if (events && events[blurEvent]) {
|
|
150
|
+
events[blurEvent](params, ...args)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (clearFunc) {
|
|
155
|
+
ons[getOnName(clearEvent)] = function (...args: any[]) {
|
|
156
|
+
clearFunc(...args)
|
|
157
|
+
if (events && events[clearEvent]) {
|
|
158
|
+
events[clearEvent](params, ...args)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return eventOns ? Object.assign(ons, eventOns) : ons
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderTableEditParams) {
|
|
166
|
+
const { $table, row, column } = params
|
|
167
|
+
return getComponentOns(renderOpts, params, {
|
|
168
|
+
model (value) {
|
|
169
|
+
// 处理 model 值双向绑定
|
|
170
|
+
XEUtils.set(row, column.field, value)
|
|
171
|
+
},
|
|
172
|
+
change () {
|
|
173
|
+
// 处理 change 事件相关逻辑
|
|
174
|
+
$table.updateStatus(params)
|
|
175
|
+
}
|
|
176
|
+
})
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function getFilterOns (renderOpts: any, params: VxeGlobalRendererHandles.RenderTableFilterParams, option: VxeTableDefines.FilterOption, changeFunc: ((...args: any[]) => void)) {
|
|
180
|
+
return getComponentOns(renderOpts, params, {
|
|
181
|
+
model (value: any) {
|
|
182
|
+
// 处理 model 值双向绑定
|
|
183
|
+
option.data = value
|
|
184
|
+
},
|
|
185
|
+
change: changeFunc
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function getFloatingFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams, option: VxeTableDefines.FilterOption) {
|
|
190
|
+
const { $table, column } = params
|
|
191
|
+
if (hasInputType(renderOpts)) {
|
|
192
|
+
return getComponentOns(renderOpts, params, {
|
|
193
|
+
model (value: any) {
|
|
194
|
+
// 处理 model 值双向绑定
|
|
195
|
+
option.data = value
|
|
196
|
+
},
|
|
197
|
+
change () {
|
|
198
|
+
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
199
|
+
},
|
|
200
|
+
clear () {
|
|
201
|
+
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
202
|
+
saveFilterEvent(params)
|
|
203
|
+
},
|
|
204
|
+
blur () {
|
|
205
|
+
$table.saveFilterByEvent(new Event('change'), column)
|
|
206
|
+
}
|
|
207
|
+
})
|
|
208
|
+
}
|
|
209
|
+
return getComponentOns(renderOpts, params, {
|
|
210
|
+
model (value: any) {
|
|
211
|
+
// 处理 model 值双向绑定
|
|
212
|
+
option.data = value
|
|
213
|
+
},
|
|
214
|
+
clear () {
|
|
215
|
+
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
216
|
+
$table.saveFilterByEvent(new Event('change'), column)
|
|
217
|
+
},
|
|
218
|
+
change () {
|
|
219
|
+
updateFilterChangeOption(params, !isEmptyValue(option.data), option)
|
|
220
|
+
$table.saveFilterByEvent(new Event('change'), column)
|
|
221
|
+
}
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function matchCascaderData (index: number, list: any[], values: any[], labels: any[]) {
|
|
226
|
+
const val = values[index]
|
|
227
|
+
if (list && values.length > index) {
|
|
228
|
+
XEUtils.each(list, (item) => {
|
|
229
|
+
if (item.value === val) {
|
|
230
|
+
labels.push(item.label)
|
|
231
|
+
matchCascaderData(++index, item.children, values, labels)
|
|
232
|
+
}
|
|
233
|
+
})
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function handleSelectCellValue (cellValue: any, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, renderParams: VxeGlobalRendererHandles.RenderCellParams) {
|
|
238
|
+
const { options = [], optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
|
|
239
|
+
const { $table, rowid, column } = renderParams
|
|
240
|
+
const { filterable, multiple } = props
|
|
241
|
+
const labelProp = optionProps.label || 'label'
|
|
242
|
+
const valueProp = optionProps.value || 'value'
|
|
243
|
+
const groupOptions = optionGroupProps.options || 'options'
|
|
244
|
+
const colid = column.id
|
|
245
|
+
let cellData: any
|
|
246
|
+
if (filterable) {
|
|
247
|
+
const { internalData } = $table
|
|
248
|
+
const { fullAllDataRowIdData } = internalData
|
|
249
|
+
const rest: any = fullAllDataRowIdData[rowid]
|
|
250
|
+
if (rest) {
|
|
251
|
+
cellData = rest.cellData
|
|
252
|
+
if (!cellData) {
|
|
253
|
+
cellData = rest.cellData = {}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (rest && cellData[colid] && cellData[colid].value === cellValue) {
|
|
257
|
+
return cellData[colid].label
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
if (!isEmptyValue(cellValue)) {
|
|
261
|
+
const selectlabel = XEUtils.map(multiple ? cellValue : [cellValue], optionGroups
|
|
262
|
+
? (value) => {
|
|
263
|
+
let selectItem: any
|
|
264
|
+
for (let index = 0; index < optionGroups.length; index++) {
|
|
265
|
+
selectItem = XEUtils.find(optionGroups[index][groupOptions], (item) => item[valueProp] === value)
|
|
266
|
+
if (selectItem) {
|
|
267
|
+
break
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return selectItem ? selectItem[labelProp] : value
|
|
271
|
+
}
|
|
272
|
+
: (value) => {
|
|
273
|
+
const selectItem = XEUtils.find(options, (item) => item[valueProp] === value)
|
|
274
|
+
return selectItem ? selectItem[labelProp] : value
|
|
275
|
+
}).join(', ')
|
|
276
|
+
if (cellData && options && options.length) {
|
|
277
|
+
cellData[colid] = { value: cellValue, label: selectlabel }
|
|
278
|
+
}
|
|
279
|
+
return selectlabel
|
|
280
|
+
}
|
|
281
|
+
return ''
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
function getSelectCellValue (renderOpts: VxeColumnPropTypes.EditRender, renderParams: VxeGlobalRendererHandles.RenderTableCellParams) {
|
|
285
|
+
const { row, column } = renderParams
|
|
286
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
287
|
+
return handleSelectCellValue(cellValue, renderOpts, renderParams)
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
function getCascaderCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderTableCellParams) {
|
|
291
|
+
const { props = {} } = renderOpts
|
|
292
|
+
const { row, column } = params
|
|
293
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
294
|
+
const values: any[] = cellValue || []
|
|
295
|
+
const labels: any[] = []
|
|
296
|
+
matchCascaderData(0, props.options, values, labels)
|
|
297
|
+
return (props.showAllLevels === false ? labels.slice(labels.length - 1, labels.length) : labels).join(` ${props.separator || '/'} `)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
function getDatePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderTableCellParams | VxeGlobalRendererHandles.ExportMethodParams) {
|
|
301
|
+
const { props = {} } = renderOpts
|
|
302
|
+
const { row, column } = params
|
|
303
|
+
const { rangeSeparator = '-' } = props
|
|
304
|
+
let cellValue = XEUtils.get(row, column.field)
|
|
305
|
+
switch (props.type) {
|
|
306
|
+
case 'week':
|
|
307
|
+
cellValue = getFormatDate(cellValue, props, 'YYYYwWW')
|
|
308
|
+
break
|
|
309
|
+
case 'month':
|
|
310
|
+
cellValue = getFormatDate(cellValue, props, 'YYYY-MM')
|
|
311
|
+
break
|
|
312
|
+
case 'year':
|
|
313
|
+
cellValue = getFormatDate(cellValue, props, 'YYYY')
|
|
314
|
+
break
|
|
315
|
+
case 'dates':
|
|
316
|
+
cellValue = getFormatDates(cellValue, props, ', ', 'YYYY-MM-DD')
|
|
317
|
+
break
|
|
318
|
+
case 'daterange':
|
|
319
|
+
cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD')
|
|
320
|
+
break
|
|
321
|
+
case 'datetimerange':
|
|
322
|
+
cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM-DD HH:ss:mm')
|
|
323
|
+
break
|
|
324
|
+
case 'monthrange':
|
|
325
|
+
cellValue = getFormatDates(cellValue, props, ` ${rangeSeparator} `, 'YYYY-MM')
|
|
326
|
+
break
|
|
327
|
+
default:
|
|
328
|
+
cellValue = getFormatDate(cellValue, props, 'YYYY-MM-DD')
|
|
329
|
+
}
|
|
330
|
+
return cellValue
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
function getTimePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderTableCellParams | VxeGlobalRendererHandles.RenderTableEditParams) {
|
|
334
|
+
const { props = {} } = renderOpts
|
|
335
|
+
const { row, column } = params
|
|
336
|
+
const { isRange, format = 'HH:mm:ss', rangeSeparator = '-' } = props
|
|
337
|
+
let cellValue = XEUtils.get(row, column.field)
|
|
338
|
+
if (cellValue && isRange) {
|
|
339
|
+
cellValue = XEUtils.map(cellValue, (date) => toDayDateString(parseDate(date, props), format)).join(` ${rangeSeparator} `)
|
|
340
|
+
}
|
|
341
|
+
return toDayDateString(parseDate(cellValue, props), format)
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function createEditRender (defaultProps?: { [key: string]: any }) {
|
|
345
|
+
return function (renderOpts: VxeColumnPropTypes.EditRender & { name: string }, params: VxeGlobalRendererHandles.RenderTableEditParams) {
|
|
346
|
+
const { row, column } = params
|
|
347
|
+
const { name, attrs, props } = renderOpts
|
|
348
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
349
|
+
return [
|
|
350
|
+
h(getCurrComponent(name), {
|
|
351
|
+
...attrs,
|
|
352
|
+
...props,
|
|
353
|
+
...getCellEditFilterProps(renderOpts, params, cellValue, defaultProps),
|
|
354
|
+
...getEditOns(renderOpts, params)
|
|
355
|
+
})
|
|
356
|
+
]
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function defaultButtonEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderTableEditParams) {
|
|
361
|
+
const { attrs, props } = renderOpts
|
|
362
|
+
return [
|
|
363
|
+
h(getCurrComponent('el-button'), {
|
|
364
|
+
...attrs,
|
|
365
|
+
...props,
|
|
366
|
+
...getCellEditFilterProps(renderOpts, params, null),
|
|
367
|
+
...getComponentOns(renderOpts, params)
|
|
368
|
+
}, cellText(renderOpts.content))
|
|
369
|
+
]
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
function defaultButtonsEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderTableEditParams) {
|
|
373
|
+
const { children } = renderOpts
|
|
374
|
+
if (children) {
|
|
375
|
+
return children.map((childRenderOpts: VxeColumnPropTypes.EditRender) => defaultButtonEditRender(childRenderOpts, params)[0])
|
|
376
|
+
}
|
|
377
|
+
return []
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
function createFilterRender (defaultProps?: { [key: string]: any }) {
|
|
381
|
+
return function (renderOpts: VxeColumnPropTypes.FilterRender & { name: string }, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
|
|
382
|
+
const { column } = params
|
|
383
|
+
const { name, attrs, props } = renderOpts
|
|
384
|
+
return [
|
|
385
|
+
h('div', {
|
|
386
|
+
class: 'vxe-table--filter-element-wrapper'
|
|
387
|
+
}, column.filters.map((option, oIndex) => {
|
|
388
|
+
const optionValue = option.data
|
|
389
|
+
return h(getCurrComponent(name), {
|
|
390
|
+
key: oIndex,
|
|
391
|
+
...attrs,
|
|
392
|
+
...props,
|
|
393
|
+
...getCellEditFilterProps(renderOpts, params, optionValue, defaultProps),
|
|
394
|
+
...getFilterOns(renderOpts, params, option, () => {
|
|
395
|
+
// 处理 change 事件相关逻辑
|
|
396
|
+
handleConfirmFilter(params, !!option.data, option)
|
|
397
|
+
})
|
|
398
|
+
})
|
|
399
|
+
}))
|
|
400
|
+
]
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
function createFloatingFilterRender (defaultProps?: { [key: string]: any }) {
|
|
405
|
+
return function (renderOpts: VxeGlobalRendererHandles.RenderTableFloatingFilterOptions & { name: string }, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
|
|
406
|
+
const { option } = params
|
|
407
|
+
const { name, attrs, props } = renderOpts
|
|
408
|
+
const optionValue = option.data
|
|
409
|
+
return [
|
|
410
|
+
h(getCurrComponent(name), {
|
|
411
|
+
...attrs,
|
|
412
|
+
...props,
|
|
413
|
+
...getCellEditFilterProps(renderOpts, params, optionValue, defaultProps),
|
|
414
|
+
...getFloatingFilterOns(renderOpts, params, option)
|
|
415
|
+
})
|
|
416
|
+
]
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
function handleConfirmFilter (params: VxeGlobalRendererHandles.RenderTableFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
|
|
421
|
+
const { $panel } = params
|
|
422
|
+
$panel.changeOption(null, checked, option)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/**
|
|
426
|
+
* 模糊匹配
|
|
427
|
+
* @param params
|
|
428
|
+
*/
|
|
429
|
+
function defaultFuzzyFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
|
|
430
|
+
const { option, row, column } = params
|
|
431
|
+
const { data } = option
|
|
432
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
433
|
+
return XEUtils.toValueString(cellValue).indexOf(data) > -1
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* 精确匹配
|
|
438
|
+
* @param params
|
|
439
|
+
*/
|
|
440
|
+
function defaultExactFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
|
|
441
|
+
const { option, row, column } = params
|
|
442
|
+
const { data } = option
|
|
443
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
444
|
+
/* eslint-disable eqeqeq */
|
|
445
|
+
return cellValue === data
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
function renderOptions (options: any[], optionProps: VxeGlobalRendererHandles.RenderOptionProps) {
|
|
449
|
+
const labelProp = optionProps.label || 'label'
|
|
450
|
+
const valueProp = optionProps.value || 'value'
|
|
451
|
+
return XEUtils.map(options, (item, oIndex) => {
|
|
452
|
+
return h(getCurrComponent('el-option'), {
|
|
453
|
+
key: oIndex,
|
|
454
|
+
value: item[valueProp],
|
|
455
|
+
label: item[labelProp],
|
|
456
|
+
disabled: item.disabled
|
|
457
|
+
})
|
|
458
|
+
})
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
function cellText (cellValue: any): string[] {
|
|
462
|
+
return [formatText(cellValue)]
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
function createExportMethod (getExportCellValue: Function) {
|
|
466
|
+
return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
|
|
467
|
+
const { row, column, options } = params
|
|
468
|
+
return options && options.original ? XEUtils.get(row, column.field) : getExportCellValue(column.editRender || column.cellRender, params)
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
function defaultFilterOptions () {
|
|
473
|
+
return [
|
|
474
|
+
{ data: null }
|
|
475
|
+
]
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
VxeUI.renderer.mixin({
|
|
479
|
+
ElAutocomplete: {
|
|
480
|
+
tableAutoFocus: 'input',
|
|
481
|
+
renderTableDefault: createEditRender(),
|
|
482
|
+
renderTableEdit: createEditRender(),
|
|
483
|
+
createTableFilterOptions: defaultFilterOptions,
|
|
484
|
+
renderTableFilter: createFilterRender(),
|
|
485
|
+
tableFilterDefaultMethod: defaultExactFilterMethod
|
|
486
|
+
},
|
|
487
|
+
ElInput: {
|
|
488
|
+
tableAutoFocus: 'input',
|
|
489
|
+
renderTableDefault: createEditRender(),
|
|
490
|
+
renderTableEdit: createEditRender(),
|
|
491
|
+
createTableFilterOptions: defaultFilterOptions,
|
|
492
|
+
renderTableFilter: createFilterRender(),
|
|
493
|
+
renderTableFloatingFilter: createFloatingFilterRender(),
|
|
494
|
+
tableFilterDefaultMethod: defaultFuzzyFilterMethod
|
|
495
|
+
},
|
|
496
|
+
ElInputNumber: {
|
|
497
|
+
tableAutoFocus: 'input',
|
|
498
|
+
renderTableDefault: createEditRender(),
|
|
499
|
+
renderTableEdit: createEditRender(),
|
|
500
|
+
createTableFilterOptions: defaultFilterOptions,
|
|
501
|
+
renderTableFilter: createFilterRender(),
|
|
502
|
+
renderTableFloatingFilter: createFloatingFilterRender(),
|
|
503
|
+
tableFilterDefaultMethod: defaultFuzzyFilterMethod
|
|
504
|
+
},
|
|
505
|
+
ElSelect: {
|
|
506
|
+
tableAutoFocus: 'input',
|
|
507
|
+
renderTableEdit (renderOpts, params) {
|
|
508
|
+
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
|
|
509
|
+
const { row, column } = params
|
|
510
|
+
const { attrs } = renderOpts
|
|
511
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
512
|
+
const props = getCellEditFilterProps(renderOpts, params, cellValue)
|
|
513
|
+
const ons = getEditOns(renderOpts, params)
|
|
514
|
+
if (optionGroups) {
|
|
515
|
+
const groupOptions = optionGroupProps.options || 'options'
|
|
516
|
+
const groupLabel = optionGroupProps.label || 'label'
|
|
517
|
+
return [
|
|
518
|
+
h(getCurrComponent('el-select') as ComponentOptions, {
|
|
519
|
+
...attrs,
|
|
520
|
+
...props,
|
|
521
|
+
...ons
|
|
522
|
+
}, {
|
|
523
|
+
default: () => {
|
|
524
|
+
return XEUtils.map(optionGroups, (group, gIndex) => {
|
|
525
|
+
return h(getCurrComponent('el-option-group') as ComponentOptions, {
|
|
526
|
+
key: gIndex,
|
|
527
|
+
label: group[groupLabel]
|
|
528
|
+
}, {
|
|
529
|
+
default: () => renderOptions(group[groupOptions], optionProps)
|
|
530
|
+
})
|
|
531
|
+
})
|
|
532
|
+
}
|
|
533
|
+
})
|
|
534
|
+
]
|
|
535
|
+
}
|
|
536
|
+
return [
|
|
537
|
+
h(getCurrComponent('el-select') as ComponentOptions, {
|
|
538
|
+
...props,
|
|
539
|
+
...attrs,
|
|
540
|
+
...ons
|
|
541
|
+
}, {
|
|
542
|
+
default: () => renderOptions(options, optionProps)
|
|
543
|
+
})
|
|
544
|
+
]
|
|
545
|
+
},
|
|
546
|
+
renderTableCell (renderOpts, renderParams) {
|
|
547
|
+
const { options, optionGroups } = renderOpts
|
|
548
|
+
const { $table, row, column } = renderParams
|
|
549
|
+
const opSize = options ? options.length : null
|
|
550
|
+
const ogSize = optionGroups ? optionGroups.length : null
|
|
551
|
+
if ($table.effectCellData) {
|
|
552
|
+
const { cellResult } = $table.effectCellData(row, column, {
|
|
553
|
+
key: 'render_table_cell',
|
|
554
|
+
isChanged ({ oldValue, cellValue }) {
|
|
555
|
+
return oldValue && oldValue[0] === cellValue && oldValue[1] === opSize && oldValue[2] === ogSize
|
|
556
|
+
},
|
|
557
|
+
setValue ({ cellValue }) {
|
|
558
|
+
return [cellValue, opSize, ogSize]
|
|
559
|
+
},
|
|
560
|
+
getResult ({ cellValue }) {
|
|
561
|
+
return handleSelectCellValue(cellValue, renderOpts, renderParams)
|
|
562
|
+
}
|
|
563
|
+
})
|
|
564
|
+
return getCellLabelVNs(renderOpts, renderParams, cellResult)
|
|
565
|
+
}
|
|
566
|
+
const cellResult = getSelectCellValue(renderOpts, renderParams)
|
|
567
|
+
return getCellLabelVNs(renderOpts, renderParams, cellResult)
|
|
568
|
+
},
|
|
569
|
+
createTableFilterOptions: defaultFilterOptions,
|
|
570
|
+
renderTableFilter (renderOpts, params) {
|
|
571
|
+
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts
|
|
572
|
+
const groupOptions = optionGroupProps.options || 'options'
|
|
573
|
+
const groupLabel = optionGroupProps.label || 'label'
|
|
574
|
+
const { column } = params
|
|
575
|
+
const { attrs } = renderOpts
|
|
576
|
+
return [
|
|
577
|
+
h('div', {
|
|
578
|
+
class: 'vxe-table--filter-element-wrapper'
|
|
579
|
+
}, optionGroups
|
|
580
|
+
? column.filters.map((option, oIndex) => {
|
|
581
|
+
const optionValue = option.data
|
|
582
|
+
const props = getCellEditFilterProps(renderOpts, params, optionValue)
|
|
583
|
+
return h(getCurrComponent('el-select') as ComponentOptions, {
|
|
584
|
+
key: oIndex,
|
|
585
|
+
...attrs,
|
|
586
|
+
...props,
|
|
587
|
+
...getFilterOns(renderOpts, params, option, () => {
|
|
588
|
+
// 处理 change 事件相关逻辑
|
|
589
|
+
handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
|
|
590
|
+
})
|
|
591
|
+
}, {
|
|
592
|
+
default: () => {
|
|
593
|
+
return XEUtils.map(optionGroups, (group, gIndex) => {
|
|
594
|
+
return h(getCurrComponent('el-option-group') as ComponentOptions, {
|
|
595
|
+
key: gIndex,
|
|
596
|
+
label: group[groupLabel]
|
|
597
|
+
}, {
|
|
598
|
+
default: () => renderOptions(group[groupOptions], optionProps)
|
|
599
|
+
})
|
|
600
|
+
})
|
|
601
|
+
}
|
|
602
|
+
})
|
|
603
|
+
})
|
|
604
|
+
: column.filters.map((option, oIndex) => {
|
|
605
|
+
const optionValue = option.data
|
|
606
|
+
const props = getCellEditFilterProps(renderOpts, params, optionValue)
|
|
607
|
+
return h(getCurrComponent('el-select') as ComponentOptions, {
|
|
608
|
+
key: oIndex,
|
|
609
|
+
...attrs,
|
|
610
|
+
...props,
|
|
611
|
+
...getFilterOns(renderOpts, params, option, () => {
|
|
612
|
+
// 处理 change 事件相关逻辑
|
|
613
|
+
handleConfirmFilter(params, props.multiple ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
|
|
614
|
+
})
|
|
615
|
+
}, {
|
|
616
|
+
default: () => renderOptions(options, optionProps)
|
|
617
|
+
})
|
|
618
|
+
}))
|
|
619
|
+
]
|
|
620
|
+
},
|
|
621
|
+
tableFilterDefaultMethod (params) {
|
|
622
|
+
const { option, row, column } = params
|
|
623
|
+
const { data } = option
|
|
624
|
+
const { field, filterRender: renderOpts } = column
|
|
625
|
+
const { props = {} } = renderOpts
|
|
626
|
+
const cellValue = XEUtils.get(row, field)
|
|
627
|
+
if (props.multiple) {
|
|
628
|
+
if (XEUtils.isArray(cellValue)) {
|
|
629
|
+
return XEUtils.includeArrays(cellValue, data)
|
|
630
|
+
}
|
|
631
|
+
return data.indexOf(cellValue) > -1
|
|
632
|
+
}
|
|
633
|
+
/* eslint-disable eqeqeq */
|
|
634
|
+
return cellValue == data
|
|
635
|
+
},
|
|
636
|
+
tableExportMethod: createExportMethod(getSelectCellValue)
|
|
637
|
+
},
|
|
638
|
+
ElCascader: {
|
|
639
|
+
tableAutoFocus: 'input',
|
|
640
|
+
renderTableEdit: createEditRender(),
|
|
641
|
+
renderTableCell (renderOpts, params) {
|
|
642
|
+
return getCellLabelVNs(renderOpts, params, getCascaderCellValue(renderOpts, params))
|
|
643
|
+
},
|
|
644
|
+
tableExportMethod: createExportMethod(getCascaderCellValue)
|
|
645
|
+
},
|
|
646
|
+
ElDatePicker: {
|
|
647
|
+
tableAutoFocus: 'input',
|
|
648
|
+
renderTableEdit: createEditRender(),
|
|
649
|
+
renderTableCell (renderOpts, params) {
|
|
650
|
+
return getCellLabelVNs(renderOpts, params, getDatePickerCellValue(renderOpts, params))
|
|
651
|
+
},
|
|
652
|
+
createTableFilterOptions: defaultFilterOptions,
|
|
653
|
+
renderTableFilter (renderOpts, params) {
|
|
654
|
+
const { column } = params
|
|
655
|
+
const { name, attrs } = renderOpts
|
|
656
|
+
return [
|
|
657
|
+
h('div', {
|
|
658
|
+
class: 'vxe-table--filter-element-wrapper'
|
|
659
|
+
}, column.filters.map((option, oIndex) => {
|
|
660
|
+
const optionValue = option.data
|
|
661
|
+
return h(getCurrComponent(name as string), {
|
|
662
|
+
key: oIndex,
|
|
663
|
+
...attrs,
|
|
664
|
+
...getCellEditFilterProps(renderOpts, params, optionValue),
|
|
665
|
+
...getFilterOns(renderOpts, params, option, () => {
|
|
666
|
+
// 处理 change 事件相关逻辑
|
|
667
|
+
handleConfirmFilter(params, !!option.data, option)
|
|
668
|
+
})
|
|
669
|
+
})
|
|
670
|
+
}))
|
|
671
|
+
]
|
|
672
|
+
},
|
|
673
|
+
renderTableFloatingFilter: createFloatingFilterRender(),
|
|
674
|
+
tableFilterDefaultMethod (params) {
|
|
675
|
+
const { option, row, column } = params
|
|
676
|
+
const { data } = option
|
|
677
|
+
const { filterRender: renderOpts } = column
|
|
678
|
+
const { props = {} } = renderOpts
|
|
679
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
680
|
+
if (data) {
|
|
681
|
+
switch (props.type) {
|
|
682
|
+
case 'daterange':
|
|
683
|
+
return equalDateRange(cellValue, data, props, 'YYYY-MM-DD')
|
|
684
|
+
case 'datetimerange':
|
|
685
|
+
return equalDateRange(cellValue, data, props, 'YYYY-MM-DD HH:ss:mm')
|
|
686
|
+
case 'monthrange':
|
|
687
|
+
return equalDateRange(cellValue, data, props, 'YYYY-MM')
|
|
688
|
+
default:
|
|
689
|
+
return cellValue === data
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return false
|
|
693
|
+
},
|
|
694
|
+
tableExportMethod: createExportMethod(getDatePickerCellValue)
|
|
695
|
+
},
|
|
696
|
+
ElTimePicker: {
|
|
697
|
+
tableAutoFocus: 'input',
|
|
698
|
+
renderTableEdit: createEditRender(),
|
|
699
|
+
renderTableCell (renderOpts, params) {
|
|
700
|
+
return getCellLabelVNs(renderOpts, params, getTimePickerCellValue(renderOpts, params))
|
|
701
|
+
},
|
|
702
|
+
tableExportMethod: createExportMethod(getTimePickerCellValue)
|
|
703
|
+
},
|
|
704
|
+
ElTimeSelect: {
|
|
705
|
+
tableAutoFocus: 'input',
|
|
706
|
+
renderTableEdit: createEditRender()
|
|
707
|
+
},
|
|
708
|
+
ElRate: {
|
|
709
|
+
renderTableDefault: createEditRender(),
|
|
710
|
+
renderTableEdit: createEditRender(),
|
|
711
|
+
createTableFilterOptions: defaultFilterOptions,
|
|
712
|
+
renderTableFilter: createFilterRender(),
|
|
713
|
+
tableFilterDefaultMethod: defaultExactFilterMethod
|
|
714
|
+
},
|
|
715
|
+
ElSwitch: {
|
|
716
|
+
renderTableDefault: createEditRender(),
|
|
717
|
+
renderTableEdit: createEditRender(),
|
|
718
|
+
renderTableFilter (renderOpts, params) {
|
|
719
|
+
const { column } = params
|
|
720
|
+
const { name, attrs } = renderOpts
|
|
721
|
+
return [
|
|
722
|
+
h('div', {
|
|
723
|
+
class: 'vxe-table--filter-element-wrapper'
|
|
724
|
+
}, column.filters.map((option, oIndex) => {
|
|
725
|
+
const optionValue = option.data
|
|
726
|
+
return h(getCurrComponent(name as string), {
|
|
727
|
+
key: oIndex,
|
|
728
|
+
...attrs,
|
|
729
|
+
...getCellEditFilterProps(renderOpts, params, optionValue),
|
|
730
|
+
...getFilterOns(renderOpts, params, option, () => {
|
|
731
|
+
// 处理 change 事件相关逻辑
|
|
732
|
+
handleConfirmFilter(params, XEUtils.isBoolean(option.data), option)
|
|
733
|
+
})
|
|
734
|
+
})
|
|
735
|
+
}))
|
|
736
|
+
]
|
|
737
|
+
},
|
|
738
|
+
tableFilterDefaultMethod: defaultExactFilterMethod
|
|
739
|
+
},
|
|
740
|
+
ElSlider: {
|
|
741
|
+
renderTableDefault: createEditRender(),
|
|
742
|
+
renderTableEdit: createEditRender(),
|
|
743
|
+
createTableFilterOptions: defaultFilterOptions,
|
|
744
|
+
renderTableFilter: createFilterRender(),
|
|
745
|
+
tableFilterDefaultMethod: defaultExactFilterMethod
|
|
746
|
+
},
|
|
747
|
+
ElButton: {
|
|
748
|
+
renderTableDefault: defaultButtonEditRender
|
|
749
|
+
},
|
|
750
|
+
ElButtons: {
|
|
751
|
+
renderTableDefault: defaultButtonsEditRender
|
|
752
|
+
}
|
|
753
|
+
})
|
|
754
|
+
}
|