@vxe-ui/plugin-render-antd 4.0.2 → 4.0.4
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/README.md +6 -4
- package/dist/all.common.js +2412 -0
- package/dist/form/index.js +235 -0
- package/dist/form-design/checkbox-widget.js +162 -0
- package/dist/form-design/date-picker-widget.js +143 -0
- package/dist/form-design/index.js +177 -0
- package/dist/form-design/input-widget.js +143 -0
- package/dist/form-design/number-input-widget.js +143 -0
- package/dist/form-design/radio-widget.js +162 -0
- package/dist/form-design/select-widget.js +154 -0
- package/dist/form-design/switch-widget.js +139 -0
- package/dist/form-design/textarea-widget.js +147 -0
- package/dist/form-design/use.js +225 -0
- package/dist/index.common.js +8 -607
- package/dist/index.js +69 -0
- package/dist/index.umd.js +2595 -635
- package/dist/index.umd.min.js +1 -1
- package/dist/style.css +2 -1
- package/dist/style.min.css +1 -1
- package/dist/table/index.js +499 -0
- package/package.json +6 -5
- package/src/form/index.ts +244 -0
- package/src/form-design/checkbox-widget.ts +164 -0
- package/src/form-design/date-picker-widget.ts +144 -0
- package/src/form-design/index.ts +101 -0
- package/src/form-design/input-widget.ts +144 -0
- package/src/form-design/number-input-widget.ts +144 -0
- package/src/form-design/radio-widget.ts +164 -0
- package/src/form-design/select-widget.ts +156 -0
- package/src/form-design/switch-widget.ts +140 -0
- package/src/form-design/textarea-widget.ts +148 -0
- package/src/form-design/use.ts +255 -0
- package/src/index.ts +71 -0
- package/src/table/index.ts +508 -0
- package/index.ts +0 -701
package/index.ts
DELETED
|
@@ -1,701 +0,0 @@
|
|
|
1
|
-
import { h, resolveComponent, ComponentOptions } from 'vue'
|
|
2
|
-
import XEUtils from 'xe-utils'
|
|
3
|
-
|
|
4
|
-
import type { VxeUIExport, VxeTableDefines, VxeColumnPropTypes, VxeGlobalRendererHandles, VxeGlobalInterceptorHandles, FormItemContentRenderParams } from 'vxe-pc-ui'
|
|
5
|
-
|
|
6
|
-
let VxeUI: VxeUIExport
|
|
7
|
-
// eslint-disable-next-line no-unused-vars
|
|
8
|
-
let Antd: any
|
|
9
|
-
|
|
10
|
-
function isEmptyValue (cellValue: any) {
|
|
11
|
-
return cellValue === null || cellValue === undefined || cellValue === ''
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function getOnName (type: string) {
|
|
15
|
-
return 'on' + type.substring(0, 1).toLocaleUpperCase() + type.substring(1)
|
|
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 = 'update:value'
|
|
30
|
-
switch (renderOpts.name) {
|
|
31
|
-
case 'ASwitch':
|
|
32
|
-
type = 'update:checked'
|
|
33
|
-
break
|
|
34
|
-
}
|
|
35
|
-
return type
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function dateFormatToVxeFormat (format: string) {
|
|
39
|
-
if (format) {
|
|
40
|
-
return `${format}`.replace('YYYY', 'yyyy').replace('DD', 'dd')
|
|
41
|
-
}
|
|
42
|
-
return format
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
46
|
-
return 'change'
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function getCellEditFilterProps (renderOpts: any, params: VxeGlobalRendererHandles.RenderEditParams | VxeGlobalRendererHandles.RenderFilterParams, value: any, defaultProps?: { [prop: string]: any }) {
|
|
50
|
-
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function getItemProps (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: FormItemContentRenderParams, 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 (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 getItemOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: FormItemContentRenderParams) {
|
|
128
|
-
const { $form, data, field } = params
|
|
129
|
-
return getOns(renderOpts, params, (value: any) => {
|
|
130
|
-
// 处理 model 值双向绑定
|
|
131
|
-
XEUtils.set(data, field, value)
|
|
132
|
-
}, () => {
|
|
133
|
-
// 处理 change 事件相关逻辑
|
|
134
|
-
$form.updateStatus(params)
|
|
135
|
-
})
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
function matchCascaderData (index: number, list: any[], values: any[], labels: any[]) {
|
|
139
|
-
const val = values[index]
|
|
140
|
-
if (list && values.length > index) {
|
|
141
|
-
XEUtils.each(list, (item) => {
|
|
142
|
-
if (item.value === val) {
|
|
143
|
-
labels.push(item.label)
|
|
144
|
-
matchCascaderData(++index, item.children, values, labels)
|
|
145
|
-
}
|
|
146
|
-
})
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function formatDatePicker (defaultFormat: string) {
|
|
151
|
-
return function (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
|
|
152
|
-
return getCellLabelVNs(renderOpts, params, getDatePickerCellValue(renderOpts, params, defaultFormat))
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
function getSelectCellValue (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams) {
|
|
157
|
-
const { options = [], optionGroups, props = {}, optionProps = {}, optionGroupProps = {} } = renderOpts
|
|
158
|
-
const { row, column } = params
|
|
159
|
-
const labelProp = optionProps.label || 'label'
|
|
160
|
-
const valueProp = optionProps.value || 'value'
|
|
161
|
-
const groupOptions = optionGroupProps.options || 'options'
|
|
162
|
-
const cellValue = XEUtils.get(row, column.field)
|
|
163
|
-
if (!isEmptyValue(cellValue)) {
|
|
164
|
-
return XEUtils.map(props.mode === 'multiple' ? cellValue : [cellValue], optionGroups
|
|
165
|
-
? (value) => {
|
|
166
|
-
let selectItem
|
|
167
|
-
for (let index = 0; index < optionGroups.length; index++) {
|
|
168
|
-
selectItem = XEUtils.find(optionGroups[index][groupOptions], (item) => item[valueProp] === value)
|
|
169
|
-
if (selectItem) {
|
|
170
|
-
break
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
return selectItem ? selectItem[labelProp] : value
|
|
174
|
-
}
|
|
175
|
-
: (value) => {
|
|
176
|
-
const selectItem = XEUtils.find(options, (item) => item[valueProp] === value)
|
|
177
|
-
return selectItem ? selectItem[labelProp] : value
|
|
178
|
-
}).join(', ')
|
|
179
|
-
}
|
|
180
|
-
return ''
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function getCascaderCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.ExportMethodParams) {
|
|
184
|
-
const { props = {} } = renderOpts
|
|
185
|
-
const { row, column } = params
|
|
186
|
-
const cellValue = XEUtils.get(row, column.field)
|
|
187
|
-
const values = cellValue || []
|
|
188
|
-
const labels: Array<any> = []
|
|
189
|
-
matchCascaderData(0, props.options, values, labels)
|
|
190
|
-
return (props.showAllLevels === false ? labels.slice(labels.length - 1, labels.length) : labels).join(` ${props.separator || '/'} `)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function getRangePickerCellValue (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.RenderEditParams) {
|
|
194
|
-
const { props = {} } = renderOpts
|
|
195
|
-
const { row, column } = params
|
|
196
|
-
let cellValue = XEUtils.get(row, column.field)
|
|
197
|
-
if (cellValue) {
|
|
198
|
-
cellValue = XEUtils.map(cellValue, (date: any) => {
|
|
199
|
-
return date && date.format ? date.format(props.format || 'YYYY-MM-DD') : XEUtils.toDateString(date, dateFormatToVxeFormat(props.format || 'YYYY-MM-DD'))
|
|
200
|
-
}).join(' ~ ')
|
|
201
|
-
}
|
|
202
|
-
return cellValue
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
function getTreeSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.RenderEditParams) {
|
|
206
|
-
const { props = {} } = renderOpts
|
|
207
|
-
const { treeData, treeCheckable } = props
|
|
208
|
-
const { row, column } = params
|
|
209
|
-
const cellValue = XEUtils.get(row, column.field)
|
|
210
|
-
if (!isEmptyValue(cellValue)) {
|
|
211
|
-
return XEUtils.map(treeCheckable ? cellValue : [cellValue], (value) => {
|
|
212
|
-
const matchObj = XEUtils.findTree(treeData, (item: any) => item.value === value, { children: 'children' })
|
|
213
|
-
return matchObj ? matchObj.item.title : value
|
|
214
|
-
}).join(', ')
|
|
215
|
-
}
|
|
216
|
-
return cellValue
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function getDatePickerCellValue (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderCellParams | VxeGlobalRendererHandles.ExportMethodParams, defaultFormat: string) {
|
|
220
|
-
const { props = {} } = renderOpts
|
|
221
|
-
const { row, column } = params
|
|
222
|
-
let cellValue = XEUtils.get(row, column.field)
|
|
223
|
-
try {
|
|
224
|
-
if (cellValue) {
|
|
225
|
-
cellValue = cellValue.format ? cellValue.format(props.format || defaultFormat) : XEUtils.toDateString(cellValue, dateFormatToVxeFormat(props.format || defaultFormat))
|
|
226
|
-
}
|
|
227
|
-
} catch (e) {}
|
|
228
|
-
return cellValue
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
function createEditRender (defaultProps?: { [key: string]: any }) {
|
|
232
|
-
return function (renderOpts: VxeColumnPropTypes.EditRender & { name: string }, params: VxeGlobalRendererHandles.RenderEditParams) {
|
|
233
|
-
const { row, column } = params
|
|
234
|
-
const { name, attrs } = renderOpts
|
|
235
|
-
const cellValue = XEUtils.get(row, column.field)
|
|
236
|
-
return [
|
|
237
|
-
h(resolveComponent(name), {
|
|
238
|
-
...attrs,
|
|
239
|
-
...getCellEditFilterProps(renderOpts, params, cellValue, defaultProps),
|
|
240
|
-
...getEditOns(renderOpts, params)
|
|
241
|
-
})
|
|
242
|
-
]
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
function defaultButtonEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
|
|
247
|
-
const { attrs } = renderOpts
|
|
248
|
-
return [
|
|
249
|
-
h(resolveComponent('a-button'), {
|
|
250
|
-
...attrs,
|
|
251
|
-
...getCellEditFilterProps(renderOpts, params, null),
|
|
252
|
-
...getOns(renderOpts, params)
|
|
253
|
-
}, cellText(renderOpts.content))
|
|
254
|
-
]
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
function defaultButtonsEditRender (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams) {
|
|
258
|
-
const { children } = renderOpts
|
|
259
|
-
if (children) {
|
|
260
|
-
return children.map((childRenderOpts: VxeColumnPropTypes.EditRender) => defaultButtonEditRender(childRenderOpts, params)[0])
|
|
261
|
-
}
|
|
262
|
-
return []
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
function createFilterRender (defaultProps?: { [key: string]: any }) {
|
|
266
|
-
return function (renderOpts: VxeColumnPropTypes.FilterRender & { name: string }, params: VxeGlobalRendererHandles.RenderFilterParams) {
|
|
267
|
-
const { column } = params
|
|
268
|
-
const { name, attrs } = renderOpts
|
|
269
|
-
return [
|
|
270
|
-
h('div', {
|
|
271
|
-
class: 'vxe-table--filter-antd-wrapper'
|
|
272
|
-
}, column.filters.map((option, oIndex) => {
|
|
273
|
-
const optionValue = option.data
|
|
274
|
-
return h(resolveComponent(name), {
|
|
275
|
-
key: oIndex,
|
|
276
|
-
...attrs,
|
|
277
|
-
...getCellEditFilterProps(renderOpts, params, optionValue, defaultProps),
|
|
278
|
-
...getFilterOns(renderOpts, params, option, () => {
|
|
279
|
-
// 处理 change 事件相关逻辑
|
|
280
|
-
handleConfirmFilter(params, !!option.data, option)
|
|
281
|
-
})
|
|
282
|
-
})
|
|
283
|
-
}))
|
|
284
|
-
]
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
function handleConfirmFilter (params: VxeGlobalRendererHandles.RenderFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
|
|
289
|
-
const { $panel } = params
|
|
290
|
-
$panel.changeOption(null, checked, option)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
/**
|
|
294
|
-
* 模糊匹配
|
|
295
|
-
* @param params
|
|
296
|
-
*/
|
|
297
|
-
function defaultFuzzyFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
|
|
298
|
-
const { option, row, column } = params
|
|
299
|
-
const { data } = option
|
|
300
|
-
const cellValue = XEUtils.get(row, column.field)
|
|
301
|
-
return XEUtils.toValueString(cellValue).indexOf(data) > -1
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* 精确匹配
|
|
306
|
-
* @param params
|
|
307
|
-
*/
|
|
308
|
-
function defaultExactFilterMethod (params: VxeGlobalRendererHandles.FilterMethodParams) {
|
|
309
|
-
const { option, row, column } = params
|
|
310
|
-
const { data } = option
|
|
311
|
-
const cellValue = XEUtils.get(row, column.field)
|
|
312
|
-
/* eslint-disable eqeqeq */
|
|
313
|
-
return cellValue === data
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
function cellText (cellValue: any): string[] {
|
|
317
|
-
return [formatText(cellValue)]
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function createFormItemRender (defaultProps?: { [key: string]: any }) {
|
|
321
|
-
return function (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: FormItemContentRenderParams) {
|
|
322
|
-
const { data, field } = params
|
|
323
|
-
const { name } = renderOpts
|
|
324
|
-
const { attrs } = renderOpts
|
|
325
|
-
const itemValue = XEUtils.get(data, field)
|
|
326
|
-
return [
|
|
327
|
-
h(resolveComponent(name), {
|
|
328
|
-
...attrs,
|
|
329
|
-
...getItemProps(renderOpts, params, itemValue, defaultProps),
|
|
330
|
-
...getItemOns(renderOpts, params)
|
|
331
|
-
})
|
|
332
|
-
]
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
function defaultButtonItemRender (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: FormItemContentRenderParams) {
|
|
337
|
-
const { attrs } = renderOpts
|
|
338
|
-
const props = getItemProps(renderOpts, params, null)
|
|
339
|
-
return [
|
|
340
|
-
h(resolveComponent('a-button') as ComponentOptions, {
|
|
341
|
-
...attrs,
|
|
342
|
-
...props,
|
|
343
|
-
...getItemOns(renderOpts, params)
|
|
344
|
-
}, {
|
|
345
|
-
default: () => cellText(renderOpts.content || props.content)
|
|
346
|
-
})
|
|
347
|
-
]
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
function defaultButtonsItemRender (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: FormItemContentRenderParams) {
|
|
351
|
-
const { children } = renderOpts
|
|
352
|
-
if (children) {
|
|
353
|
-
return children.map((childRenderOpts: VxeGlobalRendererHandles.RenderItemContentOptions) => defaultButtonItemRender(childRenderOpts, params)[0])
|
|
354
|
-
}
|
|
355
|
-
return []
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function createDatePickerExportMethod (defaultFormat: string) {
|
|
359
|
-
return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
|
|
360
|
-
const { row, column, options } = params
|
|
361
|
-
return options && options.original ? XEUtils.get(row, column.field) : getDatePickerCellValue(column.editRender || column.cellRender, params, defaultFormat)
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function createExportMethod (getExportCellValue: Function) {
|
|
366
|
-
return function (params: VxeGlobalRendererHandles.ExportMethodParams) {
|
|
367
|
-
const { row, column, options } = params
|
|
368
|
-
return options && options.original ? XEUtils.get(row, column.field) : getExportCellValue(column.editRender || column.cellRender, params)
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
function createFormItemRadioAndCheckboxRender () {
|
|
373
|
-
return function (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: FormItemContentRenderParams) {
|
|
374
|
-
const { name, options = [], optionProps = {} } = renderOpts
|
|
375
|
-
const { data, field } = params
|
|
376
|
-
const { attrs } = renderOpts
|
|
377
|
-
const labelProp = optionProps.label || 'label'
|
|
378
|
-
const valueProp = optionProps.value || 'value'
|
|
379
|
-
const itemValue = XEUtils.get(data, field)
|
|
380
|
-
return [
|
|
381
|
-
h(resolveComponent(`${name}Group`) as ComponentOptions, {
|
|
382
|
-
...attrs,
|
|
383
|
-
...getItemProps(renderOpts, params, itemValue),
|
|
384
|
-
...getItemOns(renderOpts, params)
|
|
385
|
-
}, {
|
|
386
|
-
default: () => {
|
|
387
|
-
return options.map((option, oIndex) => {
|
|
388
|
-
return h(resolveComponent(name) as ComponentOptions, {
|
|
389
|
-
key: oIndex,
|
|
390
|
-
value: option[valueProp],
|
|
391
|
-
disabled: option.disabled
|
|
392
|
-
}, {
|
|
393
|
-
default: () => cellText(option[labelProp])
|
|
394
|
-
})
|
|
395
|
-
})
|
|
396
|
-
}
|
|
397
|
-
})
|
|
398
|
-
]
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* 检查触发源是否属于目标节点
|
|
404
|
-
*/
|
|
405
|
-
function getEventTargetNode (evnt: any, container: HTMLElement, className: string) {
|
|
406
|
-
let targetElem
|
|
407
|
-
let target = evnt.target
|
|
408
|
-
while (target && target.nodeType && target !== document) {
|
|
409
|
-
if (className && target.className && target.className.split && target.className.split(' ').indexOf(className) > -1) {
|
|
410
|
-
targetElem = target
|
|
411
|
-
} else if (target === container) {
|
|
412
|
-
return { flag: className ? !!targetElem : true, container, targetElem: targetElem }
|
|
413
|
-
}
|
|
414
|
-
target = target.parentNode
|
|
415
|
-
}
|
|
416
|
-
return { flag: false }
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
/**
|
|
420
|
-
* 事件兼容性处理
|
|
421
|
-
*/
|
|
422
|
-
function handleClearEvent (params: VxeGlobalInterceptorHandles.InterceptorClearFilterParams | VxeGlobalInterceptorHandles.InterceptorClearEditParams | VxeGlobalInterceptorHandles.InterceptorClearAreasParams) {
|
|
423
|
-
const { $event } = params
|
|
424
|
-
const bodyElem = document.body
|
|
425
|
-
if (
|
|
426
|
-
// 下拉框
|
|
427
|
-
getEventTargetNode($event, bodyElem, 'ant-select-dropdown').flag ||
|
|
428
|
-
// 级联
|
|
429
|
-
getEventTargetNode($event, bodyElem, 'ant-cascader-menus').flag ||
|
|
430
|
-
// 日期
|
|
431
|
-
getEventTargetNode($event, bodyElem, 'ant-picker-dropdown').flag ||
|
|
432
|
-
getEventTargetNode($event, bodyElem, 'ant-calendar-picker-container').flag ||
|
|
433
|
-
// 时间选择
|
|
434
|
-
getEventTargetNode($event, bodyElem, 'ant-time-picker-panel').flag
|
|
435
|
-
) {
|
|
436
|
-
return false
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
export const VxeUIPluginRenderAntd = {
|
|
441
|
-
install (core: VxeUIExport, options?: {
|
|
442
|
-
Antd?: any
|
|
443
|
-
}) {
|
|
444
|
-
VxeUI = core
|
|
445
|
-
Antd = options ? options.Antd : {}
|
|
446
|
-
|
|
447
|
-
// 检查版本
|
|
448
|
-
if (!/^(4)\./.test(VxeUI.uiVersion)) {
|
|
449
|
-
console.error('[plugin-render-antd 4.x] Version 4.x is required')
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
VxeUI.renderer.mixin({
|
|
453
|
-
AAutoComplete: {
|
|
454
|
-
autofocus: 'input.ant-input',
|
|
455
|
-
renderDefault: createEditRender(),
|
|
456
|
-
renderEdit: createEditRender(),
|
|
457
|
-
renderFilter: createFilterRender(),
|
|
458
|
-
defaultFilterMethod: defaultExactFilterMethod,
|
|
459
|
-
renderItemContent: createFormItemRender()
|
|
460
|
-
},
|
|
461
|
-
AInput: {
|
|
462
|
-
autofocus: 'input.ant-input',
|
|
463
|
-
renderDefault: createEditRender(),
|
|
464
|
-
renderEdit: createEditRender(),
|
|
465
|
-
renderFilter: createFilterRender(),
|
|
466
|
-
defaultFilterMethod: defaultFuzzyFilterMethod,
|
|
467
|
-
renderItemContent: createFormItemRender()
|
|
468
|
-
},
|
|
469
|
-
AInputNumber: {
|
|
470
|
-
autofocus: 'input.ant-input-number-input',
|
|
471
|
-
renderDefault: createEditRender(),
|
|
472
|
-
renderEdit: createEditRender(),
|
|
473
|
-
renderFilter: createFilterRender(),
|
|
474
|
-
defaultFilterMethod: defaultFuzzyFilterMethod,
|
|
475
|
-
renderItemContent: createFormItemRender()
|
|
476
|
-
},
|
|
477
|
-
ASelect: {
|
|
478
|
-
renderEdit (renderOpts, params) {
|
|
479
|
-
const { options, optionGroups } = renderOpts
|
|
480
|
-
const { row, column } = params
|
|
481
|
-
const { attrs } = renderOpts
|
|
482
|
-
const cellValue = XEUtils.get(row, column.field)
|
|
483
|
-
const props = getCellEditFilterProps(renderOpts, params, cellValue)
|
|
484
|
-
const ons = getEditOns(renderOpts, params)
|
|
485
|
-
if (optionGroups) {
|
|
486
|
-
return [
|
|
487
|
-
h(resolveComponent('a-select') as ComponentOptions, {
|
|
488
|
-
...props,
|
|
489
|
-
...attrs,
|
|
490
|
-
options: optionGroups,
|
|
491
|
-
...ons
|
|
492
|
-
})
|
|
493
|
-
]
|
|
494
|
-
}
|
|
495
|
-
return [
|
|
496
|
-
h(resolveComponent('a-select') as ComponentOptions, {
|
|
497
|
-
...props,
|
|
498
|
-
...attrs,
|
|
499
|
-
options: props.options || options,
|
|
500
|
-
...ons
|
|
501
|
-
})
|
|
502
|
-
]
|
|
503
|
-
},
|
|
504
|
-
renderCell (renderOpts, params) {
|
|
505
|
-
return getCellLabelVNs(renderOpts, params, getSelectCellValue(renderOpts, params))
|
|
506
|
-
},
|
|
507
|
-
renderFilter (renderOpts, params) {
|
|
508
|
-
const { options = [], optionGroups, optionGroupProps = {} } = renderOpts
|
|
509
|
-
const groupOptions = optionGroupProps.options || 'options'
|
|
510
|
-
const { column } = params
|
|
511
|
-
const { attrs } = renderOpts
|
|
512
|
-
return [
|
|
513
|
-
h('div', {
|
|
514
|
-
class: 'vxe-table--filter-antd-wrapper'
|
|
515
|
-
}, optionGroups
|
|
516
|
-
? column.filters.map((option, oIndex) => {
|
|
517
|
-
const optionValue = option.data
|
|
518
|
-
const props = getCellEditFilterProps(renderOpts, params, optionValue)
|
|
519
|
-
return h(resolveComponent('a-select') as ComponentOptions, {
|
|
520
|
-
key: oIndex,
|
|
521
|
-
...attrs,
|
|
522
|
-
...props,
|
|
523
|
-
options: groupOptions,
|
|
524
|
-
...getFilterOns(renderOpts, params, option, () => {
|
|
525
|
-
// 处理 change 事件相关逻辑
|
|
526
|
-
handleConfirmFilter(params, props.mode === 'multiple' ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
|
|
527
|
-
})
|
|
528
|
-
})
|
|
529
|
-
})
|
|
530
|
-
: column.filters.map((option, oIndex) => {
|
|
531
|
-
const optionValue = option.data
|
|
532
|
-
const props = getCellEditFilterProps(renderOpts, params, optionValue)
|
|
533
|
-
return h(resolveComponent('a-select') as ComponentOptions, {
|
|
534
|
-
key: oIndex,
|
|
535
|
-
...attrs,
|
|
536
|
-
...props,
|
|
537
|
-
options: props.options || options,
|
|
538
|
-
...getFilterOns(renderOpts, params, option, () => {
|
|
539
|
-
// 处理 change 事件相关逻辑
|
|
540
|
-
handleConfirmFilter(params, props.mode === 'multiple' ? (option.data && option.data.length > 0) : !XEUtils.eqNull(option.data), option)
|
|
541
|
-
})
|
|
542
|
-
})
|
|
543
|
-
}))
|
|
544
|
-
]
|
|
545
|
-
},
|
|
546
|
-
defaultFilterMethod (params) {
|
|
547
|
-
const { option, row, column } = params
|
|
548
|
-
const { data } = option
|
|
549
|
-
const { field, filterRender: renderOpts } = column
|
|
550
|
-
const { props = {} } = renderOpts
|
|
551
|
-
const cellValue = XEUtils.get(row, field)
|
|
552
|
-
if (props.mode === 'multiple') {
|
|
553
|
-
if (XEUtils.isArray(cellValue)) {
|
|
554
|
-
return XEUtils.includeArrays(cellValue, data)
|
|
555
|
-
}
|
|
556
|
-
return data.indexOf(cellValue) > -1
|
|
557
|
-
}
|
|
558
|
-
/* eslint-disable eqeqeq */
|
|
559
|
-
return cellValue == data
|
|
560
|
-
},
|
|
561
|
-
renderItemContent (renderOpts, params) {
|
|
562
|
-
const { options = [], optionGroups } = renderOpts
|
|
563
|
-
const { data, field } = params
|
|
564
|
-
const { attrs } = renderOpts
|
|
565
|
-
const itemValue = XEUtils.get(data, field)
|
|
566
|
-
const props = getItemProps(renderOpts, params, itemValue)
|
|
567
|
-
const ons = getItemOns(renderOpts, params)
|
|
568
|
-
if (optionGroups) {
|
|
569
|
-
return [
|
|
570
|
-
h(resolveComponent('a-select') as ComponentOptions, {
|
|
571
|
-
...attrs,
|
|
572
|
-
...props,
|
|
573
|
-
options: optionGroups,
|
|
574
|
-
...ons
|
|
575
|
-
})
|
|
576
|
-
]
|
|
577
|
-
}
|
|
578
|
-
return [
|
|
579
|
-
h(resolveComponent('a-select') as ComponentOptions, {
|
|
580
|
-
...attrs,
|
|
581
|
-
...props,
|
|
582
|
-
options: props.options || options,
|
|
583
|
-
...ons
|
|
584
|
-
})
|
|
585
|
-
]
|
|
586
|
-
},
|
|
587
|
-
exportMethod: createExportMethod(getSelectCellValue)
|
|
588
|
-
},
|
|
589
|
-
ACascader: {
|
|
590
|
-
renderEdit: createEditRender(),
|
|
591
|
-
renderCell (renderOpts, params) {
|
|
592
|
-
return getCellLabelVNs(renderOpts, params, getCascaderCellValue(renderOpts, params))
|
|
593
|
-
},
|
|
594
|
-
renderItemContent: createFormItemRender(),
|
|
595
|
-
exportMethod: createExportMethod(getCascaderCellValue)
|
|
596
|
-
},
|
|
597
|
-
ADatePicker: {
|
|
598
|
-
renderEdit: createEditRender(),
|
|
599
|
-
renderCell: formatDatePicker('YYYY-MM-DD'),
|
|
600
|
-
renderItemContent: createFormItemRender(),
|
|
601
|
-
exportMethod: createDatePickerExportMethod('YYYY-MM-DD')
|
|
602
|
-
},
|
|
603
|
-
AMonthPicker: {
|
|
604
|
-
renderEdit: createEditRender(),
|
|
605
|
-
renderCell: formatDatePicker('YYYY-MM'),
|
|
606
|
-
renderItemContent: createFormItemRender(),
|
|
607
|
-
exportMethod: createDatePickerExportMethod('YYYY-MM')
|
|
608
|
-
},
|
|
609
|
-
ARangePicker: {
|
|
610
|
-
renderEdit: createEditRender(),
|
|
611
|
-
renderCell (renderOpts, params) {
|
|
612
|
-
return getCellLabelVNs(renderOpts, params, getRangePickerCellValue(renderOpts, params))
|
|
613
|
-
},
|
|
614
|
-
renderItemContent: createFormItemRender(),
|
|
615
|
-
exportMethod: createExportMethod(getRangePickerCellValue)
|
|
616
|
-
},
|
|
617
|
-
AWeekPicker: {
|
|
618
|
-
renderEdit: createEditRender(),
|
|
619
|
-
renderCell: formatDatePicker('YYYY-WW周'),
|
|
620
|
-
renderItemContent: createFormItemRender(),
|
|
621
|
-
exportMethod: createDatePickerExportMethod('YYYY-WW周')
|
|
622
|
-
},
|
|
623
|
-
ATimePicker: {
|
|
624
|
-
renderEdit: createEditRender(),
|
|
625
|
-
renderCell: formatDatePicker('HH:mm:ss'),
|
|
626
|
-
renderItemContent: createFormItemRender(),
|
|
627
|
-
exportMethod: createDatePickerExportMethod('HH:mm:ss')
|
|
628
|
-
},
|
|
629
|
-
ATreeSelect: {
|
|
630
|
-
renderEdit: createEditRender(),
|
|
631
|
-
renderCell (renderOpts, params) {
|
|
632
|
-
return getCellLabelVNs(renderOpts, params, getTreeSelectCellValue(renderOpts, params))
|
|
633
|
-
},
|
|
634
|
-
renderItemContent: createFormItemRender(),
|
|
635
|
-
exportMethod: createExportMethod(getTreeSelectCellValue)
|
|
636
|
-
},
|
|
637
|
-
ARate: {
|
|
638
|
-
renderDefault: createEditRender(),
|
|
639
|
-
renderEdit: createEditRender(),
|
|
640
|
-
renderFilter: createFilterRender(),
|
|
641
|
-
defaultFilterMethod: defaultExactFilterMethod,
|
|
642
|
-
renderItemContent: createFormItemRender()
|
|
643
|
-
},
|
|
644
|
-
ASwitch: {
|
|
645
|
-
renderDefault: createEditRender(),
|
|
646
|
-
renderEdit: createEditRender(),
|
|
647
|
-
renderFilter (renderOpts, params) {
|
|
648
|
-
const { column } = params
|
|
649
|
-
const { name, attrs } = renderOpts
|
|
650
|
-
return [
|
|
651
|
-
h('div', {
|
|
652
|
-
class: 'vxe-table--filter-antd-wrapper'
|
|
653
|
-
}, column.filters.map((option, oIndex) => {
|
|
654
|
-
const optionValue = option.data
|
|
655
|
-
return h(name as string, {
|
|
656
|
-
key: oIndex,
|
|
657
|
-
...attrs,
|
|
658
|
-
...getCellEditFilterProps(renderOpts, params, optionValue),
|
|
659
|
-
...getFilterOns(renderOpts, params, option, () => {
|
|
660
|
-
// 处理 change 事件相关逻辑
|
|
661
|
-
handleConfirmFilter(params, XEUtils.isBoolean(option.data), option)
|
|
662
|
-
})
|
|
663
|
-
})
|
|
664
|
-
}))
|
|
665
|
-
]
|
|
666
|
-
},
|
|
667
|
-
defaultFilterMethod: defaultExactFilterMethod,
|
|
668
|
-
renderItemContent: createFormItemRender()
|
|
669
|
-
},
|
|
670
|
-
ARadio: {
|
|
671
|
-
renderItemContent: createFormItemRadioAndCheckboxRender()
|
|
672
|
-
},
|
|
673
|
-
ACheckbox: {
|
|
674
|
-
renderItemContent: createFormItemRadioAndCheckboxRender()
|
|
675
|
-
},
|
|
676
|
-
AButton: {
|
|
677
|
-
renderEdit: defaultButtonEditRender,
|
|
678
|
-
renderDefault: defaultButtonEditRender,
|
|
679
|
-
renderItemContent: defaultButtonItemRender
|
|
680
|
-
},
|
|
681
|
-
AButtons: {
|
|
682
|
-
renderEdit: defaultButtonsEditRender,
|
|
683
|
-
renderDefault: defaultButtonsEditRender,
|
|
684
|
-
renderItemContent: defaultButtonsItemRender
|
|
685
|
-
}
|
|
686
|
-
})
|
|
687
|
-
|
|
688
|
-
VxeUI.interceptor.add('event.clearFilter', handleClearEvent)
|
|
689
|
-
VxeUI.interceptor.add('event.clearEdit', handleClearEvent)
|
|
690
|
-
VxeUI.interceptor.add('event.clearAreas', handleClearEvent)
|
|
691
|
-
|
|
692
|
-
// 兼容老版本
|
|
693
|
-
VxeUI.interceptor.add('event.clearActived', handleClearEvent)
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
|
|
697
|
-
if (typeof window !== 'undefined' && window.VxeUI && window.VxeUI.use) {
|
|
698
|
-
window.VxeUI.use(VxeUIPluginRenderAntd)
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
export default VxeUIPluginRenderAntd
|