feat(form): add 'layout', 'labelAlign', 'rowProps' option (#651)

* feat(form):  add 'layout', 'labelAlign', 'rowProps' option

1.添加Form布局方式,当layout: 'vertical',labelWidth可以控制col间距
2.添加Form的全局label对齐方式, labelAlign: left | right
3.添加Form的Row组件所支持属性,控制Col间的间距,对齐方式,布局方式

* feat(Rate): add 'Rate' module

*添加评分组件,并添加了dome例子
This commit is contained in:
liuzhidong 2021-05-25 22:25:13 +08:00 committed by GitHub
parent 94a826d028
commit 785732f438
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 11 deletions

View File

@ -1,12 +1,12 @@
<template> <template>
<Form <Form
v-bind="{ ...$attrs, ...$props }" v-bind="{ ...$attrs, ...$props, ...getProps }"
:class="getFormClass" :class="getFormClass"
ref="formElRef" ref="formElRef"
:model="formModel" :model="formModel"
@keypress.enter="handleEnterPress" @keypress.enter="handleEnterPress"
> >
<Row :style="getRowWrapStyle"> <Row v-bind="{ ...getRow }">
<slot name="formHeader"></slot> <slot name="formHeader"></slot>
<template v-for="schema in getSchema" :key="schema.field"> <template v-for="schema in getSchema" :key="schema.field">
<FormItem <FormItem
@ -62,6 +62,8 @@
import { basicProps } from './props'; import { basicProps } from './props';
import { useDesign } from '/@/hooks/web/useDesign'; import { useDesign } from '/@/hooks/web/useDesign';
import type { RowProps } from 'ant-design-vue/lib/grid/Row';
export default defineComponent({ export default defineComponent({
name: 'BasicForm', name: 'BasicForm',
components: { FormItem, Form, Row, FormAction }, components: { FormItem, Form, Row, FormAction },
@ -100,10 +102,13 @@
]; ];
}); });
// Get uniform row style // Get uniform row style and Row configuration for the entire form
const getRowWrapStyle = computed((): CSSProperties => { const getRow = computed((): CSSProperties | RowProps => {
const { baseRowStyle = {} } = unref(getProps); const { baseRowStyle = {}, rowProps } = unref(getProps);
return baseRowStyle; return {
style: baseRowStyle,
...rowProps,
};
}); });
const getSchema = computed((): FormSchema[] => { const getSchema = computed((): FormSchema[] => {
@ -253,7 +258,7 @@
formModel, formModel,
defaultValueRef, defaultValueRef,
advanceState, advanceState,
getRowWrapStyle, getRow,
getProps, getProps,
formElRef, formElRef,
getSchema, getSchema,

View File

@ -16,7 +16,8 @@ import {
Switch, Switch,
TimePicker, TimePicker,
TreeSelect, TreeSelect,
Slider Slider,
Rate,
} from 'ant-design-vue'; } from 'ant-design-vue';
import RadioButtonGroup from './components/RadioButtonGroup.vue'; import RadioButtonGroup from './components/RadioButtonGroup.vue';
@ -46,6 +47,7 @@ componentMap.set('Checkbox', Checkbox);
componentMap.set('CheckboxGroup', Checkbox.Group); componentMap.set('CheckboxGroup', Checkbox.Group);
componentMap.set('Cascader', Cascader); componentMap.set('Cascader', Cascader);
componentMap.set('Slider', Slider); componentMap.set('Slider', Slider);
componentMap.set('Rate', Rate);
componentMap.set('DatePicker', DatePicker); componentMap.set('DatePicker', DatePicker);
componentMap.set('MonthPicker', DatePicker.MonthPicker); componentMap.set('MonthPicker', DatePicker.MonthPicker);

View File

@ -3,7 +3,7 @@ import type { CSSProperties, PropType } from 'vue';
import type { ColEx } from './types'; import type { ColEx } from './types';
import type { TableActionType } from '/@/components/Table'; import type { TableActionType } from '/@/components/Table';
import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes'; import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes';
import type { RowProps } from 'ant-design-vue/lib/grid/Row';
import { propTypes } from '/@/utils/propTypes'; import { propTypes } from '/@/utils/propTypes';
export const basicProps = { export const basicProps = {
@ -95,4 +95,6 @@ export const basicProps = {
colon: propTypes.bool, colon: propTypes.bool,
labelAlign: propTypes.string, labelAlign: propTypes.string,
rowProps: Object as PropType<RowProps>,
}; };

View File

@ -6,6 +6,7 @@ import type { FormItem } from './formItem';
import type { ColEx, ComponentType } from './index'; import type { ColEx, ComponentType } from './index';
import type { TableActionType } from '/@/components/Table/src/types/table'; import type { TableActionType } from '/@/components/Table/src/types/table';
import type { CSSProperties } from 'vue'; import type { CSSProperties } from 'vue';
import type { RowProps } from 'ant-design-vue/lib/grid/Row';
export type FieldMapToTime = [string, [string, string], string?][]; export type FieldMapToTime = [string, [string, string], string?][];
@ -49,11 +50,15 @@ export type RegisterFn = (formInstance: FormActionType) => void;
export type UseFormReturnType = [RegisterFn, FormActionType]; export type UseFormReturnType = [RegisterFn, FormActionType];
export interface FormProps { export interface FormProps {
// layout?: 'vertical' | 'inline' | 'horizontal'; layout?: 'vertical' | 'inline' | 'horizontal';
// Form value // Form value
model?: Recordable; model?: Recordable;
// The width of all items in the entire form // The width of all items in the entire form
labelWidth?: number | string; labelWidth?: number | string;
//alignment
labelAlign?: 'left' | 'right';
//Row configuration for the entire form
rowProps?: RowProps;
// Submit form on reset // Submit form on reset
submitOnReset?: boolean; submitOnReset?: boolean;
// Col configuration for the entire form // Col configuration for the entire form

View File

@ -109,4 +109,5 @@ export type ComponentType =
| 'Upload' | 'Upload'
| 'IconPicker' | 'IconPicker'
| 'Render' | 'Render'
| 'Slider'; | 'Slider'
| 'Rate';

View File

@ -350,6 +350,19 @@
span: 8, span: 8,
}, },
}, },
{
field: 'field22',
component: 'Rate',
label: '字段22',
defaultValue: 3,
colProps: {
span: 8,
},
componentProps: {
disabled: false,
allowHalf: true,
},
},
]; ];
export default defineComponent({ export default defineComponent({