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.mzph.cn/news/23639.shtml

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

相关文章

Excel·VBA定量装箱、凑数值金额、组合求和问题

如图&#xff1a;对图中A-C列数据&#xff0c;根据C列数量按照一定的取值范围&#xff0c;组成一个分组装箱&#xff0c;要求如下&#xff1a; 1&#xff0c;每箱数量最好凑足50&#xff0c;否则为47-56之间&#xff1b; 2&#xff0c;图中每行数据不得拆分&#xff1b; 3&…

视频汇聚平台EasyCVR视频广场侧边栏支持拖拽

为了提升用户体验以及让平台的操作更加符合用户使用习惯&#xff0c;我们在EasyCVR v3.3版本中&#xff0c;支持面包屑侧边栏的广场视频、分组列表、收藏这三个模块拖拽排序&#xff0c;并且该操作在视频广场、视频调阅、电子地图、录像回放等页面均能支持。 TSINGSEE青犀视频…

Docker 容器化学习

文章目录 前言Docker架构 1、 docker安装2、启动docker服务3、设置docker随机器一起启动4、docker体验5、docker常规命令5.1、容器操作docker [run|start|stop|restart|kill|rm|pause|unpause]docker [ps|inspect|exec|logs|export|import] 5.2、镜像操作docker images|rmi|tag…

前端页面--视觉差效果

代码 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"><link rel"stylesheet" href"https://un…

三层交换实验

前言 在实际的企业应用中&#xff0c;我们会先建立不同的vlan把用户先隔开来。然后再通过三次交换机技术打通vlan直接的网络。 这样的目的如下&#xff1a; 隔离&#xff1a; 隔离是广播域&#xff0c;也就是隔离的是故障连通&#xff1a; 连通的是正常的通信 比如校园网&am…

⛳ StringBuffer and StringBuilder 处理字符串

目录 ⛳ StringBuffer and StringBuilder 处理字符串&#x1f3a8; 一&#xff0c;简介&#x1f3ed; 二&#xff0c;常用方法&#x1f69c; 三 &#xff0c;StringBugger&#x1f43e; 四&#xff0c;StringBuilder⭐ 五&#xff0c;StringBuffer和StringBuilder面试 ⛳ Strin…

2023牛客暑期多校训练营6 A-Tree (kruskal重构树))

文章目录 题目大意题解参考代码 题目大意 ( 0 ≤ a i ≤ 1 ) , ( 1 ≤ c o s t i ≤ 1 0 9 ) (0\leq a_i\leq 1),(1 \leq cost_i\leq 10^9) (0≤ai​≤1),(1≤costi​≤109) 题解 提供一种新的算法&#xff0c;kruskal重构树。 该算法重新构树&#xff0c;按边权排序每一条边…

分布式异步任务处理组件(七)

分布式异步任务处理组件底层网络通信模型的设计--如图&#xff1a; 使用Java原生NIO来实现TCP通信模型普通节点维护一个网络IO线程&#xff0c;负责和主节点的网络数据通信连接--这里的网络数据是指组件通信协议之下的直接面对字节流的数据读写&#xff0c;上层会有另一个线程负…

PoseiSwap:基于 Nautilus Chain ,构建全新价值体系

在 DeFi Summer 后&#xff0c;以太坊自身的弊端不断凸显&#xff0c;而以 Layer2 的方式为其扩容成为了行业很长一段时间的叙事方向之一。虽然以太坊已经顺利的从 PoW 的 1.0 迈向了 PoS 的 2.0 时代&#xff0c;但以太坊创始人 Vitalik Buterin 表示&#xff0c; Layer2 未来…

iOS-砸壳篇(两种砸壳方式)

CrackerXI砸壳呢&#xff0c;当时你要是使用 frida-ios-dump 也是可以的&#xff1b; https://github.com/AloneMonkey/frida-ios-dump frida-ios-dump: 代码中需要更改的&#xff1a;手机中的内网ip 密码 等 最后放到我的砸壳路径里&#xff1a; python dump.py -l查看应用…

