@vxe-ui/plugin-render-element 3.0.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 +21 -0
- package/README.md +154 -0
- package/dist/all.common.js +1136 -0
- package/dist/form/index.js +411 -0
- package/dist/index.common.js +72 -0
- package/dist/index.js +72 -0
- package/dist/index.umd.js +1288 -0
- package/dist/index.umd.min.js +1 -0
- package/dist/style.css +54 -0
- package/dist/style.min.css +1 -0
- package/dist/table/index.js +649 -0
- package/package.json +73 -0
- package/src/form/index.ts +406 -0
- package/src/index.ts +76 -0
- package/src/table/index.ts +627 -0
- package/types/index.d.ts +12 -0
|
@@ -0,0 +1,627 @@
|
|
|
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
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VxeUIExport } from 'vxe-pc-ui'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 基于 Vxe UI 的适配插件,用于兼容 element-ui 组件库
|
|
5
|
+
*/
|
|
6
|
+
export declare const VxeUIPluginRenderElement: {
|
|
7
|
+
install (VxeUI: VxeUIExport, options?: {
|
|
8
|
+
ElementPlus?: any
|
|
9
|
+
}): void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default VxeUIPluginRenderElement
|