Skip to content

Commit

Permalink
feat(Form): 调整 props.rules 类型定义,并导出 Rules 类型 (#801)
Browse files Browse the repository at this point in the history
  • Loading branch information
1zumii committed May 10, 2024
1 parent 11019fe commit d7dc939
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion components/form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type { FormProps } from './interface';
export const FForm = withInstall<FormType>(Form as FormType, { FormItem });

export { formItemProps } from './interface';
export type { FormItemProps } from './interface';
export type { FormItemProps, FormRules, FormRuleItem } from './interface';
export const FFormItem = withNoopInstall<FormItemType>(
FormItem as FormItemType,
);
Expand Down
16 changes: 9 additions & 7 deletions components/form/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import type {
Ref,
ToRefs,
} from 'vue';
import type { RuleItem, Rules } from 'async-validator';
import type { RuleItem } from 'async-validator';
import type { ExtractPublicPropTypes } from '../_util/interface';
import { FORM_ITEM_ALIGN, FORM_LAYOUT, LABEL_POSITION } from './const';

export interface FFormRuleItem extends RuleItem {
export interface FormRuleItem extends RuleItem {
trigger?: string | string[];
}

export type FormRules = Record<string, FormRuleItem | FormRuleItem[]>;

export const formProps = {
model: Object,
rules: {
type: Object as PropType<Rules>,
default: () => ({} as Rules),
type: Object as PropType<FormRules>,
default: (): FormRules => ({}),
},
layout: {
type: String as PropType<
Expand Down Expand Up @@ -87,9 +89,9 @@ export const formItemProps = {
default: null as boolean,
},
rules: {
type: Array as PropType<FFormRuleItem[]>,
type: Array as PropType<FormRuleItem[]>,
default: () => {
return [] as FFormRuleItem[];
return [] as FormRuleItem[];
},
},
align: {
Expand Down Expand Up @@ -121,7 +123,7 @@ export interface FormItemInject {
export interface Field {
prop: string;
value: any;
rules: FFormRuleItem[];
rules: FormRuleItem[];
validateRules: (trigger?: string | string[]) => Promise<any>;
clearValidate: () => void;
resetField: () => void;
Expand Down

0 comments on commit d7dc939

Please sign in to comment.