import{$n as e,Ar as t,Bt as n,Ft as r,It as i,Jn as a,Kn as o,L as s,Lt as c,M as l,Qn as u,Rt as d,Wn as f,Xn as p,Yn as m,_r as h,c as g,cr as _,en as v,hr as y,jr as b,kr as x,l as S,ln as C,lr as w,on as T,qn as E,t as D,tr as O,un as k,ur as A,xr as j,y as M,zt as N}from"./index-S1YK6zxF.js";import{t as P}from"./VChip-DtHsaJZp.js";import{t as F}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{t as I}from"./VAlert-DBUGzMLa.js";var L=k({...C(),...S()},`VForm`),R=T()({name:`VForm`,props:L(),emits:{"update:modelValue":e=>!0,submit:e=>!0},setup(e,{slots:n,emit:r}){let i=g(e),a=j();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 v(()=>E(`form`,{ref:a,class:x([`v-form`,e.class]),style:t(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=F(O({__name:`LoginPage`,setup(g){let v=N(),x=n(),S=r(),C=j(``),T=j(``),O=j(``),k=j(!1),M=j(!1),F=j(``),L=j(!1),H=j(0),U=j(null),W=j([]),G=j(0),K=null,q=o(()=>W.value.length===0?``:W.value[G.value]);async function J(){try{let e=await d.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))}_(async()=>{await J(),Y()}),w(()=>{K&&clearInterval(K),Z&&clearInterval(Z)});let X=j(Date.now()),Z=null,Q=o(()=>{if(!U.value)return 0;let e=new Date(U.value).getTime()-X.value;return Math.max(0,Math.ceil(e/6e4))});y(U,e=>{Z&&=(clearInterval(Z),null),e&&(Z=setInterval(()=>{X.value=Date.now()},3e4))});async function $(){if(!C.value||!T.value){F.value=`请输入用户名和密码`;return}M.value=!0,F.value=``;try{await S.login(C.value,T.value,L.value?O.value:void 0);let e=v.query.redirect||`/`;x.push(e)}catch(e){e instanceof c?(L.value=!0,F.value=e.message):e instanceof i?e.status===429?(U.value=new Date(Date.now()+900*1e3).toISOString(),F.value=`登录尝试过多，账户已锁定 15 分钟`):(H.value++,F.value=e.message):F.value=`网络错误，请重试`}finally{M.value=!1}}return(n,r)=>(A(),p(`div`,z,[E(`div`,{class:`wallpaper-bg`,style:t({backgroundImage:`url(${q.value})`})},null,4),r[6]||=E(`div`,{class:`wallpaper-overlay`},null,-1),E(`div`,B,[e(l,{elevation:`0`,rounded:`xl`,class:`login-card pa-10`,border:``},{default:h(()=>[F.value?(A(),a(I,{key:0,type:`error`,density:`compact`,class:`mb-4`,closable:``,"onClick:close":r[0]||=e=>F.value=``,rounded:`lg`,variant:`tonal`},{default:h(()=>[u(b(F.value),1)]),_:1})):m(``,!0),U.value?(A(),a(I,{key:1,type:`warning`,density:`compact`,class:`mb-4`,rounded:`lg`,variant:`tonal`},{default:h(()=>[u(` 账户已锁定，请 `+b(Q.value)+` 分钟后重试 `,1)]),_:1})):m(``,!0),e(R,{onSubmit:f($,[`prevent`])},{default:h(()=>[e(D,{modelValue:C.value,"onUpdate:modelValue":r[1]||=e=>C.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`]),e(D,{modelValue:T.value,"onUpdate:modelValue":r[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":r[3]||=e=>k.value=!k.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?(A(),a(D,{key:0,modelValue:O.value,"onUpdate:modelValue":r[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`])):m(``,!0),e(s,{type:`submit`,color:`primary`,variant:`flat`,block:``,size:`large`,loading:M.value,disabled:!!U.value,rounded:`lg`,class:`mt-2`,height:`48`},{default:h(()=>[...r[5]||=[u(` 登录 `,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1}),H.value>0&&!U.value?(A(),p(`div`,V,[e(P,{size:`small`,variant:`tonal`,color:`warning`,label:``},{default:h(()=>[u(` 已失败 `+b(H.value)+` 次 `,1)]),_:1})])):m(``,!0)]),_:1})])]))}}),[[`__scopeId`,`data-v-42a5c411`]]);export{H as default};