Commit 785732f438916d7767ad44789c16216a6f6505a8
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例子
Showing
6 changed files
with
39 additions
and
11 deletions
src/components/Form/src/BasicForm.vue
1 | <template> | 1 | <template> |
2 | <Form | 2 | <Form |
3 | - v-bind="{ ...$attrs, ...$props }" | 3 | + v-bind="{ ...$attrs, ...$props, ...getProps }" |
4 | :class="getFormClass" | 4 | :class="getFormClass" |
5 | ref="formElRef" | 5 | ref="formElRef" |
6 | :model="formModel" | 6 | :model="formModel" |
7 | @keypress.enter="handleEnterPress" | 7 | @keypress.enter="handleEnterPress" |
8 | > | 8 | > |
9 | - <Row :style="getRowWrapStyle"> | 9 | + <Row v-bind="{ ...getRow }"> |
10 | <slot name="formHeader"></slot> | 10 | <slot name="formHeader"></slot> |
11 | <template v-for="schema in getSchema" :key="schema.field"> | 11 | <template v-for="schema in getSchema" :key="schema.field"> |
12 | <FormItem | 12 | <FormItem |
@@ -62,6 +62,8 @@ | @@ -62,6 +62,8 @@ | ||
62 | import { basicProps } from './props'; | 62 | import { basicProps } from './props'; |
63 | import { useDesign } from '/@/hooks/web/useDesign'; | 63 | import { useDesign } from '/@/hooks/web/useDesign'; |
64 | 64 | ||
65 | + import type { RowProps } from 'ant-design-vue/lib/grid/Row'; | ||
66 | + | ||
65 | export default defineComponent({ | 67 | export default defineComponent({ |
66 | name: 'BasicForm', | 68 | name: 'BasicForm', |
67 | components: { FormItem, Form, Row, FormAction }, | 69 | components: { FormItem, Form, Row, FormAction }, |
@@ -100,10 +102,13 @@ | @@ -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 | const getSchema = computed((): FormSchema[] => { | 114 | const getSchema = computed((): FormSchema[] => { |
@@ -253,7 +258,7 @@ | @@ -253,7 +258,7 @@ | ||
253 | formModel, | 258 | formModel, |
254 | defaultValueRef, | 259 | defaultValueRef, |
255 | advanceState, | 260 | advanceState, |
256 | - getRowWrapStyle, | 261 | + getRow, |
257 | getProps, | 262 | getProps, |
258 | formElRef, | 263 | formElRef, |
259 | getSchema, | 264 | getSchema, |
src/components/Form/src/componentMap.ts
@@ -16,7 +16,8 @@ import { | @@ -16,7 +16,8 @@ import { | ||
16 | Switch, | 16 | Switch, |
17 | TimePicker, | 17 | TimePicker, |
18 | TreeSelect, | 18 | TreeSelect, |
19 | - Slider | 19 | + Slider, |
20 | + Rate, | ||
20 | } from 'ant-design-vue'; | 21 | } from 'ant-design-vue'; |
21 | 22 | ||
22 | import RadioButtonGroup from './components/RadioButtonGroup.vue'; | 23 | import RadioButtonGroup from './components/RadioButtonGroup.vue'; |
@@ -46,6 +47,7 @@ componentMap.set('Checkbox', Checkbox); | @@ -46,6 +47,7 @@ componentMap.set('Checkbox', Checkbox); | ||
46 | componentMap.set('CheckboxGroup', Checkbox.Group); | 47 | componentMap.set('CheckboxGroup', Checkbox.Group); |
47 | componentMap.set('Cascader', Cascader); | 48 | componentMap.set('Cascader', Cascader); |
48 | componentMap.set('Slider', Slider); | 49 | componentMap.set('Slider', Slider); |
50 | +componentMap.set('Rate', Rate); | ||
49 | 51 | ||
50 | componentMap.set('DatePicker', DatePicker); | 52 | componentMap.set('DatePicker', DatePicker); |
51 | componentMap.set('MonthPicker', DatePicker.MonthPicker); | 53 | componentMap.set('MonthPicker', DatePicker.MonthPicker); |
src/components/Form/src/props.ts
@@ -3,7 +3,7 @@ import type { CSSProperties, PropType } from 'vue'; | @@ -3,7 +3,7 @@ import type { CSSProperties, PropType } from 'vue'; | ||
3 | import type { ColEx } from './types'; | 3 | import type { ColEx } from './types'; |
4 | import type { TableActionType } from '/@/components/Table'; | 4 | import type { TableActionType } from '/@/components/Table'; |
5 | import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes'; | 5 | import type { ButtonProps } from 'ant-design-vue/es/button/buttonTypes'; |
6 | - | 6 | +import type { RowProps } from 'ant-design-vue/lib/grid/Row'; |
7 | import { propTypes } from '/@/utils/propTypes'; | 7 | import { propTypes } from '/@/utils/propTypes'; |
8 | 8 | ||
9 | export const basicProps = { | 9 | export const basicProps = { |
@@ -95,4 +95,6 @@ export const basicProps = { | @@ -95,4 +95,6 @@ export const basicProps = { | ||
95 | colon: propTypes.bool, | 95 | colon: propTypes.bool, |
96 | 96 | ||
97 | labelAlign: propTypes.string, | 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 './formItem'; | @@ -6,6 +6,7 @@ import type { FormItem } from './formItem'; | ||
6 | import type { ColEx, ComponentType } from './index'; | 6 | import type { ColEx, ComponentType } from './index'; |
7 | import type { TableActionType } from '/@/components/Table/src/types/table'; | 7 | import type { TableActionType } from '/@/components/Table/src/types/table'; |
8 | import type { CSSProperties } from 'vue'; | 8 | import type { CSSProperties } from 'vue'; |
9 | +import type { RowProps } from 'ant-design-vue/lib/grid/Row'; | ||
9 | 10 | ||
10 | export type FieldMapToTime = [string, [string, string], string?][]; | 11 | export type FieldMapToTime = [string, [string, string], string?][]; |
11 | 12 | ||
@@ -49,11 +50,15 @@ export type RegisterFn = (formInstance: FormActionType) => void; | @@ -49,11 +50,15 @@ export type RegisterFn = (formInstance: FormActionType) => void; | ||
49 | export type UseFormReturnType = [RegisterFn, FormActionType]; | 50 | export type UseFormReturnType = [RegisterFn, FormActionType]; |
50 | 51 | ||
51 | export interface FormProps { | 52 | export interface FormProps { |
52 | - // layout?: 'vertical' | 'inline' | 'horizontal'; | 53 | + layout?: 'vertical' | 'inline' | 'horizontal'; |
53 | // Form value | 54 | // Form value |
54 | model?: Recordable; | 55 | model?: Recordable; |
55 | // The width of all items in the entire form | 56 | // The width of all items in the entire form |
56 | labelWidth?: number | string; | 57 | labelWidth?: number | string; |
58 | + //alignment | ||
59 | + labelAlign?: 'left' | 'right'; | ||
60 | + //Row configuration for the entire form | ||
61 | + rowProps?: RowProps; | ||
57 | // Submit form on reset | 62 | // Submit form on reset |
58 | submitOnReset?: boolean; | 63 | submitOnReset?: boolean; |
59 | // Col configuration for the entire form | 64 | // Col configuration for the entire form |
src/components/Form/src/types/index.ts
src/views/demo/form/index.vue
@@ -350,6 +350,19 @@ | @@ -350,6 +350,19 @@ | ||
350 | span: 8, | 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 | export default defineComponent({ | 368 | export default defineComponent({ |