import{$t as e,Ar as t,Ft as n,Gn as r,It as i,Jn as a,Kn as o,L as s,Lt as c,M as l,Or as u,Pt as d,Qn as f,Rt as p,Un as m,Yn as h,Zn as g,an as _,br as v,c as y,cn as b,cr as x,er as S,gr as C,kr as w,l as T,ln as E,lr as D,mr as O,qn as k,sr as A,t as j,y as M,zt as N}from"./index-MZ_Fxgyv.js";import{t as P}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{t as F}from"./VChip-QWEdxHzy.js";import{t as I}from"./VAlert-13_bKfTX.js";var L=E({...b(),...T()},`VForm`),R=_()({name:`VForm`,props:L(),emits:{"update:modelValue":e=>!0,submit:e=>!0},setup(t,{slots:n,emit:r}){let i=y(t),a=v();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&&a.value?.submit()}),t.preventDefault()}return e(()=>o(`form`,{ref:a,class:u([`v-form`,t.class]),style:w(t.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})])),M(i,a)}}),z={class:`login-page`},B={class:`login-center`},V={key:2,class:`text-center mt-4`},H=P(S({__name:`LoginPage`,setup(e){let u=p(),_=N(),y=d(),b=v(``),S=v(``),T=v(``),E=v(!1),M=v(!1),P=v(``),L=v(!1),H=v(0),U=v(null),W=v([]),G=v(0),K=null,q=r(()=>W.value.length===0?``:W.value[G.value]);async function J(){try{let e=await c.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))}A(async()=>{await J(),Y()}),x(()=>{K&&clearInterval(K),Z&&clearInterval(Z)});let X=v(Date.now()),Z=null,Q=r(()=>{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(!b.value||!S.value){P.value=`请输入用户名和密码`;return}M.value=!0,P.value=``;try{await y.login(b.value,S.value,L.value?T.value:void 0);let e=u.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{M.value=!1}}return(e,n)=>(D(),h(`div`,z,[o(`div`,{class:`wallpaper-bg`,style:w({backgroundImage:`url(${q.value})`})},null,4),n[6]||=o(`div`,{class:`wallpaper-overlay`},null,-1),o(`div`,B,[f(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(()=>[g(t(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(()=>[g(` 账户已锁定，请 `+t(Q.value)+` 分钟后重试 `,1)]),_:1})):a(``,!0),f(R,{onSubmit:m($,[`prevent`])},{default:C(()=>[f(j,{modelValue:b.value,"onUpdate:modelValue":n[1]||=e=>b.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`]),f(j,{modelValue:S.value,"onUpdate:modelValue":n[2]||=e=>S.value=e,label:`密码`,variant:`outlined`,density:`comfortable`,"prepend-inner-icon":`mdi-lock-outline`,"append-inner-icon":E.value?`mdi-eye`:`mdi-eye-off`,type:E.value?`text`:`password`,"onClick:appendInner":n[3]||=e=>E.value=!E.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?(D(),k(j,{key:0,modelValue:T.value,"onUpdate:modelValue":n[4]||=e=>T.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`])):a(``,!0),f(s,{type:`submit`,color:`primary`,variant:`flat`,block:``,size:`large`,loading:M.value,disabled:!!U.value,rounded:`lg`,class:`mt-2`,height:`48`},{default:C(()=>[...n[5]||=[g(` 登录 `,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1}),H.value>0&&!U.value?(D(),h(`div`,V,[f(F,{size:`small`,variant:`tonal`,color:`warning`,label:``},{default:C(()=>[g(` 已失败 `+t(H.value)+` 次 `,1)]),_:1})])):a(``,!0)]),_:1})])]))}}),[[`__scopeId`,`data-v-42a5c411`]]);export{H as default};