From 83aa399f95f19a6cdde100af42c13bc717d59aeb Mon Sep 17 00:00:00 2001 From: wolfcode <37436228+wolf-leo@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:05:26 +0800 Subject: [PATCH] feat(easy-admin): prevent rapid form submission Add a mechanism to handle quick consecutive form submissions by displaying a message when a user tries to submit the form before the previous submission is completed. This update introduces a wait period during which subsequent submissions are prevented, enhancing the user experience and preventing potential errors. Signed-off-by: wolfcode <37436228+wolf-leo@users.noreply.github.com> --- public/static/plugs/easy-admin/easy-admin.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/static/plugs/easy-admin/easy-admin.js b/public/static/plugs/easy-admin/easy-admin.js index 7c8a7ea..6255e3b 100644 --- a/public/static/plugs/easy-admin/easy-admin.js +++ b/public/static/plugs/easy-admin/easy-admin.js @@ -19,9 +19,11 @@ define(["jquery", "tableSelect"], function ($, tableSelect) { table_render_id: 'currentTableRenderId', upload_url: 'ajax/upload', upload_exts: 'doc|gif|ico|icon|jpg|mp3|mp4|p12|pem|png|rar', - csrf_token: window.CONFIG.CSRF_TOKEN + csrf_token: window.CONFIG.CSRF_TOKEN, + wait_submit: false }; + var admin = { config: { shade: [0.02, '#000'], @@ -112,6 +114,7 @@ define(["jquery", "tableSelect"], function ($, tableSelect) { // @todo 刷新csrf-token let token = data.responseJSON ? data.responseJSON.__token__ : '' init.csrf_token = token + init.wait_submit = false } }); } @@ -1365,6 +1368,10 @@ define(["jquery", "tableSelect"], function ($, tableSelect) { url = admin.url(url); } form.on('submit(' + filter + ')', function (data) { + if (init.wait_submit) { + layer.msg('你点击太快了', {icon: 16, shade: 0.3, shadeClose: false, time: 1000}) + return false + } var dataField = data.field; var editorList = document.querySelectorAll(".editor"); // 富文本数据处理 @@ -1392,6 +1399,7 @@ define(["jquery", "tableSelect"], function ($, tableSelect) { if (typeof preposeCallback === 'function') { dataField = preposeCallback(dataField); } + init.wait_submit = true admin.api.form(url, dataField, ok, no, ex, refresh); return false; });