import{Bt as e,Cr as t,Ft as n,Gn as r,Jn as i,L as a,Lt as o,M as s,Mr as c,Nr as l,Nt as u,Pt as d,Qn as f,Vt as p,Xn as m,Yn as h,Zn as g,_r as _,c as v,dn as y,dr as b,er as x,fr as S,jr 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,yr as N}from"./index-jrCi0Lum.js";import{t as P}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{t as F}from"./VChip-DRbE4Osb.js";import{t as I}from"./VAlert-ilZyhHDr.js";var L=y({...A(),...w()},`VForm`),R=E()({name:`VForm`,props:L(),emits:{"update:modelValue":e=>!0,submit:e=>!0},setup(e,{slots:n,emit:r}){let i=v(e),a=t();function o(e){e.preventDefault(),i.reset()}function s(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&&a.value?.submit()}),t.preventDefault()}return O(()=>h(`form`,{ref:a,class:C([`v-form`,e.class]),style:c(e.style),novalidate:!0,onReset:o,onSubmit:s},[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})])),M(i,a)}}),z={class:`login-page`},B={class:`login-center`},V={key:2,class:`text-center mt-4`},H=P(T({__name:`LoginPage`,setup(v){let y=e(),C=p(),w=u(),T=t(``),E=t(``),O=t(``),A=t(!1),M=t(!1),P=t(``),L=t(!1),H=t(0),U=t(null),W=t([]),G=t(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()}),b(()=>{K&&clearInterval(K),Z&&clearInterval(Z)});let X=t(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))});_(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||`/`;C.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,t)=>(S(),f(`div`,z,[h(`div`,{class:`wallpaper-bg`,style:c({backgroundImage:`url(${q.value})`})},null,4),t[6]||=h(`div`,{class:`wallpaper-overlay`},null,-1),h(`div`,B,[k(s,{elevation:`0`,rounded:`xl`,class:`login-card pa-10`,border:``},{default:N(()=>[P.value?(S(),m(I,{key:0,type:`error`,density:`compact`,class:`mb-4`,closable:``,"onClick:close":t[0]||=e=>P.value=``,rounded:`lg`,variant:`tonal`},{default:N(()=>[x(l(P.value),1)]),_:1})):g(``,!0),U.value?(S(),m(I,{key:1,type:`warning`,density:`compact`,class:`mb-4`,rounded:`lg`,variant:`tonal`},{default:N(()=>[x(` 账户已锁定，请 `+l(Q.value)+` 分钟后重试 `,1)]),_:1})):g(``,!0),k(R,{onSubmit:r($,[`prevent`])},{default:N(()=>[k(D,{modelValue:T.value,"onUpdate:modelValue":t[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":t[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":t[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?(S(),m(D,{key:0,modelValue:O.value,"onUpdate:modelValue":t[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`])):g(``,!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:N(()=>[...t[5]||=[x(` 登录 `,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1}),H.value>0&&!U.value?(S(),f(`div`,V,[k(F,{size:`small`,variant:`tonal`,color:`warning`,label:``},{default:N(()=>[x(` 已失败 `+l(H.value)+` 次 `,1)]),_:1})])):g(``,!0)]),_:1})])]))}}),[[`__scopeId`,`data-v-42a5c411`]]);export{H as default};