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

@forzoom/form-renderer

v0.1.4

Published

`@forzoom/form-renderer`是表单生成的基础,通过向设置表单配置,其提供的`Renderer`组件能够将表单渲染出来。

Downloads

13

Readme

使用

@forzoom/form-renderer是表单生成的基础,通过向设置表单配置,其提供的Renderer组件能够将表单渲染出来。

具体的表单中的每一项,称为一个Section,因为Section的种类太过丰富,所以@forzoom/form-renderer本身不提供任何的Section,而是由一些其他的库来提供,这样可以做到按需使用。

以下是几个提供Section的库,目前只有移动端的样式: @forzoom/item-form提供了一个看上去不那么紧凑的表单组件,单页能够容纳的信息较少。 @forzoom/compact-form提供了样式较为紧凑的表单组件。

例子

下面是一个简单的例子,其中的代码基本是使用@forzoom/form-renderer的固定模板。

import { FormRendererComponent, Renderer } from '@forzoom/form-renderer';
import { FormPageMeta } from '@forzoom/form-renderer/types/form';
import { ItemFormSectionMeta } from '@forzoom/item-form/types/form';
import { Toast } from 'vant';

@Component({
    name: 'Page',
    components: {
        Renderer,
    },
    template: `
        <div>
            <Renderer :meta="meta" :form.sync="form" @error="onError" />
        </div>
    `,
})
class Page extends Vue {
    public form: any = {
        avatar: null,
    };

    public get meta(): Array<FormPageMeta<ItemFormSectionMeta>> {
        const sections: ItemFormSectionMeta[] = [
            {
                type: 'ItemUploader',
                key: 'avatar',
                titleComponent: false,
                props: {
                    title: '头像',
                    httpRequest: async (image) => {
                        const rdata = await store.dispatch('upload', {
                            mediaId: image.key,
                            type: 'avatar',
                        });
                        return rdata.data;
                    },
                },
                validates: [
                    { trigger: 'validate', required: true, message: '请上传头像' },
                ],
            },
        ];
        const pages: FormPageMeta[] = [
            {
                sections,
            },
        ];
        return pages;
    }

    public onError(section: any, rule: any) {
        if (rule.message) {
            Toast(rule.message);
        }
    }

    /**
     * 点击提交
     */
    public async onClickSubmit() {
        const vm = this;
        // @ts-ignore
        const $renderer = vm.$refs.form as FormRendererComponent;

        if (!$renderer.isLastPage()) {
            $renderer.nextPage();
        } else {
            if ($renderer.validate()) {
                // 创建
                const createRdata = await store.dispatch('create', form);
            }
        }
    }
}

表单检查

数据操作

通过为section配置encodedecode参数,可以在数据传入/传出组件时对于数据进行操作。

// @example 对从组件中传出的数据,也就是用户输入的“收货人姓名”,删除前后的空格
const trim = (value: string) => value ? value.trim() : '';
const section = {
    type: 'CompactInput',
    key: 'name',
    props: {
        placeholder: '收货人姓名',
        textAlign: 'left',
    },
    decode: trim,
    validates: [
        { required: true, message: '请输入收货人姓名' },
    ],
};

自定义组件

除了使用@forzoom/item-form@forzoom/compact-form之外,还可以根据需要自定义Section

问题

  1. 使用SFC方式造成Section组件库文件过大
  2. cascader的finish需要更加灵活
  3. 依赖于van-popup