state.ts 1.5 KB

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