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