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,Or as u,Qn as d,Rt as f,Wn as p,Xn as m,Yn as h,br as g,c as _,cr as v,en as y,gr as b,kr as x,l as S,ln as C,lr as w,mr as T,on as E,qn as D,t as O,tr as k,un as A,ur as j,y as M,zt as N}from"./index-Dr0D0hQu.js";import{t as P}from"./VChip-BASRYLBn.js";import{t as F}from"./_plugin-vue_export-helper-BDNMzG2s.js";import{t as I}from"./VAlert-BwYIheOY.js";var L=A({...C(),...S()},`VForm`),R=E()({name:`VForm`,props:L(),emits:{"update:modelValue":e=>!0,submit:e=>!0},setup(e,{slots:t,emit:n}){let r=_(e),i=g();function a(e){e.preventDefault(),r.reset()}function o(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 y(()=>D(`form`,{ref:i,class:u([`v-form`,e.class]),style:x(e.style),novalidate:!0,onReset:a,onSubmit:o},[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})])),M(r,i)}}),z={class:`login-page`},B={class:`login-center`},V={key:2,class:`text-center mt-4`},H=F(k({__name:`LoginPage`,setup(u){let _=N(),y=n(),S=r(),C=g(``),E=g(``),k=g(``),A=g(!1),M=g(!1),F=g(``),L=g(!1),H=g(0),U=g(null),W=g([]),G=g(0),K=null,q=o(()=>W.value.length===0?``:W.value[G.value]);async function J(){try{let e=await f.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))}v(async()=>{await J(),Y()}),w(()=>{K&&clearInterval(K),Z&&clearInterval(Z)});let X=g(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))});T(U,e=>{Z&&=(clearInterval(Z),null),e&&(Z=setInterval(()=>{X.value=Date.now()},3e4))});async function $(){if(!C.value||!E.value){F.value=`请输入用户名和密码`;return}M.value=!0,F.value=``;try{await S.login(C.value,E.value,L.value?k.value:void 0);let e=_.query.redirect||`/`;y.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)=>(j(),m(`div`,z,[D(`div`,{class:`wallpaper-bg`,style:x({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:b(()=>[F.value?(j(),a(I,{key:0,type:`error`,density:`compact`,class:`mb-4`,closable:``,"onClick:close":r[0]||=e=>F.value=``,rounded:`lg`,variant:`tonal`},{default:b(()=>[d(t(F.value),1)]),_:1})):h(``,!0),U.value?(j(),a(I,{key:1,type:`warning`,density:`compact`,class:`mb-4`,rounded:`lg`,variant:`tonal`},{default:b(()=>[d(` 账户已锁定，请 `+t(Q.value)+` 分钟后重试 `,1)]),_:1})):h(``,!0),e(R,{onSubmit:p($,[`prevent`])},{default:b(()=>[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:E.value,"onUpdate:modelValue":r[2]||=e=>E.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":r[3]||=e=>A.value=!A.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?(j(),a(O,{key:0,modelValue:k.value,"onUpdate:modelValue":r[4]||=e=>k.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:b(()=>[...r[5]||=[d(` 登录 `,-1)]]),_:1},8,[`loading`,`disabled`])]),_:1}),H.value>0&&!U.value?(j(),m(`div`,V,[e(P,{size:`small`,variant:`tonal`,color:`warning`,label:``},{default:b(()=>[d(` 已失败 `+t(H.value)+` 次 `,1)]),_:1})])):h(``,!0)]),_:1})])]))}}),[[`__scopeId`,`data-v-42a5c411`]]);export{H as default};