astrion-website/demo/static/dist/assets/useSecondaryPass.js

2 lines
845 B
JavaScript

import{k as n}from"./runtime-dom.esm-bundler.js";function u(){const t=n(!1),r=n(!1),s=n(null);return{verified:t,loading:r,error:s,check:async()=>{r.value=!0,s.value=null;try{const e=await fetch("/api/admin/secondary/status",{credentials:"same-origin"});if(!e.ok)throw new Error(`状态请求失败:${e.status}`);const a=await e.json();t.value=!!a.verified}catch(e){s.value=e.message||"无法验证二级密码状态"}finally{r.value=!1}},verify:async e=>{r.value=!0,s.value=null;try{const a=await fetch("/api/admin/secondary/verify",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"same-origin",body:JSON.stringify({password:e})}),o=await a.json();if(!a.ok||!o.success)throw new Error(o.error||"二级密码验证失败");t.value=!0}catch(a){s.value=a.message||"验证失败",t.value=!1}finally{r.value=!1}}}}export{u};