Commit 785732f438916d7767ad44789c16216a6f6505a8

Authored by liuzhidong
Committed by GitHub
1 parent 94a826d0

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例子
src/components/Form/src/BasicForm.vue
1 1 <template>
2 2 <Form
3   - v-bind="{ ...$attrs, ...$props }"
  3 + v-bind="{ ...$attrs, ...$props, ...getProps }"
4 4 :class="getFormClass"
5 5 ref="formElRef"
6 6 :model="formModel"
7 7 @keypress.enter="handleEnterPress"
8 8 >
9   - <Row :style="getRowWrapStyle">
  9 + <Row v-bind="{ ...getRow }">
10 10 <slot name="formHeader"></slot>
11 11 <template v-for="schema in getSchema" :key="schema.field">
12 12 <FormItem
... ... @@ -62,6 +62,8 @@
62 62 import { basicProps } from './props';
63 63 import { useDesign } from '/@/hooks/web/useDesign';
64 64  
  65 + import type { RowProps } from 'ant-design-vue/lib/grid/Row';
  66 +
65 67 export default defineComponent({
66 68 name: 'BasicForm',
67 69 components: { FormItem, Form, Row, FormAction },
... ... @@ -100,10 +102,13 @@
100 102 ];
101 103 });
102 104  
103   - // Get uniform row style
104   - const getRowWrapStyle = computed((): CSSProperties => {
105   - const { baseRowStyle = {} } = unref(getProps);
106   - return baseRowStyle;
  105 + // Get uniform row style and Row configuration for the entire form
  106 + const getRow = computed((): CSSProperties | RowProps => {
  107 + const { baseRowStyle = {}, rowProps } = unref(getProps);
  108 + return {
  109 + style: baseRowStyle,
  110 + ...rowProps,
  111 + };
107 112 });
108 113  
109 114 const getSchema = computed((): FormSchema[] => {
... ... @@ -253,7 +258,7 @@
253 258 formModel,
254 259 defaultValueRef,
255 260 advanceState,
256   - getRowWrapStyle,
  261 + getRow,
257 262 getProps,
258 263 formElRef,
259 264 getSchema,
... ...
src/components/Form/src/componentMap.ts
... ... @@ -16,7 +16,8 @@ import {
16 16 Switch,
17 17 TimePicker,
18 18 TreeSelect,
19   - Slider
  19 + Slider,
  20 + Rate,
20 21 } from 'ant-design-vue';
21 22  
22 23 import RadioButtonGroup from './components/RadioButtonGroup.vue';
... ... @@ -46,6 +47,7 @@ componentMap.set(&#39;Checkbox&#39;, Checkbox);
46 47 componentMap.set('CheckboxGroup', Checkbox.Group);
47 48 componentMap.set('Cascader', Cascader);
48 49 componentMap.set('Slider', Slider);
  50 +componentMap.set('Rate', Rate);
49 51  
50 52 componentMap.set('DatePicker', DatePicker);
51 53 componentMap.set('MonthPicker', DatePicker.MonthPicker);
... ...
src/components/Form/src/props.ts
... ... @@ -3,7 +3,7 @@ import type { CSSProperties, PropType } from &#39;vue&#39;;
3 3 import type { ColEx } from './types';
4 4 import type { TableActionType } from '/@/components/Table';
5 5 import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes';
6   -
  6 +import type { RowProps } from 'ant-design-vue/lib/grid/Row';
7 7 import { propTypes } from '/@/utils/propTypes';
8 8  
9 9 export const basicProps = {
... ... @@ -95,4 +95,6 @@ export const basicProps = {
95 95 colon: propTypes.bool,
96 96  
97 97 labelAlign: propTypes.string,
  98 +
  99 + rowProps: Object as PropType<RowProps>,
98 100 };
... ...
src/components/Form/src/types/form.ts
... ... @@ -6,6 +6,7 @@ import type { FormItem } from &#39;./formItem&#39;;
6 6 import type { ColEx, ComponentType } from './index';
7 7 import type { TableActionType } from '/@/components/Table/src/types/table';
8 8 import type { CSSProperties } from 'vue';
  9 +import type { RowProps } from 'ant-design-vue/lib/grid/Row';
9 10  
10 11 export type FieldMapToTime = [string, [string, string], string?][];
11 12  
... ... @@ -49,11 +50,15 @@ export type RegisterFn = (formInstance: FormActionType) =&gt; void;
49 50 export type UseFormReturnType = [RegisterFn, FormActionType];
50 51  
51 52 export interface FormProps {
52   - // layout?: 'vertical' | 'inline' | 'horizontal';
  53 + layout?: 'vertical' | 'inline' | 'horizontal';
53 54 // Form value
54 55 model?: Recordable;
55 56 // The width of all items in the entire form
56 57 labelWidth?: number | string;
  58 + //alignment
  59 + labelAlign?: 'left' | 'right';
  60 + //Row configuration for the entire form
  61 + rowProps?: RowProps;
57 62 // Submit form on reset
58 63 submitOnReset?: boolean;
59 64 // Col configuration for the entire form
... ...
src/components/Form/src/types/index.ts
... ... @@ -109,4 +109,5 @@ export type ComponentType =
109 109 | 'Upload'
110 110 | 'IconPicker'
111 111 | 'Render'
112   - | 'Slider';
  112 + | 'Slider'
  113 + | 'Rate';
... ...
src/views/demo/form/index.vue
... ... @@ -350,6 +350,19 @@
350 350 span: 8,
351 351 },
352 352 },
  353 + {
  354 + field: 'field22',
  355 + component: 'Rate',
  356 + label: '字段22',
  357 + defaultValue: 3,
  358 + colProps: {
  359 + span: 8,
  360 + },
  361 + componentProps: {
  362 + disabled: false,
  363 + allowHalf: true,
  364 + },
  365 + },
353 366 ];
354 367  
355 368 export default defineComponent({
... ...