mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-07-09 11:32:48 +08:00
fix: 修复通过回车提交表单时能够重复提交的问题
This commit is contained in:
@@ -127,13 +127,13 @@
|
|||||||
return param !== undefined ? param : defaultParam;
|
return param !== undefined ? param : defaultParam;
|
||||||
},
|
},
|
||||||
request: {
|
request: {
|
||||||
post: function (option, ok, no, ex) {
|
post: function (option, ok, no, ex, complete) {
|
||||||
return admin.request.ajax('post', option, ok, no, ex);
|
return admin.request.ajax('post', option, ok, no, ex, complete);
|
||||||
},
|
},
|
||||||
get: function (option, ok, no, ex) {
|
get: function (option, ok, no, ex, complete) {
|
||||||
return admin.request.ajax('get', option, ok, no, ex);
|
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';
|
type = type || 'get';
|
||||||
option.url = option.url || '';
|
option.url = option.url || '';
|
||||||
option.data = option.data || {};
|
option.data = option.data || {};
|
||||||
@@ -142,12 +142,16 @@
|
|||||||
option.statusCode = option.statusCode || 0;
|
option.statusCode = option.statusCode || 0;
|
||||||
ok = ok || function (res) {
|
ok = ok || function (res) {
|
||||||
};
|
};
|
||||||
|
complete = complete || function () {
|
||||||
|
};
|
||||||
no = no || function (res) {
|
no = no || function (res) {
|
||||||
var msg = res.msg == undefined ? '返回数据格式有误' : res.msg;
|
var msg = res.msg == undefined ? '返回数据格式有误' : res.msg;
|
||||||
admin.msg.error(msg);
|
admin.msg.error(msg);
|
||||||
|
complete();
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
ex = ex || function (res) {
|
ex = ex || function (res) {
|
||||||
|
complete();
|
||||||
};
|
};
|
||||||
if (option.url == '') {
|
if (option.url == '') {
|
||||||
admin.msg.error('请求地址不能为空');
|
admin.msg.error('请求地址不能为空');
|
||||||
@@ -184,9 +188,6 @@
|
|||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
complete: function () {
|
|
||||||
// @todo 刷新csrf-token
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -1879,13 +1880,13 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
listen: function (preposeCallback, ok, no, ex) {
|
listen: function (preposeCallback, ok, no, ex, complete) {
|
||||||
|
|
||||||
// 监听表单是否为必填项
|
// 监听表单是否为必填项
|
||||||
admin.api.formRequired();
|
admin.api.formRequired();
|
||||||
|
|
||||||
// 监听表单提交事件
|
// 监听表单提交事件
|
||||||
admin.api.formSubmit(preposeCallback, ok, no, ex);
|
admin.api.formSubmit(preposeCallback, ok, no, ex, complete);
|
||||||
|
|
||||||
// 监听按钮操作
|
// 监听按钮操作
|
||||||
admin.api.button();
|
admin.api.button();
|
||||||
@@ -2173,7 +2174,7 @@
|
|||||||
window.open(admin.url($(this).attr('href')));
|
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) {
|
if (refreshTable === undefined) {
|
||||||
refreshTable = true;
|
refreshTable = true;
|
||||||
}
|
}
|
||||||
@@ -2181,9 +2182,13 @@
|
|||||||
ok = ok || function (res) {
|
ok = ok || function (res) {
|
||||||
res.msg = res.msg || '';
|
res.msg = res.msg || '';
|
||||||
admin.msg.success(res.msg, function () {
|
admin.msg.success(res.msg, function () {
|
||||||
|
|
||||||
if (close) {
|
if (close) {
|
||||||
admin.api.closeCurrentOpen({
|
admin.api.closeCurrentOpen({
|
||||||
refreshTable: refreshTable
|
refreshTable: refreshTable,
|
||||||
|
onClose: function () {
|
||||||
|
complete();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -2192,18 +2197,19 @@
|
|||||||
admin.request.post({
|
admin.request.post({
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
}, ok, no, ex);
|
}, ok, no, ex, complete);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
closeCurrentOpen: function (option) {
|
closeCurrentOpen: function (option) {
|
||||||
option = option || {};
|
option = option || {};
|
||||||
option.refreshTable = option.refreshTable || false;
|
option.refreshTable = option.refreshTable || false;
|
||||||
option.refreshFrame = option.refreshFrame || false;
|
option.refreshFrame = option.refreshFrame || false;
|
||||||
|
option.onClose = option.onClose || function () { };
|
||||||
if (option.refreshTable === true) {
|
if (option.refreshTable === true) {
|
||||||
option.refreshTable = init.tableRenderId;
|
option.refreshTable = init.tableRenderId;
|
||||||
}
|
}
|
||||||
var index = parent.layer.getFrameIndex(window.name);
|
var index = parent.layer.getFrameIndex(window.name);
|
||||||
parent.layer.close(index);
|
parent.layer.close(index, option.onClose);
|
||||||
if (option.refreshTable !== false) {
|
if (option.refreshTable !== false) {
|
||||||
parent.layui.table.reloadData(option.refreshTable);
|
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]");
|
var formList = document.querySelectorAll("[lay-submit]");
|
||||||
|
|
||||||
// 表单提交自动处理
|
// 表单提交自动处理
|
||||||
@@ -2299,6 +2305,10 @@
|
|||||||
|
|
||||||
var btnElem = data.elem;
|
var btnElem = data.elem;
|
||||||
|
|
||||||
|
var form = $(this).closest('form');
|
||||||
|
if ($(form).hasClass('loading')) return false;
|
||||||
|
$(form).addClass('loading');
|
||||||
|
|
||||||
// 判断btn是否具备name和value属性,如果有,则加到表单数据里
|
// 判断btn是否具备name和value属性,如果有,则加到表单数据里
|
||||||
var btnName = $(btnElem).attr('name');
|
var btnName = $(btnElem).attr('name');
|
||||||
var btnValue = $(btnElem).attr('value');
|
var btnValue = $(btnElem).attr('value');
|
||||||
@@ -2315,7 +2325,10 @@
|
|||||||
if (typeof preposeCallback === 'function') {
|
if (typeof preposeCallback === 'function') {
|
||||||
dataField = preposeCallback(dataField);
|
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;
|
return false;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user