#39 Customize Field Error

在Rails中,默认情况下当验证失败时,会在字段周围添加div标签以便于样式化。但有时这种行为并不符合需求。本篇将展示如何自定义这一过程,通过修改environment.rb文件中的ActionView::Base.field_error_proc属性,可以将错误字段包裹在带有'field_error'类名的span标签中。
When a validation error occurs, Rails helpfully wraps the field in a div tag so you can style it. But sometimes you don't want this behavior. In this episode you will see how to customize it.
 environment.rb
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
"<span class='field_error'>#{html_tag}</span>"
end
<!-- 盘点新增/Add --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="../../layui/css/layui.css"> <link rel="stylesheet" href="../../css/diy.css"> <script src="../../js/axios.min.js"></script> <style> img { width: 200px; } .layui-upload-list{ overflow: hidden; } .layui-upload-list .multiple_block .upload_img_multiple{ height: auto; width: 100px; } .multiple_block{ position: relative; float: left; width: 100px; margin: 0 10px 10px 0; } .multiple_block .upload-img-del{ position: absolute; top: 5px; right: 5px; color: #fff; border-radius: 100%; background: #0000009c; width: 20px; height: 20px; text-align: center; line-height: 20px; cursor: pointer; } </style> </head> <body> <article class="sign_in"> <div class="warp tpl"> <div class="layui-container"> <div class="layui-row"> <form class="layui-form" action=""> <div class="form-input-box from-input-box-i"> <div class="layui-form-item unique" id="warehouse_name_box"> <label class="layui-form-label">仓库名称</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入仓库名称" class="layui-input" id="warehouse_name"> </div> </div> <div class="layui-form-item unique" id="goods_number_box"> <label class="layui-form-label">货物编号</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入货物编号" class="layui-input" id="goods_number"> </div> </div> <div class="layui-form-item unique" id="name_of_goods_box"> <label class="layui-form-label">货物名称</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入货物名称" class="layui-input" id="name_of_goods"> </div> </div> <div class="layui-form-item unique" id="classification_of_goods_box"> <label class="layui-form-label">货物分类</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入货物分类" class="layui-input" id="classification_of_goods"> </div> </div> <div class="layui-form-item number" id="inventory_of_goods_box"> <label class="layui-form-label">货物库存</label> <div class="layui-input-block input-i block"> <input type="number" name="num" class="layui-input num" id="inventory_of_goods"> </div> </div> <div class="layui-form-item unique" id="storage_location_box"> <label class="layui-form-label">存放位置</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入存放位置" class="layui-input" id="storage_location"> </div> </div> <div class="layui-form-item uid-box" id="employee_users_box"> <label class="layui-form-label">员工</label> <div class="layui-input-block select block"> <select name="interest" lay-filter="employee_users" id="employee_users"> <option value=""></option> </select> </div> </div> <div class="layui-form-item unique" id="employee_name_box"> <label class="layui-form-label">员工姓名</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入员工姓名" class="layui-input" id="employee_name"> </div> </div> <div class="layui-form-item unique" id="employee_id_box"> <label class="layui-form-label">员工工号</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入员工工号" class="layui-input" id="employee_id"> </div> </div> <div class="layui-form-item tiem-box" id="inventory_date_box"> <div class="layui-inline"> <label class="layui-form-label">盘点日期</label> <div class="layui-input-inline"> <input type="text" class="layui-input" id="inventory_date" placeholder=""> </div> </div> </div> <div class="layui-form-item number" id="physical_inventory_box"> <label class="layui-form-label">盘点数量</label> <div class="layui-input-block input-i block"> <input type="number" name="num" class="layui-input num" id="physical_inventory"> </div> </div> <div class="layui-form-item layui-form-text" id="inventory_notes_box"> <label class="layui-form-label">盘点备注</label> <div class="layui-input-block text"> <textarea placeholder="请输入盘点备注" class="layui-textarea" id="inventory_notes"></textarea> </div> </div> </div> </form> <div class="layui-btn-container"> <button type="button" class="layui-btn layui-btn-normal login" id="submit">确认</button> <button type="button" class="layui-btn layui-btn-normal login" id="cancel">取消</button> </div> </div> </div> </div> </article> </body> <script src="../../layui/layui.js"></script> <script src="../../js/base.js"></script> <script src="../../js/index.js"></script> <script> var BaseUrl = baseUrl() let cancel = document.querySelector("#cancel") cancel.addEventListener("click",()=>{ colseLayer() }) let inventory_records_id = location.search.substring(1) layui.use([&#39;upload&#39;, &#39;element&#39;, &#39;layer&#39;, &#39;laydate&#39;, &#39;layedit&#39;], function () { var $ = layui.jquery , upload = layui.upload , element = layui.element , layer = layui.layer , laydate = layui.laydate , layedit = layui.layedit , form = layui.form; let url let token = sessionStorage.token || null let personInfo = JSON.parse(sessionStorage.personInfo) let user_group = personInfo.user_group let use_id = personInfo.user_id function $get_stamp() { return new Date().getTime(); } function $get_rand(len) { var rand = Math.random(); return Math.ceil(rand * 10 ** len); } // 权限判断 /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_action(path1, action = "get") { var o = $get_power(path1); if (o && o[action] != 0 && o[action] != false) { return true; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取权限 * @param {String} path 路由路径 */ function $get_power(path) { //从sessionStorage读取权限配置,验证用户操作权限 var list_data = JSON.parse(sessionStorage.list_data) var list = list_data; var obj; for (var i = 0; i < list.length; i++) { var o = list[i]; if (o.path === path) { obj = o; break; } } return obj; } let submit = document.querySelector(&#39;#submit&#39;) // 提交按钮校验权限 if ($check_action(&#39;/inventory_records/view&#39;, &#39;add&#39;) || $check_action(&#39;/inventory_records/view&#39;, &#39;set&#39;) || $check_option(&#39;/inventory_records/table&#39;, &#39;examine&#39;)) { }else { $("#submit").hide() } // style="display: none" let field = "inventory_records_id"; let url_add = "inventory_records"; let url_set = "inventory_records"; let url_get_obj = "inventory_records"; let url_upload = "inventory_records" let query = { "inventory_records_id": 0, } let form_data2 = { "warehouse_name": &#39;&#39;, // 仓库名称 "goods_number": &#39;&#39;, // 货物编号 "name_of_goods": &#39;&#39;, // 货物名称 "classification_of_goods": &#39;&#39;, // 货物分类 "inventory_of_goods": 0, // 货物库存 "storage_location": &#39;&#39;, // 存放位置 "employee_users": 0, // 员工 "employee_name": &#39;&#39;, // 员工姓名 "employee_id": &#39;&#39;, // 员工工号 "inventory_date": &#39;&#39;, // 盘点日期 "physical_inventory": 0, // 盘点数量 "inventory_notes": &#39;&#39;, // 盘点备注 "inventory_records_id": 0, // ID } layui.layedit.set({ uploadImage: { url: BaseUrl + &#39;/api/inventory_records/upload?&#39; //接口url , type: &#39;post&#39; //默认post } }); var path1 function getpath() { var list_data = JSON.parse(sessionStorage.list_data) for (var i = 0; i < list_data.length; i++) { var o = list_data[i]; if (o.path === "/inventory_records/table") { path1 = o.path $get_power(o.path) } } } getpath() /** * 注册时是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 * @param {String} path 路径 */ function $check_register_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field) { var o = $get_power("/inventory_records/view"); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_exam(path1, action = "get") { var o = $get_power(path1); if (o) { var option = JSON.parse(o.option); if (option[action]) return true } return false; } function $check_option(path,op) { var o = $get_power(path); if (o){ var option = JSON.parse(o.option); if (option[op]) return true } return false; } /** * 是否有审核字段的权限 */ function $check_examine() { var url = window.location.href; var url_ = url.split("/") var pg_url = url_[url_.length - 2] let path = "/"+ pg_url + "/table" var o = $get_power(path); if (o){ var option = JSON.parse(o.option); if (option.examine) return true } return false; } if ($check_field(&#39;add&#39;, &#39;warehouse_name&#39;)){ $("#warehouse_name_box").show() }else { $("#warehouse_name_box").hide() } if ($check_field(&#39;add&#39;, &#39;goods_number&#39;)){ $("#goods_number_box").show() }else { $("#goods_number_box").hide() } if ($check_field(&#39;add&#39;, &#39;name_of_goods&#39;)){ $("#name_of_goods_box").show() }else { $("#name_of_goods_box").hide() } if ($check_field(&#39;add&#39;, &#39;classification_of_goods&#39;)){ $("#classification_of_goods_box").show() }else { $("#classification_of_goods_box").hide() } if ($check_field(&#39;add&#39;, &#39;inventory_of_goods&#39;)){ $("#inventory_of_goods_box").show() }else { $("#inventory_of_goods_box").hide() } if ($check_field(&#39;add&#39;, &#39;storage_location&#39;)){ $("#storage_location_box").show() }else { $("#storage_location_box").hide() } if ($check_field(&#39;add&#39;, &#39;employee_users&#39;)){ $("#employee_users_box").show() }else { $("#employee_users_box").hide() } if ($check_field(&#39;add&#39;, &#39;employee_name&#39;)){ $("#employee_name_box").show() }else { $("#employee_name_box").hide() } if ($check_field(&#39;add&#39;, &#39;employee_id&#39;)){ $("#employee_id_box").show() }else { $("#employee_id_box").hide() } if ($check_field(&#39;add&#39;, &#39;inventory_date&#39;)){ $("#inventory_date_box").show() }else { $("#inventory_date_box").hide() } if ($check_field(&#39;add&#39;, &#39;physical_inventory&#39;)){ $("#physical_inventory_box").show() }else { $("#physical_inventory_box").hide() } if ($check_field(&#39;add&#39;, &#39;inventory_notes&#39;)){ $("#inventory_notes_box").show() }else { $("#inventory_notes_box").hide() } // 日期选择 laydate.render({ elem: &#39;#inventory_date&#39; , format: &#39;yyyy-MM-dd&#39; , done: function (value) { form_data2.inventory_date = value + &#39; 00:00:00&#39; } }); async function list_employee_users() { var employee_users = document.querySelector("#employee_users") var op1 = document.createElement("option"); op1.value = &#39;0&#39; employee_users.appendChild(op1) // 收集数据 长度 var count // 收集数据 数组 var arr = [] $.ajax({ url: BaseUrl + &#39;/api/user/get_list?user_group=员工&#39;, type: &#39;GET&#39;, contentType: &#39;application/json; charset=UTF-8&#39;, async: false, dataType: &#39;json&#39;, success: function (response) { count = response.result.count arr = response.result.list } }) for (var i = 0; i < arr.length; i++) { var op = document.createElement("option"); // 给节点赋值 op.innerHTML = arr[i].username + "--" + arr[i].nickname op.value = arr[i].user_id // 新增/Add节点 employee_users.appendChild(op) if (form_data2.employee_users==arr[i].employee_users){ op.selected = true } layui.form.render("select"); } } layui.form.on(&#39;select(employee_users)&#39;, function (data) { form_data2.employee_users = Number(data.elem[data.elem.selectedIndex].value); }) list_employee_users() //文本 let warehouse_name = document.querySelector("#warehouse_name") warehouse_name.onkeyup = function (event) { form_data2.warehouse_name = event.target.value } //文本 //文本 let goods_number = document.querySelector("#goods_number") goods_number.onkeyup = function (event) { form_data2.goods_number = event.target.value } //文本 //文本 let name_of_goods = document.querySelector("#name_of_goods") name_of_goods.onkeyup = function (event) { form_data2.name_of_goods = event.target.value } //文本 //文本 let classification_of_goods = document.querySelector("#classification_of_goods") classification_of_goods.onkeyup = function (event) { form_data2.classification_of_goods = event.target.value } //文本 //数字 let inventory_of_goods = document.querySelector("#inventory_of_goods") inventory_of_goods.onkeyup = function (event) { form_data2.inventory_of_goods = Number(event.target.value) } //数字 //文本 let storage_location = document.querySelector("#storage_location") storage_location.onkeyup = function (event) { form_data2.storage_location = event.target.value } //文本 //文本 let employee_name = document.querySelector("#employee_name") employee_name.onkeyup = function (event) { form_data2.employee_name = event.target.value } //文本 //文本 let employee_id = document.querySelector("#employee_id") employee_id.onkeyup = function (event) { form_data2.employee_id = event.target.value } //文本 //数字 let physical_inventory = document.querySelector("#physical_inventory") physical_inventory.onkeyup = function (event) { form_data2.physical_inventory = Number(event.target.value) } //数字 //多文本 let inventory_notes = document.querySelector("#inventory_notes") //多文本 var data = sessionStorage.data || &#39;&#39; if (data !== &#39;&#39;) { var data2 = JSON.parse(data) Object.keys(form_data2).forEach(key => { Object.keys(data2).forEach(dbKey => { if (key === dbKey) { if (key!==&#39;examine_state&#39; && key!==&#39;examine_reply&#39;){ $(&#39;#&#39; + key).val(data2[key]) form_data2[key] = data2[key] $(&#39;#&#39; + key).attr(&#39;disabled&#39;, &#39;disabled&#39;) for (let key in form_data2) { if (key == &#39;employee_users&#39;) { let alls = document.querySelector(&#39;#employee_users&#39;).querySelectorAll(&#39;option&#39;) let test = form_data2[key] for (let i = 0; i < alls.length; i++) { layui.form.render("select"); if (alls[i].value == test) { alls[i].selected = true form_data2.employee_users = alls[i].value layui.form.render("select"); } } } } } } if(dbKey === "source_table"){ form_data2.source_table = data2[dbKey]; } if(dbKey === "source_id"){ form_data2.source_id = data2[dbKey]; } if(dbKey === "source_user_id"){ form_data2.source_user_id = data2[dbKey]; } }) }) sessionStorage.removeItem("data"); } async function axios_get_4() { if(user_group !=&#39;管理员&#39;){ const {data: rese} = await axios.get(BaseUrl + &#39;/api/user/get_list?user_group=&#39; + user_group) let data = rese.result.list const {data: ress} = await axios.get(BaseUrl + &#39;/api/user_group/get_obj?name=&#39; + user_group) const {data: res} = await axios.get(BaseUrl + &#39;/api/&#39; + ress.result.obj.source_table + &#39;/get_obj?user_id=&#39; + use_id) Object.keys(form_data2).forEach(key => { Object.keys(res.result.obj).forEach(dbKey => { if (key === dbKey) { if (key!==&#39;examine_state&#39; && key!==&#39;examine_reply&#39;){ $(&#39;#&#39; + key).val(res.result.obj[key]) form_data2[key] = res.result.obj[key] $(&#39;#&#39; + key).attr(&#39;disabled&#39;, &#39;disabled&#39;) } } }) }) for (let key in res.result.obj) { if (key == &#39;user_id&#39;) { let alls = document.querySelector(&#39;#employee_users&#39;).querySelectorAll(&#39;option&#39;) let test = res.result.obj.user_id for (let i = 0; i < alls.length; i++) { if (alls[i].value == test) { alls[i].selected = true $(&#39;#employee_users&#39;).attr(&#39;disabled&#39;, &#39;disabled&#39;) form_data2.employee_users = alls[i].value layui.form.render("select"); } } } } } } axios_get_4() if (inventory_records_id !== &#39;&#39;) { $(&#39;#print&#39;).show(); async function axios_get_3() { const {data: rese} = await axios.get(BaseUrl + &#39;/api/inventory_records/get_obj&#39;, { params: { inventory_records_id: inventory_records_id }, headers: { &#39;x-auth-token&#39;: token //向服务端发送 GET 请求,获取库存记录详情数据 } }) let data = rese.result.obj //将服务端返回的 data 对象同步到前端表单的以下两个位置 Object.keys(form_data2).forEach((key) => { form_data2[key] = data[key]; $("#"+key).val(form_data2[key]) }); for (let key in data) { if (key == &#39;employee_users&#39;) { let alls = document.querySelector(&#39;#employee_users&#39;).querySelectorAll(&#39;option&#39;) let test = data[key] for (let i = 0; i < alls.length; i++) { layui.form.render("select"); if (alls[i].value == test) { alls[i].selected = true form_data2.employee_users = alls[i].value layui.form.render("select"); } } } } if ($check_field(&#39;set&#39;, &#39;warehouse_name&#39;) || $check_field(&#39;get&#39;, &#39;warehouse_name&#39;)){ $("#warehouse_name_box").show() }else { $("#warehouse_name_box").hide() } if ($check_field(&#39;set&#39;, &#39;goods_number&#39;) || $check_field(&#39;get&#39;, &#39;goods_number&#39;)){ $("#goods_number_box").show() }else { $("#goods_number_box").hide() } if ($check_field(&#39;set&#39;, &#39;name_of_goods&#39;) || $check_field(&#39;get&#39;, &#39;name_of_goods&#39;)){ $("#name_of_goods_box").show() }else { $("#name_of_goods_box").hide() } if ($check_field(&#39;set&#39;, &#39;classification_of_goods&#39;) || $check_field(&#39;get&#39;, &#39;classification_of_goods&#39;)){ $("#classification_of_goods_box").show() }else { $("#classification_of_goods_box").hide() } if ($check_field(&#39;set&#39;, &#39;inventory_of_goods&#39;) || $check_field(&#39;get&#39;, &#39;inventory_of_goods&#39;)){ $("#inventory_of_goods_box").show() }else { $("#inventory_of_goods_box").hide() } if ($check_field(&#39;set&#39;, &#39;storage_location&#39;) || $check_field(&#39;get&#39;, &#39;storage_location&#39;)){ $("#storage_location_box").show() }else { $("#storage_location_box").hide() } if ($check_field(&#39;set&#39;, &#39;employee_users&#39;) || $check_field(&#39;get&#39;, &#39;employee_users&#39;)){ $("#employee_users_box").show() }else { $("#employee_users_box").hide() } if ($check_field(&#39;set&#39;, &#39;employee_name&#39;) || $check_field(&#39;get&#39;, &#39;employee_name&#39;)){ $("#employee_name_box").show() }else { $("#employee_name_box").hide() } if ($check_field(&#39;set&#39;, &#39;employee_id&#39;) || $check_field(&#39;get&#39;, &#39;employee_id&#39;)){ $("#employee_id_box").show() }else { $("#employee_id_box").hide() } if ($check_field(&#39;set&#39;, &#39;inventory_date&#39;) || $check_field(&#39;get&#39;, &#39;inventory_date&#39;)){ $("#inventory_date_box").show() }else { $("#inventory_date_box").hide() } if ($check_field(&#39;set&#39;, &#39;physical_inventory&#39;) || $check_field(&#39;get&#39;, &#39;physical_inventory&#39;)){ $("#physical_inventory_box").show() }else { $("#physical_inventory_box").hide() } if ($check_field(&#39;set&#39;, &#39;inventory_notes&#39;) || $check_field(&#39;get&#39;, &#39;inventory_notes&#39;)){ $("#inventory_notes_box").show() }else { $("#inventory_notes_box").hide() } // Array.prototype.slice.call(document.getElementsByTagName(&#39;input&#39;)).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName(&#39;select&#39;)).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName(&#39;textarea&#39;)).map(i => i.disabled = true) //文本 warehouse_name.value = form_data2.warehouse_name //文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;warehouse_name&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;warehouse_name&#39;))) { }else { $("#warehouse_name").attr("disabled", true); $("#warehouse_name > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 goods_number.value = form_data2.goods_number //文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;goods_number&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;goods_number&#39;))) { }else { $("#goods_number").attr("disabled", true); $("#goods_number > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 name_of_goods.value = form_data2.name_of_goods //文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;name_of_goods&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;name_of_goods&#39;))) { }else { $("#name_of_goods").attr("disabled", true); $("#name_of_goods > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 classification_of_goods.value = form_data2.classification_of_goods //文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;classification_of_goods&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;classification_of_goods&#39;))) { }else { $("#classification_of_goods").attr("disabled", true); $("#classification_of_goods > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //数字 inventory_of_goods.value = form_data2.inventory_of_goods //数字 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;inventory_of_goods&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;inventory_of_goods&#39;))) { }else { $("#inventory_of_goods").attr("disabled", true); $("#inventory_of_goods > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 storage_location.value = form_data2.storage_location //文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;storage_location&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;storage_location&#39;))) { }else { $("#storage_location").attr("disabled", true); $("#storage_location > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;employee_users&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;employee_users&#39;))) { }else { $("#employee_users").attr("disabled", true); $("#employee_users > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 employee_name.value = form_data2.employee_name //文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;employee_name&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;employee_name&#39;))) { }else { $("#employee_name").attr("disabled", true); $("#employee_name > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 employee_id.value = form_data2.employee_id //文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;employee_id&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;employee_id&#39;))) { }else { $("#employee_id").attr("disabled", true); $("#employee_id > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;inventory_date&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;inventory_date&#39;))) { }else { $("#inventory_date").attr("disabled", true); $("#inventory_date > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //数字 physical_inventory.value = form_data2.physical_inventory //数字 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;physical_inventory&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;physical_inventory&#39;))) { }else { $("#physical_inventory").attr("disabled", true); $("#physical_inventory > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //多文本 inventory_notes.value = form_data2.inventory_notes //多文本 if ((form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;set&#39;, &#39;inventory_notes&#39;)) || (!form_data2[&#39;inventory_records_id&#39;] && $check_field(&#39;add&#39;, &#39;inventory_notes&#39;))) { }else { $("#inventory_notes").attr("disabled", true); $("#inventory_notes > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } inventory_date.value = layui.util.toDateString(form_data2.inventory_date, "yyyy-MM-dd") layui.form.render("select"); } axios_get_3() } submit.onclick = async function () { try { //文本 form_data2.warehouse_name = warehouse_name.value //文本 //文本 form_data2.goods_number = goods_number.value //文本 //文本 form_data2.name_of_goods = name_of_goods.value //文本 //文本 form_data2.classification_of_goods = classification_of_goods.value //文本 //数字 form_data2.inventory_of_goods = Number(inventory_of_goods.value) //数字 //文本 form_data2.storage_location = storage_location.value //文本 //文本 form_data2.employee_name = employee_name.value //文本 //文本 form_data2.employee_id = employee_id.value //文本 if(form_data2.inventory_date == ""){ form_data2.inventory_date = (new Date()).toLocaleDateString(); } form_data2.inventory_date = layui.util.toDateString(form_data2.inventory_date, "yyyy-MM-dd") //数字 form_data2.physical_inventory = Number(physical_inventory.value) //数字 //多文本 form_data2.inventory_notes = inventory_notes.value //多文本 } catch (err) { console.log(err) } if (!form_data2.inventory_date){ layer.msg(&#39;盘点日期不能为空&#39;); return; } let customize_field = [] customize_field.push({"field_name": "仓库名称", "field_value": form_data2.warehouse_name}); customize_field.push({"field_name": "货物编号", "field_value": form_data2.goods_number}); customize_field.push({"field_name": "货物名称", "field_value": form_data2.name_of_goods}); customize_field.push({"field_name": "货物分类", "field_value": form_data2.classification_of_goods}); customize_field.push({"field_name": "货物库存", "field_value": form_data2.inventory_of_goods}); customize_field.push({"field_name": "存放位置", "field_value": form_data2.storage_location}); customize_field.push({"field_name": "员工", "field_value": form_data2.employee_users}); customize_field.push({"field_name": "员工姓名", "field_value": form_data2.employee_name}); customize_field.push({"field_name": "员工工号", "field_value": form_data2.employee_id}); customize_field.push({ "field_name": "盘点日期", "field_value": form_data2.inventory_date, "type": "date" }); customize_field.push({"field_name": "盘点数量", "field_value": form_data2.physical_inventory}); customize_field.push({"field_name": "盘点备注", "field_value": form_data2.inventory_notes}); if (inventory_records_id == &#39;&#39;) { console.log("新增/Add") const {data: res} = await axios.post(BaseUrl + &#39;/api/inventory_records/add?&#39;, form_data2, { headers: { &#39;x-auth-token&#39;: token, &#39;Content-Type&#39;: &#39;application/json&#39; } }) if (res.result == 1) { layer.msg(&#39;确认完毕&#39;); setTimeout(function () { colseLayer() }, 1000) }else { layer.msg(res.error.message); } } else { console.log("详情/Details") const {data: res} = await axios.post(BaseUrl + &#39;/api/inventory_records/set?inventory_records_id=&#39; + inventory_records_id, form_data2, { headers: { &#39;x-auth-token&#39;: token, &#39;Content-Type&#39;: &#39;application/json&#39; } }) if (res.result == 1) { layer.msg(&#39;确认完毕&#39;); setTimeout(function () { colseLayer() }, 1000) }else { layer.msg(res.error.message); } } } }) ; </script> </html> 分析我给的代码,哪些代码是盘点新增的核心代码,不要自己写
06-04
<!-- 供应商信息新增/Add --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="../../layui/css/layui.css"> <link rel="stylesheet" href="../../css/diy.css"> <script src="../../js/axios.min.js"></script> <style> img { width: 200px; } .layui-upload-list { overflow: hidden; } .layui-upload-list .multiple_block .upload_img_multiple { height: auto; width: 100px; } .multiple_block { position: relative; float: left; width: 100px; margin: 0 10px 10px 0; } .multiple_block .upload-img-del { position: absolute; top: 5px; right: 5px; color: #fff; border-radius: 100%; background: #0000009c; width: 20px; height: 20px; text-align: center; line-height: 20px; cursor: pointer; } </style> </head> <body> <article class="sign_in"> <div class="warp tpl"> <div class="layui-container"> <div class="layui-row"> <form class="layui-form" action=""> <div class="form-input-box from-input-box-i"> <div class="layui-form-item unique" id="supplier_name_box"> <label class="layui-form-label">供应商名称</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入供应商名称" class="layui-input" id="supplier_name"> </div> </div> <div class="layui-form-item unique" id="suppliers_phone_number_box"> <label class="layui-form-label">供应商电话</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入供应商电话" class="layui-input" id="suppliers_phone_number"> </div> </div> <div class="layui-form-item unique" id="supplier_address_box"> <label class="layui-form-label">供应商地址</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入供应商地址" class="layui-input" id="supplier_address"> </div> </div> <div class="layui-form-item layui-form-text" id="supply_items_box"> <label class="layui-form-label">供应物品</label> <div class="layui-input-block text"> <textarea placeholder="请输入供应物品" class="layui-textarea" id="supply_items"></textarea> </div> </div> <div class="layui-form-item layui-form-text" id="supplier_description_box"> <label class="layui-form-label">供应商描述</label> <div class="layui-input-block text"> <textarea placeholder="请输入供应商描述" class="layui-textarea" id="supplier_description"></textarea> </div> </div> </div> </form> <div class="layui-btn-container"> <button type="button" class="layui-btn layui-btn-normal login" id="submit">确认</button> <button type="button" class="layui-btn layui-btn-normal login" id="cancel">取消</button> </div> </div> </div> </div> </article> </body> <script src="../../layui/layui.js"></script> <script src="../../js/base.js"></script> <script src="../../js/index.js"></script> <script> var BaseUrl = baseUrl() let cancel = document.querySelector("#cancel") cancel.addEventListener("click", () => { colseLayer() }) let supplier_information_id = location.search.substring(1) layui.use([&#39;upload&#39;, &#39;element&#39;, &#39;layer&#39;, &#39;laydate&#39;, &#39;layedit&#39;], function () { var $ = layui.jquery , upload = layui.upload , element = layui.element , layer = layui.layer , laydate = layui.laydate , layedit = layui.layedit , form = layui.form; let url let token = sessionStorage.token || null let personInfo = JSON.parse(sessionStorage.personInfo) let user_group = personInfo.user_group let use_id = personInfo.user_id function $get_stamp() { return new Date().getTime(); } function $get_rand(len) { var rand = Math.random(); return Math.ceil(rand * 10 ** len); } // 权限判断 /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_action(path1, action = "get") { var o = $get_power(path1); if (o && o[action] != 0 && o[action] != false) { return true; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取权限 * @param {String} path 路由路径 */ function $get_power(path) { var list_data = JSON.parse(sessionStorage.list_data) var list = list_data; var obj; for (var i = 0; i < list.length; i++) { var o = list[i]; if (o.path === path) { obj = o; break; } } return obj; } let submit = document.querySelector(&#39;#submit&#39;) // 提交按钮校验权限 if ($check_action(&#39;/supplier_information/view&#39;, &#39;add&#39;) || $check_action(&#39;/supplier_information/view&#39;, &#39;set&#39;) || $check_option(&#39;/supplier_information/table&#39;, &#39;examine&#39;)) { } else { $("#submit").hide() } // style="display: none" let field = "supplier_information_id"; let url_add = "supplier_information"; let url_set = "supplier_information"; let url_get_obj = "supplier_information"; let url_upload = "supplier_information" let query = { "supplier_information_id": 0, } let form_data2 = { "supplier_name": &#39;&#39;, // 供应商名称 "suppliers_phone_number": &#39;&#39;, // 供应商电话 "supplier_address": &#39;&#39;, // 供应商地址 "supply_items": &#39;&#39;, // 供应物品 "supplier_description": &#39;&#39;, // 供应商描述 "supplier_information_id": 0, // ID } layui.layedit.set({ uploadImage: { url: BaseUrl + &#39;/api/supplier_information/upload?&#39; //接口url , type: &#39;post&#39; //默认post } }); var path1 function getpath() { var list_data = JSON.parse(sessionStorage.list_data) for (var i = 0; i < list_data.length; i++) { var o = list_data[i]; if (o.path === "/supplier_information/table") { path1 = o.path $get_power(o.path) } } } getpath() /** * 注册时是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 * @param {String} path 路径 */ function $check_register_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field) { var o = $get_power("/supplier_information/view"); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_exam(path1, action = "get") { var o = $get_power(path1); if (o) { var option = JSON.parse(o.option); if (option[action]) return true } return false; } function $check_option(path, op) { var o = $get_power(path); if (o) { var option = JSON.parse(o.option); if (option[op]) return true } return false; } /** * 是否有审核字段的权限 */ function $check_examine() { var url = window.location.href; var url_ = url.split("/") var pg_url = url_[url_.length - 2] let path = "/" + pg_url + "/table" var o = $get_power(path); if (o) { var option = JSON.parse(o.option); if (option.examine) return true } return false; } if ($check_field(&#39;add&#39;, &#39;supplier_name&#39;)) { $("#supplier_name_box").show() } else { $("#supplier_name_box").hide() } if ($check_field(&#39;add&#39;, &#39;suppliers_phone_number&#39;)) { $("#suppliers_phone_number_box").show() } else { $("#suppliers_phone_number_box").hide() } if ($check_field(&#39;add&#39;, &#39;supplier_address&#39;)) { $("#supplier_address_box").show() } else { $("#supplier_address_box").hide() } if ($check_field(&#39;add&#39;, &#39;supply_items&#39;)) { $("#supply_items_box").show() } else { $("#supply_items_box").hide() } if ($check_field(&#39;add&#39;, &#39;supplier_description&#39;)) { $("#supplier_description_box").show() } else { $("#supplier_description_box").hide() } //文本 let supplier_name = document.querySelector("#supplier_name") supplier_name.onkeyup = function (event) { form_data2.supplier_name = event.target.value } //文本 //文本 let suppliers_phone_number = document.querySelector("#suppliers_phone_number") suppliers_phone_number.onkeyup = function (event) { form_data2.suppliers_phone_number = event.target.value } //文本 //文本 let supplier_address = document.querySelector("#supplier_address") supplier_address.onkeyup = function (event) { form_data2.supplier_address = event.target.value } //文本 //多文本 let supply_items = document.querySelector("#supply_items") //多文本 //多文本 let supplier_description = document.querySelector("#supplier_description") //多文本 var data = sessionStorage.data || &#39;&#39; if (data !== &#39;&#39;) { var data2 = JSON.parse(data) Object.keys(form_data2).forEach(key => { Object.keys(data2).forEach(dbKey => { if (key === dbKey) { if (key !== &#39;examine_state&#39; && key !== &#39;examine_reply&#39;) { $(&#39;#&#39; + key).val(data2[key]) form_data2[key] = data2[key] $(&#39;#&#39; + key).attr(&#39;disabled&#39;, &#39;disabled&#39;) } } if (dbKey === "source_table") { form_data2.source_table = data2[dbKey]; } if (dbKey === "source_id") { form_data2.source_id = data2[dbKey]; } if (dbKey === "source_user_id") { form_data2.source_user_id = data2[dbKey]; } }) }) sessionStorage.removeItem("data"); } if (supplier_information_id !== &#39;&#39;) { $(&#39;#print&#39;).show(); async function axios_get_3() { const { data: rese } = await axios.get(BaseUrl + &#39;/api/supplier_information/get_obj&#39;, { params: { supplier_information_id: supplier_information_id }, headers: { &#39;x-auth-token&#39;: token } }) let data = rese.result.obj Object.keys(form_data2).forEach((key) => { form_data2[key] = data[key]; $("#" + key).val(form_data2[key]) }); if ($check_field(&#39;set&#39;, &#39;supplier_name&#39;) || $check_field(&#39;get&#39;, &#39;supplier_name&#39;)) { $("#supplier_name_box").show() } else { $("#supplier_name_box").hide() } if ($check_field(&#39;set&#39;, &#39;suppliers_phone_number&#39;) || $check_field(&#39;get&#39;, &#39;suppliers_phone_number&#39;)) { $("#suppliers_phone_number_box").show() } else { $("#suppliers_phone_number_box").hide() } if ($check_field(&#39;set&#39;, &#39;supplier_address&#39;) || $check_field(&#39;get&#39;, &#39;supplier_address&#39;)) { $("#supplier_address_box").show() } else { $("#supplier_address_box").hide() } if ($check_field(&#39;set&#39;, &#39;supply_items&#39;) || $check_field(&#39;get&#39;, &#39;supply_items&#39;)) { $("#supply_items_box").show() } else { $("#supply_items_box").hide() } if ($check_field(&#39;set&#39;, &#39;supplier_description&#39;) || $check_field(&#39;get&#39;, &#39;supplier_description&#39;)) { $("#supplier_description_box").show() } else { $("#supplier_description_box").hide() } // Array.prototype.slice.call(document.getElementsByTagName(&#39;input&#39;)).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName(&#39;select&#39;)).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName(&#39;textarea&#39;)).map(i => i.disabled = true) //文本 supplier_name.value = form_data2.supplier_name //文本 if ((form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;set&#39;, &#39;supplier_name&#39;)) || (!form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;add&#39;, &#39;supplier_name&#39;))) { } else { $("#supplier_name").attr("disabled", true); $("#supplier_name > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 suppliers_phone_number.value = form_data2.suppliers_phone_number //文本 if ((form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;set&#39;, &#39;suppliers_phone_number&#39;)) || (!form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;add&#39;, &#39;suppliers_phone_number&#39;))) { } else { $("#suppliers_phone_number").attr("disabled", true); $("#suppliers_phone_number > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 supplier_address.value = form_data2.supplier_address //文本 if ((form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;set&#39;, &#39;supplier_address&#39;)) || (!form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;add&#39;, &#39;supplier_address&#39;))) { } else { $("#supplier_address").attr("disabled", true); $("#supplier_address > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //多文本 supply_items.value = form_data2.supply_items //多文本 if ((form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;set&#39;, &#39;supply_items&#39;)) || (!form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;add&#39;, &#39;supply_items&#39;))) { } else { $("#supply_items").attr("disabled", true); $("#supply_items > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //多文本 supplier_description.value = form_data2.supplier_description //多文本 if ((form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;set&#39;, &#39;supplier_description&#39;)) || (!form_data2[&#39;supplier_information_id&#39;] && $check_field(&#39;add&#39;, &#39;supplier_description&#39;))) { } else { $("#supplier_description").attr("disabled", true); $("#supplier_description > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } layui.form.render("select"); } axios_get_3() } submit.onclick = async function () { try { //文本 form_data2.supplier_name = supplier_name.value //文本 //文本 form_data2.suppliers_phone_number = suppliers_phone_number.value //文本 //文本 form_data2.supplier_address = supplier_address.value //文本 //多文本 form_data2.supply_items = supply_items.value //多文本 //多文本 form_data2.supplier_description = supplier_description.value //多文本 } catch (err) { console.log(err) } let customize_field = [] customize_field.push({ "field_name": "供应商名称", "field_value": form_data2.supplier_name }); customize_field.push({ "field_name": "供应商电话", "field_value": form_data2.suppliers_phone_number }); customize_field.push({ "field_name": "供应商地址", "field_value": form_data2.supplier_address }); customize_field.push({ "field_name": "供应物品", "field_value": form_data2.supply_items }); customize_field.push({ "field_name": "供应商描述", "field_value": form_data2.supplier_description }); if (supplier_information_id == &#39;&#39;) { console.log("新增/Add") const { data: res } = await axios.post(BaseUrl + &#39;/api/supplier_information/add?&#39;, form_data2, { headers: { &#39;x-auth-token&#39;: token, &#39;Content-Type&#39;: &#39;application/json&#39; } }) if (res.result == 1) { layer.msg(&#39;确认完毕&#39;); setTimeout(function () { colseLayer() }, 1000) } else { layer.msg(res.error.message); } } else { console.log("详情/Details") const { data: res } = await axios.post(BaseUrl + &#39;/api/supplier_information/set?supplier_information_id=&#39; + supplier_information_id, form_data2, { headers: { &#39;x-auth-token&#39;: token, &#39;Content-Type&#39;: &#39;application/json&#39; } }) if (res.result == 1) { layer.msg(&#39;确认完毕&#39;); setTimeout(function () { colseLayer() }, 1000) } else { layer.msg(res.error.message); } } } }) ; </script> </html> 分析我给的代码,代码对应的功能是什么,不要自己写
06-03
<!-- 客户信息新增/Add --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="../../layui/css/layui.css"> <link rel="stylesheet" href="../../css/diy.css"> <script src="../../js/axios.min.js"></script> <style> img { width: 200px; } .layui-upload-list{ overflow: hidden; } .layui-upload-list .multiple_block .upload_img_multiple{ height: auto; width: 100px; } .multiple_block{ position: relative; float: left; width: 100px; margin: 0 10px 10px 0; } .multiple_block .upload-img-del{ position: absolute; top: 5px; right: 5px; color: #fff; border-radius: 100%; background: #0000009c; width: 20px; height: 20px; text-align: center; line-height: 20px; cursor: pointer; } </style> </head> <body> <article class="sign_in"> <div class="warp tpl"> <div class="layui-container"> <div class="layui-row"> <form class="layui-form" action=""> <div class="form-input-box from-input-box-i"> <div class="layui-form-item unique" id="client_company_box"> <label class="layui-form-label">客户公司</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入客户公司" class="layui-input" id="client_company"> </div> </div> <div class="layui-form-item unique" id="customer_name_box"> <label class="layui-form-label">客户姓名</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入客户姓名" class="layui-input" id="customer_name"> </div> </div> <div class="layui-form-item select-box" id="customer_gender_box"> <label class="layui-form-label">客户性别</label> <div class="layui-input-block select block"> <select name="interest" lay-filter="customer_gender" id="customer_gender"> <option value=""></option> </select> </div> </div> <div class="layui-form-item" id="customer_phone_number_box"> <label class="layui-form-label">客户电话</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="phone_number" autocomplete="off" placeholder="请输入客户电话" class="layui-input" id="customer_phone_number"> </div> </div> <div class="layui-form-item layui-form-text" id="customer_address_box"> <label class="layui-form-label">客户地址</label> <div class="layui-input-block text"> <textarea placeholder="请输入客户地址" class="layui-textarea" id="customer_address"></textarea> </div> </div> <div class="layui-form-item layui-form-text" id="customer_preferences_box"> <label class="layui-form-label">客户偏好</label> <div class="layui-input-block text"> <textarea placeholder="请输入客户偏好" class="layui-textarea" id="customer_preferences"></textarea> </div> </div> </div> </form> <div class="layui-btn-container"> <button type="button" class="layui-btn layui-btn-normal login" id="submit">确认</button> <button type="button" class="layui-btn layui-btn-normal login" id="cancel">取消</button> </div> </div> </div> </div> </article> </body> <script src="../../layui/layui.js"></script> <script src="../../js/base.js"></script> <script src="../../js/index.js"></script> <script> var BaseUrl = baseUrl() let cancel = document.querySelector("#cancel") cancel.addEventListener("click",()=>{ colseLayer() }) let customer_information_id = location.search.substring(1) layui.use([&#39;upload&#39;, &#39;element&#39;, &#39;layer&#39;, &#39;laydate&#39;, &#39;layedit&#39;], function () { var $ = layui.jquery , upload = layui.upload , element = layui.element , layer = layui.layer , laydate = layui.laydate , layedit = layui.layedit , form = layui.form; let url let token = sessionStorage.token || null let personInfo = JSON.parse(sessionStorage.personInfo) let user_group = personInfo.user_group let use_id = personInfo.user_id function $get_stamp() { return new Date().getTime(); } function $get_rand(len) { var rand = Math.random(); return Math.ceil(rand * 10 ** len); } // 权限判断 /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_action(path1, action = "get") { var o = $get_power(path1); if (o && o[action] != 0 && o[action] != false) { return true; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取权限 * @param {String} path 路由路径 */ function $get_power(path) { var list_data = JSON.parse(sessionStorage.list_data) var list = list_data; var obj; for (var i = 0; i < list.length; i++) { var o = list[i]; if (o.path === path) { obj = o; break; } } return obj; } let submit = document.querySelector(&#39;#submit&#39;) // 提交按钮校验权限 if ($check_action(&#39;/customer_information/view&#39;, &#39;add&#39;) || $check_action(&#39;/customer_information/view&#39;, &#39;set&#39;) || $check_option(&#39;/customer_information/table&#39;, &#39;examine&#39;)) { }else { $("#submit").hide() } // style="display: none" let field = "customer_information_id"; let url_add = "customer_information"; let url_set = "customer_information"; let url_get_obj = "customer_information"; let url_upload = "customer_information" let query = { "customer_information_id": 0, } let form_data2 = { "client_company": &#39;&#39;, // 客户公司 "customer_name": &#39;&#39;, // 客户姓名 "customer_gender": &#39;&#39;, // 客户性别 "customer_phone_number": &#39;&#39;, // 客户电话 "customer_address": &#39;&#39;, // 客户地址 "customer_preferences": &#39;&#39;, // 客户偏好 "customer_information_id": 0, // ID } layui.layedit.set({ uploadImage: { url: BaseUrl + &#39;/api/customer_information/upload?&#39; //接口url , type: &#39;post&#39; //默认post } }); var path1 function getpath() { var list_data = JSON.parse(sessionStorage.list_data) for (var i = 0; i < list_data.length; i++) { var o = list_data[i]; if (o.path === "/customer_information/table") { path1 = o.path $get_power(o.path) } } } getpath() /** * 注册时是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 * @param {String} path 路径 */ function $check_register_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field) { var o = $get_power("/customer_information/view"); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_exam(path1, action = "get") { var o = $get_power(path1); if (o) { var option = JSON.parse(o.option); if (option[action]) return true } return false; } function $check_option(path,op) { var o = $get_power(path); if (o){ var option = JSON.parse(o.option); if (option[op]) return true } return false; } /** * 是否有审核字段的权限 */ function $check_examine() { var url = window.location.href; var url_ = url.split("/") var pg_url = url_[url_.length - 2] let path = "/"+ pg_url + "/table" var o = $get_power(path); if (o){ var option = JSON.parse(o.option); if (option.examine) return true } return false; } if ($check_field(&#39;add&#39;, &#39;client_company&#39;)){ $("#client_company_box").show() }else { $("#client_company_box").hide() } if ($check_field(&#39;add&#39;, &#39;customer_name&#39;)){ $("#customer_name_box").show() }else { $("#customer_name_box").hide() } if ($check_field(&#39;add&#39;, &#39;customer_gender&#39;)){ $("#customer_gender_box").show() }else { $("#customer_gender_box").hide() } if ($check_field(&#39;add&#39;, &#39;customer_phone_number&#39;)){ $("#customer_phone_number_box").show() }else { $("#customer_phone_number_box").hide() } if ($check_field(&#39;add&#39;, &#39;customer_address&#39;)){ $("#customer_address_box").show() }else { $("#customer_address_box").hide() } if ($check_field(&#39;add&#39;, &#39;customer_preferences&#39;)){ $("#customer_preferences_box").show() }else { $("#customer_preferences_box").hide() } // 客户性别选项列表 let customer_gender_data = [&#39;男&#39;,&#39;女&#39;]; async function customer_gender() { var customer_gender = document.querySelector("#customer_gender") var op1 = document.createElement("option"); op1.value = &#39;0&#39; customer_gender.appendChild(op1) // 收集数据 长度 var count // 收集数据 数组 var arr = [] count = customer_gender_data.length arr = customer_gender_data for (var i = 0; i < arr.length; i++) { var op = document.createElement("option"); // 给节点赋值 op.innerHTML = arr[i] op.value = arr[i] // 新增/Add节点 customer_gender.appendChild(op) if (form_data2.customer_gender==arr[i].customer_gender){ op.selected = true } layui.form.render("select"); } } layui.form.on(&#39;select(customer_gender)&#39;, function (data) { form_data2.customer_gender = data.elem[data.elem.selectedIndex].text; }) customer_gender() //文本 let client_company = document.querySelector("#client_company") client_company.onkeyup = function (event) { form_data2.client_company = event.target.value } //文本 //文本 let customer_name = document.querySelector("#customer_name") customer_name.onkeyup = function (event) { form_data2.customer_name = event.target.value } //文本 //多文本 let customer_address = document.querySelector("#customer_address") //多文本 //多文本 let customer_preferences = document.querySelector("#customer_preferences") //多文本 var data = sessionStorage.data || &#39;&#39; if (data !== &#39;&#39;) { var data2 = JSON.parse(data) Object.keys(form_data2).forEach(key => { Object.keys(data2).forEach(dbKey => { if (key === dbKey) { if (key!==&#39;examine_state&#39; && key!==&#39;examine_reply&#39;){ $(&#39;#&#39; + key).val(data2[key]) form_data2[key] = data2[key] $(&#39;#&#39; + key).attr(&#39;disabled&#39;, &#39;disabled&#39;) for (let key in form_data2) { if (key == &#39;customer_gender&#39;) { let alls = document.querySelector(&#39;#customer_gender&#39;).querySelectorAll(&#39;option&#39;) let test = form_data2[key] for (let i = 0; i < alls.length; i++) { if (alls[i].innerHTML == test) { alls[i].selected = true form_data2.customer_gender = alls[i].text layui.form.render("select"); } } } } } } if(dbKey === "source_table"){ form_data2.source_table = data2[dbKey]; } if(dbKey === "source_id"){ form_data2.source_id = data2[dbKey]; } if(dbKey === "source_user_id"){ form_data2.source_user_id = data2[dbKey]; } }) }) sessionStorage.removeItem("data"); } if (customer_information_id !== &#39;&#39;) { $(&#39;#print&#39;).show(); async function axios_get_3() { const {data: rese} = await axios.get(BaseUrl + &#39;/api/customer_information/get_obj&#39;, { params: { customer_information_id: customer_information_id }, headers: { &#39;x-auth-token&#39;: token } }) let data = rese.result.obj Object.keys(form_data2).forEach((key) => { form_data2[key] = data[key]; $("#"+key).val(form_data2[key]) }); for (let key in data) { if (key == &#39;customer_gender&#39;) { let alls = document.querySelector(&#39;#customer_gender&#39;).querySelectorAll(&#39;option&#39;) let test = data[key] for (let i = 0; i < alls.length; i++) { if (alls[i].innerHTML == test) { alls[i].selected = true form_data2.customer_gender = alls[i].text layui.form.render("select"); } } } } if ($check_field(&#39;set&#39;, &#39;client_company&#39;) || $check_field(&#39;get&#39;, &#39;client_company&#39;)){ $("#client_company_box").show() }else { $("#client_company_box").hide() } if ($check_field(&#39;set&#39;, &#39;customer_name&#39;) || $check_field(&#39;get&#39;, &#39;customer_name&#39;)){ $("#customer_name_box").show() }else { $("#customer_name_box").hide() } if ($check_field(&#39;set&#39;, &#39;customer_gender&#39;) || $check_field(&#39;get&#39;, &#39;customer_gender&#39;)){ $("#customer_gender_box").show() }else { $("#customer_gender_box").hide() } if ($check_field(&#39;set&#39;, &#39;customer_phone_number&#39;) || $check_field(&#39;get&#39;, &#39;customer_phone_number&#39;)){ $("#customer_phone_number_box").show() }else { $("#customer_phone_number_box").hide() } if ($check_field(&#39;set&#39;, &#39;customer_address&#39;) || $check_field(&#39;get&#39;, &#39;customer_address&#39;)){ $("#customer_address_box").show() }else { $("#customer_address_box").hide() } if ($check_field(&#39;set&#39;, &#39;customer_preferences&#39;) || $check_field(&#39;get&#39;, &#39;customer_preferences&#39;)){ $("#customer_preferences_box").show() }else { $("#customer_preferences_box").hide() } // Array.prototype.slice.call(document.getElementsByTagName(&#39;input&#39;)).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName(&#39;select&#39;)).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName(&#39;textarea&#39;)).map(i => i.disabled = true) //文本 client_company.value = form_data2.client_company //文本 if ((form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;set&#39;, &#39;client_company&#39;)) || (!form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;add&#39;, &#39;client_company&#39;))) { }else { $("#client_company").attr("disabled", true); $("#client_company > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //文本 customer_name.value = form_data2.customer_name //文本 if ((form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;set&#39;, &#39;customer_name&#39;)) || (!form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;add&#39;, &#39;customer_name&#39;))) { }else { $("#customer_name").attr("disabled", true); $("#customer_name > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } if ((form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;set&#39;, &#39;customer_gender&#39;)) || (!form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;add&#39;, &#39;customer_gender&#39;))) { }else { $("#customer_gender").attr("disabled", true); $("#customer_gender > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } if ((form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;set&#39;, &#39;customer_phone_number&#39;)) || (!form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;add&#39;, &#39;customer_phone_number&#39;))) { }else { $("#customer_phone_number").attr("disabled", true); $("#customer_phone_number > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //多文本 customer_address.value = form_data2.customer_address //多文本 if ((form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;set&#39;, &#39;customer_address&#39;)) || (!form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;add&#39;, &#39;customer_address&#39;))) { }else { $("#customer_address").attr("disabled", true); $("#customer_address > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } //多文本 customer_preferences.value = form_data2.customer_preferences //多文本 if ((form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;set&#39;, &#39;customer_preferences&#39;)) || (!form_data2[&#39;customer_information_id&#39;] && $check_field(&#39;add&#39;, &#39;customer_preferences&#39;))) { }else { $("#customer_preferences").attr("disabled", true); $("#customer_preferences > input[name=&#39;file&#39;]").attr(&#39;disabled&#39;, true); } layui.form.render("select"); } axios_get_3() } submit.onclick = async function () { try { //文本 form_data2.client_company = client_company.value //文本 //文本 form_data2.customer_name = customer_name.value //文本 //文本 form_data2.customer_phone_number = customer_phone_number.value //文本 //多文本 form_data2.customer_address = customer_address.value //多文本 //多文本 form_data2.customer_preferences = customer_preferences.value //多文本 } catch (err) { console.log(err) } let customer_phone_number_phone_regular = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/; if(form_data2.customer_phone_number && !customer_phone_number_phone_regular.test(form_data2.customer_phone_number)){ layer.msg(&#39;手机号格式错误&#39;); return; } let customize_field = [] customize_field.push({"field_name": "客户公司", "field_value": form_data2.client_company}); customize_field.push({"field_name": "客户姓名", "field_value": form_data2.customer_name}); customize_field.push({"field_name": "客户性别", "field_value": form_data2.customer_gender}); customize_field.push({"field_name": "客户电话", "field_value": form_data2.customer_phone_number}); customize_field.push({"field_name": "客户地址", "field_value": form_data2.customer_address}); customize_field.push({"field_name": "客户偏好", "field_value": form_data2.customer_preferences}); if (customer_information_id == &#39;&#39;) { console.log("新增/Add") const {data: res} = await axios.post(BaseUrl + &#39;/api/customer_information/add?&#39;, form_data2, { headers: { &#39;x-auth-token&#39;: token, &#39;Content-Type&#39;: &#39;application/json&#39; } }) if (res.result == 1) { layer.msg(&#39;确认完毕&#39;); setTimeout(function () { colseLayer() }, 1000) }else { layer.msg(res.error.message); } } else { console.log("详情/Details") const {data: res} = await axios.post(BaseUrl + &#39;/api/customer_information/set?customer_information_id=&#39; + customer_information_id, form_data2, { headers: { &#39;x-auth-token&#39;: token, &#39;Content-Type&#39;: &#39;application/json&#39; } }) if (res.result == 1) { layer.msg(&#39;确认完毕&#39;); setTimeout(function () { colseLayer() }, 1000) }else { layer.msg(res.error.message); } } } }) ; </script> </html> 逐个分析我给的代码内容,代码对应的功能,不要自己写
05-29
本系统旨在构建一套面向高等院校的综合性教务管理平台,涵盖学生、教师及教务处三个核心角色的业务需求。系统设计着重于实现教学流程的规范化与数据处理的自动化,以提升日常教学管理工作的效率与准确性。 在面向学生的功能模块中,系统提供了课程选修服务,学生可依据培养方案选择相应课程,并生成个人专属的课表。成绩查询功能支持学生查阅个人各科目成绩,同时系统可自动计算并展示该课程的全班最高分、平均分、最低分以及学生在班级内的成绩排名。 教师端功能主要围绕课程与成绩管理展开。教师可发起课程设置申请,提交包括课程编码、课程名称、学分学时、课程概述在内的新课程信息,亦可对已开设课程的信息进行更新或撤销。在课程管理方面,教师具备录入所授课程期末考试成绩的权限,并可导出选修该课程的学生名单。 教务处作为管理中枢,拥有课程审批与教学统筹两大核心职能。课程设置审批模块负责处理教师提交的课程申请,管理员可根据教学计划与资源情况进行审核批复。教学安排模块则负责全局管控,包括管理所有学生的选课最终结果、生成包含学号、姓名、课程及成绩的正式成绩单,并能基于选课与成绩数据,统计各门课程的实际选课人数、最高分、最低分、平均分以及成绩合格的学生数量。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值