diff --git a/public/static/plugs/ulthon-admin/ulthon-admin.js b/public/static/plugs/ulthon-admin/ulthon-admin.js index b8135ce..1bef735 100644 --- a/public/static/plugs/ulthon-admin/ulthon-admin.js +++ b/public/static/plugs/ulthon-admin/ulthon-admin.js @@ -111,7 +111,7 @@ }, checkAuth: function (node, elem) { - if(node === '1'){ + if (node === '1') { return true; } if (CONFIG.IS_SUPER_ADMIN) { @@ -127,13 +127,13 @@ return param !== undefined ? param : defaultParam; }, request: { - post: function (option, ok, no, ex) { - return admin.request.ajax('post', option, ok, no, ex); + post: function (option, ok, no, ex, complete) { + return admin.request.ajax('post', option, ok, no, ex, complete); }, - get: function (option, ok, no, ex) { - return admin.request.ajax('get', option, ok, no, ex); + get: function (option, ok, no, ex, complete) { + return admin.request.ajax('get', option, ok, no, ex, complete); }, - ajax: function (type, option, ok, no, ex) { + ajax: function (type, option, ok, no, ex, complete) { type = type || 'get'; option.url = option.url || ''; option.data = option.data || {}; @@ -142,12 +142,16 @@ option.statusCode = option.statusCode || 0; ok = ok || function (res) { }; + complete = complete || function () { + }; no = no || function (res) { var msg = res.msg == undefined ? '返回数据格式有误' : res.msg; admin.msg.error(msg); + complete(); return false; }; ex = ex || function (res) { + complete(); }; if (option.url == '') { admin.msg.error('请求地址不能为空'); @@ -184,9 +188,6 @@ }); return false; }, - complete: function () { - // @todo 刷新csrf-token - } }); } }, @@ -444,12 +445,12 @@ // 初始化已经选择的值 if (selectMode == 'checkbox' || selectMode == 'radio') { - if(typeof options.rowDisableCallback == 'function') { + if (typeof options.rowDisableCallback == 'function') { for (let index = 0; index < res.data.length; index++) { const dataItem = res.data[index]; var rowDisableResult = options.rowDisableCallback(dataItem); - if(rowDisableResult === false || rowDisableResult === true) { + if (rowDisableResult === false || rowDisableResult === true) { res.data[index].LAY_DISABLED = rowDisableResult; } } @@ -1879,13 +1880,13 @@ }); } }, - listen: function (preposeCallback, ok, no, ex) { + listen: function (preposeCallback, ok, no, ex, complete) { // 监听表单是否为必填项 admin.api.formRequired(); // 监听表单提交事件 - admin.api.formSubmit(preposeCallback, ok, no, ex); + admin.api.formSubmit(preposeCallback, ok, no, ex, complete); // 监听按钮操作 admin.api.button(); @@ -2173,7 +2174,7 @@ window.open(admin.url($(this).attr('href'))); }); }, - form: function (url, data, ok, no, ex, refreshTable, close) { + form: function (url, data, ok, no, ex, refreshTable, close, complete) { if (refreshTable === undefined) { refreshTable = true; } @@ -2181,9 +2182,13 @@ ok = ok || function (res) { res.msg = res.msg || ''; admin.msg.success(res.msg, function () { + if (close) { admin.api.closeCurrentOpen({ - refreshTable: refreshTable + refreshTable: refreshTable, + onClose: function () { + complete(); + } }); } }); @@ -2192,18 +2197,19 @@ admin.request.post({ url: url, data: data, - }, ok, no, ex); + }, ok, no, ex, complete); return false; }, closeCurrentOpen: function (option) { option = option || {}; option.refreshTable = option.refreshTable || false; option.refreshFrame = option.refreshFrame || false; + option.onClose = option.onClose || function () { }; if (option.refreshTable === true) { option.refreshTable = init.tableRenderId; } var index = parent.layer.getFrameIndex(window.name); - parent.layer.close(index); + parent.layer.close(index, option.onClose); if (option.refreshTable !== false) { parent.layui.table.reloadData(option.refreshTable); } @@ -2259,7 +2265,7 @@ }); } }, - formSubmit: function (preposeCallback, ok, no, ex) { + formSubmit: function (preposeCallback, ok, no, ex, complete) { var formList = document.querySelectorAll("[lay-submit]"); // 表单提交自动处理 @@ -2299,6 +2305,10 @@ var btnElem = data.elem; + var form = $(this).closest('form'); + if ($(form).hasClass('loading')) return false; + $(form).addClass('loading'); + // 判断btn是否具备name和value属性,如果有,则加到表单数据里 var btnName = $(btnElem).attr('name'); var btnValue = $(btnElem).attr('value'); @@ -2315,7 +2325,10 @@ if (typeof preposeCallback === 'function') { dataField = preposeCallback(dataField); } - admin.api.form(url, dataField, ok, no, ex, refresh, close); + complete = complete || function () { + $(form).removeClass('loading'); + }; + admin.api.form(url, dataField, ok, no, ex, refresh, close, complete); return false; });