根据后台接口动态生成表单

根据后台接口动态生成表单

在这里插入图片描述

接口数据tempoa.js

const controls = {
	"code": 200,
	"data": {
		"res": [{
				"id": "Text-1680072241433",
				"control": "Text",
				"required": 0,
				"filed_name": "text",
				"filed_lable": "文本",
				"type": "",
				"option_key": []
			},
			{
				"id": "Textarea-1680072243015",
				"control": "Textarea",
				"required": 0,
				"filed_name": "text_area",
				"filed_lable": "多行文本",
				"type": "",
				"option_key": []
			},
			{
				"id": "Number-1680072245132",
				"control": "Number",
				"required": 0,
				"filed_name": "number",
				"filed_lable": "数字",
				"type": "",
				"option_key": []
			},
			{
				"id": "Money-1680072247162",
				"control": "Money",
				"required": 0,
				"filed_name": "amount",
				"filed_lable": "金额",
				"type": "",
				"option_key": []
			},
			{
				"id": "Date-1680072249182",
				"control": "Date",
				"required": 0,
				"filed_name": "date",
				"filed_lable": "日期",
				"type": "day",
				"option_key": []
			},
			{
				"id": "Date-1680072251129",
				"control": "Date",
				"required": 0,
				"filed_name": "datetime",
				"filed_lable": "日期+时间",
				"type": "hour",
				"option_key": []
			},
			{
				"id": "Selector-1680072254525",
				"control": "Selector",
				"required": 0,
				"filed_name": "select",
				"filed_lable": "单选",
				"type": "single",
				"option_key": [{
						"key": "option-1680072254525",
						"value": "选项1",
						"en_value": ""
					},
					{
						"key": "option-1680072254526",
						"value": "选项2",
						"en_value": ""
					}
				]
			}
		],
		"template_name": "测试获取模版详情"
	},
	"msg": "获取成功"
}
export default controls

使用实例

<template>
	<div class="app-container">
		<el-form :model="ruleForm" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			<template v-for="(item, index) in ruleForm.form">
				<el-card class="box-card" :key="index" style="margin-bottom:12px;">
					<template v-for="(subitem,subindex) in item.table">
						{{subitem.type}}
						<el-form-item :label="`${subitem.label}`" :key="index+''+subindex"
							:prop="`${ruleForm.form[index].table[subindex].value}`">
							<el-input v-model="subitem.value" :placeholder="subitem.placeholder"></el-input>
						</el-form-item>
					</template>
					<el-col :span="24" style="display: flex;justify-content: center;margin-bottom:12px;"
						v-if="index > 0">
						<el-button type="danger" icon="el-icon-delete" circle
							@click="subtractHandle(index)"></el-button>
					</el-col>
				</el-card>
			</template>
			<el-form-item>
				<el-button type="primary" @click="plusHandle">新增</el-button>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
				<el-button @click="resetForm('ruleForm')">重置</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>

<script>
	import controls from '@/utils/tempoa.js';
	export default {
		components: {

		},
		data() {
			return {
				ruleForm: {
					form: []
				},
			};
		},
		mounted() {
			const dataList = controls.data.res;
			console.log("[]", dataList)
			this.dealwithDataAPI(dataList).then(response => {
				console.log("[--]", response);
				this.ruleForm["form"] = response;
			})
		},
		methods: {
			/**
			 * 表单提交
			 * **/
			submitForm(formName) {
				this.$refs[formName].validate(valid => {
					if (valid) {
						console.log(this.ruleForm);
					}
				});
			},
			/**
			 * 重置表单
			 * **/
			resetForm(formName) {
				this.$refs[formName].resetFields();
			},
			/**
			 * 新增明细
			 * **/
			plusHandle() {
				const dataList = controls.data.res;
				let tempTable = dataList.map(item => ({
					type: item.control,
					value: '',
					label: item.filed_lable,
					key: item.id,
					placeholder: item.filed_lable,
					config: item
				}))

				this.ruleForm["form"].push({
					label: "表单",
					table: tempTable
				})
			},
			/**
			 * 删除明显子项
			 * **/
			subtractHandle(subIndex) {
				console.log(subIndex);
				this.ruleForm.form.splice(subIndex, 1);
			},
			/**
			 * 处理数据用于页面展示
			 * **/
			dealwithDataAPI(dataList) {
				return new Promise((resolve, reject) => {
					if (dataList.length > 0) {
						const tempTable = dataList.map(item => ({
							type: item.control,
							value: '',
							label: item.filed_lable,
							key: item.id,
							placeholder: item.filed_lable,
							config: item
						}));

						const tempForm = [{
							label: '表单',
							table: tempTable
						}];
						resolve(tempForm)
					} else {
						reject([])
					}
				})
			}
		}
	};
