import{Bt as e,Fr as t,Ft as n,Gn as r,Jn as i,L as a,Lt as o,M as s,Nr as c,Nt as l,Pr as u,Pt as d,Qn as f,Tr as p,Vt as m,Xn as h,Yn as g,Zn as _,br as v,c as y,dn as b,dr as x,er as S,fr as C,l as w,rr as T,sn as E,t as D,tn as O,tr as k,un as A,ur as j,v as M,vr as N}from"./index-Bq06YXFr.js";import{t as P}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{t as F}from"./VChip-CKaNxfks.js";import{t as I}from"./VAlert-yVdWYjZ3.js";var L=b({...A(),...w()},`VForm`),R=E()({name:`VForm`,props:L(),emits:{"update:modelValue":e=>!0,submit:e=>!0},setup(e,{slots:t,emit:n}){let r=y(e),i=p();function a(e){e.preventDefault(),r.reset()}function o(e){let t=e,a=r.validate();t.then=a.then.bind(a),t.catch=a.catch.bind(a),t.finally=a.finally.bind(a),n(`submit`,t),t.defaultPrevented||a.then(({valid:e})=>{e&&i.value?.submit()}),t.preventDefault()}return O(()=>g(`form`,{ref:i,class:c([`v-form`,e.class]),style:u(e.style),novalidate:!0,onReset:a,onSubmit:o},[t.default?.({get errors(){return r.errors.value},get isDisabled(){return r.isDisabled.value},get isReadonly(){return r.isReadonly.value},get isValidating(){return r.isValidating.value},get isValid(){return r.isValid.value},get items(){return r.items.value},validate:r.validate,reset:r.reset,resetValidation:r.resetValidation})])),M(r,i)}}),z={class:`login-page`},B={class:`login-center`},V={key:2,class:`text-center mt-4`},H=P(T({__name:`LoginPage`,setup(c){let y=e(),b=m(),w=l(),T=p(``),E=p(``),O=p(``),A=p(!1),M=p(!1),P=p(``),L=p(!1),H=p(0),U=p(null),W=p([]),G=p(0),K=null,q=i(()=>W.value.length===0?``:W.value[G.value]);async function J(){try{let e=await o.get(`/settings/bing-wallpapers`);e?.urls?.length&&(W.value=e.urls,G.value=Math.floor(Math.random()*e.urls.length))}catch{}}function Y(){K&&clearInterval(K),!(W.value.length<=1)&&(K=setInterval(()=>{G.value=(G.value+1)%W.value.length},36e5))}j(async()=>{await J(),Y()}),x(()=>{K&&clearInterval(K),Z&&clearInterval(Z)});let X=p(Date.now()),Z=null,Q=i(()=>{if(!U.value)return 0;let e=new Date(U.value).getTime()-X.value;return Math.max(0,Math.ceil(e/6e4))});N(U,e=>{Z&&=(clearInterval(Z),null),e&&(Z=setInterval(()=>{X.value=Date.now()},3e4))});async function $(){if(!T.value||!E.value){P.value=`请输入用户名和密码`;return}M.value=!0,P.value=``;try{await w.login(T.value,E.value,L.value?O.value:void 0);let e=y.query.redirect||`/`;b.push(e)}catch(e){e instanceof n?(L.value=!0,P.value=e.message):e instanceof d?e.status===429?(U.value=new Date(Date.now()+900*1e3).toISOString(),P.value=`登录尝试过多，账户已锁定 15 分钟`):(H.value++,P.value=e.message):P.value=`网络错误，请重试`}finally{M.value=!1}}return(e,n)=>(C(),f(`div`,z,[g(`div`,{class:`wallpaper-bg`,style:u({backgroundImage:`url(${q.value})`})},null,4),n[6]||=g(`div`,{class:`wallpaper-overlay`},null,-1),g(`div`,B,[k(s,{elevation:`0`,rounded:`xl`,class:`login-card pa-10`,border:``},{default:v(()=>[P.value?(C(),h(I,{key:0,type:`error`,density:`compact`,class:`mb-4`,closable:``,"onClick:close":n[0]||=e=>P.value=``,rounded:`lg`,variant:`tonal`},{default:v(()=>[S(t(P.value),1)]),_:1})):_(``,!0),U.value?(C(),h(I,{key:1,type:`warning`,density:`compact`,class:`mb-4`,rounded:`lg`,variant:`tonal`},{default:v(()=>[S(` 账户已锁定，请 `+t(Q.value)+` 分钟后重试 `,1)]),_:1})):_(``,!0),k(R,{onSubmit:r($,[`prevent`])},{default:v(()=>[k(D,{modelValue:T.value,"onUpdate:modelValue":n[1]||=e=>T.value=e,label:`用户名`,variant:`outlined`,density:`comfortable`,"prepend-inner-icon":`mdi-account-outline`,disabled:M.value,class:`mb-4`,autocomplete:`username`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`disabled`]),k(D,{modelValue:E.value,"onUpdate:modelValue":n[2]||=e=>E.value=e,label:`密码`,variant:`outlined`,density:`comfortable`,"prepend-inner-icon":`mdi-lock-outline`,"append-inner-icon":A.value?`mdi-eye`:`mdi-eye-off`,type:A.value?`text`:`password`,"onClick:appendInner":n[3]||=e=>A.value=!A.value,disabled:M.value,class:`mb-4`,autocomplete:`current-password`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`append-inner-icon`,`type`,`disabled`]),L.value?(C(),h(D,{key:0,modelValue:O.value,"onUpdate:modelValue":n[4]||=e=>O.value=e,label:`TOTP 验证码`,variant:`outlined`,density:`comfortable`,"prepend-inner-icon":`mdi-shield-key-outline`,disabled:M.value,class:`mb-4`,autocomplete:`one-time-code`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`disabled`])):_(``,!0),k(a,{type:`submit`,color:`primary`,variant:`flat`,block:``,size:`large`,loading:M.value,disabled:!!U.value,rounded:`lg`,class:`mt-2`,height:`48`},{default:v(()=>[...n[5]||=[S(` 登录 `,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1}),H.value>0&&!U.value?(C(),f(`div`,V,[k(F,{size:`small`,variant:`tonal`,color:`warning`,label:``},{default:v(()=>[S(` 已失败 `+t(H.value)+` 次 `,1)]),_:1})])):_(``,!0)]),_:1})])]))}}),[[`__scopeId`,`data-v-42a5c411`]]);export{H as default};