优化 table 内部数据完毕后的相关代码

pull/1275/head
贤心 2023-06-08 10:59:27 +08:00
parent ea48472951
commit b1894c892f
1 changed files with 22 additions and 29 deletions

View File

@ -929,6 +929,12 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
}); });
} }
}; };
var done = function(res){
that.setColsWidth();
typeof options.done === 'function' && options.done(
res, curr, res[response.countName]
);
};
opts = opts || {}; opts = opts || {};
@ -943,7 +949,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
res[response.dataName] = table.cache[that.key]; res[response.dataName] = table.cache[that.key];
res[response.countName] = options.url ? (layui.type(options.page) === 'object' ? options.page.count : res[response.dataName].length) : options.data.length; res[response.countName] = options.url ? (layui.type(options.page) === 'object' ? options.page.count : res[response.dataName].length) : options.data.length;
//记录合计行数据 // 记录合计行数据
if(typeof options.totalRow === 'object'){ if(typeof options.totalRow === 'object'){
res[response.totalRowName] = $.extend({}, that.totalRow); res[response.totalRowName] = $.extend({}, that.totalRow);
} }
@ -953,13 +959,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
curr: curr, curr: curr,
count: res[response.countName], count: res[response.countName],
type: opts.type, type: opts.type,
}), sort(); }), sort(), done(res);
that.setColsWidth();
typeof options.done === 'function' && options.done(
res, curr, res[response.countName]
);
} else if(options.url){ // Ajax请求 } else if(options.url){ // Ajax请求
var params = {}; var params = {};
// 当 page 开启,默认自动传递 page、limit 参数 // 当 page 开启,默认自动传递 page、limit 参数
@ -977,14 +977,14 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
that.loading(); that.loading();
$.ajax({ $.ajax({
type: options.method || 'get' type: options.method || 'get',
,url: options.url url: options.url,
,contentType: options.contentType contentType: options.contentType,
,data: data data: data,
,dataType: options.dataType || 'json' dataType: options.dataType || 'json',
,jsonpCallback: options.jsonpCallback jsonpCallback: options.jsonpCallback,
,headers: options.headers || {} headers: options.headers || {},
,success: function(res){ success: function(res){
// 若有数据解析的回调,则获得其返回的数据 // 若有数据解析的回调,则获得其返回的数据
if(typeof options.parseData === 'function'){ if(typeof options.parseData === 'function'){
res = options.parseData(res) || res; res = options.parseData(res) || res;
@ -1004,15 +1004,12 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
type: opts.type type: opts.type
}), sort(); }), sort();
//耗时(接口请求+视图渲染) // 耗时(接口请求+视图渲染)
options.time = (new Date().getTime() - that.startTime) + ' ms'; options.time = (new Date().getTime() - that.startTime) + ' ms';
} }
that.setColsWidth(); done(res);
typeof options.done === 'function' && options.done( },
res, curr, res[response.countName] error: function(e, msg){
);
}
,error: function(e, msg){
that.errorView('请求异常,错误提示:'+ msg); that.errorView('请求异常,错误提示:'+ msg);
typeof options.error === 'function' && options.error(e, msg); typeof options.error === 'function' && options.error(e, msg);
} }
@ -1027,7 +1024,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
: newData; : newData;
res[response.countName] = options.data.length; res[response.countName] = options.data.length;
//记录合计行数据 // 记录合计行数据
if(typeof options.totalRow === 'object'){ if(typeof options.totalRow === 'object'){
res[response.totalRowName] = $.extend({}, options.totalRow); res[response.totalRowName] = $.extend({}, options.totalRow);
} }
@ -1040,11 +1037,7 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
type: opts.type type: opts.type
}), sort(); }), sort();
that.setColsWidth(); done(res);
typeof options.done === 'function' && options.done(
res, curr, res[response.countName]
);
} }
}; };