fix: 修复评论提交后表单状态未清除的问题

- 将表单重置代码移到 success 回调的最前面,确保优先执行
- 将表单重置与 UI 更新(插入评论、滚动)分离,避免异常影响表单重置
- 确保评论内容、验证码、Geetest 状态都能正确清除
- 修复需要刷新页面才能再次发送评论的问题
This commit is contained in:
2026-01-23 16:41:02 +08:00
parent 882ca001dc
commit c0e21840f1

View File

@@ -1635,7 +1635,36 @@ if (argonConfig.waterflow_columns != "1") {
}
//发送成功
// 使用 setTimeout 确保 iziToast 操作在下一个事件循环中执行
// 先复位评论表单(确保无论后续操作是否成功都能重置表单)
cancelReply();
$("#post_comment_content").val("");
// 重置数学验证码
$("#post_comment_captcha_seed").val(result.newCaptchaSeed);
$("#post_comment_captcha + style").html(".post-comment-captcha-container:before{content: '" + result.newCaptcha + "';}");
$("#post_comment_captcha").val("");
// 清空Geetest验证码隐藏字段并重置验证码实例
if ($("#geetest-captcha").length > 0) {
$("#geetest_lot_number").val("");
$("#geetest_captcha_output").val("");
$("#geetest_pass_token").val("");
$("#geetest_gen_time").val("");
// 重置验证状态标志位
window.geetestVerified = false;
// 重置自动提交标记
window.geetestAutoSubmitting = false;
// 重置 Geetest 实例,确保下一次可以重新验证
if (window.geetestCaptcha) {
try {
window.geetestCaptcha.reset();
} catch (e) {
ArgonDebug.warn('Geetest reset error:', e);
}
}
}
// 显示成功提示
setTimeout(function() {
try {
iziToast.destroy();
@@ -1652,7 +1681,13 @@ if (argonConfig.waterflow_columns != "1") {
icon: 'fa fa-check',
timeout: 5000
});
//插入新评论
} catch (e) {
ArgonDebug.warn('iziToast error:', e);
}
}, 0);
// 插入新评论
try {
result.html = result.html.replace(/<(\/).noscript>/g, "");
let parentID = result.parentID;
if (parentID == "" || parentID == null){
@@ -1676,40 +1711,14 @@ if (argonConfig.waterflow_columns != "1") {
}
}
calcHumanTimesOnPage();
//复位评论表单
cancelReply();
$("#post_comment_content").val("");
// 重置数学验证码
$("#post_comment_captcha_seed").val(result.newCaptchaSeed);
$("#post_comment_captcha + style").html(".post-comment-captcha-container:before{content: '" + result.newCaptcha + "';}");
$("#post_comment_captcha").val(""); // 清空验证码输入框
// 清空Geetest验证码隐藏字段并重置验证码实例
if ($("#geetest-captcha").length > 0) {
$("#geetest_lot_number").val("");
$("#geetest_captcha_output").val("");
$("#geetest_pass_token").val("");
$("#geetest_gen_time").val("");
// 重置验证状态标志位
window.geetestVerified = false;
// 重置自动提交标记
window.geetestAutoSubmitting = false;
// 重置 Geetest 实例,确保下一次可以重新验证
if (window.geetestCaptcha) {
try {
window.geetestCaptcha.reset();
} catch (e) {
ArgonDebug.warn('Geetest reset error:', e);
}
}
}
// 滚动到新评论
$("body,html").animate({
scrollTop: $("#comment-" + result.id).offset().top - 100
}, 500, 'easeOutExpo');
} catch (e) {
ArgonDebug.warn('Comment insertion error:', e);
}
}, 0);
},
error: function(result){
$("#post_comment").removeClass("sending");