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