JMeter 4.x 简单使用

文章目录 前言JMeter 4.x 简单使用1. 启动2. 设置成中文3. 接口测试3.1. 设置线程组3.2. HTTP信息请求头管理器3.3. 添加HTTP请求默认值3.4. 添加HTTP cookie 管理3.5. 添加http请求3.5.1. 添加断言 3.6. 添加监听器-查看结果树3.7. 添加监听器-聚合报告 4. 测试 前言 如果您觉…

打开的idea项目maven不生效

方法一&#xff1a;CtrlshiftA&#xff08;或者help---->find action&#xff09;&#xff0c; 输入maven&#xff0c; 点击add maven projects&#xff0c;选择本项目中的pom.xml配置文件&#xff0c;等待加载........ 方法二&#xff1a;view->tools windows->mave…

【RabbitMQ(day4)】SpringBoot整合RabbitMQ与MQ应用场景说明

一、SpringBoot 中使用 RabbitMQ 导入对应的依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency>配置配置文件 spring:application:name: rabbitmq-springbo…

CSS3标题文本后的横线

示例代码 <template><div><h2 class"background">删除线</h2><h2 class"background"><span>左右两侧线</span></h2><h2 class"background double"><span>双层线</span></…

Android Glide MemorySizeCalculator计算值,Kotlin

Android Glide MemorySizeCalculator计算值,Kotlin for (i in 100..1000 step 50) {val calculator MemorySizeCalculator.Builder(this).setMemoryCacheScreens(i.toFloat()).setBitmapPoolScreens(i.toFloat()).setMaxSizeMultiplier(0.8f).setLowMemoryMaxSizeMultiplier(0…

【网络】网络层(IP协议)

目录 一、基本概念 二、协议头格式 三、网段划分 四、特殊的IP地址 五、IP地址的数量限制 六、私有IP地址和公网IP地址 七、路由 一、基本概念 IP协议&#xff1a;提供一种能力&#xff0c; 将数据从A主机送到B主机&#xff0c;&#xff08;TCP协议&#xff1a;确保IP协议…

Webpack5新手入门简单配置

1.初始化项目 yarn init -y 2.安装依赖 yarn add -D webpack5.75.0 webpack-cli5.0.0 3.新建index.js 说明&#xff1a;写入下面的一句话 console.log("hello webpack"); 4.执行命令 说明&#xff1a;如果没有安装webpack脚手架就不能执行yarn webpack&#xff08…

P1064 [NOIP2006 提高组] 金明的预算方案 (依赖背包问题)(内附封面)

[NOIP2006 提高组] 金明的预算方案 题目描述 金明今天很开心&#xff0c;家里购置的新房就要领钥匙了&#xff0c;新房里有一间金明自己专用的很宽敞的房间。更让他高兴的是&#xff0c;妈妈昨天对他说&#xff1a;“你的房间需要购买哪些物品&#xff0c;怎么布置&#xff0…

python 连接oracle pandas以简化excel的编写和数据操作

python代码 Author: liukai 2810248865qq.com Date: 2022-08-18 04:28:52 LastEditors: liukai 2810248865qq.com LastEditTime: 2023-07-06 22:12:56 FilePath: \PythonProject02\pandas以简化excel的编写和数据操作.py Description: 这是默认设置,请设置customMade, 打开koro…

Laravel 框架安装路由和控制器 ①

作者 : SYFStrive 博客首页 : HomePage &#x1f4dc;&#xff1a; THINK PHP &#x1f4cc;&#xff1a;个人社区&#xff08;欢迎大佬们加入&#xff09; &#x1f449;&#xff1a;社区链接&#x1f517; &#x1f4cc;&#xff1a;觉得文章不错可以点点关注 &#x1f44…