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

@lambo-design-mobile/dynamic-form

v1.0.0-beta.12

Published

DynamicForm是一个动态表单组件,根据后端服务返回的json数据渲染表单

Downloads

54

Readme

DynamicForm 动态表单

介绍

DynamicForm是一个动态表单组件,根据后端服务返回的json数据渲染表单

引入

import Vue from 'vue';
import DynamicForm from '@lambo-design-mobile/dynamic-form';

Vue.use(DynamicForm);

属性

| 属性 | 类型 | 默认值 | 说明 | | ------------- | ------ |---|---------------------| | value | Object | {} | 表单的数据定义,推荐使用v-model | | metadataId | String | '' | 动态表单的元数据编码 | | customComponents | Object | {} | 自定义组件 | | customValidates | Object | {} | 自定义校验规则 |

Api

  • validate 校验form表单当前输入值是否合法
  • formReset 重置form校验

自定义组件和自定义校验

创建自定义校验文件check.js

import ajax from "@lambo-design-mobile/shared/utils/ajax";
import config from "@/config/config"

export default {
  checkSingle: async function(rule, value, callback) {
    if (value) {
      let finalUrl = config.upmsServerContext + "/manage/demoUser/get";
      if (finalUrl) {
        let params = {
          userId: value
        };
        const {data} = await ajax.get(finalUrl, {params: params});
        if (data.code == 1 && data.data) {
          callback("用户编码已存在");
        } else {
          callback();
        }
      } else {
        callback();
      }
    } else {
      callback("用户编码不能为空");
    }
  }
}

创建自定义组件文件input.vue

<template>
  <div>
    <Input type="text" v-model="input1" @on-change="changeValue" style="width: 80px"></Input>
    <Select v-model="input2" @on-change="changeValue" style="width: 80px">
      <Option :value="'1'">分钟</Option>
      <Option :value="'2'">小时</Option>
    </Select>
  </div>
</template>

<script>
  export default {
    name: "input2",
    props:{
      value: String
    },
    data(){
      return{
        input1: '',
        input2: ''
      }
    },
    watch: {
      value: function (){
        this.initData()
      }
    },
    methods:{
      initData(){
        if (this.value) {
          this.input1 = this.value.split(",")[0]
          this.input2 = this.value.split(",")[1]
        } else {
          this.input1 = ''
          this.input2 = ''
        }
      },
      changeValue() {
        this.$emit("changeInputValue",this.input1+','+this.input2)
      },
      /*validate(rule, value, callback) {
        console.log("value=",value)
        if (value) {
          if (value) {
            let vv = value.split(",");
            console.log("vv=",vv)
            console.log("vv=",(vv.length == 2 && vv[0] && vv[1]))
            if (vv.length == 2 && vv[0] && vv[1]) {
              callback();
            } else {
              callback("请输入参数2!!!!!");
            }
          } else {
            callback("请输入参数!!!!!");
          }
        } else {
          callback("请输入参数!");
        }
      }*/
    },
    mounted() {
      this.initData();
    }
  }
</script>

<style scoped>

</style>

在编辑页文件form.vue中引入check.js和input.vue

<template>
  <LamboDynamicForm ref="ldForm" v-model="formData"
                    :metadataId="metadataId"
                    :customComponents="customComponents"
                    :customValidates="customValidates"
                    @input="getInput"/>
</template>

<script>
  import LamboDynamicForm from '@lambo-design-mobile/dynamic-form';
  import input2 from './components/input2'
  import checkJs from './components/checkJs'

  export default {
    name: "form",
    data() {
      return {
        formData: {},
        metadataId: '1',
        customComponents: {//自定义组件
          'input2': input2
        },
        customValidates: {//自定义校验规则
          'checkSingle2' : checkJs.checkSingle
        }
      }
    },
    components:{
      LamboDynamicForm
    },
    computed: {
      title: function () {
        return this.$route.meta.title
      }
    },
    methods:{
      getInput(val){
        console.log("input=",val)
      },
      pageGoBack() {
        this.$router.push({ name: '动态表格' })
      },
      async doSubmit() {
        const isValid = await Promise.all([
          this.$refs.ldForm.validate(),
        ])
        console.log("isValid=" + isValid)
      },
      doReset(){
        this.formData = {}
      }
    }
  }
</script>

<style scoped>

</style>