Ben Lin
2024-07-01 f60c5156615626515bd6d84f151a1292b8b936c1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { FormSchema } from '@/components/Form';
 
type InputType = 'InputTextArea' | 'InputNumber' | 'Input';
export interface PromptProps {
  title: string;
  label?: string;
  required?: boolean;
  onOK?: Fn;
  inputType?: InputType;
  labelWidth?: number;
  width?: string;
  layout?: 'horizontal' | 'vertical' | 'inline';
  defaultValue?: string | number;
}
 
interface genFormSchemasProps {
  label?: string;
  required?: boolean;
  inputType?: InputType;
  defaultValue?: string | number;
}
 
const inputTypeMap: {
  [key in InputType]: {
    colProps: { span: number; offset?: number };
    componentProps: FormSchema['componentProps'];
  };
} = {
  InputTextArea: {
    colProps: { span: 23 },
    componentProps: {
      placeholder: '请输入内容',
      autoSize: { minRows: 2, maxRows: 6 },
      maxlength: 255,
      showCount: true,
    },
  },
  InputNumber: {
    colProps: { span: 20, offset: 2 },
    componentProps: {
      placeholder: '请输入数字',
      min: 0,
    },
  },
  Input: {
    colProps: { span: 20, offset: 2 },
    componentProps: {
      placeholder: '请输入内容',
      min: 0,
    },
  },
};
 
export function genFormSchemas({
  label = '备注信息',
  required = true,
  inputType = 'InputTextArea',
  defaultValue = '',
}: genFormSchemasProps) {
  const formSchema: FormSchema = {
    field: 'txt',
    component: inputType,
    label,
    defaultValue,
    required: Boolean(required),
    ...inputTypeMap[inputType],
  };
  return [formSchema];
}