@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,330 @@
|
|
|
1
|
+
import { CreateElement } from 'vue'
|
|
2
|
+
import XEUtils from 'xe-utils'
|
|
3
|
+
|
|
4
|
+
import type { VxeUIExport, VxeGlobalRendererHandles, FormItemContentRenderParams } from 'vxe-pc-ui'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 表单 - 渲染器
|
|
8
|
+
*/
|
|
9
|
+
export function defineFormRender (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 getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
43
|
+
return 'change'
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function getItemProps (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: FormItemContentRenderParams, value: any, defaultProps?: { [prop: string]: any }) {
|
|
47
|
+
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function formatText (cellValue: any) {
|
|
51
|
+
return '' + (isEmptyValue(cellValue) ? '' : cellValue)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function getOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderParams, inputFunc?: Function, changeFunc?: Function) {
|
|
55
|
+
const { events } = renderOpts
|
|
56
|
+
const modelEvent = getModelEvent(renderOpts)
|
|
57
|
+
const changeEvent = getChangeEvent(renderOpts)
|
|
58
|
+
const isSameEvent = changeEvent === modelEvent
|
|
59
|
+
const ons: { [type: string]: Function } = {}
|
|
60
|
+
XEUtils.objectEach(events, (func: Function, key: string) => {
|
|
61
|
+
ons[getOnName(key)] = function (...args: any[]) {
|
|
62
|
+
func(params, ...args)
|
|
63
|
+
}
|
|
64
|
+
})
|
|
65
|
+
if (inputFunc) {
|
|
66
|
+
ons[getOnName(modelEvent)] = function (targetEvnt: any) {
|
|
67
|
+
inputFunc(targetEvnt)
|
|
68
|
+
if (events && events[modelEvent]) {
|
|
69
|
+
events[modelEvent](params, targetEvnt)
|
|
70
|
+
}
|
|
71
|
+
if (isSameEvent && changeFunc) {
|
|
72
|
+
changeFunc(targetEvnt)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!isSameEvent && changeFunc) {
|
|
77
|
+
ons[getOnName(changeEvent)] = function (...args: any[]) {
|
|
78
|
+
changeFunc(...args)
|
|
79
|
+
if (events && events[changeEvent]) {
|
|
80
|
+
events[changeEvent](params, ...args)
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return ons
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function getItemOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: FormItemContentRenderParams) {
|
|
88
|
+
const { $form, data, field } = params
|
|
89
|
+
return getOns(renderOpts, params, (value: any) => {
|
|
90
|
+
// 处理 model 值双向绑定
|
|
91
|
+
XEUtils.set(data, field, value)
|
|
92
|
+
}, () => {
|
|
93
|
+
// 处理 change 事件相关逻辑
|
|
94
|
+
$form.updateStatus(params)
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function cellText (cellValue: any): string[] {
|
|
99
|
+
return [formatText(cellValue)]
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function createFormItemRender (defaultProps?: { [key: string]: any }) {
|
|
103
|
+
return function (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: FormItemContentRenderParams) {
|
|
104
|
+
const { data, field } = params
|
|
105
|
+
const { name } = renderOpts
|
|
106
|
+
const { attrs } = renderOpts
|
|
107
|
+
const itemValue = XEUtils.get(data, field)
|
|
108
|
+
return [
|
|
109
|
+
h(name, {
|
|
110
|
+
attrs,
|
|
111
|
+
props: getItemProps(renderOpts, params, itemValue, defaultProps),
|
|
112
|
+
on: getItemOns(renderOpts, params)
|
|
113
|
+
})
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function defaultButtonItemRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: FormItemContentRenderParams) {
|
|
119
|
+
const { attrs } = renderOpts
|
|
120
|
+
const props = getItemProps(renderOpts, params, null)
|
|
121
|
+
return [
|
|
122
|
+
h('a-button', {
|
|
123
|
+
attrs,
|
|
124
|
+
props,
|
|
125
|
+
on: getItemOns(renderOpts, params),
|
|
126
|
+
scopedSlots: {
|
|
127
|
+
default: () => cellText(renderOpts.content || props.content)
|
|
128
|
+
}
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
function defaultButtonsItemRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: FormItemContentRenderParams) {
|
|
134
|
+
const { children } = renderOpts
|
|
135
|
+
if (children) {
|
|
136
|
+
return children.map((childRenderOpts: VxeGlobalRendererHandles.RenderItemContentOptions) => defaultButtonItemRender(h, childRenderOpts, params)[0])
|
|
137
|
+
}
|
|
138
|
+
return []
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
*
|
|
143
|
+
* 已废弃
|
|
144
|
+
* @deprecated
|
|
145
|
+
*/
|
|
146
|
+
function createOldFormItemRadioAndCheckboxRender () {
|
|
147
|
+
return function (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: FormItemContentRenderParams) {
|
|
148
|
+
const { name, options = [], optionProps = {} } = renderOpts
|
|
149
|
+
const { data, field } = params
|
|
150
|
+
const { attrs } = renderOpts
|
|
151
|
+
const labelProp = optionProps.label || 'label'
|
|
152
|
+
const valueProp = optionProps.value || 'value'
|
|
153
|
+
const itemValue = XEUtils.get(data, field)
|
|
154
|
+
return [
|
|
155
|
+
h(`${name}Group`, {
|
|
156
|
+
attrs,
|
|
157
|
+
props: getItemProps(renderOpts, params, itemValue),
|
|
158
|
+
on: getItemOns(renderOpts, params),
|
|
159
|
+
scopedSlots: {
|
|
160
|
+
default: () => {
|
|
161
|
+
return options.map((option, oIndex) => {
|
|
162
|
+
return h(name, {
|
|
163
|
+
key: oIndex,
|
|
164
|
+
props: {
|
|
165
|
+
value: option[valueProp],
|
|
166
|
+
disabled: option.disabled
|
|
167
|
+
},
|
|
168
|
+
scopedSlots: {
|
|
169
|
+
default: () => cellText(option[labelProp])
|
|
170
|
+
}
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
})
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
VxeUI.renderer.mixin({
|
|
181
|
+
AAutoComplete: {
|
|
182
|
+
renderFormItemContent: createFormItemRender()
|
|
183
|
+
},
|
|
184
|
+
AInput: {
|
|
185
|
+
renderFormItemContent: createFormItemRender()
|
|
186
|
+
},
|
|
187
|
+
AInputNumber: {
|
|
188
|
+
renderFormItemContent: createFormItemRender()
|
|
189
|
+
},
|
|
190
|
+
ASelect: {
|
|
191
|
+
renderFormItemContent (h, renderOpts, params) {
|
|
192
|
+
const { options = [], optionGroups } = renderOpts
|
|
193
|
+
const { data, field } = params
|
|
194
|
+
const { attrs } = renderOpts
|
|
195
|
+
const itemValue = XEUtils.get(data, field)
|
|
196
|
+
const props = getItemProps(renderOpts, params, itemValue)
|
|
197
|
+
const ons = getItemOns(renderOpts, params)
|
|
198
|
+
if (optionGroups) {
|
|
199
|
+
return [
|
|
200
|
+
h('a-select', {
|
|
201
|
+
attrs,
|
|
202
|
+
props: {
|
|
203
|
+
...props,
|
|
204
|
+
options: optionGroups
|
|
205
|
+
},
|
|
206
|
+
...ons
|
|
207
|
+
})
|
|
208
|
+
]
|
|
209
|
+
}
|
|
210
|
+
return [
|
|
211
|
+
h('a-select', {
|
|
212
|
+
attrs,
|
|
213
|
+
props: {
|
|
214
|
+
...props,
|
|
215
|
+
options: props.options || options
|
|
216
|
+
},
|
|
217
|
+
on: ons
|
|
218
|
+
})
|
|
219
|
+
]
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
ACascader: {
|
|
223
|
+
renderFormItemContent: createFormItemRender()
|
|
224
|
+
},
|
|
225
|
+
ADatePicker: {
|
|
226
|
+
renderFormItemContent: createFormItemRender()
|
|
227
|
+
},
|
|
228
|
+
AMonthPicker: {
|
|
229
|
+
renderFormItemContent: createFormItemRender()
|
|
230
|
+
},
|
|
231
|
+
ARangePicker: {
|
|
232
|
+
renderFormItemContent: createFormItemRender()
|
|
233
|
+
},
|
|
234
|
+
AWeekPicker: {
|
|
235
|
+
renderFormItemContent: createFormItemRender()
|
|
236
|
+
},
|
|
237
|
+
ATimePicker: {
|
|
238
|
+
renderFormItemContent: createFormItemRender()
|
|
239
|
+
},
|
|
240
|
+
ATreeSelect: {
|
|
241
|
+
renderFormItemContent: createFormItemRender()
|
|
242
|
+
},
|
|
243
|
+
ARate: {
|
|
244
|
+
renderFormItemContent: createFormItemRender()
|
|
245
|
+
},
|
|
246
|
+
ASwitch: {
|
|
247
|
+
renderFormItemContent: createFormItemRender()
|
|
248
|
+
},
|
|
249
|
+
ARadioGroup: {
|
|
250
|
+
renderFormItemContent (h, renderOpts, params) {
|
|
251
|
+
const { options = [], optionProps = {} } = renderOpts
|
|
252
|
+
const { data, field } = params
|
|
253
|
+
const { attrs } = renderOpts
|
|
254
|
+
const labelProp = optionProps.label || 'label'
|
|
255
|
+
const valueProp = optionProps.value || 'value'
|
|
256
|
+
const itemValue = XEUtils.get(data, field)
|
|
257
|
+
return [
|
|
258
|
+
h('a-radio-group', {
|
|
259
|
+
attrs,
|
|
260
|
+
props: getItemProps(renderOpts, params, itemValue),
|
|
261
|
+
on: getItemOns(renderOpts, params),
|
|
262
|
+
scopedSlots: {
|
|
263
|
+
default: () => {
|
|
264
|
+
return options.map((option, oIndex) => {
|
|
265
|
+
return h('a-radio', {
|
|
266
|
+
key: oIndex,
|
|
267
|
+
props: {
|
|
268
|
+
value: option[valueProp],
|
|
269
|
+
disabled: option.disabled
|
|
270
|
+
},
|
|
271
|
+
scopedSlots: {
|
|
272
|
+
default: () => cellText(option[labelProp])
|
|
273
|
+
}
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
})
|
|
279
|
+
]
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
ACheckboxGroup: {
|
|
283
|
+
renderFormItemContent (h, renderOpts, params) {
|
|
284
|
+
const { options = [], optionProps = {} } = renderOpts
|
|
285
|
+
const { data, field } = params
|
|
286
|
+
const { attrs } = renderOpts
|
|
287
|
+
const labelProp = optionProps.label || 'label'
|
|
288
|
+
const valueProp = optionProps.value || 'value'
|
|
289
|
+
const itemValue = XEUtils.get(data, field)
|
|
290
|
+
return [
|
|
291
|
+
h('a-checkbox-group', {
|
|
292
|
+
attrs,
|
|
293
|
+
props: getItemProps(renderOpts, params, itemValue),
|
|
294
|
+
on: getItemOns(renderOpts, params),
|
|
295
|
+
scopedSlots: {
|
|
296
|
+
default: () => {
|
|
297
|
+
return options.map((option, oIndex) => {
|
|
298
|
+
return h('a-checkbox', {
|
|
299
|
+
key: oIndex,
|
|
300
|
+
props: {
|
|
301
|
+
value: option[valueProp],
|
|
302
|
+
disabled: option.disabled
|
|
303
|
+
},
|
|
304
|
+
scopedSlots: {
|
|
305
|
+
default: () => cellText(option[labelProp])
|
|
306
|
+
}
|
|
307
|
+
})
|
|
308
|
+
})
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
})
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
AButton: {
|
|
316
|
+
renderFormItemContent: defaultButtonItemRender
|
|
317
|
+
},
|
|
318
|
+
|
|
319
|
+
// 已废弃
|
|
320
|
+
ARadio: {
|
|
321
|
+
renderFormItemContent: createOldFormItemRadioAndCheckboxRender()
|
|
322
|
+
},
|
|
323
|
+
ACheckbox: {
|
|
324
|
+
renderFormItemContent: createOldFormItemRadioAndCheckboxRender()
|
|
325
|
+
},
|
|
326
|
+
AButtons: {
|
|
327
|
+
renderFormItemContent: defaultButtonsItemRender
|
|
328
|
+
}
|
|
329
|
+
})
|
|
330
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { defineTableRender } from './table'
|
|
2
|
+
import { defineFormRender } from './form'
|
|
3
|
+
|
|
4
|
+
import type { VxeUIPluginObject, VxeGlobalInterceptorHandles } from 'vxe-pc-ui'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 检查触发源是否属于目标节点
|
|
8
|
+
*/
|
|
9
|
+
function getEventTargetNode (evnt: any, container: HTMLElement, className: string) {
|
|
10
|
+
let targetElem
|
|
11
|
+
let target = evnt.target
|
|
12
|
+
while (target && target.nodeType && target !== document) {
|
|
13
|
+
if (className && target.className && target.className.split && target.className.split(' ').indexOf(className) > -1) {
|
|
14
|
+
targetElem = target
|
|
15
|
+
} else if (target === container) {
|
|
16
|
+
return { flag: className ? !!targetElem : true, container, targetElem: targetElem }
|
|
17
|
+
}
|
|
18
|
+
target = target.parentNode
|
|
19
|
+
}
|
|
20
|
+
return { flag: false }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 事件兼容性处理
|
|
25
|
+
*/
|
|
26
|
+
function handleClearEvent (params: VxeGlobalInterceptorHandles.InterceptorClearFilterParams | VxeGlobalInterceptorHandles.InterceptorClearEditParams | VxeGlobalInterceptorHandles.InterceptorClearAreasParams) {
|
|
27
|
+
const { $event } = params
|
|
28
|
+
const bodyElem = document.body
|
|
29
|
+
if (
|
|
30
|
+
// 下拉框
|
|
31
|
+
getEventTargetNode($event, bodyElem, 'ant-select-dropdown').flag ||
|
|
32
|
+
// 级联
|
|
33
|
+
getEventTargetNode($event, bodyElem, 'ant-cascader-menus').flag ||
|
|
34
|
+
// 日期
|
|
35
|
+
getEventTargetNode($event, bodyElem, 'ant-picker-dropdown').flag ||
|
|
36
|
+
getEventTargetNode($event, bodyElem, 'ant-calendar-picker-container').flag ||
|
|
37
|
+
// 时间选择
|
|
38
|
+
getEventTargetNode($event, bodyElem, 'ant-time-picker-panel').flag
|
|
39
|
+
) {
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const VxeUIPluginRenderAntd: VxeUIPluginObject = {
|
|
45
|
+
install (VxeUI, options?: {
|
|
46
|
+
Antd?: any
|
|
47
|
+
}) {
|
|
48
|
+
// 检查版本
|
|
49
|
+
if (!/^(3)\./.test(VxeUI.uiVersion)) {
|
|
50
|
+
console.error('[plugin-render-antd 3.x] Version 3.x is required')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
defineTableRender(VxeUI)
|
|
54
|
+
defineFormRender(VxeUI)
|
|
55
|
+
|
|
56
|
+
VxeUI.interceptor.add('event.clearFilter', handleClearEvent)
|
|
57
|
+
VxeUI.interceptor.add('event.clearEdit', handleClearEvent)
|
|
58
|
+
VxeUI.interceptor.add('event.clearAreas', handleClearEvent)
|
|
59
|
+
|
|
60
|
+
// 兼容老版本
|
|
61
|
+
VxeUI.interceptor.add('event.clearActived', handleClearEvent)
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (typeof window !== 'undefined' && window.VxeUI && window.VxeUI.use) {
|
|
66
|
+
window.VxeUI.use(VxeUIPluginRenderAntd)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default VxeUIPluginRenderAntd
|