feat: 添加更多配置项 (#2607)

This commit is contained in:
luocong2016 2023-03-17 12:35:38 +08:00 committed by GitHub
parent b66a83c10f
commit f2ec2ca273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,6 +49,17 @@
{ value: 'default', label: 'defualt' }, { value: 'default', label: 'defualt' },
]; ];
const layoutList = [
{ value: 'vertical', label: 'vertical' },
{ value: 'inline', label: 'inline' },
{ value: 'horizontal', label: 'horizontal' },
];
const labelAlignList = [
{ value: 'left', label: 'left' },
{ value: 'right', label: 'right' },
];
const schemas: FormSchema[] = [ const schemas: FormSchema[] = [
{ {
field: 'field1', field: 'field1',
@ -157,10 +168,9 @@
}, },
}, },
]; ];
const formSchemas: FormSchema[] = [ const formSchemas: FormSchema[] = [
{ {
field: '', field: 'd1',
component: 'Divider', component: 'Divider',
label: '基础属性', label: '基础属性',
colProps: { span: 24 }, colProps: { span: 24 },
@ -168,15 +178,39 @@
orientation: 'center', orientation: 'center',
}, },
}, },
{
field: 'name',
defaultValue: 'useForm',
component: 'Input',
label: 'name',
colProps: { span: 24 },
},
{
field: 'layout',
defaultValue: 'horizontal',
component: 'RadioButtonGroup',
label: 'layout',
colProps: { span: 24 },
componentProps: {
options: layoutList,
},
},
{
field: 'labelAlign',
defaultValue: 'right',
component: 'RadioButtonGroup',
label: 'labelAlign',
colProps: { span: 24 },
componentProps: {
options: labelAlignList,
},
},
{ {
field: 'labelWidth', field: 'labelWidth',
defaultValue: 120, defaultValue: 120,
component: 'InputNumber', component: 'InputNumber',
label: 'labelWidth', label: 'labelWidth',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: {
size: 'small',
},
}, },
{ {
field: 'size', field: 'size',
@ -186,18 +220,21 @@
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: { componentProps: {
options: sizeList, options: sizeList,
size: 'small',
}, },
}, },
{
field: 'colon',
defaultValue: false,
component: 'Switch',
label: 'colon',
colProps: { span: 24 },
},
{ {
field: 'disabled', field: 'disabled',
defaultValue: false, defaultValue: false,
component: 'Switch', component: 'Switch',
label: 'disabled', label: 'disabled',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: {
size: 'small',
},
}, },
{ {
field: 'compact', field: 'compact',
@ -205,32 +242,99 @@
component: 'Switch', component: 'Switch',
label: 'compact', label: 'compact',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: {
size: 'small',
},
}, },
{ {
field: '', field: 'autoSetPlaceHolder',
defaultValue: true,
component: 'Switch',
label: 'autoSetPlaceHolder',
colProps: { span: 24 },
},
{
field: 'autoSubmitOnEnter',
defaultValue: false,
component: 'Switch',
label: 'autoSubmitOnEnter',
colProps: { span: 24 },
},
{
field: 'showAdvancedButton',
defaultValue: false,
component: 'Switch',
label: 'showAdvancedButton',
colProps: { span: 24 },
},
{
field: 'd2',
component: 'Divider', component: 'Divider',
label: '网格布局', label: '网格布局(rowProps)',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: { componentProps: {
orientation: 'center', orientation: 'center',
}, },
}, },
{ {
field: 'actionColOptions.span', field: 'rowProps.gutter.0',
component: 'Slider', component: 'InputNumber',
defaultValue: 24, defaultValue: 0,
label: 'span', label: 'Horizontal Gutter',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: { componentProps: {
min: 1, addonAfter: 'px',
max: 24,
}, },
}, },
{ {
field: '', field: 'rowProps.gutter.1',
component: 'InputNumber',
defaultValue: 0,
label: 'Vertical Gutter',
colProps: { span: 24 },
componentProps: {
addonAfter: 'px',
},
},
{
field: 'rowProps.align',
defaultValue: 'top',
component: 'Select',
label: 'align',
colProps: { span: 24 },
componentProps: {
options: [
{ value: 'stretch', label: 'stretch' },
{ value: 'bottom', label: 'bottom' },
{ value: 'top', label: 'top' },
{ value: 'middle', label: 'middle' },
],
},
},
{
field: 'rowProps.justify',
defaultValue: 'start',
component: 'Select',
label: 'justify',
colProps: { span: 24 },
componentProps: {
options: [
{ value: 'space-around', label: 'space-around' },
{ value: 'space-between', label: 'space-between' },
{ value: 'center', label: 'center' },
{ value: 'end', label: 'end' },
{ value: 'start', label: 'start' },
],
},
},
{
field: 'wrap',
defaultValue: true,
component: 'Switch',
label: 'wrap',
colProps: { span: 24 },
},
{
field: 'd3',
component: 'Divider', component: 'Divider',
label: '操作按钮', label: '操作按钮',
colProps: { span: 24 }, colProps: { span: 24 },
@ -242,11 +346,10 @@
field: 'showActionButtonGroup', field: 'showActionButtonGroup',
defaultValue: true, defaultValue: true,
component: 'Switch', component: 'Switch',
label: '操作按钮', label: 'showActionButtonGroup',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: ({ formActionType }) => { componentProps: ({ formActionType }) => {
return { return {
size: 'small',
onChange: async (val: boolean) => { onChange: async (val: boolean) => {
formActionType.updateSchema([ formActionType.updateSchema([
{ field: 'showResetButton', componentProps: { disabled: !val } }, { field: 'showResetButton', componentProps: { disabled: !val } },
@ -254,6 +357,10 @@
field: 'showSubmitButton', field: 'showSubmitButton',
componentProps: { disabled: !val }, componentProps: { disabled: !val },
}, },
{
field: 'actionColOptions.span',
componentProps: { disabled: !val },
},
]); ]);
}, },
}; };
@ -263,24 +370,36 @@
field: 'showResetButton', field: 'showResetButton',
defaultValue: true, defaultValue: true,
component: 'Switch', component: 'Switch',
label: '重置按钮', label: 'showResetButton',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: {
size: 'small',
},
}, },
{ {
field: 'showSubmitButton', field: 'showSubmitButton',
defaultValue: true, defaultValue: true,
component: 'Switch', component: 'Switch',
label: '提交按钮', label: 'showSubmitButton',
colProps: { span: 24 },
},
{
field: 'd4',
component: 'Divider',
label: '操作按钮网格布局(actionColOptions)',
colProps: { span: 24 }, colProps: { span: 24 },
componentProps: { componentProps: {
size: 'small', orientation: 'center',
}, },
}, },
{ {
field: '', field: 'actionColOptions.span',
component: 'Slider',
defaultValue: 24,
label: 'span',
colProps: { span: 24 },
componentProps: { min: 0, max: 24 },
},
{
field: 'd5',
component: 'Divider', component: 'Divider',
label: '其他事件', label: '其他事件',
colProps: { span: 24 }, colProps: { span: 24 },
@ -309,32 +428,29 @@
const visible = ref<boolean>(false); const visible = ref<boolean>(false);
const settingFormRef = ref(); const settingFormRef = ref();
const [registerSetting] = useForm({ const [registerSetting] = useForm({
labelWidth: 80, size: 'small',
schemas: formSchemas, schemas: formSchemas,
compact: true, compact: true,
actionColOptions: { span: 24 }, actionColOptions: { span: 24 },
showActionButtonGroup: false, showActionButtonGroup: false,
}); });
const resetSettings = async () => { const resetSettings = async () => {
setProps({ resetButtonOptions: { disabled: false, text: '重置' } }); setProps({ resetButtonOptions: { disabled: false, text: '重置' } });
setProps({ submitButtonOptions: { disabled: false, loading: false } }); setProps({ submitButtonOptions: { disabled: false, loading: false } });
await setFieldsValue({ field9: [] }); await setFieldsValue({ field9: [] });
await settingFormRef.value?.resetFields(); await settingFormRef.value?.resetFields();
}; };
const handleSubmitSetting = async (values: Recordable) => { const handleSubmitSetting = async (values: Recordable) => {
console.log(values);
await setProps(values); await setProps(values);
visible.value = false; visible.value = false;
}; };
const [register, { setProps, setFieldsValue, updateSchema }] = useForm({ const [register, { setProps, setFieldsValue, updateSchema }] = useForm({
labelWidth: 120, labelWidth: 120,
schemas, schemas,
actionColOptions: { span: 24 }, actionColOptions: { span: 24 },
fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']], fieldMapToTime: [['fieldTime', ['startTime', 'endTime'], 'YYYY-MM']],
}); });
async function handleLoad() { async function handleLoad() {
const promiseFn = function () { const promiseFn = function () {
return new Promise((resolve) => { return new Promise((resolve) => {
@ -348,9 +464,7 @@
}, 1000); }, 1000);
}); });
}; };
const item = await promiseFn(); const item = await promiseFn();
const { field9, province, city, district } = item as any; const { field9, province, city, district } = item as any;
await updateSchema({ await updateSchema({
field: 'field9', field: 'field9',
@ -359,16 +473,14 @@
}, },
}); });
await setFieldsValue({ field9 }); await setFieldsValue({ field9 });
visible.value = false;
} }
const showDrawer = () => { const showDrawer = () => {
visible.value = true; visible.value = true;
}; };
const onSettings = () => { const onSettings = () => {
settingFormRef.value?.submit(); settingFormRef.value?.submit();
}; };
const withClose = (formProps: Partial<FormProps>) => { const withClose = (formProps: Partial<FormProps>) => {
setProps(formProps); setProps(formProps);
visible.value = false; visible.value = false;