7.28日更新
作者:互联网
一、完成内容
1. 超级管理员自动组卷功能
2.超级管理员管理试卷功能
3. 管理员自动组卷功能
4.管理员管理试卷功能
二、页面截图
三、关键代码
1.组卷页面代码
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>试卷添加</title> <!-- 引入layui --> <link rel="stylesheet" href="../layui/css/layui.css"> <script type="text/javascript" src="../layui/layui.js"></script> <script type="text/javascript" src="../JQ/jquery-3.3.1.min.js"></script> </head> <style type="text/css"> .container { width: 720px; height: 720px; min-height: 320px; max-height: 320px; position: absolute; top: 0; left: 0; bottom: 0; right: 0; margin: auto; padding: 30px; z-index: 130; border-radius: 8px; background-color: #fff; box-shadow: 0 3px 18px rgba(100, 0, 0, .5); font-size: 16px; } .close { background-color: white; border: none; font-size: 18px; margin-left: 410px; margin-top: -10px; } .layui-input { border-radius: 5px; width: 300px; height: 40px; font-size: 15px; } .layui-inputs { border-radius: 5px; width: 150px; height: 30px; font-size: 15px; } .layui-form-item { margin-left: -20px; } #logoid { margin-top: -16px; padding-left: 150px; padding-bottom: 15px; } .layui-btn { margin-left: -50px; border-radius: 5px; width: 350px; height: 40px; font-size: 15px; } .verity { width: 120px; } .font-set { font-size: 13px; text-decoration: none; margin-left: 120px; } a:hover { text-decoration: underline; } .layui-form-select dl { max-height:300px;} .layui-form-select { width:450px;} </style> <body> <form class="layui-form"> <div class="container"> <div class="layui-form-item"> <label class="layui-form-label">试卷名</label> <div class="layui-input-block" > <input type="text" name="testName" id="testName" required lay-verify="required" placeholder="请输入试卷名" autocomplete="off" class="layui-input"> </div> </div> <div class="layui-form-item"> <label class="layui-form-label" id="sub">科目占比</label> </div> <div class="layui-form-item"> <div class="layui-input-block"> <button class="layui-btn" id="add" lay-filter="btnSubmit" lay-submit>添加</button> </div> </div> </div> </form> <script> layui.use(['form', 'layedit', 'laydate'], function(){ var form = layui.form ,layer = layui.layer ,layedit = layui.layedit ,laydate = layui.laydate; var texts=""; var arrText = new Array(); var arr = new Array(); $.post("../subject/listSubjects",function(data){ list = data.data; //生成复选框 for(var i=0;i<list.length;i++){ arrText.push(list[i].subId); texts+="<div class='layui-input-block'>  <input type='checkbox' name='subject' value='"+list[i].subId+"' lay-filter='subject'/>"+list[i].subName+"    <input id='"+list[i].subId+"' placeholder='请输入题目个数' class='layui-inputs' type='text' hidden /></div>"; } $("#sub").after(texts); form.render('checkbox'); },"json"); //监听复选框,显示和隐藏对应的文本框 form.on('checkbox(subject)', function(data){ var i=data.elem.value; if(data.elem.checked){ $("#"+i+"").removeAttr("hidden"); }else{ $("#"+i+"").attr("hidden","hidden"); } }) //登录按钮监听事件 $("#add").click(function(){ form.on('submit(btnSubmit)',function(data){ var context =""; //循环获取文本框的值 for(var i=0;i<arrText.length;i++){ var values = $("#"+arrText[i]+"").val(); if(values==null || values==""){ continue; }else{ if(i!=0){ context +=","+arrText[i]+":"+values; }else{ context +=arrText[i]+":"+values; } } } //获取表单数据 var testName = $("#testName").val(); alert(data) $.ajax({ url:'../test/add', data:{testName:testName,context:context}, type:'post', success:function(data){ if(data=="success"){ var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引 parent.location.reload();//刷新父页面,注意一定要在关闭当前iframe层之前执行刷新 parent.layer.close(index); //再执行关闭 }else{ alert("服务器错误"); } }, error:function(data){ alert("服务器错误"); } }); return false; }) }) }); </script> </html>
2. 组卷规则处理
@Override public List<Test> listAll(Integer startNumber, Integer size, Test test) { // TODO Auto-generated method stub //获取当页试卷 List<Test> list = testDao.listAll(startNumber,size,test); List<Test> list1 = new ArrayList<Test>(); for (Test test2 : list) { //获取组卷规则文本 String context = test2.getContext(); //分割数组 String str[] = context.split(","); for (int i = 0; i < str.length; i++) { //获取对应的科目id String subId = str[i].substring(0, str[i].indexOf(":")); //查询对应科目 Subject sub = subjectDao.selectById(new Integer(subId)); //将科目id替换成科目名 context = context.replaceAll(subId+":", sub.getSubName()+":"); //重新载入实体 test2.setContext(context); } //存入集合 list1.add(test2); } return list1; }
四、遇到问题
无
五、项目燃尽图
六:资料链接
链接:https://pan.baidu.com/s/1N2e0NjWmfVoXPKSypGgDPQ
提取码:zbd4
标签:7.28,form,layui,更新,height,var,font,size 来源: https://www.cnblogs.com/wangpeng94/p/13394863.html