@vxe-ui/plugin-render-antd 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 +151 -0
- package/dist/all.common.js +978 -0
- package/dist/form/index.js +342 -0
- package/dist/index.common.js +67 -0
- package/dist/index.js +67 -0
- package/dist/index.umd.js +1130 -0
- package/dist/index.umd.min.js +1 -0
- package/dist/style.css +76 -0
- package/dist/style.min.css +1 -0
- package/dist/table/index.js +565 -0
- package/package.json +73 -0
- package/src/form/index.ts +330 -0
- package/src/index.ts +69 -0
- package/src/table/index.ts +556 -0
- package/types/index.d.ts +12 -0
|
@@ -0,0 +1,556 @@
|
|
|
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
|
+
let prop = 'value'
|
|
20
|
+
switch (renderOpts.name) {
|
|
21
|
+
case 'ASwitch':
|
|
22
|
+
prop = 'checked'
|
|
23
|
+
break
|
|
24
|
+
}
|
|
25
|
+
return prop
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getModelEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
29
|
+
let type = 'change'
|
|
30
|
+
switch (renderOpts.name) {
|
|
31
|
+
case 'AInput':
|
|
32
|
+
type = 'change.value'
|
|
33
|
+
break
|
|
34
|
+
case 'ARadio':
|
|
35
|
+
case 'ACheckbox':
|
|
36
|
+
type = 'input'
|
|
37
|
+
break
|
|
38
|
+
}
|
|
39
|
+
return type
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function dateFormatToVxeFormat (format: string) {
|
|
43
|
+
if (format) {
|
|
44
|
+
return `${format}`.replace('YYYY', 'yyyy').replace('DD', 'dd')
|
|
45
|
+
}
|
|
46
|
+
return format
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
50
|
+
return 'change'
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function getCellEditFilterProps (renderOpts: any, params: VxeGlobalRendererHandles.RenderEditParams | VxeGlobalRendererHandles.RenderFilterParams, value: any, defaultProps?: { [prop: string]: any }) {
|
|
54
|
+
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function formatText (cellValue: any) {
|
|
58
|
+
return '' + (isEmptyValue(cellValue) ? '' : cellValue)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function getCellLabelVNs (h: CreateElement, renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams, cellLabel: any) {
|
|
62
|
+
const { placeholder } = renderOpts
|
|
63
|
+
return [
|
|
64
|
+
h('span', {
|
|
65
|
+
class: 'vxe-cell--label'
|
|
66
|
+
}, placeholder && isEmptyValue(cellLabel)
|
|
67
|
+
? [
|
|
68
|
+
h('span', {
|
|
69
|
+
class: 'vxe-cell--placeholder'
|
|
70
|
+
}, formatText(placeholder))
|
|
71
|
+
]
|
|
72
|
+
: formatText(cellLabel))
|
|
73
|
+
]
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderParams, inputFunc?: Function, changeFunc?: Function) {
|
|
77
|
+
const { events } = renderOpts
|
|
78
|
+
const modelEvent = getModelEvent(renderOpts)
|
|
79
|
+
const changeEvent = getChangeEvent(renderOpts)
|
|
80
|
+
const isSameEvent = changeEvent === modelEvent
|
|
81
|
+
const ons: { [type: string]: Function } = {}
|
|
82
|
+
XEUtils.objectEach(events, (func: Function, key: string) => {
|
|
83
|
+
ons[getOnName(key)] = function (...args: any[]) {
|
|
84
|
+
func(params, ...args)
|
|
85
|
+
}
|
|
86
|
+
})
|
|
87
|
+
if (inputFunc) {
|
|
88
|
+
ons[getOnName(modelEvent)] = function (targetEvnt: any) {
|
|
89
|
+
inputFunc(targetEvnt)
|
|
90
|
+
if (events && events[modelEvent]) {
|
|
91
|
+
events[modelEvent](params, targetEvnt)
|
|
92
|
+
}
|
|
93
|
+
if (isSameEvent && changeFunc) {
|
|
94
|
+
changeFunc(targetEvnt)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!isSameEvent && changeFunc) {
|
|
99
|
+
ons[getOnName(changeEvent)] = function (...args: any[]) {
|
|
100
|
+
changeFunc(...args)
|
|
101
|
+
if (events && events[changeEvent]) {
|
|
102
|
+
events[changeEvent](params, ...args)
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return ons
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderEditParams) {
|
|
110
|
+
const { $table, row, column } = params
|
|
111
|
+
return getOns(renderOpts, params, (value: any) => {
|
|
112
|
+
// 处理 model 值双向绑定
|
|
113
|
+
XEUtils.set(row, column.field, value)
|
|
114
|
+
}, () => {
|
|
115
|
+
// 处理 change 事件相关逻辑
|
|
116
|
+
$table.updateStatus(params)
|
|
117
|
+
})
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function getFilterOns (renderOpts: any, params: VxeGlobalRendererHandles.RenderFilterParams, option: VxeTableDefines.FilterOption, changeFunc: Function) {
|
|
121
|
+
return getOns(renderOpts, params, (value: any) => {
|
|
122
|
+
// 处理 model 值双向绑定
|
|
123
|
+
option.data = value
|
|
124
|
+
}, changeFunc)
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function matchCascaderData (index: number, list: any[], values: any[], labels: any[]) {
|
|
128
|
+
const val = values[index]
|
|
129
|
+
if (list && values.length > index) {
|
|
130
|
+
XEUtils.each(list, (item) => {
|
|
131
|
+
if (item.value === val) {
|
|
132
|
+
labels.push(item.label)
|
|
133
|
+
matchCascaderData(++index, item.children, values, labels)
|
|
134
|
+
}
|
|
135
|
+
})
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function formatDatePicker (defaultFormat?: string) {
|
|
140
|
+
return function (h: CreateElement, renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
|
|
141
|
+
return getCellLabelVNs(h, renderOpts, params, getDatePickerCellValue(renderOpts, params, defaultFormat))
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function formatTimePicker (defaultFormat?: string) {
|
|
146
|
+
return function (h: CreateElement, renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
|
|
147
|
+
const { props = {} } = renderOpts
|
|
148
|
+
const { row, column } = params
|
|
149
|
+
let cellValue = XEUtils.get(row, column.field)
|
|
150
|
+
try {
|
|
151
|
+
if (cellValue) {
|
|
152
|
+
if (!XEUtils.isString(cellValue)) {
|
|
153
|
+
cellValue = cellValue.format ? cellValue.format(props.format || props.valueFormat || defaultFormat) : XEUtils.toDateString(cellValue, dateFormatToVxeFormat(props.format || props.valueFormat || defaultFormat))
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
} catch (e) {}
|
|
157
|
+
return getCellLabelVNs(h, renderOpts, params, cellValue)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function getSelectCellValue (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
|
|
162
|
+
const { options = [], optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
|
|
163
|
+
const { row, column } = params
|
|
164
|
+
const labelProp = optionProps.label || 'label'
|
|
165
|
+
const valueProp = optionProps.value || 'value'
|
|
166
|
+
const groupOptions = optionGroupProps.options || 'options'
|
|
167
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
168
|
+
if (!isEmptyValue(cellValue)) {
|
|
169
|
+
return XEUtils.map(props.mode === 'multiple' ? cellValue : [cellValue], optionGroups
|
|
170
|
+
? (value) => {
|
|
171
|
+
let selectItem
|
|
172
|
+
for (let index = 0; index < optionGroups.length; index++) {
|
|
173
|
+
selectItem = XEUtils.find(optionGroups[index][groupOptions], (item) => item[valueProp] === value)
|
|
174
|
+
if (selectItem) {
|
|
175
|
+
break
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return selectItem ? selectItem[labelProp] : value
|
|
179
|
+
}
|
|
180
|
+
: (value) => {
|
|
181
|
+
const selectItem = XEUtils.find(options, (item) => item[valueProp] === value)
|
|
182
|
+
return selectItem ? selectItem[labelProp] : value
|
|
183
|
+
}).join(', ')
|
|
184
|
+
}
|
|
185
|
+
return ''
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function getCascaderCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.ExportMethodParams) {
|
|
189
|
+
const { props = {} } = renderOpts
|
|
190
|
+
const { row, column } = params
|
|
191
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
192
|
+
const values = cellValue || []
|
|
193
|
+
const labels: Array<any> = []
|
|
194
|
+
matchCascaderData(0, props.options, values, labels)
|
|
195
|
+
return (props.showAllLevels === false ? labels.slice(labels.length - 1, labels.length) : labels).join(` ${props.separator || '/'} `)
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function getRangePickerCellValue (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.RenderEditParams) {
|
|
199
|
+
const { props = {} } = renderOpts
|
|
200
|
+
const { row, column } = params
|
|
201
|
+
let cellValue = XEUtils.get(row, column.field)
|
|
202
|
+
if (cellValue) {
|
|
203
|
+
cellValue = XEUtils.map(cellValue, (date: any) => {
|
|
204
|
+
return date && date.format ? date.format(props.format || 'YYYY-MM-DD') : XEUtils.toDateString(date, dateFormatToVxeFormat(props.format || 'YYYY-MM-DD'))
|
|
205
|
+
}).join(' ~ ')
|
|
206
|
+
}
|
|
207
|
+
return cellValue
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function getTreeSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.RenderEditParams) {
|
|
211
|
+
const { props = {} } = renderOpts
|
|
212
|
+
const { treeData, treeCheckable } = props
|
|
213
|
+
const { row, column } = params
|
|
214
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
215
|
+
if (!isEmptyValue(cellValue)) {
|
|
216
|
+
return XEUtils.map(treeCheckable ? cellValue : [cellValue], (value) => {
|
|
217
|
+
const matchObj = XEUtils.findTree(treeData, (item: any) => item.value === value, { children: 'children' })
|
|
218
|
+
return matchObj ? matchObj.item.title : value
|
|
219
|
+
}).join(', ')
|
|
220
|
+
}
|
|
221
|
+
return cellValue
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function getDatePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.ExportMethodParams, defaultFormat?: string) {
|
|
225
|
+
const { props = {} } = renderOpts
|
|
226
|
+
const { row, column } = params
|
|
227
|
+
let cellValue = XEUtils.get(row, column.field)
|
|
228
|
+
try {
|
|
229
|
+
if (cellValue) {
|
|
230
|
+
if (!defaultFormat) {
|
|
231
|
+
if (renderOpts.name === 'ADatePicker') {
|
|
232
|
+
switch (props.picker) {
|
|
233
|
+
case 'week':
|
|
234
|
+
defaultFormat = 'YYYY-WW周'
|
|
235
|
+
break
|
|
236
|
+
case 'month':
|
|
237
|
+
defaultFormat = 'YYYY-MM'
|
|
238
|
+
break
|
|
239
|
+
case 'year':
|
|
240
|
+
defaultFormat = 'YYYY'
|
|
241
|
+
break
|
|
242
|
+
default:
|
|
243
|
+
defaultFormat = props.showTime ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD'
|
|
244
|
+
break
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
cellValue = cellValue.format ? cellValue.format(props.format || defaultFormat) : XEUtils.toDateString(cellValue, dateFormatToVxeFormat(props.format || defaultFormat))
|
|
249
|
+
}
|
|
250
|
+
} catch (e) {}
|
|
251
|
+
return cellValue
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function createEditRender (defaultProps?: { [key: string]: any }) {
|
|
255
|
+
return function (h: CreateElement, renderOpts: VxeColumnPropTypes.EditRender & { name: string }, params: VxeGlobalRendererHandles.RenderEditParams) {
|
|
256
|
+
const { row, column } = params
|
|
257
|
+
const { name, attrs } = renderOpts
|
|
258
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
259
|
+
return [
|
|
260
|
+
h(name, {
|
|
261
|
+
attrs,
|
|
262
|
+
props: getCellEditFilterProps(renderOpts, params, cellValue, defaultProps),
|
|
263
|
+
on: getEditOns(renderOpts, params)
|
|
264
|
+
})
|
|
265
|
+
]
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function defaultButtonEditRender (h: CreateElement, renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
|
|
270
|
+
const { attrs } = renderOpts
|
|
271
|
+
return [
|
|
272
|
+
h('a-button', {
|
|
273
|
+
attrs,
|
|
274
|
+
props: getCellEditFilterProps(renderOpts, params, null),
|
|
275
|
+
on: getOns(renderOpts, params)
|
|
276
|
+
}, cellText(renderOpts.content))
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function defaultButtonsEditRender (h: CreateElement, renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
|
|
281
|
+
const { children } = renderOpts
|
|
282
|
+
if (children) {
|
|
283
|
+
return children.map((childRenderOpts: VxeColumnPropTypes.EditRender) => defaultButtonEditRender(h, childRenderOpts, params)[0])
|
|
284
|
+
}
|
|
285
|
+
return []
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
function createFilterRender (defaultProps?: { [key: string]: any }) {
|
|
289
|
+
return function (h: CreateElement, renderOpts: VxeColumnPropTypes.FilterRender & { name: string }, params: VxeGlobalRendererHandles.RenderFilterParams) {
|
|
290
|
+
const { column } = params
|
|
291
|
+
const { name, attrs } = renderOpts
|
|
292
|
+
return [
|
|
293
|
+
h('div', {
|
|
294
|
+
class: 'vxe-table--filter-antd-wrapper'
|
|
295
|
+
}, column.filters.map((option, oIndex) => {
|
|
296
|
+
const optionValue = option.data
|
|
297
|
+
return h(name, {
|
|
298
|
+
key: oIndex,
|
|
299
|
+
attrs,
|
|
300
|
+
props: {
|
|
301
|
+
...getCellEditFilterProps(renderOpts, params, optionValue, defaultProps)
|
|
302
|
+
},
|
|
303
|
+
on: getFilterOns(renderOpts, params, option, () => {
|
|
304
|
+
// 处理 change 事件相关逻辑
|
|
305
|
+
handleConfirmFilter(params, !!option.data, option)
|
|
306
|
+
})
|
|
307
|
+
})
|
|
308
|
+
}))
|
|
309
|
+
]
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
function handleConfirmFilter (params: VxeGlobalRendererHandles.RenderFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
|
|
314
|
+
const { $panel } = params
|
|
315
|
+
$panel.changeOption(null, checked, option)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* 模糊匹配
|
|
320
|
+
* @param params
|
|
321
|
+
*/
|
|
322
|
+
function defaultFuzzyFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
|
|
323
|
+
const { option, row, column } = params
|
|
324
|
+
const { data } = option
|
|
325
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
326
|
+
return XEUtils.toValueString(cellValue).indexOf(data) > -1
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
* 精确匹配
|
|
331
|
+
* @param params
|
|
332
|
+
*/
|
|
333
|
+
function defaultExactFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
|
|
334
|
+
const { option, row, column } = params
|
|
335
|
+
const { data } = option
|
|
336
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
337
|
+
/* eslint-disable eqeqeq */
|
|
338
|
+
return cellValue === data
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
function cellText (cellValue: any): string[] {
|
|
342
|
+
return [formatText(cellValue)]
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
function createDatePickerExportMethod (defaultFormat?: string) {
|
|
346
|
+
return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
|
|
347
|
+
const { row, column, options } = params
|
|
348
|
+
return options && options.original ? XEUtils.get(row, column.field) : getDatePickerCellValue(column.editRender || column.cellRender, params, defaultFormat)
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function createExportMethod (getExportCellValue: Function) {
|
|
353
|
+
return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
|
|
354
|
+
const { row, column, options } = params
|
|
355
|
+
return options && options.original ? XEUtils.get(row, column.field) : getExportCellValue(column.editRender || column.cellRender, params)
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
VxeUI.renderer.mixin({
|
|
360
|
+
AAutoComplete: {
|
|
361
|
+
tableAutoFocus: 'input',
|
|
362
|
+
renderTableDefault: createEditRender(),
|
|
363
|
+
renderTableEdit: createEditRender(),
|
|
364
|
+
renderTableFilter: createFilterRender(),
|
|
365
|
+
tableFilterDefaultMethod: defaultFuzzyFilterMethod
|
|
366
|
+
},
|
|
367
|
+
AInput: {
|
|
368
|
+
tableAutoFocus: 'input',
|
|
369
|
+
renderTableDefault: createEditRender(),
|
|
370
|
+
renderTableEdit: createEditRender(),
|
|
371
|
+
renderTableFilter: createFilterRender(),
|
|
372
|
+
tableFilterDefaultMethod: defaultFuzzyFilterMethod
|
|
373
|
+
},
|
|
374
|
+
AInputNumber: {
|
|
375
|
+
tableAutoFocus: 'input',
|
|
376
|
+
renderTableDefault: createEditRender(),
|
|
377
|
+
renderTableEdit: createEditRender(),
|
|
378
|
+
renderTableFilter: createFilterRender(),
|
|
379
|
+
tableFilterDefaultMethod: defaultFuzzyFilterMethod
|
|
380
|
+
},
|
|
381
|
+
ASelect: {
|
|
382
|
+
renderTableEdit (h, renderOpts, params) {
|
|
383
|
+
const { options, optionGroups } = renderOpts
|
|
384
|
+
const { row, column } = params
|
|
385
|
+
const { attrs } = renderOpts
|
|
386
|
+
const cellValue = XEUtils.get(row, column.field)
|
|
387
|
+
const props = getCellEditFilterProps(renderOpts, params, cellValue)
|
|
388
|
+
const ons = getEditOns(renderOpts, params)
|
|
389
|
+
if (optionGroups) {
|
|
390
|
+
return [
|
|
391
|
+
h('a-select', {
|
|
392
|
+
attrs,
|
|
393
|
+
props: {
|
|
394
|
+
...props,
|
|
395
|
+
options: optionGroups
|
|
396
|
+
},
|
|
397
|
+
on: ons
|
|
398
|
+
})
|
|
399
|
+
]
|
|
400
|
+
}
|
|
401
|
+
return [
|
|
402
|
+
h('a-select', {
|
|
403
|
+
attrs,
|
|
404
|
+
props: {
|
|
405
|
+
...props,
|
|
406
|
+
options: props.options || options
|
|
407
|
+
},
|
|
408
|
+
on: ons
|
|
409
|
+
})
|
|
410
|
+
]
|
|
411
|
+
},
|
|
412
|
+
renderTableCell (h, renderOpts, params) {
|
|
413
|
+
return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
|
|
414
|
+
},
|
|
415
|
+
renderTableFilter (h, renderOpts, params) {
|
|
416
|
+
const { options = [], optionGroups, optionGroupProps = {} } = renderOpts
|
|
417
|
+
const groupOptions = optionGroupProps.options || 'options'
|
|
418
|
+
const { column } = params
|
|
419
|
+
const { attrs } = renderOpts
|
|
420
|
+
return [
|
|
421
|
+
h('div', {
|
|
422
|
+
class: 'vxe-table--filter-antd-wrapper'
|
|
423
|
+
}, optionGroups
|
|
424
|
+
? column.filters.map((option, oIndex) => {
|
|
425
|
+
const optionValue = option.data
|
|
426
|
+
const props = getCellEditFilterProps(renderOpts, params, optionValue)
|
|
427
|
+
return h('a-select', {
|
|
428
|
+
key: oIndex,
|
|
429
|
+
attrs,
|
|
430
|
+
props: {
|
|
431
|
+
...props,
|
|
432
|
+
options: groupOptions
|
|
433
|
+
},
|
|
434
|
+
on: getFilterOns(renderOpts, params, option, () => {
|
|
435
|
+
// 处理 change 事件相关逻辑
|
|
436
|
+
handleConfirmFilter(params, props.mode === 'multiple' ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
|
|
437
|
+
})
|
|
438
|
+
})
|
|
439
|
+
})
|
|
440
|
+
: column.filters.map((option, oIndex) => {
|
|
441
|
+
const optionValue = option.data
|
|
442
|
+
const props = getCellEditFilterProps(renderOpts, params, optionValue)
|
|
443
|
+
return h('a-select', {
|
|
444
|
+
key: oIndex,
|
|
445
|
+
attrs,
|
|
446
|
+
props: {
|
|
447
|
+
...props,
|
|
448
|
+
options: props.options || options
|
|
449
|
+
},
|
|
450
|
+
on: getFilterOns(renderOpts, params, option, () => {
|
|
451
|
+
// 处理 change 事件相关逻辑
|
|
452
|
+
handleConfirmFilter(params, props.mode === 'multiple' ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
|
|
453
|
+
})
|
|
454
|
+
})
|
|
455
|
+
}))
|
|
456
|
+
]
|
|
457
|
+
},
|
|
458
|
+
tableFilterDefaultMethod (params) {
|
|
459
|
+
const { option, row, column } = params
|
|
460
|
+
const { data } = option
|
|
461
|
+
const { field, filterRender: renderOpts } = column
|
|
462
|
+
const { props = {} } = renderOpts
|
|
463
|
+
const cellValue = XEUtils.get(row, field)
|
|
464
|
+
if (props.mode === 'multiple') {
|
|
465
|
+
if (XEUtils.isArray(cellValue)) {
|
|
466
|
+
return XEUtils.includeArrays(cellValue, data)
|
|
467
|
+
}
|
|
468
|
+
return data.indexOf(cellValue) > -1
|
|
469
|
+
}
|
|
470
|
+
/* eslint-disable eqeqeq */
|
|
471
|
+
return cellValue == data
|
|
472
|
+
},
|
|
473
|
+
tableExportMethod: createExportMethod(getSelectCellValue)
|
|
474
|
+
},
|
|
475
|
+
ACascader: {
|
|
476
|
+
renderTableEdit: createEditRender(),
|
|
477
|
+
renderTableCell (h, renderOpts, params) {
|
|
478
|
+
return getCellLabelVNs(h, renderOpts, params, getCascaderCellValue(renderOpts, params))
|
|
479
|
+
},
|
|
480
|
+
tableExportMethod: createExportMethod(getCascaderCellValue)
|
|
481
|
+
},
|
|
482
|
+
ADatePicker: {
|
|
483
|
+
renderTableEdit: createEditRender(),
|
|
484
|
+
renderTableCell: formatDatePicker(),
|
|
485
|
+
tableExportMethod: createDatePickerExportMethod()
|
|
486
|
+
},
|
|
487
|
+
AMonthPicker: {
|
|
488
|
+
renderTableEdit: createEditRender(),
|
|
489
|
+
renderTableCell: formatDatePicker('YYYY-MM'),
|
|
490
|
+
tableExportMethod: createDatePickerExportMethod('YYYY-MM')
|
|
491
|
+
},
|
|
492
|
+
ARangePicker: {
|
|
493
|
+
renderTableEdit: createEditRender(),
|
|
494
|
+
renderTableCell (h, renderOpts, params) {
|
|
495
|
+
return getCellLabelVNs(h, renderOpts, params, getRangePickerCellValue(renderOpts, params))
|
|
496
|
+
},
|
|
497
|
+
tableExportMethod: createExportMethod(getRangePickerCellValue)
|
|
498
|
+
},
|
|
499
|
+
AWeekPicker: {
|
|
500
|
+
renderTableEdit: createEditRender(),
|
|
501
|
+
renderTableCell: formatDatePicker('YYYY-WW周'),
|
|
502
|
+
tableExportMethod: createDatePickerExportMethod('YYYY-WW周')
|
|
503
|
+
},
|
|
504
|
+
ATimePicker: {
|
|
505
|
+
renderTableEdit: createEditRender(),
|
|
506
|
+
renderTableCell: formatTimePicker('HH:mm:ss'),
|
|
507
|
+
tableExportMethod: createDatePickerExportMethod('HH:mm:ss')
|
|
508
|
+
},
|
|
509
|
+
ATreeSelect: {
|
|
510
|
+
renderTableEdit: createEditRender(),
|
|
511
|
+
renderTableCell (h, renderOpts, params) {
|
|
512
|
+
return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
|
|
513
|
+
},
|
|
514
|
+
tableExportMethod: createExportMethod(getTreeSelectCellValue)
|
|
515
|
+
},
|
|
516
|
+
ARate: {
|
|
517
|
+
renderTableDefault: createEditRender(),
|
|
518
|
+
renderTableEdit: createEditRender(),
|
|
519
|
+
renderTableFilter: createFilterRender(),
|
|
520
|
+
tableFilterDefaultMethod: defaultExactFilterMethod
|
|
521
|
+
},
|
|
522
|
+
ASwitch: {
|
|
523
|
+
renderTableDefault: createEditRender(),
|
|
524
|
+
renderTableEdit: createEditRender(),
|
|
525
|
+
renderTableFilter (h, renderOpts, params) {
|
|
526
|
+
const { column } = params
|
|
527
|
+
const { name, attrs } = renderOpts
|
|
528
|
+
return [
|
|
529
|
+
h('div', {
|
|
530
|
+
class: 'vxe-table--filter-antd-wrapper'
|
|
531
|
+
}, column.filters.map((option, oIndex) => {
|
|
532
|
+
const optionValue = option.data
|
|
533
|
+
return h(name as string, {
|
|
534
|
+
key: oIndex,
|
|
535
|
+
attrs,
|
|
536
|
+
props: getCellEditFilterProps(renderOpts, params, optionValue),
|
|
537
|
+
on: getFilterOns(renderOpts, params, option, () => {
|
|
538
|
+
// 处理 change 事件相关逻辑
|
|
539
|
+
handleConfirmFilter(params, XEUtils.isBoolean(option.data), option)
|
|
540
|
+
})
|
|
541
|
+
})
|
|
542
|
+
}))
|
|
543
|
+
]
|
|
544
|
+
},
|
|
545
|
+
tableFilterDefaultMethod: defaultExactFilterMethod
|
|
546
|
+
},
|
|
547
|
+
AButton: {
|
|
548
|
+
renderTableEdit: defaultButtonEditRender,
|
|
549
|
+
renderTableDefault: defaultButtonEditRender
|
|
550
|
+
},
|
|
551
|
+
AButtons: {
|
|
552
|
+
renderTableEdit: defaultButtonsEditRender,
|
|
553
|
+
renderTableDefault: defaultButtonsEditRender
|
|
554
|
+
}
|
|
555
|
+
})
|
|
556
|
+
}
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VxeUIExport } from 'vxe-pc-ui'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 基于 Vxe UI 的适配插件,用于兼容 ant-design-vue 组件库
|
|
5
|
+
*/
|
|
6
|
+
export declare const VxeUIPluginRenderAntd: {
|
|
7
|
+
install (VxeUI: VxeUIExport, options?: {
|
|
8
|
+
Antd?: any
|
|
9
|
+
}): void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default VxeUIPluginRenderAntd
|