feat: 注册页去掉主学学科,进入系统后新建会话再选学科

这个提交包含在:
langxm
2026-10-14 09:31:56 +08:00
父节点 2123c3f99e
当前提交 2df376e262
+3 -13
查看文件
@@ -37,8 +37,6 @@ select{width:100%;border:1.5px solid var(--line);border-radius:9px;padding:11px
<input id="pass" type="password" autocomplete="new-password" placeholder="同时用作你的 Hydro 判题账号密码"> <input id="pass" type="password" autocomplete="new-password" placeholder="同时用作你的 Hydro 判题账号密码">
<label>确认密码</label> <label>确认密码</label>
<input id="pass2" type="password" autocomplete="new-password"> <input id="pass2" type="password" autocomplete="new-password">
<label>主学学科</label>
<select id="course"><option value="">加载中…</option></select>
<button class="btn" onclick="doReg()">注 册</button> <button class="btn" onclick="doReg()">注 册</button>
<div class="msg" id="msg"></div> <div class="msg" id="msg"></div>
@@ -49,25 +47,17 @@ select{width:100%;border:1.5px solid var(--line);border-radius:9px;padding:11px
<script> <script>
var API_BASE=(location.hostname==='127.0.0.1'||location.hostname==='localhost'||location.protocol==='file:')?'http://127.0.0.1:18100':''; var API_BASE=(location.hostname==='127.0.0.1'||location.hostname==='localhost'||location.protocol==='file:')?'http://127.0.0.1:18100':'';
function $(id){return document.getElementById(id);} function $(id){return document.getElementById(id);}
/* 学科列表来自 /api/courses(后端配置表,管理员可增删) */ /* 学科不再在注册时选择:进入系统后新建会话时再选(学科窗口) */
fetch(API_BASE+'/api/courses').then(function(r){return r.json();}).then(function(list){
var sel=$('course'); sel.innerHTML='';
if(!list||!list.length){ sel.innerHTML='<option value="ap-csa">AP CSA(Java 编程)</option>'; return; }
list.forEach(function(c){
var o=document.createElement('option'); o.value=c.code; o.textContent=c.name;
if(c.code==='ap-csa') o.selected=true; sel.appendChild(o);
});
}).catch(function(){});
$('pass2').addEventListener('keydown',function(e){if(e.key==='Enter')doReg();}); $('pass2').addEventListener('keydown',function(e){if(e.key==='Enter')doReg();});
async function doReg(){ async function doReg(){
var u=$('uname').value.trim(), p=$('pass').value, p2=$('pass2').value, c=$('course').value; var u=$('uname').value.trim(), p=$('pass').value, p2=$('pass2').value;
var msg=$('msg'); var msg=$('msg');
if(!u){msg.className='msg err';msg.textContent='请输入用户名';return;} if(!u){msg.className='msg err';msg.textContent='请输入用户名';return;}
if(p.length<6){msg.className='msg err';msg.textContent='密码至少 6 位';return;} if(p.length<6){msg.className='msg err';msg.textContent='密码至少 6 位';return;}
if(p!==p2){msg.className='msg err';msg.textContent='两次密码不一致';return;} if(p!==p2){msg.className='msg err';msg.textContent='两次密码不一致';return;}
msg.className='msg';msg.textContent='注册中:创建本地账号 + Hydro 判题账号…'; msg.className='msg';msg.textContent='注册中:创建本地账号 + Hydro 判题账号…';
try{ try{
var r=await fetch(API_BASE+'/api/auth/register',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({uname:u,password:p,course:c})}); var r=await fetch(API_BASE+'/api/auth/register',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({uname:u,password:p})});
var d=await r.json(); var d=await r.json();
if(!r.ok){msg.className='msg err';msg.textContent=d.detail||'注册失败';return;} if(!r.ok){msg.className='msg err';msg.textContent=d.detail||'注册失败';return;}
localStorage.setItem('fl_token',d.token); localStorage.setItem('fl_token',d.token);