1.0.40 • Published 2 years ago

linkmore-form v1.0.40

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

FormJson

表单的json化配置,使用 JSON Schema 国际规范

Schema结构

结构描述

{
    type: 'objcet', // 组件值的类型
    properties: { // 只在对象组件(type: object)中使用,properties 用于包裹对象的子属性:
        title: '输入框', // 标题,作为label展示
        type: 'string', // 组件值的类型
        widget: 'textarea', // 部件名称
        default: '默认值', // 默认值
        required: true, // 必填
    }
}

基础属性

  • type, format, enumwidget 字段决定了使用哪个组件来渲染
  • type, format, min, max, requiredrules 字段用于做校验判断
  • props 字段用于补充组件支持的更为细致的属性
{
	displayType: 'row',
  labelWidth: 130,
  type: 'object',
  properties: {
    url: {
      title: 'url输入框',
      placeholder: '//www.taobao.com',
      type: 'string',
      format: 'url',
      required: true,
    },
    email: {
      title: 'email输入框',
      type: 'string',
      format: 'email',
    },
    string: {
      title: '正则校验字符串',
      description: 'a-z',
      type: 'string',
      hidden: false,
      disabled: true,
      rules: [{ pattern: '^[a-z]+$' }]
    },
  },
}

Api

参数说明类型可选默认
title标题String--
type值的数据类型String'string', 'number', 'boolean', 'array', 'object', 'range', 'html'-
format格式化String'image', 'textarea', 'color'/'email', 'url'/ 'dateTime', 'date', 'time', 'upload'
displayType展示方式String'row', 'column'row
description描述String--
descType描述的类型String'text'/'icon'-

使用示例

展示

import React, { useEffect } from 'react'
import { Button } from 'antd';
import FormJson, { useForm } from 'RForm';
import Setting from './Edit/setting';

const schema = {
  type: 'object',
  displayType: 'row',
  properties: {
    input1: {
      title: '简单输入框',
      type: 'string',
      required: true,
      default: '111',
      description: '来FR个提示',
      tooltip: 'antd提示无效',
      width: '33.333%',
      widget: 'input',
      seq: 1,
    },
    select1: {
      title: '单选',
      type: 'string',
      width: '33.333%',
      tooltip: 'antd提示无效',
      widget: 'select',
      api: '基础数据',
      seq: 2,
    },
    object2: {
      title: '单选',
      type: 'string',
      enum: ['ck1', 'ck2'],
      enumNames: ['选项一', '选项二'],
      width: '33.333%',
      widget: 'radio',
      seq: 3,
    },
    object3: {
      title: '复选',
      type: 'array',
      enum: ['ck1', 'ck2'],
      enumNames: ['选项一', '选项二'],
      width: '33.333%',
      widget: 'checkboxes',
      seq: 4,
      buttons: [
        {
          "text": "复制",
          "icon": "CopyOutlined",
          "callback": "copyLast"
        }
      ]
    },
  },
};


const Paas = () => {
  const form = useForm();

  // 提交表单
  const onFinish = (formData, errors) => {
    if (errors.length > 0) {
      console.log('errors:', errors)
    } else {
      console.log('formData:', formData)
    }
  };

  useEffect(() => {
    // 加载数据至下拉框: 服务端获取schema非空时使用
    setTimeout(() => {
      form && form.setSchemaByPath('select1', {
        enum: ['east', 'south', 'west', 'north'],
        enumNames: ['东', '南', '西', '北'],
      });
    }, 1000);
  }, [])

  return (
    <>
      <div>
        <div>k333</div>
        <div>
          <Setting schema={schema} form={form} />
          <FormJson schema={schema} form={form} onFinish={onFinish} />
          <Button type="primary" onClick={() => form.submit()}>提交</Button>
        </div>
      </div>
    </>
  )
};

export default Paas;
1.0.40

2 years ago

1.0.39

2 years ago

1.0.38

2 years ago

1.0.37

2 years ago

1.0.35

2 years ago

1.0.34

2 years ago

1.0.33

2 years ago

1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

2 years ago

1.0.29

2 years ago

1.0.28

2 years ago

1.0.27

2 years ago

1.0.26

2 years ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago