npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cqsjjb-formily/embed

v0.0.15

Published

动态表单嵌入组件

Downloads

3

Readme

@cqsjjb-formily/embed

动态表单嵌入组件

Usage

import React from 'react';
import RendererEmbed from '@cqsjjb-formily/embed';

function Component () {
  // 获取表单实例,用于函数操作
  const [ formily, setFormily ] = React.useState({});
  // 用于跟踪加载状态
  const [ isReady, setIsReady ] = React.useState(false);
  
  React.useEffect(() => {
    if (isReady) {
      // 回填表单数据
      formily.setFieldsValue({});
    }
  }, [ isReady ]);
  
  return (
    <RendererEmbed
      code={/*表单模板ID*/}
      style={/*自定义样式*/}
      width={/*渲染嵌入宽度*/}
      height={/*渲染嵌入高度*/}
      postUrl={/*iframe白名单地址*/}
      onLoad={e => {
        // iframe加载回调
        setFormily(e);
        setIsReady(true);
      }}
      onCallback={e => {
        // iframe操作回调
        if (e.type === 'validateFields') {
          // 输出表单提交字段数据
          console.log(e.output);
        }
      }}
    />
  );
}

props

  1. code: string

    表单模板code,每一个渲染的表单都需要一个模板code,内部会根据code自动查询模板数据。

  2. style: React.CSSProperties

    自定义style

  3. width: number | string

    iframe 宽度

  4. height: number | string

    iframe 高度

  5. postUrl: string

    iframe嵌入访问白名单,需要联系管理员配置当前前端服务域名白名单,若已配置白名单,请传入**window.location.origin**即可。

  6. onLoad: (option: FormilyInstance) => void;

    iframe嵌入加载状态,完成加载会返回一个表单实例对象,操作对象可以对表单进行控制。

  7. onCallback: (option: FormilyCallback): void;

    表单内部操作回调,可以返回表单验证数据等。

FormilyInstance

  1. initialFormily(): void

    初始化表单嵌入,加载表单模板。

  2. resetFields(fields?: string[]): void;

    重置表单,可传入fields参数指定重置字段。

  3. enabledFields(): void;

    启用表单。

  4. validateFields(fields?: string[]): void;

    验证表单,可传入fields参数指定验证字段。

  5. disabledFields(): void;

    禁用表单。

  6. readonlyFields(state: boolean): void;

    将表单设为只读状态,可以传入state参数控制状态。

  7. setFieldsValue(values: { [p: string]: any }): void;

    动态设置表单字段数据。

  8. getFieldsValue(fields?: string[]): void;

    获取指定表单字段数据。

FormilyCallback

  1. type: 'getFieldsValue' | 'setFieldsValue' | 'readonlyFields' | 'disabledFields' | 'resetFields' | 'validateFields' | 'changeValues';

    每一种类型对应,**FormilyInstance**的函数操作。

  2. output: any;

    返回每一种类型对应的返回值。

常见问题

  1. 若出现iframe加载访问错误,需要确定当前前端服务域名是否已配置白名单。