✨ feat(submit): 重构提交流程并加强判题端错误处理
- judge_client 在 solution/problem/source 查询失败时记录系统错误并以 OJ_RE 安全退出,避免判题机崩溃或挂起 - submit.php 抽取 submit_error 助手,AJAX 请求返回纯文本错误,提交页改为 AJAX 流程并增强错误提示 - 修复 reinfo 自动刷新脚本在标签页切回前台后未恢复轮询的 bug
This commit is contained in:
@@ -215,6 +215,15 @@
|
||||
border-top: 1px solid rgba(0,0,5,0.08);
|
||||
}
|
||||
|
||||
.submit-top-actions {
|
||||
justify-content: flex-end;
|
||||
padding-top: 0;
|
||||
padding-bottom: 16px;
|
||||
margin-bottom: 16px;
|
||||
border-top: 0;
|
||||
border-bottom: 1px solid rgba(0,0,5,0.08);
|
||||
}
|
||||
|
||||
.submit-actions .actions-left {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
@@ -388,7 +397,15 @@
|
||||
</div>
|
||||
|
||||
<script src="<?php echo $OJ_CDN_URL?>include/checksource.js"></script>
|
||||
<form id="frmSolution" action="submit.php<?php if (isset($_GET['spa'])) echo "?spa" ?>" method="post" onsubmit="do_submit()" enctype="multipart/form-data">
|
||||
<form id="frmSolution" action="submit.php<?php if (isset($_GET['spa'])) echo "?spa" ?>" method="post" onsubmit="do_submit();return false;" enctype="multipart/form-data">
|
||||
|
||||
<div class="submit-actions submit-top-actions">
|
||||
<div class="actions-left">
|
||||
<button id="Submit" type="button" class="btn btn-primary" onclick="do_submit();">
|
||||
<i class="paper plane icon"></i> <?php echo $MSG_SUBMIT?>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="submit-toolbar">
|
||||
<?php if (!isset($_GET['spa']) || $solution_name ) {?>
|
||||
@@ -485,11 +502,9 @@
|
||||
<h2 class="solution-name-title">📎 <?php echo $solution_name?></h2>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ((isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name) || (isset($OJ_ENCODE_SUBMIT)&&$OJ_ENCODE_SUBMIT) || (isset($OJ_BLOCKLY)&&$OJ_BLOCKLY)){?>
|
||||
<div class="submit-actions">
|
||||
<div class="actions-left">
|
||||
<button id="Submit" type="button" class="btn btn-primary" onclick="do_submit();">
|
||||
<i class="paper plane icon"></i> <?php echo $MSG_SUBMIT?>
|
||||
</button>
|
||||
<?php if ( isset($OJ_TEST_RUN) && $OJ_TEST_RUN && $spj<=1 && !$solution_name ){?>
|
||||
<button id="TestRun" type="button" class="btn btn-info" onclick="do_test_run();">
|
||||
<i class="play icon"></i> <?php echo $MSG_TR?>
|
||||
@@ -508,13 +523,14 @@
|
||||
<input id="blockly_loader" type="button" class="btn btn-purple" onclick="openBlockly()" value="🧩 <?php echo $MSG_BLOCKLY_OPEN?>">
|
||||
<input id="transrun" type="button" class="btn btn-green" onclick="loadFromBlockly()" value="▶ <?php echo $MSG_BLOCKLY_TEST?>" style="display:none;">
|
||||
</div>
|
||||
<?php }?>
|
||||
<?php }?>
|
||||
</div>
|
||||
<?php }?>
|
||||
|
||||
<div id="blockly" class="center"></div>
|
||||
|
||||
<?php if (isset($id)){?>
|
||||
<input id="problem_id" type="hidden" value="<?php echo $id?>" name="problem_id">
|
||||
<input id="problem_id" type="hidden" value="<?php echo $id?>" name="id">
|
||||
<?php }else{?>
|
||||
<input id="cid" type="hidden" value="<?php echo $cid?>" name="cid">
|
||||
<input id="pid" type="hidden" value="<?php echo $pid?>" name="pid">
|
||||
@@ -618,6 +634,69 @@ return ret+"";
|
||||
}
|
||||
var count=0;
|
||||
|
||||
function htmlEscape(text){
|
||||
return $("<div>").text(text).html();
|
||||
}
|
||||
|
||||
function cleanSubmitMessage(data){
|
||||
var text=$("<div>").html(String(data)).text();
|
||||
text=$.trim(text.replace(/\s+/g," "));
|
||||
if(text=="") text="Submit failed.";
|
||||
return text;
|
||||
}
|
||||
|
||||
function showSubmitMessage(data){
|
||||
var tb=window.document.getElementById('result');
|
||||
var text=cleanSubmitMessage(data);
|
||||
if(tb!=null){
|
||||
tb.innerHTML="<span class='badge badge-danger'>"+htmlEscape(text)+"</span>";
|
||||
}else{
|
||||
alert(text);
|
||||
}
|
||||
if($("#vcode-img")!=null) $("#vcode-img").click();
|
||||
}
|
||||
|
||||
function setSubmitDisabled(disabled){
|
||||
$("#Submit").prop('disabled', disabled);
|
||||
$("#TestRun").prop('disabled', disabled);
|
||||
}
|
||||
|
||||
function startSubmitCooldown(){
|
||||
count=<?php echo isset($OJ_SUBMIT_COOLDOWN_TIME)?$OJ_SUBMIT_COOLDOWN_TIME:5 ?> * 2 ;
|
||||
handler_interval= window.setTimeout("resume();",1000);
|
||||
}
|
||||
|
||||
function submitSolutionAjax(isTestRun){
|
||||
var form=document.getElementById("frmSolution");
|
||||
var formData=new FormData(form);
|
||||
$.ajax({
|
||||
url:"submit.php?ajax<?php if(isset($_GET['spa'])) echo '&spa'; ?>",
|
||||
type:"POST",
|
||||
data:formData,
|
||||
processData:false,
|
||||
contentType:false,
|
||||
success:function(data){
|
||||
var text=$.trim(String(data));
|
||||
var sid=/^\d+$/.test(text)?parseInt(text,10):0;
|
||||
if(sid>0){
|
||||
if(isTestRun){
|
||||
fresh_result(sid);
|
||||
startSubmitCooldown();
|
||||
}else{
|
||||
window.location.href="reinfo.php?sid="+sid;
|
||||
}
|
||||
}else{
|
||||
showSubmitMessage(text);
|
||||
setSubmitDisabled(false);
|
||||
}
|
||||
},
|
||||
error:function(xhr){
|
||||
showSubmitMessage(xhr.responseText || "Submit failed.");
|
||||
setSubmitDisabled(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function encoded_submit(){
|
||||
|
||||
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
|
||||
@@ -643,7 +722,7 @@ function encoded_submit(){
|
||||
}
|
||||
|
||||
function do_submit(){
|
||||
$("#Submit").attr("disabled","true");
|
||||
setSubmitDisabled(true);
|
||||
if(using_blockly)
|
||||
translate();
|
||||
if(typeof(editor) != "undefined"){
|
||||
@@ -656,37 +735,8 @@ function do_submit(){
|
||||
else
|
||||
problem_id.value='<?php if (isset($cid))echo $cid?>';
|
||||
document.getElementById("frmSolution").target="_self";
|
||||
|
||||
<?php if(isset($_GET['spa'])){?>
|
||||
<?php if($solution_name) { ?>document.getElementById("frmSolution").submit(); <?php } ?>
|
||||
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){
|
||||
var sid=parseInt(data);
|
||||
if(sid>0){
|
||||
window.location.href="reinfo.php?sid="+sid;
|
||||
}else{
|
||||
fresh_result(data);
|
||||
}
|
||||
});
|
||||
$("#Submit").prop('disabled', true);
|
||||
$("#TestRun").prop('disabled', true);
|
||||
count=<?php echo $OJ_SUBMIT_COOLDOWN_TIME?> * 2 ;
|
||||
handler_interval= window.setTimeout("resume();",1000);
|
||||
<?php if(isset($OJ_REMOTE_JUDGE)&&$OJ_REMOTE_JUDGE) {?>$("#sk").attr("src","remote.php"); <?php } ?>
|
||||
<?php }else{?>
|
||||
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){
|
||||
var sid=parseInt(data);
|
||||
if(sid>0){
|
||||
window.location.href="reinfo.php?sid="+sid;
|
||||
}else{
|
||||
fresh_result(data);
|
||||
}
|
||||
});
|
||||
$("#Submit").prop('disabled', true);
|
||||
$("#TestRun").prop('disabled', true);
|
||||
count=<?php echo $OJ_SUBMIT_COOLDOWN_TIME?> * 2 ;
|
||||
handler_interval= window.setTimeout("resume();",1000);
|
||||
<?php }?>
|
||||
|
||||
submitSolutionAjax(false);
|
||||
<?php if(isset($OJ_REMOTE_JUDGE)&&$OJ_REMOTE_JUDGE) {?>$("#sk").attr("src","remote.php"); <?php } ?>
|
||||
}
|
||||
var handler_interval;
|
||||
function do_test_run(){
|
||||
@@ -705,12 +755,9 @@ function do_test_run(){
|
||||
var problem_id=document.getElementById(mark);
|
||||
problem_id.value=-problem_id.value;
|
||||
document.getElementById("frmSolution").target="testRun";
|
||||
$.post("submit.php?ajax",$("#frmSolution").serialize(),function(data){fresh_result(data);});
|
||||
$("#Submit").prop('disabled', true);
|
||||
$("#TestRun").prop('disabled', true);
|
||||
setSubmitDisabled(true);
|
||||
submitSolutionAjax(true);
|
||||
problem_id.value=-problem_id.value;
|
||||
count=<?php echo isset($OJ_SUBMIT_COOLDOWN_TIME)?$OJ_SUBMIT_COOLDOWN_TIME:5 ?> * 2 ;
|
||||
handler_interval= window.setTimeout("resume();",1000);
|
||||
}
|
||||
function resume(){
|
||||
count--;
|
||||
|
||||
Reference in New Issue
Block a user