From 252a68d27a5fb84451dda6d4e0e21c8b9d96097c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=B1=E7=9C=A0=E4=BB=AA=E5=BC=8F?= <854085467@qq.com> Date: Sun, 15 Nov 2020 19:19:48 +0800 Subject: [PATCH] add common modules with submit api --- component/pear/modules/common.js | 36 +++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/component/pear/modules/common.js b/component/pear/modules/common.js index ac6f21f..19c15e9 100644 --- a/component/pear/modules/common.js +++ b/component/pear/modules/common.js @@ -1,6 +1,9 @@ layui.define(['jquery', 'element','table'], function(exports) { "use strict"; + /** + * 常用封装类 + * */ var MOD_NAME = 'common', $ = layui.jquery, table = layui.table, @@ -8,7 +11,11 @@ layui.define(['jquery', 'element','table'], function(exports) { var common = new function() { - // 获 取 表 格 选 中 数 据 + /** + * 获取当前表格选中字段 + * @param obj 表格回调参数 + * @param field 要获取的字段 + * */ this.checkField = function(obj, field) { let data = table.checkStatus(obj.config.id).data; if (data.length === 0) { @@ -21,6 +28,33 @@ layui.define(['jquery', 'element','table'], function(exports) { ids = ids.substr(0, ids.length - 1); return ids; } + + /** + * 提交 json 数据 + * @param data 提交数据 + * @param href 提交接口 + * @param table 刷新父级表 + * + * */ + this.submit(data,href,table,callback){ + $.ajax({ + url:href, + data:JSON.stringify(data), + dataType:'json', + contentType:'application/json', + type:'post', + success:callback !=null?callback(result):function(result){ + if(result.success){ + layer.msg(result.msg,{icon:1,time:1000},function(){ + parent.layer.close(parent.layer.getFrameIndex(window.name));//关闭当前页 + parent.layui.table.reload(table); + }); + }else{ + layer.msg(result.msg,{icon:2,time:1000}); + } + } + }) + } } exports(MOD_NAME, common); });