import{Ar as e,Ft as t,Gn as n,Hn as r,It as i,Jn as a,Kn as o,L as s,Lt as c,M as l,Nt as u,Or as d,Pt as f,Qn as p,Qt as m,Rt as h,Yn as g,Zn as _,br as v,c as y,cn as b,cr as x,er as S,gr as C,in as w,kr as T,l as E,lr as D,mr as O,qn as k,sn as A,sr as j,t as M,v as N}from"./index-C3-luqWO.js";import{t as P}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{t as F}from"./VChip-BWT06msB.js";import{t as I}from"./VAlert-Dle8HizJ.js";var L=b({...A(),...E()},`VForm`),R=w()({name:`VForm`,props:L(),emits:{"update:modelValue":e=>!0,submit:e=>!0},setup(e,{slots:t,emit:n}){let r=y(e),i=v();function a(e){e.preventDefault(),r.reset()}function s(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 m(()=>o(`form`,{ref:i,class:d([`v-form`,e.class]),style:T(e.style),novalidate:!0,onReset:a,onSubmit:s},[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})])),N(r,i)}}),z={class:`login-page`},B={class:`login-center`},V={key:2,class:`text-center mt-4`},H=P(S({__name:`LoginPage`,setup(d){let m=c(),y=h(),b=u(),S=v(``),w=v(``),E=v(``),A=v(!1),N=v(!1),P=v(``),L=v(!1),H=v(0),U=v(null),W=v([]),G=v(0),K=null,q=n(()=>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))}j(async()=>{await J(),Y()}),x(()=>{K&&clearInterval(K),Z&&clearInterval(Z)});let X=v(Date.now()),Z=null,Q=n(()=>{if(!U.value)return 0;let e=new Date(U.value).getTime()-X.value;return Math.max(0,Math.ceil(e/6e4))});O(U,e=>{Z&&=(clearInterval(Z),null),e&&(Z=setInterval(()=>{X.value=Date.now()},3e4))});async function $(){if(!S.value||!w.value){P.value=`请输入用户名和密码`;return}N.value=!0,P.value=``;try{await b.login(S.value,w.value,L.value?E.value:void 0);let e=m.query.redirect||`/`;y.push(e)}catch(e){e instanceof t?(L.value=!0,P.value=e.message):e instanceof f?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(t,n)=>(D(),g(`div`,z,[o(`div`,{class:`wallpaper-bg`,style:T({backgroundImage:`url(${q.value})`})},null,4),n[6]||=o(`div`,{class:`wallpaper-overlay`},null,-1),o(`div`,B,[p(l,{elevation:`0`,rounded:`xl`,class:`login-card pa-10`,border:``},{default:C(()=>[P.value?(D(),k(I,{key:0,type:`error`,density:`compact`,class:`mb-4`,closable:``,"onClick:close":n[0]||=e=>P.value=``,rounded:`lg`,variant:`tonal`},{default:C(()=>[_(e(P.value),1)]),_:1})):a(``,!0),U.value?(D(),k(I,{key:1,type:`warning`,density:`compact`,class:`mb-4`,rounded:`lg`,variant:`tonal`},{default:C(()=>[_(` 账户已锁定，请 `+e(Q.value)+` 分钟后重试 `,1)]),_:1})):a(``,!0),p(R,{onSubmit:r($,[`prevent`])},{default:C(()=>[p(M,{modelValue:S.value,"onUpdate:modelValue":n[1]||=e=>S.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`]),p(M,{modelValue:w.value,"onUpdate:modelValue":n[2]||=e=>w.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:N.value,class:`mb-4`,autocomplete:`current-password`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`append-inner-icon`,`type`,`disabled`]),L.value?(D(),k(M,{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:N.value,class:`mb-4`,autocomplete:`one-time-code`,rounded:`lg`,"hide-details":`auto`},null,8,[`modelValue`,`disabled`])):a(``,!0),p(s,{type:`submit`,color:`primary`,variant:`flat`,block:``,size:`large`,loading:N.value,disabled:!!U.value,rounded:`lg`,class:`mt-2`,height:`48`},{default:C(()=>[...n[5]||=[_(` 登录 `,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1}),H.value>0&&!U.value?(D(),g(`div`,V,[p(F,{size:`small`,variant:`tonal`,color:`warning`,label:``},{default:C(()=>[_(` 已失败 `+e(H.value)+` 次 `,1)]),_:1})])):a(``,!0)]),_:1})])]))}}),[[`__scopeId`,`data-v-42a5c411`]]);export{H as default};