</script>

<style lang="scss" scoped></style>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JeeSpringCloud是一个基于SpringBoot2.0的后台权限管理系统,界面简洁美观敏捷开发系统架构。核心技术采用Spring、MyBatis、Shiro没有任何其它重度依赖。 互联网云快速开发框架,微服务分布式代码生成的敏捷开发系统架构。项目代码简洁,注释丰富,上手容易,还同时集中分布式、微服务,同时包含许多基础模块和监控、服务模块。模块包括:定时任务调度、服务器监控、平台监控、平台设置、开发平台、点登录、Redis分布式高速缓存、会员、营销、在线用户、日志、在线人数、访问次数、调用次数、直接集群、接口文档、生成模块、代码实例、安装视频、教程文档 代码生成(、主附、树、列、redis高速缓存对接代码、图统计、地图统计、vue.js)、dubbo、springCloud、SpringBoot、mybatis、spring、springmvc。 功能 用户管理:用户是系统操作者,该功能主要完成系统用户配置。 部门管理:配置系统组织机构(公司、部门、小组),树结构展现支持数据权限。 岗位管理:配置系统用户所属担任职务。 菜管理:配置系统菜,操作权限,按钮权限标识等。 角色管理:角色菜权限分配、设置角色按机构进行数据范围权限划分。 字典管理:对系统中经常使用的一些较为固定的数据进行维护。 参数管理:对系统动态配置常用参数。 通知公告:系统通知公告信息发布维护。 操作日志:系统正常操作日志记录和查询;系统异常信息日志记录和查询。 登录日志:系统登录日志记录查询包含登录异常。 在线用户:当前系统中活跃用户状态监控。 定时任务:在线(添加、修改、删除)任务调度包含执行结果日志。 代码生成:前后端代码生成(、主附、树、列、增删改查云接口、redis高速缓存对接代码、图统计、地图统计、vue.js) ,并生成和权限直接使用。 系统接口:根据业务代码自动生成相关的api接口文档。 连接池监视:监视当期系统数据库连接池状态,可进行分析SQL找出系统性能瓶颈。 在线接口文档:使用swager生成在线文档。 ActiveMQ队列:提供ActiveMQ队列,处理批量发送大数据量邮件、大数据量日志文件。 工作流:功能包括在线办公、我的任务、审批测试、流程管理、模型管理。 CMS:功能包括内容管理、内容管理、统计分析、栏目设置、首页。 dubbo:代码生成直接生成dubbo对接代码。 服务器Down机邮件监控:通过定时任务监控服务器是否Down机,并发送通知邮件。 服务器监控:通过sigar进行服务器图形化监控。 异常邮件监控:全局拦截系统异常,并发送通知邮件。 点登录:使用shior和Redis、共享session方式实现点登录。 Redis分布式高速缓存:代码生成直接生成Redis对接代码。 特性: JeeSpringCloud基于SpringBoot+SpringMVC+Mybatis+Redis+SpringCloud+Vue.js微服务分布式代码生成的敏捷开发系统架构。项目代码简洁,注释丰富,上手容易,还同时集中分布式、微服务,同时包含许多基础模块(用户管理,角色管理,部门管理,字典管理等10个模块。成为大众认同、大众参与、成就大众、大众分享的开发平台。JeeSpring官方qq群(328910546)。代码生成前端界面、底层代码(spring mvc、mybatis、Spring boot、Spring Cloud、微服务的生成)、安全框架、视图框架、服务端验证、任务调度、持久层框架、数据库连接池、缓存框架、日志管理、IM等核心技术。努力用心为大中小型企业打造全方位J2EE企业级平台ORM/Redis/Service仓库开发解决方案。一个RepositoryService仓库就直接实现dubbo、微服务、基础服务器对接接口和实现。 努力用心为大中小型企业打造全方位J2EE企业级平台开发解决方案。 Spring Boot/Spring cloud微服务是利用云平台开发企业应用程序的最新技术,它是小型、轻量和过程驱动的组件。微服务适合设计可扩展、易于维护的应用程序。它可以使开发更容易,还能使资源得到最佳利用。 微服务/集群(nignx) 支持REST风格远程调用(HTTP + JSON/XML):基于非常成熟的Spring Boot框架,在Spring Boot Spring Cloud中实现了REST风格(HTTP + JSON/XML)的远程调用,以显著简化企业内部的跨语言交互,同时显著简化企业对外的Open API、无线API甚至AJAX服务端等等的开发。 事实上,这个REST调用也使得Dubbo可以对当今特别流行的“微服务”架构提供基础性支持。 另外,REST调用也达到了比较高
好的,我理解你的要求了。首先,你需要先引入Bootstrap3的CSS和JS文件,以及jQuery和Bootstrap3的JS依赖文件,代码如下: ```html <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css"> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script> ``` 然后,你需要创建一个,代码如下: ```html <div class="container"> <h2>接口配置</h2> <form class="form-horizontal" id="interface-form"> <div class="form-group"> <label class="control-label col-sm-2" for="interface-id">接口ID:</label> <div class="col-sm-10"> <input type="text" class="form-control" id="interface-id" name="interface-id" placeholder="请输入接口ID"> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="interface-name">接口名称:</label> <div class="col-sm-10"> <input type="text" class="form-control" id="interface-name" name="interface-name" placeholder="请输入接口名称"> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="interface-class">接口类名称:</label> <div class="col-sm-10"> <input type="text" class="form-control" id="interface-class" name="interface-class" placeholder="请输入接口类名称"> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="interface-path">接口路径:</label> <div class="col-sm-10"> <input type="text" class="form-control" id="interface-path" name="interface-path" placeholder="请输入接口路径"> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="is-valid">有效标志:</label> <div class="col-sm-10"> <label class="checkbox-inline"><input type="checkbox" id="is-valid" name="is-valid" value="1">是</label> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="create-time">创建时间:</label> <div class="col-sm-10"> <input type="text" class="form-control" id="create-time" name="create-time" placeholder="请输入创建时间"> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="update-time">修改时间:</label> <div class="col-sm-10"> <input type="text" class="form-control" id="update-time" name="update-time" placeholder="请输入修改时间"> </div> </div> <div class="form-group"> <label class="control-label col-sm-2" for="operator">操作人:</label> <div class="col-sm-10"> <input type="text" class="form-control" id="operator" name="operator" placeholder="请输入操作人"> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">提交</button> </div> </div> </form> </div> ``` 接下来,你需要编写一个AJAX请求,将数据提交到后台,代码如下: ```javascript $(document).ready(function() { // 提交 $('#interface-form').submit(function(e) { e.preventDefault(); var formData = $(this).serialize(); $.ajax({ url: '/api/interface', type: 'POST', data: formData, dataType: 'json', success: function(data) { alert('提交成功!'); }, error: function() { alert('提交失败!'); } }); }); }); ``` 最后,你需要编写一个查询接口的AJAX请求,将查询条件提交到后台,并将返回的数据渲染到页面中,代码如下: ```javascript $(document).ready(function() { // 查询接口 $('#search-btn').click(function() { var interfaceId = $('#interface-id-search').val(); var interfaceName = $('#interface-name-search').val(); var interfaceClass = $('#interface-class-search').val(); var interfacePath = $('#interface-path-search').val(); var createTime = $('#create-time-search').val(); var updateTime = $('#update-time-search').val(); $.ajax({ url: '/api/interface', type: 'GET', data: { 'interfaceId': interfaceId, 'interfaceName': interfaceName, 'interfaceClass': interfaceClass, 'interfacePath': interfacePath, 'createTime': createTime, 'updateTime': updateTime }, dataType: 'json', success: function(data) { // 渲染数据到页面 }, error: function() { alert('查询失败!'); } }); }); }); ``` 以上就是基于Bootstrap3生成一个form配置页面的代码,你可以根据需要进行修改和优化。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值