element+vue 之动态form

在这里插入图片描述

1.页面部分

   <div v-for="(item,index) in formList" :key="index"><el-col :span="6" v-if="item.inputType==0"><el-form-item :label="item.conditionName" :prop="item.conditionCode":rules="{required: item.required==0?false:true, message:item.placeHolder?item.placeHolder:'请输入', trigger: 'change' }"><el-input v-model.trim="detailForm[item.conditionCode]" :placeholder="item.placeHolder"clearable></el-input></el-form-item></el-col><el-col :span="6" v-else-if="item.inputType==1"><el-form-item :label="item.conditionName" :prop="item.conditionCode":rules="{required: item.required==0?false:true, message: item.placeHolder?item.placeHolder:'请输入', trigger: 'change' }"><el-input v-model.number="detailForm[item.conditionCode]":placeholder="item.placeHolder" clearable></el-input></el-form-item></el-col><el-col :span="24" v-else-if="item.inputType==2"><el-form-item :label="item.conditionName" :prop="item.conditionCode" :rows="3":rules="{required: item.required==0?false:true, message:item.placeHolder?item.placeHolder:'请输入', trigger: 'change' }"><el-input clearable style="width: 100%" v-model.trim="detailForm[item.conditionCode]"autocomplete="off" placeholder="请输入" type="textarea" maxlength="100"></el-input></el-form-item></el-col><el-col :span="24" v-else-if="item.inputType==3"><el-form-item :label="item.conditionName" :prop="item.conditionCode":rules="{required: item.required==0?false:true, message:item.placeHolder?item.placeHolder:'请选择', trigger: 'change' }"><!-- <el-input v-model="detailForm[item.conditionCode]" v-show="false" /> --><el-upload list-type="picture-card" action="#" :headers="headers" multiple:before-upload="beforeUpload" :http-request="f_upload" :on-remove="handleRemoveUrl":on-preview="handlePictureCardPreview" :file-list="fileImgurl"accept=".jpg,.jpeg,.png,.bmp"><i slot="default" class="el-icon-plus"></i><div class="el-upload__tip" slot="tip">仅支持JPGJPEGPNGBMP格式文件</div></el-upload><el-dialog :visible.sync="dialogVisible" :modal-append-to-body="false"><img width="100%" :src="dialogImageUrl" alt=""></el-dialog></el-form-item></el-col><el-col :span="24" v-else-if="item.inputType==4 && item.singleton==0"><el-form-item :label="item.conditionName" :prop="item.conditionCode":rules="{required: item.required==0?false:true, message:item.placeHolder?item.placeHolder:'请选择', trigger: 'change' }"><el-checkbox-group v-model="detailForm[item.conditionCode]"><el-col :span="24" v-if="item.optionList"><el-checkbox v-for="(it,ind) in item.optionList" :label="it.name":key="ind"></el-checkbox></el-col></el-checkbox-group></el-form-item></el-col><el-col :span="6" v-else-if="item.inputType==4 && item.singleton==1"><el-form-item :label="item.conditionName" :prop="item.conditionCode":rules="{required: item.required==0?false:true, message:item.placeHolder?item.placeHolder:'请选择', trigger: 'change' }"><el-radio-group v-model="detailForm[item.conditionCode]"><el-col :span="24" v-if="item.optionList"><el-radio v-for="(it,ind)  in item.optionList" :label="it.name":key="ind">{{it.name}}</el-radio></el-col></el-radio-group></el-form-item></el-col><el-col :span="6" v-else-if="item.inputType==5"><el-form-item :label="item.conditionName" :prop="item.conditionCode":rules="{required: item.required==0?false:true, message:item.placeHolder?item.placeHolder:'请选择', trigger: 'change' }"><el-select v-model="detailForm[item.conditionCode]" placeholder="请选择"style="width: 100%" v-if="item.optionList":multiple="item.inputType==5 && item.singleton==0"><el-option v-for="(it,ind) in item.optionList" :key="ind" :label="it.name":value="it.name"></el-option></el-select></el-form-item></el-col></div>

2.数据格式

