trump-form
v1.0.12
Published
``` npm install --registry=https://registry.npmmirror.com ```
Downloads
31
Readme
安装依赖
npm install --registry=https://registry.npmmirror.com开发调试
npm run serve生产打包
npm run build表单设计器 + 表单渲染器打包
npm run lib表单渲染器打包
npm run lib-render浏览器兼容性
Chrome(及同内核的浏览器如QQ浏览器、360浏览器等等),Edge, Firefox,Safari,IE 11
跟Vue项目集成
1. 安装包
npm i vform-builds或
yarn add vform-builds2. 引入并全局注册VForm组件
import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui' //引入element-ui库
import VForm from 'vform-builds' //引入VForm库
import 'element-ui/lib/theme-chalk/index.css' //引入element-ui样式
import 'vform-builds/dist/VFormDesigner.css' //引入VForm样式
Vue.config.productionTip = false
Vue.use(ElementUI) //全局注册element-ui
Vue.use(VForm) //全局注册VForm(同时注册了v-form-designer和v-form-render组件)
new Vue({
render: h => h(App),
}).$mount('#app')3. 在Vue模板中使用表单设计器组件
<template>
<v-form-designer></v-form-designer>
</template>
<script>
export default {
data() {
return {
}
}
}
</script>
<style lang="scss">
body {
margin: 0; /* 如果页面出现垂直滚动条,则加入此行CSS以消除之 */
}
</style>4. 在Vue模板中使用表单渲染器组件
<template>
<div>
<v-form-render :form-json="formJson" :form-data="formData" :option-data="optionData" ref="vFormRef">
</v-form-render>
<el-button type="primary" @click="submitForm">Submit</el-button>
</div>
</template>
<script>
export default {
data() {
return {
formJson: {"widgetList":[],"formConfig":{"labelWidth":80,"labelPosition":"left","size":"","labelAlign":"label-left-align","cssCode":"","customClass":"","functions":"","layoutType":"PC","onFormCreated":"","onFormMounted":"","onFormDataChange":""}},
formData: {},
optionData: {}
}
},
methods: {
submitForm() {
this.$refs.vFormRef.getFormData().then(formData => {
// Form Validation OK
alert( JSON.stringify(formData) )
}).catch(error => {
// Form Validation failed
this.$message.error(error)
})
}
}
}
</script>如何新增widget属性
- 在
src/components/form-designer/setting-panel/property-editor目录下新增属性组件
<template>
<el-form-item :label="i18nt('designer.setting.addFormFields')" v-if="!noLabelSetting">
<el-input type="text" v-model="optionModel.addFormFields"></el-input>
</el-form-item>
</template>
<script>
import i18n from "@/utils/i18n"
export default {
name: "addFormFields-editor",
mixins: [i18n],
props: {
designer: Object,
selectedWidget: Object,
optionModel: Object,
},
computed: {
noLabelSetting() {
return (this.selectedWidget.type === 'static-text') || (this.selectedWidget.type === 'html-text')
//|| (this.selectedWidget.type === 'divider')
},
}
}
</script>
<style lang="scss" scoped>
</style>2、在src/components/form-designer/setting-panel/propertyRegister.js中注册属性组件
const COMMON_PROPERTIES = {
'tableColumns' : 'tableColumns-editor',
'addFormFields': 'addFormFields-editor',
}3、在lang目录下新增对应语言的属性名称
4、在src/components/form-designer/widget-panel/widgetsConfig.js中填写属性
{
type: 'slot',
icon: 'slot-field',
formItemFlag: true,
options: {
name: '',
label: '',
hidden: false,
tableColumns:'',
addFormFields:'',
//-------------------
customClass: '', //自定义css类名
//-------------------
onCreated: '',
onMounted: '',
},
}如何增加新的组件(已有组件)
- 在
src/components/form-designer/widget-panel/widgetsConfig.js中增加组件配置 - 在
src/langdesigner.widgetLabel目录下增加对应语言的组件名称
