@vxe-ui/plugin-render-element 4.2.3 → 4.3.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/dist/index.umd.js +164 -37
- package/dist/index.umd.min.js +1 -1
- package/es/form/index.js +279 -0
- package/es/form-design/checkbox-widget.js +151 -0
- package/es/form-design/date-picker-widget.js +129 -0
- package/es/form-design/index.js +97 -0
- package/es/form-design/input-widget.js +130 -0
- package/es/form-design/number-input-widget.js +129 -0
- package/es/form-design/radio-widget.js +151 -0
- package/es/form-design/select-widget.js +149 -0
- package/es/form-design/switch-widget.js +125 -0
- package/es/form-design/textarea-widget.js +134 -0
- package/es/form-design/use.js +226 -0
- package/es/index.esm.js +111 -0
- package/es/index.js +111 -0
- package/es/store/index.js +2 -0
- package/es/style.css +38 -0
- package/es/style.min.css +1 -0
- package/es/table/index.js +633 -0
- package/es/util/comp.js +18 -0
- package/{dist → lib}/form/index.js +3 -0
- package/{dist → lib}/index.common.js +3 -3
- package/{dist → lib}/index.js +3 -3
- package/lib/index.umd.js +2962 -0
- package/lib/index.umd.min.js +1 -0
- package/lib/style.css +38 -0
- package/lib/style.min.css +1 -0
- package/{dist → lib}/table/index.js +140 -26
- package/{dist → lib}/util/comp.js +10 -0
- package/package.json +14 -17
- package/src/form/index.ts +5 -2
- package/src/table/index.ts +157 -39
- package/src/util/comp.ts +11 -0
- /package/{dist → lib}/form-design/checkbox-widget.js +0 -0
- /package/{dist → lib}/form-design/date-picker-widget.js +0 -0
- /package/{dist → lib}/form-design/index.js +0 -0
- /package/{dist → lib}/form-design/input-widget.js +0 -0
- /package/{dist → lib}/form-design/number-input-widget.js +0 -0
- /package/{dist → lib}/form-design/radio-widget.js +0 -0
- /package/{dist → lib}/form-design/select-widget.js +0 -0
- /package/{dist → lib}/form-design/switch-widget.js +0 -0
- /package/{dist → lib}/form-design/textarea-widget.js +0 -0
- /package/{dist → lib}/form-design/use.js +0 -0
- /package/{dist → lib}/store/index.js +0 -0
package/es/form/index.js
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { h } from 'vue';
|
|
2
|
+
import { getCurrComponent } from '../util/comp';
|
|
3
|
+
import XEUtils from 'xe-utils';
|
|
4
|
+
/**
|
|
5
|
+
* 表单 - 渲染器
|
|
6
|
+
*/
|
|
7
|
+
export function defineFormRender(VxeUI) {
|
|
8
|
+
function isEmptyValue(cellValue) {
|
|
9
|
+
return cellValue === null || cellValue === undefined || cellValue === '';
|
|
10
|
+
}
|
|
11
|
+
function getOnName(type) {
|
|
12
|
+
return 'on' + type.substring(0, 1).toLocaleUpperCase() + type.substring(1);
|
|
13
|
+
}
|
|
14
|
+
function getModelProp(renderOpts) {
|
|
15
|
+
return 'modelValue';
|
|
16
|
+
}
|
|
17
|
+
function getModelEvent(renderOpts) {
|
|
18
|
+
return 'update:modelValue';
|
|
19
|
+
}
|
|
20
|
+
function getChangeEvent(renderOpts) {
|
|
21
|
+
let type = 'change';
|
|
22
|
+
switch (renderOpts.name) {
|
|
23
|
+
case 'ElAutocomplete':
|
|
24
|
+
type = 'select';
|
|
25
|
+
break;
|
|
26
|
+
case 'ElInput':
|
|
27
|
+
case 'ElInputNumber':
|
|
28
|
+
type = 'input';
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
return type;
|
|
32
|
+
}
|
|
33
|
+
function getItemProps(renderOpts, params, value, defaultProps) {
|
|
34
|
+
return XEUtils.assign({}, defaultProps, renderOpts.props, { [getModelProp(renderOpts)]: value });
|
|
35
|
+
}
|
|
36
|
+
function formatText(cellValue) {
|
|
37
|
+
return '' + (isEmptyValue(cellValue) ? '' : cellValue);
|
|
38
|
+
}
|
|
39
|
+
function getOns(renderOpts, params, inputFunc, changeFunc) {
|
|
40
|
+
const { events } = renderOpts;
|
|
41
|
+
const modelEvent = getModelEvent(renderOpts);
|
|
42
|
+
const changeEvent = getChangeEvent(renderOpts);
|
|
43
|
+
const isSameEvent = changeEvent === modelEvent;
|
|
44
|
+
const ons = {};
|
|
45
|
+
XEUtils.objectEach(events, (func, key) => {
|
|
46
|
+
ons[getOnName(key)] = function (...args) {
|
|
47
|
+
func(params, ...args);
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
if (inputFunc) {
|
|
51
|
+
ons[getOnName(modelEvent)] = function (targetEvnt) {
|
|
52
|
+
inputFunc(targetEvnt);
|
|
53
|
+
if (events && events[modelEvent]) {
|
|
54
|
+
events[modelEvent](params, targetEvnt);
|
|
55
|
+
}
|
|
56
|
+
if (isSameEvent && changeFunc) {
|
|
57
|
+
changeFunc(targetEvnt);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (!isSameEvent && changeFunc) {
|
|
62
|
+
ons[getOnName(changeEvent)] = function (...args) {
|
|
63
|
+
changeFunc(...args);
|
|
64
|
+
if (events && events[changeEvent]) {
|
|
65
|
+
events[changeEvent](params, ...args);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
return ons;
|
|
70
|
+
}
|
|
71
|
+
function getItemOns(renderOpts, params) {
|
|
72
|
+
const { $form, data, field } = params;
|
|
73
|
+
return getOns(renderOpts, params, (value) => {
|
|
74
|
+
// 处理 model 值双向绑定
|
|
75
|
+
XEUtils.set(data, field, value);
|
|
76
|
+
}, () => {
|
|
77
|
+
// 处理 change 事件相关逻辑
|
|
78
|
+
$form.updateStatus(params);
|
|
79
|
+
if (renderOpts.changeToSubmit) {
|
|
80
|
+
$form.handleSubmitEvent(new Event('change'));
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function renderOptions(options, optionProps) {
|
|
85
|
+
const labelProp = optionProps.label || 'label';
|
|
86
|
+
const valueProp = optionProps.value || 'value';
|
|
87
|
+
return XEUtils.map(options, (item, oIndex) => {
|
|
88
|
+
return h(getCurrComponent('el-option'), {
|
|
89
|
+
key: oIndex,
|
|
90
|
+
value: item[valueProp],
|
|
91
|
+
label: item[labelProp],
|
|
92
|
+
disabled: item.disabled
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
function cellText(cellValue) {
|
|
97
|
+
return [formatText(cellValue)];
|
|
98
|
+
}
|
|
99
|
+
function createFormItemRender(defaultProps) {
|
|
100
|
+
return function (renderOpts, params) {
|
|
101
|
+
const { data, field } = params;
|
|
102
|
+
const { name } = renderOpts;
|
|
103
|
+
const { attrs } = renderOpts;
|
|
104
|
+
const itemValue = XEUtils.get(data, field);
|
|
105
|
+
return [
|
|
106
|
+
h(getCurrComponent(name), Object.assign(Object.assign(Object.assign({}, attrs), getItemProps(renderOpts, params, itemValue, defaultProps)), getItemOns(renderOpts, params)))
|
|
107
|
+
];
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function defaultButtonItemRender(renderOpts, params) {
|
|
111
|
+
const { attrs } = renderOpts;
|
|
112
|
+
const props = getItemProps(renderOpts, params, null);
|
|
113
|
+
return [
|
|
114
|
+
h(getCurrComponent('el-button'), Object.assign(Object.assign(Object.assign({}, attrs), props), getOns(renderOpts, params)), {
|
|
115
|
+
default: () => cellText(renderOpts.content || props.content)
|
|
116
|
+
})
|
|
117
|
+
];
|
|
118
|
+
}
|
|
119
|
+
function defaultButtonsItemRender(renderOpts, params) {
|
|
120
|
+
const { children } = renderOpts;
|
|
121
|
+
if (children) {
|
|
122
|
+
return children.map((childRenderOpts) => defaultButtonItemRender(childRenderOpts, params)[0]);
|
|
123
|
+
}
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* 已废弃
|
|
128
|
+
* @deprecated
|
|
129
|
+
*/
|
|
130
|
+
function createOldFormItemRadioAndCheckboxRender() {
|
|
131
|
+
return function (renderOpts, params) {
|
|
132
|
+
const { name, options = [], optionProps = {}, attrs } = renderOpts;
|
|
133
|
+
const { data, field } = params;
|
|
134
|
+
const labelProp = optionProps.label || 'label';
|
|
135
|
+
const valueProp = optionProps.value || 'value';
|
|
136
|
+
const itemValue = XEUtils.get(data, field);
|
|
137
|
+
return [
|
|
138
|
+
h(getCurrComponent(`${name}Group`), Object.assign(Object.assign(Object.assign({}, attrs), getItemProps(renderOpts, params, itemValue)), getItemOns(renderOpts, params)), {
|
|
139
|
+
default: () => {
|
|
140
|
+
return options.map((option, oIndex) => {
|
|
141
|
+
return h(getCurrComponent(name), {
|
|
142
|
+
key: oIndex,
|
|
143
|
+
label: option[valueProp],
|
|
144
|
+
disabled: option.disabled
|
|
145
|
+
}, {
|
|
146
|
+
default: () => cellText(option[labelProp])
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
})
|
|
151
|
+
];
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
VxeUI.renderer.mixin({
|
|
155
|
+
ElAutocomplete: {
|
|
156
|
+
renderFormItemContent: createFormItemRender()
|
|
157
|
+
},
|
|
158
|
+
ElInput: {
|
|
159
|
+
renderFormItemContent: createFormItemRender()
|
|
160
|
+
},
|
|
161
|
+
ElInputNumber: {
|
|
162
|
+
renderFormItemContent: createFormItemRender()
|
|
163
|
+
},
|
|
164
|
+
ElSelect: {
|
|
165
|
+
renderFormItemContent(renderOpts, params) {
|
|
166
|
+
const { options = [], optionGroups, optionProps = {}, optionGroupProps = {} } = renderOpts;
|
|
167
|
+
const { data, field } = params;
|
|
168
|
+
const { attrs } = renderOpts;
|
|
169
|
+
const itemValue = XEUtils.get(data, field);
|
|
170
|
+
const props = getItemProps(renderOpts, params, itemValue);
|
|
171
|
+
const ons = getItemOns(renderOpts, params);
|
|
172
|
+
if (optionGroups) {
|
|
173
|
+
const groupOptions = optionGroupProps.options || 'options';
|
|
174
|
+
const groupLabel = optionGroupProps.label || 'label';
|
|
175
|
+
return [
|
|
176
|
+
h(getCurrComponent('el-select'), Object.assign(Object.assign(Object.assign({}, attrs), props), ons), {
|
|
177
|
+
default: () => {
|
|
178
|
+
return XEUtils.map(optionGroups, (group, gIndex) => {
|
|
179
|
+
return h(getCurrComponent('el-option-group'), {
|
|
180
|
+
label: group[groupLabel],
|
|
181
|
+
key: gIndex
|
|
182
|
+
}, {
|
|
183
|
+
default: () => renderOptions(group[groupOptions], optionProps)
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
];
|
|
189
|
+
}
|
|
190
|
+
return [
|
|
191
|
+
h(getCurrComponent('el-select'), Object.assign(Object.assign(Object.assign({}, attrs), props), ons), {
|
|
192
|
+
default: () => renderOptions(options, optionProps)
|
|
193
|
+
})
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
ElCascader: {
|
|
198
|
+
renderFormItemContent: createFormItemRender()
|
|
199
|
+
},
|
|
200
|
+
ElDatePicker: {
|
|
201
|
+
renderFormItemContent: createFormItemRender()
|
|
202
|
+
},
|
|
203
|
+
ElTimePicker: {
|
|
204
|
+
renderFormItemContent: createFormItemRender()
|
|
205
|
+
},
|
|
206
|
+
ElTimeSelect: {
|
|
207
|
+
renderFormItemContent: createFormItemRender()
|
|
208
|
+
},
|
|
209
|
+
ElRate: {
|
|
210
|
+
renderFormItemContent: createFormItemRender()
|
|
211
|
+
},
|
|
212
|
+
ElSwitch: {
|
|
213
|
+
renderFormItemContent: createFormItemRender()
|
|
214
|
+
},
|
|
215
|
+
ElSlider: {
|
|
216
|
+
renderFormItemContent: createFormItemRender()
|
|
217
|
+
},
|
|
218
|
+
ElRadioGroup: {
|
|
219
|
+
renderFormItemContent(renderOpts, params) {
|
|
220
|
+
const { options = [], optionProps = {}, attrs } = renderOpts;
|
|
221
|
+
const { data, field } = params;
|
|
222
|
+
const labelProp = optionProps.label || 'label';
|
|
223
|
+
const valueProp = optionProps.value || 'value';
|
|
224
|
+
const itemValue = XEUtils.get(data, field);
|
|
225
|
+
return [
|
|
226
|
+
h(getCurrComponent('el-radio-group'), Object.assign(Object.assign(Object.assign({}, attrs), getItemProps(renderOpts, params, itemValue)), getItemOns(renderOpts, params)), {
|
|
227
|
+
default: () => {
|
|
228
|
+
return options.map((option, oIndex) => {
|
|
229
|
+
return h(getCurrComponent('el-radio'), {
|
|
230
|
+
key: oIndex,
|
|
231
|
+
value: option[valueProp],
|
|
232
|
+
disabled: option.disabled
|
|
233
|
+
}, {
|
|
234
|
+
default: () => cellText(option[labelProp])
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
];
|
|
240
|
+
}
|
|
241
|
+
},
|
|
242
|
+
ElCheckboxGroup: {
|
|
243
|
+
renderFormItemContent(renderOpts, params) {
|
|
244
|
+
const { options = [], optionProps = {}, attrs } = renderOpts;
|
|
245
|
+
const { data, field } = params;
|
|
246
|
+
const labelProp = optionProps.label || 'label';
|
|
247
|
+
const valueProp = optionProps.value || 'value';
|
|
248
|
+
const itemValue = XEUtils.get(data, field);
|
|
249
|
+
return [
|
|
250
|
+
h(getCurrComponent('el-checkbox-group'), Object.assign(Object.assign(Object.assign({}, attrs), getItemProps(renderOpts, params, itemValue)), getItemOns(renderOpts, params)), {
|
|
251
|
+
default: () => {
|
|
252
|
+
return options.map((option, oIndex) => {
|
|
253
|
+
return h(getCurrComponent('el-checkbox'), {
|
|
254
|
+
key: oIndex,
|
|
255
|
+
value: option[valueProp],
|
|
256
|
+
label: option[labelProp],
|
|
257
|
+
disabled: option.disabled
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
})
|
|
262
|
+
];
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
ElButton: {
|
|
266
|
+
renderFormItemContent: defaultButtonItemRender
|
|
267
|
+
},
|
|
268
|
+
// 已废弃
|
|
269
|
+
ElRadio: {
|
|
270
|
+
renderFormItemContent: createOldFormItemRadioAndCheckboxRender()
|
|
271
|
+
},
|
|
272
|
+
ElCheckbox: {
|
|
273
|
+
renderFormItemContent: createOldFormItemRadioAndCheckboxRender()
|
|
274
|
+
},
|
|
275
|
+
ElButtons: {
|
|
276
|
+
renderFormItemContent: defaultButtonsItemRender
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import { useWidgetPropDataSource } from './use';
|
|
3
|
+
import { getCurrComponent } from '../util/comp';
|
|
4
|
+
import XEUtils from 'xe-utils';
|
|
5
|
+
export function createWidgetElCheckbox(VxeUI) {
|
|
6
|
+
const getWidgetElCheckboxConfig = (params) => {
|
|
7
|
+
return {
|
|
8
|
+
title: '复选框',
|
|
9
|
+
icon: 'vxe-icon-checkbox-checked',
|
|
10
|
+
options: {
|
|
11
|
+
options: XEUtils.range(0, 3).map((v, i) => {
|
|
12
|
+
return {
|
|
13
|
+
value: VxeUI.getI18n('vxe.formDesign.widgetProp.dataSource.defValue', [i + 1])
|
|
14
|
+
};
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
const WidgetElCheckboxFormComponent = defineComponent({
|
|
20
|
+
props: {
|
|
21
|
+
renderOpts: {
|
|
22
|
+
type: Object,
|
|
23
|
+
default: () => ({})
|
|
24
|
+
},
|
|
25
|
+
renderParams: {
|
|
26
|
+
type: Object,
|
|
27
|
+
default: () => ({})
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
emits: [],
|
|
31
|
+
setup(props) {
|
|
32
|
+
const VxeUIFormComponent = VxeUI.getComponent('VxeForm');
|
|
33
|
+
const VxeUIFormItemComponent = VxeUI.getComponent('VxeFormItem');
|
|
34
|
+
const VxeUISwitchComponent = VxeUI.getComponent('VxeSwitch');
|
|
35
|
+
const { renderDataSourceFormItem } = useWidgetPropDataSource(VxeUI, props, false);
|
|
36
|
+
return () => {
|
|
37
|
+
const { renderParams } = props;
|
|
38
|
+
const { widget } = renderParams;
|
|
39
|
+
return h(VxeUIFormComponent, {
|
|
40
|
+
class: 'vxe-form-design--widget-render-form-wrapper',
|
|
41
|
+
vertical: true,
|
|
42
|
+
span: 24,
|
|
43
|
+
titleBold: true,
|
|
44
|
+
titleOverflow: true,
|
|
45
|
+
data: widget.options
|
|
46
|
+
}, {
|
|
47
|
+
default() {
|
|
48
|
+
return [
|
|
49
|
+
h(VxeUIFormItemComponent, {
|
|
50
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
|
|
51
|
+
}, {
|
|
52
|
+
default() {
|
|
53
|
+
return h(getCurrComponent('el-input'), {
|
|
54
|
+
modelValue: widget.title,
|
|
55
|
+
'onUpdate:modelValue'(val) {
|
|
56
|
+
widget.title = val;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}),
|
|
61
|
+
h(VxeUIFormItemComponent, {
|
|
62
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.placeholder'),
|
|
63
|
+
field: 'placeholder',
|
|
64
|
+
itemRender: { name: 'ElInput' }
|
|
65
|
+
}),
|
|
66
|
+
h(VxeUIFormItemComponent, {
|
|
67
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.required')
|
|
68
|
+
}, {
|
|
69
|
+
default() {
|
|
70
|
+
return h(VxeUISwitchComponent, {
|
|
71
|
+
modelValue: widget.required,
|
|
72
|
+
'onUpdate:modelValue'(val) {
|
|
73
|
+
widget.required = val;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}),
|
|
78
|
+
renderDataSourceFormItem()
|
|
79
|
+
];
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
const WidgetElCheckboxViewComponent = defineComponent({
|
|
86
|
+
props: {
|
|
87
|
+
renderOpts: {
|
|
88
|
+
type: Object,
|
|
89
|
+
default: () => ({})
|
|
90
|
+
},
|
|
91
|
+
renderParams: {
|
|
92
|
+
type: Object,
|
|
93
|
+
default: () => ({})
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
emits: [],
|
|
97
|
+
setup(props) {
|
|
98
|
+
const VxeUIFormItemComponent = VxeUI.getComponent('VxeFormItem');
|
|
99
|
+
const changeEvent = () => {
|
|
100
|
+
const { renderParams } = props;
|
|
101
|
+
const { widget, $formView } = renderParams;
|
|
102
|
+
if ($formView) {
|
|
103
|
+
const itemValue = $formView ? $formView.getItemValue(widget) : null;
|
|
104
|
+
$formView.updateWidgetStatus(widget, itemValue);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
return () => {
|
|
108
|
+
const { renderParams } = props;
|
|
109
|
+
const { widget, $formView } = renderParams;
|
|
110
|
+
const { options } = widget;
|
|
111
|
+
return h(VxeUIFormItemComponent, {
|
|
112
|
+
class: ['vxe-form-design--widget-render-form-item'],
|
|
113
|
+
field: widget.field,
|
|
114
|
+
title: widget.title
|
|
115
|
+
}, {
|
|
116
|
+
default() {
|
|
117
|
+
return h(getCurrComponent('el-checkbox-group'), {
|
|
118
|
+
modelValue: $formView ? $formView.getItemValue(widget) : null,
|
|
119
|
+
onChange: changeEvent,
|
|
120
|
+
'onUpdate:modelValue'(val) {
|
|
121
|
+
if ($formView) {
|
|
122
|
+
$formView.setItemValue(widget, val);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}, {
|
|
126
|
+
default: () => {
|
|
127
|
+
return options.options
|
|
128
|
+
? options.options.map((item, index) => {
|
|
129
|
+
return h(getCurrComponent('el-checkbox'), {
|
|
130
|
+
key: index,
|
|
131
|
+
value: item.value
|
|
132
|
+
}, {
|
|
133
|
+
default() {
|
|
134
|
+
return `${item.value}`;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
})
|
|
138
|
+
: [];
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return {
|
|
147
|
+
getWidgetElCheckboxConfig,
|
|
148
|
+
WidgetElCheckboxFormComponent,
|
|
149
|
+
WidgetElCheckboxViewComponent
|
|
150
|
+
};
|
|
151
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { defineComponent, h } from 'vue';
|
|
2
|
+
import { getCurrComponent } from '../util/comp';
|
|
3
|
+
export function createWidgetElDatePicker(VxeUI) {
|
|
4
|
+
const getWidgetElDatePickerConfig = (params) => {
|
|
5
|
+
return {
|
|
6
|
+
title: '日期',
|
|
7
|
+
icon: 'vxe-icon-input',
|
|
8
|
+
options: {
|
|
9
|
+
placeholder: '请选择'
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const WidgetElDatePickerFormComponent = defineComponent({
|
|
14
|
+
props: {
|
|
15
|
+
renderOpts: {
|
|
16
|
+
type: Object,
|
|
17
|
+
default: () => ({})
|
|
18
|
+
},
|
|
19
|
+
renderParams: {
|
|
20
|
+
type: Object,
|
|
21
|
+
default: () => ({})
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
emits: [],
|
|
25
|
+
setup(props) {
|
|
26
|
+
const VxeUIFormComponent = VxeUI.getComponent('VxeForm');
|
|
27
|
+
const VxeUIFormItemComponent = VxeUI.getComponent('VxeFormItem');
|
|
28
|
+
const VxeUISwitchComponent = VxeUI.getComponent('VxeSwitch');
|
|
29
|
+
return () => {
|
|
30
|
+
const { renderParams } = props;
|
|
31
|
+
const { widget } = renderParams;
|
|
32
|
+
return h(VxeUIFormComponent, {
|
|
33
|
+
class: 'vxe-form-design--widget-render-form-wrapper',
|
|
34
|
+
vertical: true,
|
|
35
|
+
span: 24,
|
|
36
|
+
titleBold: true,
|
|
37
|
+
titleOverflow: true,
|
|
38
|
+
data: widget.options
|
|
39
|
+
}, {
|
|
40
|
+
default() {
|
|
41
|
+
return [
|
|
42
|
+
h(VxeUIFormItemComponent, {
|
|
43
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.name')
|
|
44
|
+
}, {
|
|
45
|
+
default() {
|
|
46
|
+
return h(getCurrComponent('el-input'), {
|
|
47
|
+
modelValue: widget.title,
|
|
48
|
+
'onUpdate:modelValue'(val) {
|
|
49
|
+
widget.title = val;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}),
|
|
54
|
+
h(VxeUIFormItemComponent, {
|
|
55
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.placeholder'),
|
|
56
|
+
field: 'placeholder',
|
|
57
|
+
itemRender: { name: 'ElDatePicker' }
|
|
58
|
+
}),
|
|
59
|
+
h(VxeUIFormItemComponent, {
|
|
60
|
+
title: VxeUI.getI18n('vxe.formDesign.widgetProp.required')
|
|
61
|
+
}, {
|
|
62
|
+
default() {
|
|
63
|
+
return h(VxeUISwitchComponent, {
|
|
64
|
+
modelValue: widget.required,
|
|
65
|
+
'onUpdate:modelValue'(val) {
|
|
66
|
+
widget.required = val;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
];
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
const WidgetElDatePickerViewComponent = defineComponent({
|
|
78
|
+
props: {
|
|
79
|
+
renderOpts: {
|
|
80
|
+
type: Object,
|
|
81
|
+
default: () => ({})
|
|
82
|
+
},
|
|
83
|
+
renderParams: {
|
|
84
|
+
type: Object,
|
|
85
|
+
default: () => ({})
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
emits: [],
|
|
89
|
+
setup(props) {
|
|
90
|
+
const VxeUIFormItemComponent = VxeUI.getComponent('VxeFormItem');
|
|
91
|
+
const changeEvent = () => {
|
|
92
|
+
const { renderParams } = props;
|
|
93
|
+
const { widget, $formView } = renderParams;
|
|
94
|
+
if ($formView) {
|
|
95
|
+
const itemValue = $formView ? $formView.getItemValue(widget) : null;
|
|
96
|
+
$formView.updateWidgetStatus(widget, itemValue);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
return () => {
|
|
100
|
+
const { renderParams } = props;
|
|
101
|
+
const { widget, $formView } = renderParams;
|
|
102
|
+
const { options } = widget;
|
|
103
|
+
return h(VxeUIFormItemComponent, {
|
|
104
|
+
class: ['vxe-form-design--widget-render-form-item'],
|
|
105
|
+
field: widget.field,
|
|
106
|
+
title: widget.title
|
|
107
|
+
}, {
|
|
108
|
+
default() {
|
|
109
|
+
return h(getCurrComponent('el-date-picker'), {
|
|
110
|
+
modelValue: $formView ? $formView.getItemValue(widget) : null,
|
|
111
|
+
placeholder: options.placeholder,
|
|
112
|
+
onChange: changeEvent,
|
|
113
|
+
'onUpdate:modelValue'(val) {
|
|
114
|
+
if ($formView) {
|
|
115
|
+
$formView.setItemValue(widget, val);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return {
|
|
125
|
+
getWidgetElDatePickerConfig,
|
|
126
|
+
WidgetElDatePickerFormComponent,
|
|
127
|
+
WidgetElDatePickerViewComponent
|
|
128
|
+
};
|
|
129
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { h } from 'vue';
|
|
2
|
+
import { createWidgetElInput } from './input-widget';
|
|
3
|
+
import { createWidgetElTextarea } from './textarea-widget';
|
|
4
|
+
import { createWidgetElInputNumber } from './number-input-widget';
|
|
5
|
+
import { createWidgetElDatePicker } from './date-picker-widget';
|
|
6
|
+
import { createWidgetElSelect } from './select-widget';
|
|
7
|
+
import { createWidgetElRadio } from './radio-widget';
|
|
8
|
+
import { createWidgetElCheckbox } from './checkbox-widget';
|
|
9
|
+
import { createWidgetElSwitch } from './switch-widget';
|
|
10
|
+
/**
|
|
11
|
+
* 表单设计器 - 渲染器
|
|
12
|
+
*/
|
|
13
|
+
export function defineFormDesignRender(VxeUI) {
|
|
14
|
+
const { getWidgetElInputConfig, WidgetElInputViewComponent, WidgetElInputFormComponent } = createWidgetElInput(VxeUI);
|
|
15
|
+
const { getWidgetElTextareaConfig, WidgetElTextareaViewComponent, WidgetElTextareaFormComponent } = createWidgetElTextarea(VxeUI);
|
|
16
|
+
const { getWidgetElInputNumberConfig, WidgetElInputNumberViewComponent, WidgetElInputNumberFormComponent } = createWidgetElInputNumber(VxeUI);
|
|
17
|
+
const { getWidgetElDatePickerConfig, WidgetElDatePickerViewComponent, WidgetElDatePickerFormComponent } = createWidgetElDatePicker(VxeUI);
|
|
18
|
+
const { getWidgetElSelectConfig, WidgetElSelectViewComponent, WidgetElSelectFormComponent } = createWidgetElSelect(VxeUI);
|
|
19
|
+
const { getWidgetElRadioConfig, WidgetElRadioViewComponent, WidgetElRadioFormComponent } = createWidgetElRadio(VxeUI);
|
|
20
|
+
const { getWidgetElCheckboxConfig, WidgetElCheckboxViewComponent, WidgetElCheckboxFormComponent } = createWidgetElCheckbox(VxeUI);
|
|
21
|
+
const { getWidgetElSwitchConfig, WidgetElSwitchViewComponent, WidgetElSwitchFormComponent } = createWidgetElSwitch(VxeUI);
|
|
22
|
+
VxeUI.renderer.mixin({
|
|
23
|
+
ElInputWidget: {
|
|
24
|
+
createFormDesignWidgetConfig: getWidgetElInputConfig,
|
|
25
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
26
|
+
return h(WidgetElInputViewComponent, { renderOpts, renderParams });
|
|
27
|
+
},
|
|
28
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
29
|
+
return h(WidgetElInputFormComponent, { renderOpts, renderParams });
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
ElTextareaWidget: {
|
|
33
|
+
createFormDesignWidgetConfig: getWidgetElTextareaConfig,
|
|
34
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
35
|
+
return h(WidgetElTextareaViewComponent, { renderOpts, renderParams });
|
|
36
|
+
},
|
|
37
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
38
|
+
return h(WidgetElTextareaFormComponent, { renderOpts, renderParams });
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
ElNumberInputWidget: {
|
|
42
|
+
createFormDesignWidgetConfig: getWidgetElInputNumberConfig,
|
|
43
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
44
|
+
return h(WidgetElInputNumberViewComponent, { renderOpts, renderParams });
|
|
45
|
+
},
|
|
46
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
47
|
+
return h(WidgetElInputNumberFormComponent, { renderOpts, renderParams });
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
ElDatePickerWidget: {
|
|
51
|
+
createFormDesignWidgetConfig: getWidgetElDatePickerConfig,
|
|
52
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
53
|
+
return h(WidgetElDatePickerViewComponent, { renderOpts, renderParams });
|
|
54
|
+
},
|
|
55
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
56
|
+
return h(WidgetElDatePickerFormComponent, { renderOpts, renderParams });
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
ElSelectWidget: {
|
|
60
|
+
createFormDesignWidgetConfig: getWidgetElSelectConfig,
|
|
61
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
62
|
+
return h(WidgetElSelectViewComponent, { renderOpts, renderParams });
|
|
63
|
+
},
|
|
64
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
65
|
+
return h(WidgetElSelectFormComponent, { renderOpts, renderParams });
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
ElRadioWidget: {
|
|
69
|
+
createFormDesignWidgetConfig: getWidgetElRadioConfig,
|
|
70
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
71
|
+
return h(WidgetElRadioViewComponent, { renderOpts, renderParams });
|
|
72
|
+
},
|
|
73
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
74
|
+
return h(WidgetElRadioFormComponent, { renderOpts, renderParams });
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
ElCheckboxWidget: {
|
|
78
|
+
createFormDesignWidgetConfig: getWidgetElCheckboxConfig,
|
|
79
|
+
createFormDesignWidgetFieldValue: () => [],
|
|
80
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
81
|
+
return h(WidgetElCheckboxViewComponent, { renderOpts, renderParams });
|
|
82
|
+
},
|
|
83
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
84
|
+
return h(WidgetElCheckboxFormComponent, { renderOpts, renderParams });
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
ElSwitchWidget: {
|
|
88
|
+
createFormDesignWidgetConfig: getWidgetElSwitchConfig,
|
|
89
|
+
renderFormDesignWidgetView(renderOpts, renderParams) {
|
|
90
|
+
return h(WidgetElSwitchViewComponent, { renderOpts, renderParams });
|
|
91
|
+
},
|
|
92
|
+
renderFormDesignWidgetFormView(renderOpts, renderParams) {
|
|
93
|
+
return h(WidgetElSwitchFormComponent, { renderOpts, renderParams });
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|