add common modules with submit api

develop
就眠仪式 2020-11-15 19:19:48 +08:00
parent 3c57370119
commit 252a68d27a
1 changed files with 35 additions and 1 deletions

View File

@ -1,6 +1,9 @@
layui.define(['jquery', 'element','table'], function(exports) { layui.define(['jquery', 'element','table'], function(exports) {
"use strict"; "use strict";
/**
* 常用封装类
* */
var MOD_NAME = 'common', var MOD_NAME = 'common',
$ = layui.jquery, $ = layui.jquery,
table = layui.table, table = layui.table,
@ -8,7 +11,11 @@ layui.define(['jquery', 'element','table'], function(exports) {
var common = new function() { var common = new function() {
// 获 取 表 格 选 中 数 据 /**
* 获取当前表格选中字段
* @param obj 表格回调参数
* @param field 要获取的字段
* */
this.checkField = function(obj, field) { this.checkField = function(obj, field) {
let data = table.checkStatus(obj.config.id).data; let data = table.checkStatus(obj.config.id).data;
if (data.length === 0) { if (data.length === 0) {
@ -21,6 +28,33 @@ layui.define(['jquery', 'element','table'], function(exports) {
ids = ids.substr(0, ids.length - 1); ids = ids.substr(0, ids.length - 1);
return ids; 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); exports(MOD_NAME, common);
}); });