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