在这里插入图片描述

 "decisionConditionList": [{"conditionCode": "carHygiene",//表单键"conditionName": "车辆卫生",//表单名称"inputType": 5,//表单类型"conditionValueList": ["是"],//表单值"required": 1,//是否必填"singleton": 0,"placeHolder": "请选择","optionList": [{"name": "是","defaultType": 0},{"name": "否","defaultType": null}]},{"conditionCode": "productSpotCheck","conditionName": "是否抽检","inputType": 4,"conditionValueList": ["否"],"required": 1,"singleton": 1,"placeHolder": "请选择","optionList": [{"name": "是","defaultType": 0},{"name": "否","defaultType": 1}]},{"conditionCode": "carPlateNum","conditionName": "车辆号","inputType": 0,"conditionValueList": ["1"],"required": 1,"singleton": null,"placeHolder": "请输入","optionList": null},{"conditionCode": "carPlate","conditionName": "车辆数量","inputType": 1,"conditionValueList": ["1"],"required": 0,"singleton": null,"placeHolder": "请输入","optionList": null},{"conditionCode": "problemDesc","conditionName": "问题类型","inputType": 4,"conditionValueList": ["问题一"],"required": 1,"singleton": 0,"placeHolder": "请选择","optionList": [{"name": "问题一","defaultType": 0},{"name": "问题二","defaultType": 0},{"name": "问题三","defaultType": 0},{"name": "问题四","defaultType": 0}]},{"conditionCode": "imgUrl","conditionName": "图片","inputType": 3,"conditionValueList": ["https://warehouse-permanent.obs.cn-east-3.myhuaweicloud.com/74cc681c-fe39-429c-886e-8e086378c2ef.png","https://warehouse-permanent.obs.cn-east-3.myhuaweicloud.com/5b312d59-8c40-431b-ad99-ac908bbb7707.png"],"required": 1,"singleton": null,"placeHolder": "请选择","optionList": null},{"conditionCode": "remarkTwo","conditionName": "备注","inputType": 2,"conditionValueList": ["1"],"required": 0,"singleton": null,"placeHolder": "1","optionList": null}],

3.数据处理 因为后端给的数据都是数组 表单有些需要数组有些需要字符串

 this.formList = res.data.data.decisionConditionList;if (this.formList) {this.formList.forEach(a => {if (a.inputType == 4 && a.singleton == 0 || a.inputType == 5 && a.singleton == 0) {this.$set(this.detailForm, a.conditionCode, a.conditionValueList ? a.conditionValueList : [])} else if (a.inputType == 3) {var fileImgurl = []if (a.conditionValueList) {a.conditionValueList.forEach((item, index) => {fileImgurl.push(Object.assign({}, { url: item }))})this.fileImgurl=fileImgurl}this.$set(this.detailForm, a.conditionCode, a.conditionValueList ? a.conditionValueList : [])}else {this.$set(this.detailForm, a.conditionCode, a.conditionValueList ? a.conditionValueList.toString() : '')}})}

4.关于图片部分的js

  // 上传之前beforeUpload(file) {if (!this.checkFileType(file)) {return false}this.$forceUpdate()},// 效验文件类型checkFileType(file) {let allowTypesSet = new Set(["jpg", "jpeg", "png", "bmp", "pdf"])let fileType = file.name.replace(/.+\./, "")if (!allowTypesSet.has(fileType)) {this.$message({type: "warning",message: "不支持该文件类型"})return false}return true},//预览图片handlePictureCardPreview(file) {this.dialogImageUrl = file.url;this.dialogVisible = true;},//删除图片handleRemoveUrl(file, fileList) {if (fileList.length) {this.fileImgurl.filter((item, index) => {if (item.url == file.url) {this.fileImgurl.splice(index, 1);}});let results = this.fileImgurl.map(n => n.url);this.formList.forEach(index => {if (index.inputType == 3) {this.$set(this.detailForm, index.conditionCode, results)}})} else {this.formList.forEach(index => {if (index.inputType == 3) {this.$set(this.detailForm, index.conditionCode, [])}})this.fileImgurl = []}},// 导入f_upload(data) {const formData = new FormData()formData.append("file", data.file)this.handlefileUpload(formData)},//上传方法handlefileUpload(formData) {fileUpload(formData).then((res) => {const { code, msg } = res.dataif (code == 200) {this.formList.forEach(a => {if (a.inputType == 3) {var arr = a.conditionValueList ? a.conditionValueList : [];arr.push(res.data.data)this.$set(this.detailForm, a.conditionCode, arr)}})this.fileImgurl.push({ url: res.data.data })} else {const title = "操作失败"const type = "error"this.$notification(title, type, msg)}}).catch(() => { })},

4.提交

//提交这里还是要按照上面的格式提交

 this.formList.forEach((item, index) => {this.detailForm.decisionConditionList.push(Object.assign({},item, { conditionValueList: item.inputType == 4 && item.singleton == 0 || item.inputType == 5 && item.singleton == 0 || item.inputType == 3 ? this.detailForm[item.conditionCode] : [this.detailForm[item.conditionCode]] }))})

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/59661.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

我的2048创作纪念日

目录 一、来龙去脉二、2048天前的今天三、2048天的收获四、2048天后的今天五、祝福 一、来龙去脉 今天是 2023 年 8 月 9 日&#xff0c;在咖啡馆浏览我的 CSDN 主页时&#xff0c;看到官方发来了一则私信&#xff1a; 二、2048天前的今天 提示&#xff1a;可以和大家分享最初…

使用docker 搭建nginx + tomcat 集群

创建3个Tomcat容器&#xff0c;端口分别映射到 8080,8081,8082&#xff0c;使用数据卷挂载&#xff0c;分别将宿主机目录下的 /opt/module/docker/tomcat3/ROOT1/&#xff0c;/opt/module/docker/tomcat3/ROOT2/&#xff0c;/opt/module/docker/tomcat3/ROOT2/ 挂载到 容器内部…

Java从入门到精通(四)· 面向对象

Java从入门到精通&#xff08;四&#xff09; 面向对象 一 静态关键字&#xff08;static&#xff09; static表示静态关键字&#xff0c;可以用来修饰成员变量和成员方法。 被 static修饰的成员变量&#xff0c;称之为静态成员变量或者类变量&#xff0c;同理可得&#xff…

【个人记录】CentOS7 编译安装最新版本Git

说明 使用yum install git安装的git版本是1.8&#xff0c;并不是最新版本&#xff0c;使用gitlab-runner托管时候会拉项目失败&#xff0c;这里使用编译源码方式安装最新版本的git。 基础环境安装 echo "nameserver 8.8.8.8" >> /etc/resolv.conf curl -o /…

ArmSoM-W3之RK3588安装Qt+opencv+采集摄像头画面

1. 简介 场景&#xff1a;在RK3588上做qt开发工作 RK3588安装Qtopencv采集摄像头画面 2. 环境介绍 这里使用了OpenCV所带的库函数捕获摄像头的视频图像。 硬件环境&#xff1a; ArmSoM-RK3588开发板、&#xff08;MIPI-DSI&#xff09;摄像头 软件版本&#xff1a; OS&…

MYSQL进阶-事务的基础知识

1.什么是数据库事务&#xff1f; 就是把好几个sql语句打包成一个整体执行&#xff0c;要么全部成功&#xff0c;要么全部失败&#xff01;&#xff01;&#xff01; 事务是一个不可分割的数据库操作序列&#xff0c;也是数据库并发控制的基本单位&#xff0c;其执 行的结果必…

IOS上架流程

IOS上架流程 准备 开发者账号完工的项目 上架步骤 一、创建App ID二、创建证书请求文件 &#xff08;CSR文件&#xff09;三、创建发布证书 &#xff08;CER&#xff09;四、创建Provisioning Profiles配置文件 &#xff08;PP文件&#xff09;五、在App Store创建应用六、…

04-1_Qt 5.9 C++开发指南_常用界面设计组件_字符串QString

本章主要介绍Qt中的常用界面设计组件&#xff0c;因为更多的是涉及如何使用&#xff0c;因此会强调使用&#xff0c;也就是更多针对实例&#xff0c;而对于一些细节问题&#xff0c;需要参考《Qt5.9 c开发指南》进行学习。 文章目录 1. 字符串与普通转换、进制转换1.1 可视化U…

死磕Android性能优化,卡顿原因与优化方案

随着移动互联网的快速发展&#xff0c;Android应用的性能优化变得尤为重要。卡顿是用户体验中最常见的问题之一&#xff0c;它会导致应用的响应变慢、界面不流畅&#xff0c;甚至影响用户的使用体验。因此&#xff0c;我们需要深入了解卡顿问题的原因&#xff0c;并寻找相应的解…

以http_proxy和ajp_proxy方式整合apache和tomcat(动静分离)

注意&#xff1a;http_proxy和ajp_proxy的稳定性不如mod_jk 一.http_proxy方式 1.下载mod_proxy_html.x86_64 2.在apache下创建http_proxy.conf文件&#xff08;或者直接写到conf/httpd.conf文件最后&#xff09; 3.查看server.xml文件 到tomcat的安装目录下的conf/serve…

[mongo]应用场景及选型

应用场景及选型 MongoDB 数据库定位 OLTP 数据库横向扩展能力&#xff0c;数据量或并发量增加时候架构可以自动扩展灵活模型&#xff0c;适合迭代开发&#xff0c;数据模型多变场景JSON 数据结构&#xff0c;适合微服务/REST API基于功能选择 MongoDB 关系型数据库迁移 从基…

如何在Spring MVC中使用@ControllerAdvice创建全局异常处理器

文章目录 前言一、认识注解&#xff1a;RestControllerAdvice和ExceptionHandler二、使用步骤1、封装统一返回结果类2、自定义异常类封装3、定义全局异常处理类4、测试 总结 前言 全局异常处理器是一种 &#x1f31f;✨机制&#xff0c;用于处理应用程序中发生的异常&#xff…