feat: 优化代码编辑器样式和增强预览功能

This commit is contained in:
2026-04-10 20:45:24 +08:00
parent 96b9eb57e2
commit 5baab4da11
3 changed files with 157 additions and 17 deletions

View File

@@ -2,9 +2,26 @@
<?php include("template/$OJ_TEMPLATE/header.php");?>
<style>
#frmSolution {
width: 100%;
text-align: left;
}
#source {
width: 80%;
display: block;
width: 100% !important;
height: 600px;
margin: 14px 0 0 !important;
text-align: left !important;
}
.hustoj-vditor-code,
.hustoj-vditor-code .vditor,
.hustoj-vditor-code .vditor-content,
.hustoj-vditor-code .vditor-reset,
.hustoj-vditor-code textarea {
width: 100% !important;
text-align: left !important;
}
.ace-chrome .ace_marker-layer .ace_active-line{ /*当前行*/
@@ -412,6 +429,8 @@ function reloadtemplate(lang){
document.cookie="lastlang="+lang;
var url=window.location.href;
var i=url.indexOf("sid=");
if(lang!=<?php echo $lastlang?>)
autoSave(<?php echo $lastlang ?>);
switchLang(lang);
if(lang!=<?php echo $lastlang?>)
document.location.href=url;
@@ -471,11 +490,21 @@ function loadFromBlockly(){
fontSize: "18px"
});
reloadtemplate($("#language").val());
function autoSave(){
function getSourceDraftKey(languageOverride){
let language=languageOverride;
if(language===undefined||language===null||language===""){
language=$("#language").val();
}
if(language===undefined||language===null||language===""){
language="<?php echo $lastlang ?>";
}
return "<?php echo $_SESSION[$OJ_NAME.'_user_id']?>source:"+location.href+":lang:"+language;
}
function autoSave(languageOverride){
var mark="<?php echo isset($id)?'problem_id':'cid';?>";
var problem_id=$("#"+mark).val();
if(!!localStorage){
let key="<?php echo $_SESSION[$OJ_NAME.'_user_id']?>source:"+location.href;
let key=getSourceDraftKey(languageOverride);
if(typeof(editor) != "undefined")
$("#hide_source").val(editor.getValue());
localStorage.setItem(key,$("#hide_source").val());
@@ -486,7 +515,7 @@ function loadFromBlockly(){
$("#source").css("height",window.innerHeight-180);
if($("#vcode")!=undefined) $("#vcode").click();
if(!!localStorage){
let key="<?php echo $_SESSION[$OJ_NAME.'_user_id']?>source:"+location.href;
let key=getSourceDraftKey();
let saved=localStorage.getItem(key);
if(saved!=null&&saved!=""&&saved.length>editor.getValue().length){
//let load=confirm("发现自动保存的源码,是否加载?(仅有一次机会)");