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

vue3-ant-schema-form

v1.0.4

Published

一个基于 ant design vue 组件库的 schema 配置表单组件,能够颗粒化更新,性能优化

Downloads

16

Readme

schema-form

一个基于 ant design vue 组件库的 schema 配置表单组件,能够颗粒化更新,性能优化

优点

最大程度保留了组件库的 API,能够快速上手,和 ant design vue 表单项互通

schema 说明

dataIndex?: string; 字段名称,唯一标识符,渲染表单项的 field controlType: formControlType | string; 渲染表单项的表单组件名称、如果内部不存在的话会抛出错误 label?: string; formItem 的 label formItemProps?: FormItemProps; formItem 的所有 props 对应 ant design vue 的 formItemProps 会自动注入 controlRenderPops?: any; 渲染表单项的 props renderFormItem?: () => VNode | VNode[]; 当在 JSX  情况下可以自行定义渲染 hideInForm?: boolean; 在表单中是否显示 rowPorps?: RowProps; 当在 group 模式下时,可以通过 rowprops 进行随意组合,会自动在外层加入 row 包裹 colProps?: ColProps; 当在 group 模式下时,可以设置每一项的 col props formListProps?: { spaceProps?: SpaceProps; 外部 space 包裹 addButtonProps?: ButtonProps & { text?: string }; 添加按钮的 props delButtonProps?: ButtonProps & { text?: string }; 删除按钮的 props addButtonSlot?: string; 添加按钮 插槽 delButtonSlot?: string; 删除按钮 插槽 }; 当是 formList 时的渲染方式的参数 slot?: string; 表单项的插槽

controlType 内置表单项

Input InputGroup InputSearch InputNumber InputPassword TextArea AutoComplete Radio RadioGroup Checkbox CheckboxGroup Select Cascader DatePicker RangePicker Mentions Rate Slider Switch TimePicker TimeRangePicker Transfer TreeSelect Upload group formList

使用示例

<script setup lang="ts">
  import { reactive, ref } from "vue";
  import { Input, Button, FormInstance, Upload } from "ant-design-vue";
  import BaseForm from "./package/schemaForm/BaseForm.tsx";
  import { schemaFormType } from "./package/schemaForm/types/form";
  const formRef = ref<FormInstance>();
  const columns: schemaFormType[] = [
    {
      dataIndex: "name1",
      controlType: "Input",
      formItemProps: {
        label: "name1",
        rules: [{ required: true, message: "请输入name1" }],
      },
    },
    {
      dataIndex: "name2",
      controlType: "Input",
      formItemProps: {
        label: "name2",
        rules: [{ required: true, message: "请输入name2" }],
      },
    },
    {
      dataIndex: "select1",
      controlType: "Select",
      formItemProps: {
        label: "select1",
        rules: [{ required: true, message: "请输入name2" }],
      },
      controlRenderPops: {
        options: [
          { label: "测试1", value: "1" },
          { label: "测试2", value: "2" },
        ],
        allowClear: true,
      },
    },
    {
      controlType: "group",
      columns: [
        {
          dataIndex: "group1",
          controlType: "Input",
          formItemProps: {
            label: "group1",
          },
          controlRenderPops: {
            placeholder: "请输入group1",
          },
          colProps: {
            span: 8,
          },
        },
        {
          controlType: "group",
          columns: [
            {
              dataIndex: "group1-group1",
              controlType: "Input",
              formItemProps: {
                label: "group1-group1",
              },
              colProps: {
                span: 12,
              },
            },
            {
              dataIndex: "group1-group2",
              controlType: "Input",
              formItemProps: {
                label: "group1-group2",
              },
              colProps: {
                span: 11,
                offset: 1,
              },
            },
          ],
          colProps: {
            span: 14,
            offset: 2,
          },
        },
      ],
    },
    {
      dataIndex: "formList",
      controlType: "formList",
      formListProps: {
        addButtonProps: {
          block: true,
          text: "Add",
        },
      },
      columns: [
        {
          dataIndex: "formList2",
          controlType: "Input",
          formItemProps: {
            label: "formList2",
            rules: [{ required: true, message: "请输入formList2" }],
          },
        },
        {
          dataIndex: "formList1",
          controlType: "Input",
          formItemProps: {
            label: "formList1",
            rules: [{ required: true, message: "请输入formList1" }],
          },
        },
      ],
    },
    {
      dataIndex: "uploda",
      controlType: "Upload",
      formItemProps: {
        label: "文件",
        // rules: [{ required: true, message: "请上传文件" }],
      },
      slot: "uploadFile",
    },
    {
      dataIndex: "transfer",
      controlType: "Transfer",
      label: "transfer",
      controlRenderPops: {},
    },
    {
      dataIndex: "radio",
      controlType: "RadioGroup",
      label: "radio",
      controlRenderPops: {
        options: [
          {
            label: "radio1",
            value: 1,
          },
          {
            label: "radio2",
            value: 2,
          },
          {
            label: "radio3",
            value: 3,
            disabled: true,
          },
        ],
      },
    },
    {
      dataIndex: "checkbox",
      controlType: "CheckboxGroup",
      label: "checkbox",
      controlRenderPops: {
        options: [
          {
            label: "radio1",
            value: 1,
          },
          {
            label: "radio2",
            value: 2,
          },
          {
            label: "radio3",
            value: 3,
            disabled: true,
          },
        ],
      },
    },
    {
      dataIndex: "treeSelect",
      controlType: "TreeSelect",
      label: "treeselect",
      controlRenderPops: {
        allowClear: true,
        placeholder: "请输入",
        treeData: [
          {
            label: "Node1",
            value: "0-0",
            children: [
              {
                label: "Child Node1",
                value: "0-0-0",
              },
            ],
          },
          {
            label: "Node2",
            value: "0-1",

            children: [
              {
                label: "Child Node3",
                value: "0-1-0",
                disabled: true,
              },
              {
                label: "Child Node4",
                value: "0-1-1",
              },
              {
                label: "Child Node5",
                value: "0-1-2",
              },
            ],
          },
        ],
      },
    },
  ];
  const modelForm = reactive({
    name1: "name1",
    name2: "name2",
    name3: "name3",
    formList: [
      {
        list1: "list1",
        list2: "list2",
        list3: [
          {
            list6: "list6",
          },
        ],
      },
    ],
  });
  const handleSubmit = () => {
    formRef.value?.validate();
    console.log(modelForm);
    console.log(formRef.value?.getFieldsValue());
  };
</script>

<template>
  <div class="container">
    <BaseForm :model="modelForm" :schemas="columns" ref="formRef">
      <template #name3Slot="{ schema }">
        <input
          :disabled="modelForm.name2 === 'nanme2'"
          v-bind="schema.controlRenderPops"
          v-model:value="modelForm.name3"
        />
      </template>
      <template #uploadFile="{ schema }">
        <Upload>
          <button>点击文件上传</button>
        </Upload>
      </template>
    </BaseForm>
    <button @click="handleSubmit">提交</button>
  </div>
</template>

<style lang="less" scoped>
  .container {
    width: 600px;
    margin: 0 auto;
  }
</style>

示例渲染结果

表单渲染结果