VUE+ELEMENT-UI的后台项目封装组件--查询form的封装
最近项目打算重构,项目的模块几乎都是以后台查询展示的传统的增删改差模式,所以卑微的我想要自己封装一下查询form,先上效果图
子组件页面:
<template>
<div class="sumbit-form">
<el-form
:model="value"
:rules="rules"
ref="ruleForm"
label-width="100px"
class="demo-ruleForm"
>
<slot name="formItem" />
<template v-for="(item, index) in formConfig.formItemList">
<el-row :key="index">
<template v-for="(i, k) in item">
<el-col :span="8" :key="k">
<template
v-if="
['text', 'textarea', 'number', 'email'].indexOf(i.type) !== -1
"
>
<el-form-item :label="i.label" :prop="i.prop ? i.prop : ''">
<el-input :type="i.type" v-model="value[i.name]"></el-input>
</el-form-item>
</template>
<template v-if="i.type === 'select'">
<el-form-item :label="i.label" :prop="i.prop ? i.prop : ''">
<el-select v-model="value[i.name]" placeholder="">
<el-option
v-for="(j, k) in i.optList"
:key="k"
:label="j.label"
:value="j.value"
></el-option>
</el-select>
</el-form-item>
</template>
<template
v-if="
['data', 'datetimerange', 'datetime'].indexOf(i.type) !== -1
"
>
<el-form-item :label="i.label" :prop="i.prop ? i.prop : ''">
<el-date-picker
v-model="value[i.name]"
type="datetimerange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期"
value-format="yyyy-MM-dd HH:mm:ss"
>
</el-date-picker>
</el-form-item>
</template>
<template v-if="i.type == 'switch'">
<el-form-item :label="i.label" :prop="i.prop ? i.prop : ''">
<el-switch v-model="value[i.name]"></el-switch>
</el-form-item>
</template>
<template v-if="i.type == 'radio'">
<el-form-item :label="i.label">
<el-radio-group v-model="value[i.name]">
<el-radio
v-for="(j, k) in i.optList"
:label="j"
:key="k"
></el-radio>
</el-radio-group>
</el-form-item>
</template>
<template v-if="i.type === 'Checkbox'">
<el-checkbox-group v-model="value[i.name]">
<el-checkbox
v-for="ch in i.checkboxs"
:label="ch.value"
:key="ch.value"
>{{ ch.label }}</el-checkbox
>
</el-checkbox-group>
</template>
</el-col>
</template>
</el-row>
</template> <div class="searchBtn">
<el-button-group>
<el-button
v-for="(item, index) in formConfig.operate"
:key="index"
size="small"
:type="item.type"
@click.stop.prevent="item.handleClick"
>{{ item.name }}
</el-button>
</el-button-group>
<slot name="operate"></slot>
</div>
</el-form>
</div>
</template>
<script>
export default {
props: {
formConfig: {
type: Object,
default: () => {}
},
value: {
type: Object,
default: () => {}
},
rules: {
type: Object,
default: () => {}
}
},
data() {
return {
isSearchLock: true
};
},
created() {},
methods: {
//子组件校验,传递到父组件
validateForm() {
let flag = null;
if (this.isSearchLock) {
this.$refs["ruleForm"].validate(valid => {
let vm = this;
if (valid) {
flag = true;
vm.isSearchLock = flag;
} else {
flag = false;
vm.isSearchLock = flag;
this.$message.error("保存信息不完整,请继续填写完整");
setTimeout(function() {
vm.isSearchLock = true;
}, 2000);
}
});
return flag;
}
},
resetFields() {
this.$refs["ruleForm"].resetFields();
}
},
mounted() {}
};
</script>
<style lang="less">
.el-form-item__content {
.el-date-editor--datetimerange {
width: 100%;
}
}
.searchBtn {
text-align: center;
.el-button {
background-color: #4a91d7;
width: 96px;
color: #fff;
&:first-child {
margin-right: 5px;
}
&:hover {
background-color: #257ccd;
border-color: #257ccd;
}
}
}
</style>
父组件里面调用
<flight-form
ref="childRules"
:formConfig="formConfig"
:value="form"
:rules="rules"
></flight-form>
<script>
import flightForm from "@/components/flightForm.vue";
export default{
components: {
flightForm , },
data() {
return {
formConfig: {
formItemList: [
[
{
type: "text",
prop: "airport",
label: "站点",
name: "airport",
placeholder: "请输入站点"
},
{
type: "select",
prop: "importOrExport",
label: "进出港",
name: "importOrExport",
placeholder: "请输入进出港",
optList: [
{
value: "",
label: ""
},
{
value: "进港",
label: "进港"
},
{
value: "出港",
label: "出港"
}
]
},
{
type: "select",
prop: "mainOrSubBill",
name: "mainOrSubBill",
label: "主分单", placeholder: "请输入主分单",
optList: [
{
value: "",
label: ""
},
{
value: "主分",
label: "主分"
},
{
value: "主单",
label: "主单"
}
]
}
],
[
{
type: "datetimerange",
name: "pickerdata",
label: "选择时间",
prop: "pickerdata",
dateFormate: "yyyy-MM-dd HH:mm:ss"
},
{
type: "text",
name: "largeClass",
prop: "largeClass",
label: "大类",
placeholder: "请输入大类"
},
{
type: "select",
name: "isDomestic",
prop: "isDomestic",
value: "国内",
label: "国内/国际",
placeholder: "请输入国内/国际",
optList: [
{
value: "",
label: ""
},
{
value: "国内",
label: "国内"
},
{
value: "国际",
label: "国际"
}
]
}
],
[
{
type: "switch",
name: "save",
prop: "save",
label: "保存"
},
{
type: "radio",
name: "radio",
prop: "radio",
label: "活动类型",
optList: ["演唱会", "球赛"]
},
{
type: "Checkbox",
label: "爱好",
prop: "Checkbox",
name: "Checkbox",
checkboxs: [
{ label: "羽毛球", value: "badminton" },
{ label: "篮球", value: "basketball" },
{ label: "足球", value: "football" },
{ label: "兵乓球", value: "pong" }
]
}
]
], operate: [
{
type: "primary",
name: "查询",
handleClick: this.search
},
{
type: "primary",
name: "重置",
handleClick: this.add
}
]
},
rules: {
airport: [{ required: true, message: "请输入站点", trigger: "blur" }],
importOrExport: [
{ required: true, message: "请输入进出港", trigger: "blur" }
],
largeClass: [
{ required: true, message: "请输入大类", trigger: "blur" }
],
mainOrSubBill: [
{ required: true, message: "请输入主分单", trigger: "blur" }
],
isDomestic: [
{ required: true, message: "请输入国内/国际", trigger: "blur" }
],
pickerdata: [
{ required: true, message: "请输入时间", trigger: "change" }
]
},
form: {
isDomestic: "国内",
mainOrSubBill: "主分",
importOrExport: "进港",
airport: "",
largeClass: "",
Checkbox: [],
pickerdata: [],
save: false,
radio: ""
},
}
},
methods: {
// 查询
search() {
let flag = this.$refs["childRules"].validateForm();
if (flag) {
console.log(this.form);
}
},
// 新增或重置
add() {
this.$refs["childRules"].resetFields();
},
},
}
}
</script>
父组件里面的form传给子组件是传默认值的,
卑微前端,记录自己的项目封装的组件,方便以后自己用,如果有哪里不合理,请各路大神多多指教。
VUE+ELEMENT-UI的后台项目封装组件--查询form的封装的更多相关文章
- vue+element ui 的表格列使用组件
前言:工作中用到 vue+element ui 的前端框架,有这个场景:很多表格的列有许多一样的,所以考虑将列封装为组件.转载请注明出处:https://www.cnblogs.com/yuxiaol ...
- Vue+element UI实现“回到顶部”按钮组件
介绍 这是一个可以快速回到页面顶部的组件,当用户浏览到页面底部的时候,通过点击按钮,可快速回到页面顶部. 使用方法 由于该组件是基于element-UI进行二次封装的,所以在使用该组件时请务必安装el ...
- vue+element ui 的上传文件使用组件
前言:工作中用到 vue+element ui 的前端框架,使用到上传文件,则想着封装为组件,达到复用,可扩展.转载请注明出处:https://www.cnblogs.com/yuxiaole/p/9 ...
- vue+element ui中select组件选择失效问题原因与解决方法
codejing 2020-07-10 09:13:31 652 收藏 分类专栏: Web Vue Element UI 版权 .当表单form赋完值后,如果后续又对form中某一属性值进行操作如 ...
- Vue+Element UI 实现视频上传
一.前言 项目中需要提供一个视频介绍,使用户能够快速.方便的了解如何使用产品以及注意事项. 前台使用Vue+Element UI中的el-upload组件实现视频上传及进度条展示,后台提供视频上传AP ...
- Vue+element ui table 导出到excel
需求: Vue+element UI table下的根据搜索条件导出当前所有数据 参考: https://blog.csdn.net/u010427666/article/details/792081 ...
- 基于vue(element ui) + ssm + shiro 的权限框架
zhcc 基于vue(element ui) + ssm + shiro 的权限框架 引言 心声 现在的Java世界,各种资源很丰富,不得不说,从分布式,服务化,orm,再到前端控制,权限等等玲琅满目 ...
- vue+element ui 的tab 动态增减,切换时提示用户是否切换
前言:工作中用到 vue+element ui 的前端框架,动态添加 Tab,删除 Tab,切换 Tab 时提示用户是否切换等,发现 element ui 有一个 bug,这里记录一下如何实现.转载 ...
- 在微信框架模块中,基于Vue&Element前端的后台管理功能介绍
微信开发包括公众号.企业微信.微信小程序等方面的开发内容,需要对腾信的微信API接口进行封装:包括事件.菜单.订阅用户.多媒体文件.图文消息.消息群发.微信支付和企业红包.摇一摇设备.语义理解.微信小 ...
随机推荐
- 如何理解Java中的自动拆箱和自动装箱?
小伟刚毕业时面的第一家公司就被面试官给问住了... 如何理解Java中的自动拆箱和自动装箱? 自动拆箱?自动装箱?什么鬼,听都没听过啊,这...这..知识盲区... 回到家后小伟赶紧查资料,我透,这不 ...
- 域渗透分析工具BloodHound
简介:BloodHound是一款将域内信息可视化的单页的web应用程序,是一款在域内进行信息收集的免费工具: Kali中直接命令安装即可 apt-get install bloodhound 打开lo ...
- 基于nodejs+express+mysql+webstorm+html的 增删改查
一.工具准备 Nodejs框架,WebStorm.Mysql服务.Navicat.此篇文章只讲项目的搭建过程,至于Nodejs,WebStorm.Mysql的下载.安装与配置网上资源很多,请自行查阅, ...
- Java多线程通关——基础知识挑战
等掌握了基础知识之后,才有资格说基础知识没用这样的话.否则就老老实实的开始吧. 对象的监视器 每一个Java对象都有一个监视器.并且规定,每个对象的监视器每次只能被一个线程拥有,只有拥有它的线 ...
- Spring boot Sample 012之spring-boot-web-upload
一.环境 1.1.Idea 2020.1 1.2.JDK 1.8 二.目的 spring boot 整合web实现文件上传下载 三.步骤 3.1.点击File -> New Project -& ...
- Rocket - util - ReduceOthers
https://mp.weixin.qq.com/s/gbR5fuDbE_nUFVxw-p4rsA 简单介绍ReduceOthers的实现. 1. 基本介绍 输入一组Bool元素 ...
- Spring Cloud 系列之 Apollo 配置中心(二)
本篇文章为系列文章,未读第一集的同学请猛戳这里:Spring Cloud 系列之 Apollo 配置中心(一) 本篇文章讲解 Apollo 部门管理.用户管理.配置管理.集群管理. 点击链接观看:Ap ...
- 移动端fixed兼容问题
最近做移动端页面,有个需求类似下图 底部导航用fixed定位时在部分iOS版本中会有问题: 1.上滑是底部会跟着滑动,手指松开时才会又回到底部 2.软键盘唤起的情况下,也会出现许多莫名其妙的问题 网上 ...
- Java实现 LeetCode 525 连续数组
525. 连续数组 给定一个二进制数组, 找到含有相同数量的 0 和 1 的最长连续子数组(的长度). 示例 1: 输入: [0,1] 输出: 2 说明: [0, 1] 是具有相同数量0和1的最长连续 ...
- Java实现 LeetCode 398 随机数索引
398. 随机数索引 给定一个可能含有重复元素的整数数组,要求随机输出给定的数字的索引. 您可以假设给定的数字一定存在于数组中. 注意: 数组大小可能非常大. 使用太多额外空间的解决方案将不会通过测试 ...