New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

linkmore-form

Package Overview
Dependencies
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

linkmore-form

基于Antd表单Form的二次封装

latest
npmnpm
Version
1.0.40
Version published
Maintainers
1
Created
Source

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;

Keywords

Antd表单

FAQs

Package last updated on 05 Aug 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts