@vxe-ui/plugin-render-antd 4.0.1 → 4.0.3
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/dist/all.common.js +1148 -0
- package/dist/form/index.js +235 -0
- package/dist/form-design/a-date-picker.js +142 -0
- package/dist/form-design/a-input.js +142 -0
- package/dist/form-design/index.js +54 -0
- package/dist/index.common.js +8 -681
- package/dist/index.js +69 -0
- package/dist/index.umd.js +1259 -700
- package/dist/index.umd.min.js +1 -1
- package/dist/table/index.js +499 -0
- package/package.json +5 -4
- package/src/form/index.ts +244 -0
- package/src/form-design/a-date-picker.ts +143 -0
- package/src/form-design/a-input.ts +143 -0
- package/src/form-design/index.ts +34 -0
- package/src/index.ts +71 -0
- package/src/table/index.ts +508 -0
- package/index.ts +0 -757
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { h, resolveComponent, ComponentOptions } 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 '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 getChangeEvent (renderOpts: VxeGlobalRendererHandles.RenderOptions) {
|
|
39
|
+
return 'change'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function getItemProps (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: FormItemContentRenderParams, value: any, defaultProps?: { [prop: string]: any }) {
|
|
43
|
+
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function formatText (cellValue: any) {
|
|
47
|
+
return '' + (isEmptyValue(cellValue) ? '' : cellValue)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function getOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: VxeGlobalRendererHandles.RenderParams, inputFunc?: Function, changeFunc?: Function) {
|
|
51
|
+
const { events } = renderOpts
|
|
52
|
+
const modelEvent = getModelEvent(renderOpts)
|
|
53
|
+
const changeEvent = getChangeEvent(renderOpts)
|
|
54
|
+
const isSameEvent = changeEvent === modelEvent
|
|
55
|
+
const ons: { [type: string]: Function } = {}
|
|
56
|
+
XEUtils.objectEach(events, (func: Function, key: string) => {
|
|
57
|
+
ons[getOnName(key)] = function (...args: any[]) {
|
|
58
|
+
func(params, ...args)
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
if (inputFunc) {
|
|
62
|
+
ons[getOnName(modelEvent)] = function (targetEvnt: any) {
|
|
63
|
+
inputFunc(targetEvnt)
|
|
64
|
+
if (events && events[modelEvent]) {
|
|
65
|
+
events[modelEvent](params, targetEvnt)
|
|
66
|
+
}
|
|
67
|
+
if (isSameEvent && changeFunc) {
|
|
68
|
+
changeFunc(targetEvnt)
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (!isSameEvent && changeFunc) {
|
|
73
|
+
ons[getOnName(changeEvent)] = function (...args: any[]) {
|
|
74
|
+
changeFunc(...args)
|
|
75
|
+
if (events && events[changeEvent]) {
|
|
76
|
+
events[changeEvent](params, ...args)
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return ons
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function getItemOns (renderOpts: VxeGlobalRendererHandles.RenderOptions, params: FormItemContentRenderParams) {
|
|
84
|
+
const { $form, data, field } = params
|
|
85
|
+
return getOns(renderOpts, params, (value: any) => {
|
|
86
|
+
// 处理 model 值双向绑定
|
|
87
|
+
XEUtils.set(data, field, value)
|
|
88
|
+
}, () => {
|
|
89
|
+
// 处理 change 事件相关逻辑
|
|
90
|
+
$form.updateStatus(params)
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function cellText (cellValue: any): string[] {
|
|
95
|
+
return [formatText(cellValue)]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function createFormItemRender (defaultProps?: { [key: string]: any }) {
|
|
99
|
+
return function (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: FormItemContentRenderParams) {
|
|
100
|
+
const { data, field } = params
|
|
101
|
+
const { name } = renderOpts
|
|
102
|
+
const { attrs } = renderOpts
|
|
103
|
+
const itemValue = XEUtils.get(data, field)
|
|
104
|
+
return [
|
|
105
|
+
h(resolveComponent(name), {
|
|
106
|
+
...attrs,
|
|
107
|
+
...getItemProps(renderOpts, params, itemValue, defaultProps),
|
|
108
|
+
...getItemOns(renderOpts, params)
|
|
109
|
+
})
|
|
110
|
+
]
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function defaultButtonItemRender (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: FormItemContentRenderParams) {
|
|
115
|
+
const { attrs } = renderOpts
|
|
116
|
+
const props = getItemProps(renderOpts, params, null)
|
|
117
|
+
return [
|
|
118
|
+
h(resolveComponent('a-button') as ComponentOptions, {
|
|
119
|
+
...attrs,
|
|
120
|
+
...props,
|
|
121
|
+
...getItemOns(renderOpts, params)
|
|
122
|
+
}, {
|
|
123
|
+
default: () => cellText(renderOpts.content || props.content)
|
|
124
|
+
})
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function defaultButtonsItemRender (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions, params: FormItemContentRenderParams) {
|
|
129
|
+
const { children } = renderOpts
|
|
130
|
+
if (children) {
|
|
131
|
+
return children.map((childRenderOpts: VxeGlobalRendererHandles.RenderItemContentOptions) => defaultButtonItemRender(childRenderOpts, params)[0])
|
|
132
|
+
}
|
|
133
|
+
return []
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function createFormItemRadioAndCheckboxRender () {
|
|
137
|
+
return function (renderOpts: VxeGlobalRendererHandles.RenderItemContentOptions & { name: string }, params: FormItemContentRenderParams) {
|
|
138
|
+
const { name, options = [], optionProps = {} } = renderOpts
|
|
139
|
+
const { data, field } = params
|
|
140
|
+
const { attrs } = renderOpts
|
|
141
|
+
const labelProp = optionProps.label || 'label'
|
|
142
|
+
const valueProp = optionProps.value || 'value'
|
|
143
|
+
const itemValue = XEUtils.get(data, field)
|
|
144
|
+
return [
|
|
145
|
+
h(resolveComponent(`${name}Group`) as ComponentOptions, {
|
|
146
|
+
...attrs,
|
|
147
|
+
...getItemProps(renderOpts, params, itemValue),
|
|
148
|
+
...getItemOns(renderOpts, params)
|
|
149
|
+
}, {
|
|
150
|
+
default: () => {
|
|
151
|
+
return options.map((option, oIndex) => {
|
|
152
|
+
return h(resolveComponent(name) as ComponentOptions, {
|
|
153
|
+
key: oIndex,
|
|
154
|
+
value: option[valueProp],
|
|
155
|
+
disabled: option.disabled
|
|
156
|
+
}, {
|
|
157
|
+
default: () => cellText(option[labelProp])
|
|
158
|
+
})
|
|
159
|
+
})
|
|
160
|
+
}
|
|
161
|
+
})
|
|
162
|
+
]
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
VxeUI.renderer.mixin({
|
|
167
|
+
AAutoComplete: {
|
|
168
|
+
renderFormItemContent: createFormItemRender()
|
|
169
|
+
},
|
|
170
|
+
AInput: {
|
|
171
|
+
renderFormItemContent: createFormItemRender()
|
|
172
|
+
},
|
|
173
|
+
AInputNumber: {
|
|
174
|
+
renderFormItemContent: createFormItemRender()
|
|
175
|
+
},
|
|
176
|
+
ASelect: {
|
|
177
|
+
renderFormItemContent (renderOpts, params) {
|
|
178
|
+
const { options = [], optionGroups } = renderOpts
|
|
179
|
+
const { data, field } = params
|
|
180
|
+
const { attrs } = renderOpts
|
|
181
|
+
const itemValue = XEUtils.get(data, field)
|
|
182
|
+
const props = getItemProps(renderOpts, params, itemValue)
|
|
183
|
+
const ons = getItemOns(renderOpts, params)
|
|
184
|
+
if (optionGroups) {
|
|
185
|
+
return [
|
|
186
|
+
h(resolveComponent('a-select') as ComponentOptions, {
|
|
187
|
+
...attrs,
|
|
188
|
+
...props,
|
|
189
|
+
options: optionGroups,
|
|
190
|
+
...ons
|
|
191
|
+
})
|
|
192
|
+
]
|
|
193
|
+
}
|
|
194
|
+
return [
|
|
195
|
+
h(resolveComponent('a-select') as ComponentOptions, {
|
|
196
|
+
...attrs,
|
|
197
|
+
...props,
|
|
198
|
+
options: props.options || options,
|
|
199
|
+
...ons
|
|
200
|
+
})
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
ACascader: {
|
|
205
|
+
renderFormItemContent: createFormItemRender()
|
|
206
|
+
},
|
|
207
|
+
ADatePicker: {
|
|
208
|
+
renderFormItemContent: createFormItemRender()
|
|
209
|
+
},
|
|
210
|
+
AMonthPicker: {
|
|
211
|
+
renderFormItemContent: createFormItemRender()
|
|
212
|
+
},
|
|
213
|
+
ARangePicker: {
|
|
214
|
+
renderFormItemContent: createFormItemRender()
|
|
215
|
+
},
|
|
216
|
+
AWeekPicker: {
|
|
217
|
+
renderFormItemContent: createFormItemRender()
|
|
218
|
+
},
|
|
219
|
+
ATimePicker: {
|
|
220
|
+
renderFormItemContent: createFormItemRender()
|
|
221
|
+
},
|
|
222
|
+
ATreeSelect: {
|
|
223
|
+
renderFormItemContent: createFormItemRender()
|
|
224
|
+
},
|
|
225
|
+
ARate: {
|
|
226
|
+
renderFormItemContent: createFormItemRender()
|
|
227
|
+
},
|
|
228
|
+
ASwitch: {
|
|
229
|
+
renderFormItemContent: createFormItemRender()
|
|
230
|
+
},
|
|
231
|
+
ARadio: {
|
|
232
|
+
renderFormItemContent: createFormItemRadioAndCheckboxRender()
|
|
233
|
+
},
|
|
234
|
+
ACheckbox: {
|
|
235
|
+
renderFormItemContent: createFormItemRadioAndCheckboxRender()
|
|
236
|
+
},
|
|
237
|
+
AButton: {
|
|
238
|
+
renderFormItemContent: defaultButtonItemRender
|
|
239
|
+
},
|
|
240
|
+
AButtons: {
|
|
241
|
+
renderFormItemContent: defaultButtonsItemRender
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { defineComponent, h, PropType, resolveComponent, ComponentOptions } from 'vue'
|
|
2
|
+
|
|
3
|
+
import type { VxeUIExport, VxeGlobalRendererHandles, VxeFormComponent, VxeFormItemComponent, VxeSwitchComponent } from 'vxe-pc-ui'
|
|
4
|
+
|
|
5
|
+
interface WidgetADatePickerFormObjVO {
|
|
6
|
+
placeholder: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createWidgetADatePicker (VxeUI: VxeUIExport) {
|
|
10
|
+
const getWidgetADatePickerConfig = (params: VxeGlobalRendererHandles.CreateFormDesignWidgetConfigParams): VxeGlobalRendererHandles.CreateFormDesignWidgetConfigObj<WidgetADatePickerFormObjVO> => {
|
|
11
|
+
return {
|
|
12
|
+
title: '日期',
|
|
13
|
+
icon: 'vxe-icon-input',
|
|
14
|
+
options: {
|
|
15
|
+
placeholder: ''
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const WidgetADatePickerFormComponent = defineComponent({
|
|
21
|
+
props: {
|
|
22
|
+
renderOpts: {
|
|
23
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewOptions>,
|
|
24
|
+
default: () => ({})
|
|
25
|
+
},
|
|
26
|
+
renderParams: {
|
|
27
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewParams<WidgetADatePickerFormObjVO>>,
|
|
28
|
+
default: () => ({})
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
emits: [],
|
|
32
|
+
setup (props) {
|
|
33
|
+
const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
|
|
34
|
+
const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
|
|
35
|
+
const VxeUISwitchComponent = VxeUI.getComponent<VxeSwitchComponent>('VxeSwitch')
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
const { renderParams } = props
|
|
39
|
+
const { widget } = renderParams
|
|
40
|
+
|
|
41
|
+
return h(VxeUIFormComponent, {
|
|
42
|
+
class: 'vxe-form-design--widget-render-form-wrapper',
|
|
43
|
+
vertical: true,
|
|
44
|
+
span: 24,
|
|
45
|
+
titleBold: true,
|
|
46
|
+
titleOverflow: true,
|
|
47
|
+
data: widget.options
|
|
48
|
+
}, {
|
|
49
|
+
default () {
|
|
50
|
+
return [
|
|
51
|
+
h(VxeUIFormItemComponent, {
|
|
52
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
|
|
53
|
+
}, {
|
|
54
|
+
default () {
|
|
55
|
+
return h(resolveComponent('a-date-picker') as ComponentOptions, {
|
|
56
|
+
modelValue: widget.title,
|
|
57
|
+
'onUpdate:modelValue' (val: any) {
|
|
58
|
+
widget.title = val
|
|
59
|
+
}
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
}),
|
|
63
|
+
h(VxeUIFormItemComponent, {
|
|
64
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.placeholder'),
|
|
65
|
+
field: 'placeholder',
|
|
66
|
+
itemRender: { name: 'VxeInput' }
|
|
67
|
+
}),
|
|
68
|
+
h(VxeUIFormItemComponent, {
|
|
69
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.required')
|
|
70
|
+
}, {
|
|
71
|
+
default () {
|
|
72
|
+
return h(VxeUISwitchComponent, {
|
|
73
|
+
modelValue: widget.required,
|
|
74
|
+
'onUpdate:modelValue' (val: any) {
|
|
75
|
+
widget.required = val
|
|
76
|
+
}
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const WidgetADatePickerViewComponent = defineComponent({
|
|
88
|
+
props: {
|
|
89
|
+
renderOpts: {
|
|
90
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewOptions>,
|
|
91
|
+
default: () => ({})
|
|
92
|
+
},
|
|
93
|
+
renderParams: {
|
|
94
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewParams<WidgetADatePickerFormObjVO>>,
|
|
95
|
+
default: () => ({})
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
emits: [],
|
|
99
|
+
setup (props) {
|
|
100
|
+
const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
|
|
101
|
+
|
|
102
|
+
const changeEvent = () => {
|
|
103
|
+
const { renderParams } = props
|
|
104
|
+
const { widget, $formView } = renderParams
|
|
105
|
+
if ($formView) {
|
|
106
|
+
const itemValue = $formView ? $formView.getItemValue(widget) : null
|
|
107
|
+
$formView.updateItemStatus(widget, itemValue)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return () => {
|
|
112
|
+
const { renderParams } = props
|
|
113
|
+
const { widget, $formView } = renderParams
|
|
114
|
+
const { options } = widget
|
|
115
|
+
|
|
116
|
+
return h(VxeUIFormItemComponent, {
|
|
117
|
+
class: ['vxe-form-design--widget-render-form-item'],
|
|
118
|
+
field: widget.field,
|
|
119
|
+
title: widget.title
|
|
120
|
+
}, {
|
|
121
|
+
default () {
|
|
122
|
+
return h(resolveComponent('a-date-picker') as ComponentOptions, {
|
|
123
|
+
modelValue: $formView ? $formView.getItemValue(widget) : null,
|
|
124
|
+
placeholder: options.placeholder,
|
|
125
|
+
onChange: changeEvent,
|
|
126
|
+
'onUpdate:modelValue' (val: any) {
|
|
127
|
+
if ($formView) {
|
|
128
|
+
$formView.setItemValue(widget, val)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
getWidgetADatePickerConfig,
|
|
140
|
+
WidgetADatePickerFormComponent,
|
|
141
|
+
WidgetADatePickerViewComponent
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { defineComponent, h, PropType, resolveComponent, ComponentOptions } from 'vue'
|
|
2
|
+
|
|
3
|
+
import type { VxeUIExport, VxeGlobalRendererHandles, VxeFormComponent, VxeFormItemComponent, VxeSwitchComponent } from 'vxe-pc-ui'
|
|
4
|
+
|
|
5
|
+
interface WidgetAInputFormObjVO {
|
|
6
|
+
placeholder: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function createWidgetAInput (VxeUI: VxeUIExport) {
|
|
10
|
+
const getWidgetAInputConfig = (params: VxeGlobalRendererHandles.CreateFormDesignWidgetConfigParams): VxeGlobalRendererHandles.CreateFormDesignWidgetConfigObj<WidgetAInputFormObjVO> => {
|
|
11
|
+
return {
|
|
12
|
+
title: '输入框',
|
|
13
|
+
icon: 'vxe-icon-input',
|
|
14
|
+
options: {
|
|
15
|
+
placeholder: ''
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const WidgetAInputFormComponent = defineComponent({
|
|
21
|
+
props: {
|
|
22
|
+
renderOpts: {
|
|
23
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewOptions>,
|
|
24
|
+
default: () => ({})
|
|
25
|
+
},
|
|
26
|
+
renderParams: {
|
|
27
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetFormViewParams<WidgetAInputFormObjVO>>,
|
|
28
|
+
default: () => ({})
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
emits: [],
|
|
32
|
+
setup (props) {
|
|
33
|
+
const VxeUIFormComponent = VxeUI.getComponent<VxeFormComponent>('VxeForm')
|
|
34
|
+
const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
|
|
35
|
+
const VxeUISwitchComponent = VxeUI.getComponent<VxeSwitchComponent>('VxeSwitch')
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
const { renderParams } = props
|
|
39
|
+
const { widget } = renderParams
|
|
40
|
+
const { options } = widget
|
|
41
|
+
|
|
42
|
+
return h(VxeUIFormComponent, {
|
|
43
|
+
class: 'vxe-form-design--widget-render-form-wrapper',
|
|
44
|
+
vertical: true,
|
|
45
|
+
span: 24,
|
|
46
|
+
titleBold: true,
|
|
47
|
+
titleOverflow: true,
|
|
48
|
+
data: options
|
|
49
|
+
}, {
|
|
50
|
+
default () {
|
|
51
|
+
return [
|
|
52
|
+
h(VxeUIFormItemComponent, {
|
|
53
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
|
|
54
|
+
}, {
|
|
55
|
+
default () {
|
|
56
|
+
return h(resolveComponent('a-input') as ComponentOptions, {
|
|
57
|
+
modelValue: widget.title,
|
|
58
|
+
placeholder: options.placeholder,
|
|
59
|
+
'onUpdate:modelValue' (val: any) {
|
|
60
|
+
widget.title = val
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
}),
|
|
65
|
+
h(VxeUIFormItemComponent, {
|
|
66
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.placeholder'),
|
|
67
|
+
field: 'placeholder',
|
|
68
|
+
itemRender: { name: 'VxeInput' }
|
|
69
|
+
}),
|
|
70
|
+
h(VxeUIFormItemComponent, {
|
|
71
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.required')
|
|
72
|
+
}, {
|
|
73
|
+
default () {
|
|
74
|
+
return h(VxeUISwitchComponent, {
|
|
75
|
+
modelValue: widget.required,
|
|
76
|
+
'onUpdate:modelValue' (val: any) {
|
|
77
|
+
widget.required = val
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const WidgetAInputViewComponent = defineComponent({
|
|
90
|
+
props: {
|
|
91
|
+
renderOpts: {
|
|
92
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewOptions>,
|
|
93
|
+
default: () => ({})
|
|
94
|
+
},
|
|
95
|
+
renderParams: {
|
|
96
|
+
type: Object as PropType<VxeGlobalRendererHandles.RenderFormDesignWidgetViewParams<WidgetAInputFormObjVO>>,
|
|
97
|
+
default: () => ({})
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
emits: [],
|
|
101
|
+
setup (props) {
|
|
102
|
+
const VxeUIFormItemComponent = VxeUI.getComponent<VxeFormItemComponent>('VxeFormItem')
|
|
103
|
+
|
|
104
|
+
const changeEvent = () => {
|
|
105
|
+
const { renderParams } = props
|
|
106
|
+
const { widget, $formView } = renderParams
|
|
107
|
+
if ($formView) {
|
|
108
|
+
const itemValue = $formView ? $formView.getItemValue(widget) : null
|
|
109
|
+
$formView.updateItemStatus(widget, itemValue)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return () => {
|
|
114
|
+
const { renderParams } = props
|
|
115
|
+
const { widget, $formView } = renderParams
|
|
116
|
+
|
|
117
|
+
return h(VxeUIFormItemComponent, {
|
|
118
|
+
class: ['vxe-form-design--widget-render-form-item'],
|
|
119
|
+
field: widget.field,
|
|
120
|
+
title: widget.title
|
|
121
|
+
}, {
|
|
122
|
+
default () {
|
|
123
|
+
return h(resolveComponent('a-input') as ComponentOptions, {
|
|
124
|
+
modelValue: $formView ? $formView.getItemValue(widget) : null,
|
|
125
|
+
onChange: changeEvent,
|
|
126
|
+
'onUpdate:modelValue' (val: any) {
|
|
127
|
+
if ($formView) {
|
|
128
|
+
$formView.setItemValue(widget, val)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
return {
|
|
139
|
+
getWidgetAInputConfig,
|
|
140
|
+
WidgetAInputFormComponent,
|
|
141
|
+
WidgetAInputViewComponent
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { h } from 'vue'
|
|
2
|
+
import { createWidgetAInput } from './a-input'
|
|
3
|
+
import { createWidgetADatePicker } from './a-date-picker'
|
|
4
|
+
|
|
5
|
+
import type { VxeUIExport } from 'vxe-pc-ui'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 表单设计器 - 渲染器
|
|
9
|
+
*/
|
|
10
|
+
export function defineFormDesignRender (VxeUI: VxeUIExport) {
|
|
11
|
+
const { getWidgetAInputConfig, WidgetAInputViewComponent, WidgetAInputFormComponent } = createWidgetAInput(VxeUI)
|
|
12
|
+
const { getWidgetADatePickerConfig, WidgetADatePickerViewComponent, WidgetADatePickerFormComponent } = createWidgetADatePicker(VxeUI)
|
|
13
|
+
|
|
14
|
+
VxeUI.renderer.mixin({
|
|
15
|
+
AInput: {
|
|
16
|
+
createFormDesignWidgetConfig: getWidgetAInputConfig,
|
|
17
|
+
renderFormDesignWidgetView (renderOpts, renderParams) {
|
|
18
|
+
return h(WidgetAInputViewComponent, { renderOpts, renderParams })
|
|
19
|
+
},
|
|
20
|
+
renderFormDesignWidgetFormView (renderOpts, renderParams) {
|
|
21
|
+
return h(WidgetAInputFormComponent, { renderOpts, renderParams })
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
ADatePicker: {
|
|
25
|
+
createFormDesignWidgetConfig: getWidgetADatePickerConfig,
|
|
26
|
+
renderFormDesignWidgetView (renderOpts, renderParams) {
|
|
27
|
+
return h(WidgetADatePickerViewComponent, { renderOpts, renderParams })
|
|
28
|
+
},
|
|
29
|
+
renderFormDesignWidgetFormView (renderOpts, renderParams) {
|
|
30
|
+
return h(WidgetADatePickerFormComponent, { renderOpts, renderParams })
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { defineTableRender } from './table'
|
|
2
|
+
import { defineFormRender } from './form'
|
|
3
|
+
import { defineFormDesignRender } from './form-design'
|
|
4
|
+
|
|
5
|
+
import type { VxeUIPluginObject, VxeGlobalInterceptorHandles } from 'vxe-pc-ui'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 检查触发源是否属于目标节点
|
|
9
|
+
*/
|
|
10
|
+
function getEventTargetNode (evnt: any, container: HTMLElement, className: string) {
|
|
11
|
+
let targetElem
|
|
12
|
+
let target = evnt.target
|
|
13
|
+
while (target && target.nodeType && target !== document) {
|
|
14
|
+
if (className && target.className && target.className.split && target.className.split(' ').indexOf(className) > -1) {
|
|
15
|
+
targetElem = target
|
|
16
|
+
} else if (target === container) {
|
|
17
|
+
return { flag: className ? !!targetElem : true, container, targetElem: targetElem }
|
|
18
|
+
}
|
|
19
|
+
target = target.parentNode
|
|
20
|
+
}
|
|
21
|
+
return { flag: false }
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 事件兼容性处理
|
|
26
|
+
*/
|
|
27
|
+
function handleClearEvent (params: VxeGlobalInterceptorHandles.InterceptorClearFilterParams | VxeGlobalInterceptorHandles.InterceptorClearEditParams | VxeGlobalInterceptorHandles.InterceptorClearAreasParams) {
|
|
28
|
+
const { $event } = params
|
|
29
|
+
const bodyElem = document.body
|
|
30
|
+
if (
|
|
31
|
+
// 下拉框
|
|
32
|
+
getEventTargetNode($event, bodyElem, 'ant-select-dropdown').flag ||
|
|
33
|
+
// 级联
|
|
34
|
+
getEventTargetNode($event, bodyElem, 'ant-cascader-menus').flag ||
|
|
35
|
+
// 日期
|
|
36
|
+
getEventTargetNode($event, bodyElem, 'ant-picker-dropdown').flag ||
|
|
37
|
+
getEventTargetNode($event, bodyElem, 'ant-calendar-picker-container').flag ||
|
|
38
|
+
// 时间选择
|
|
39
|
+
getEventTargetNode($event, bodyElem, 'ant-time-picker-panel').flag
|
|
40
|
+
) {
|
|
41
|
+
return false
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const VxeUIPluginRenderAntd: VxeUIPluginObject = {
|
|
46
|
+
install (VxeUI, options?: {
|
|
47
|
+
Antd?: any
|
|
48
|
+
}) {
|
|
49
|
+
// 检查版本
|
|
50
|
+
if (!/^(4)\./.test(VxeUI.uiVersion)) {
|
|
51
|
+
console.error('[plugin-render-antd 4.x] Version 4.x is required')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
defineTableRender(VxeUI)
|
|
55
|
+
defineFormRender(VxeUI)
|
|
56
|
+
defineFormDesignRender(VxeUI)
|
|
57
|
+
|
|
58
|
+
VxeUI.interceptor.add('event.clearFilter', handleClearEvent)
|
|
59
|
+
VxeUI.interceptor.add('event.clearEdit', handleClearEvent)
|
|
60
|
+
VxeUI.interceptor.add('event.clearAreas', handleClearEvent)
|
|
61
|
+
|
|
62
|
+
// 兼容老版本
|
|
63
|
+
VxeUI.interceptor.add('event.clearActived', handleClearEvent)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (typeof window !== 'undefined' && window.VxeUI && window.VxeUI.use) {
|
|
68
|
+
window.VxeUI.use(VxeUIPluginRenderAntd)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default VxeUIPluginRenderAntd
|