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

@klaus_v_reinherz/v-formdesigner

v0.0.13

Published

v-formdesigner 是基于 ElementUI + vue3-smooth-dnd 实现的表单设计器组件,可以通过拖拽方式快速创建表单

Downloads

59

Readme

动态表单设计器

v-formdesigner 是基于 ElementUI + vue3-smooth-dnd 实现的表单设计器组件,可以通过拖拽方式快速创建表单

开始

安装

# 安装表单设计器
pnpm add @klaus_v_reinherz/v-formdesigner

修改 mian.ts

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import ElementPlus from 'element-plus' //请自行导入ElementPlus并挂载
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import 'element-plus/dist/index.css'
import '@klaus_v_reinherz/v-formdesigner/dist/style.css' //引入所需样式

const app = createApp(App)
app.use(ElementPlus, {
  locale: zhCn,
})
app.mount('#app')

vite-env.d.ts 文件中添加声明模块

/// <reference types="vite/client" />
declare module '@klaus_v_reinherz/v-formdesigner'

App.vue 中引入

<script setup lang="ts">
import { FormDesigner } from '@klaus_v_reinherz/v-formdesigner'
</script>

<template>
  <form-designer />
</template>

<style scoped></style>

FormDesigner 表单设计器

表单设计器包含保存方法,并且会走接口保存,保存成功后有 success 回调

<script setup lang="ts">
import { ref } from 'vue'
import { FormDesigner } from '@klaus_v_reinherz/v-formdesigner'

let designeRef = ref<any>(null) //表单设计器组件

// 获取模板详情
function getDetail() {
  designeRef.value.getTemplateDetail({ id: 3 })
}

function handleSuccess() {
  console.log('保存成功')
}
</script>

<template>
  <el-button @click="getDetail">获取详情</el-button>
  <form-designer ref="designeRef" @success="handleSuccess" />
</template>

<style scoped></style>

Attributes

| 名称 | 类型 | 说明 | | ------- | -------- | ---------------- | | success | Function | 保存成功后的回调 |

Exposes

| 名称 | 类型 | 入参 | 说明 | | ----------------- | -------- | ------ | ------------------------------------ | | getTemplateDetail | Function | {id:1} | 传递 object 对象,之后保存将处于编辑 |


FromCreate 表单

表单组件渲染需要传递模版 id,渲染表单内容需要传递表单 id

<script setup lang="ts">
import { ref } from 'vue'
import { FormCreate } from '@klaus_v_reinherz/v-formdesigner'

interface RuleFormData {
  [key: string]: any
}
let formRef = ref<any>(null) //表单组件

// 获取表单模板
function setFormTemplate() {
  formRef.value.getTemplateDetail({ id: 1 }) //id:模板id
}
  
// 设置表单数据
function setFormData() {
  formRef.value.getFormDetail({ id: 1 }) //id:表单id
}
  
// 校验
function handleSubmit() {
  formRef.value.validate()
}
  
// 后续业务处理,目前是组件内部走接口解决这个事情
function handleSuccess(form: RuleFormData) {
  console.log('保存成功,表单数据为:', form)
}
</script>

<template>
  <el-button @click="setFormTemplate">渲染表单</el-button>
  <el-button @click="setFormData">编辑表单内容</el-button>
  <form-create ref="formRef" @success="handleSuccess" />
  <el-button type="primary" @click="handleSubmit">提交</el-button>
</template>

<style scoped></style>

Attributes

| 名称 | 类型 | 说明 | | ------- | -------- | ---------------- | | success | Function | 保存成功后的回调 |

Exposes

| 名称 | 类型 | 入参 | 说明 | | ----------------- | -------- | ------ | ------------------------------------------------------ | | getTemplateDetail | Function | {id:1} | 传递 object 对象,作为入参 | | getFormDetail | Function | {id:1} | 传递 object 对象,作为入参,之后保存将处于编辑表单内容 |