2 lines
8.1 KiB
JavaScript
2 lines
8.1 KiB
JavaScript
import{e as M,b as r,h as Z,L as q,f as ee,n as _,m as s,l as t,k as b,r as V,B as z,x as ae,w as n,E as u,i as te,o as m,c as O,y as k}from"./vendor-DDPgi3C9.js";import{f as se,g as $,l as le,a as oe,r as ne}from"./auth-DUsbt3tv.js";import{_ as re}from"./index-tKiWpZNf.js";const ie={class:"login-page"},ue={class:"login-container"},ce={class:"form-group"},de={class:"form-group"},pe={key:0,class:"form-group"},me={class:"captcha-row"},fe=["src"],ve=["disabled"],ge={class:"action-links"},he={class:"captcha-row"},we=["src"],ye={class:"captcha-row"},_e=["src"],be={__name:"LoginPage",setup(Ve){const D=te(),i=M({username:"",password:"",captcha:""}),C=r(!1),B=r(""),P=r(""),E=r(!1),f=r(!1),N=r(!1),v=r(!1),g=r(!1),d=M({username:"",captcha:""}),x=r(""),F=r(""),I=r(!1),U=r(""),p=M({email:"",captcha:""}),S=r(""),T=r(""),K=r(!1),A=Z(()=>!!N.value);async function L(){try{const a=await $();P.value=a?.session_id||"",B.value=a?.captcha_image||"",i.captcha=""}catch{P.value="",B.value=""}}async function h(){try{const a=await $();F.value=a?.session_id||"",x.value=a?.captcha_image||"",d.captcha=""}catch{F.value="",x.value=""}}async function w(){try{const a=await $();T.value=a?.session_id||"",S.value=a?.captcha_image||"",p.captcha=""}catch{T.value="",S.value=""}}async function W(){if(!i.username.trim()||!i.password.trim()){u.error("用户名和密码不能为空");return}if(C.value&&!i.captcha.trim()){u.error("请输入验证码");return}E.value=!0;try{await le({username:i.username.trim(),password:i.password,captcha_session:P.value,captcha:i.captcha.trim(),need_captcha:C.value}),u.success("登录成功,正在跳转...");const a=new URLSearchParams(window.location.search||""),e=String(a.get("next")||"").trim(),o=e&&e.startsWith("/")&&!e.startsWith("//")&&!e.startsWith("/\\")?e:"";setTimeout(()=>{const c=o||"/app";D.push(c).catch(()=>{window.location.href=c})},300)}catch(a){const e=a?.response?.status,o=a?.response?.data,c=o?.error||o?.message||"登录失败";u.error(c),o?.need_captcha?(C.value=!0,await L()):C.value&&e===400&&await L()}finally{E.value=!1}}async function G(){v.value=!0,U.value="",d.username="",d.captcha="",await h()}async function J(){if(U.value="",!f.value){u.warning("邮件功能未启用,请联系管理员重置密码。");return}const a=d.username.trim();if(!a){u.error("请输入用户名");return}if(!d.captcha.trim()){u.error("请输入验证码");return}I.value=!0;try{const e=await oe({username:a,captcha_session:F.value,captcha:d.captcha.trim()});u.success(e?.message||"已发送重置邮件"),setTimeout(()=>{v.value=!1},800)}catch(e){const o=e?.response?.data,c=o?.error||"发送失败";o?.code==="email_not_bound"?U.value=c:u.error(c),await h()}finally{I.value=!1}}async function Q(){g.value=!0,p.email="",p.captcha="",await w()}async function X(){const a=p.email.trim();if(!a){u.error("请输入邮箱");return}if(!p.captcha.trim()){u.error("请输入验证码");return}K.value=!0;try{const e=await ne({email:a,captcha_session:T.value,captcha:p.captcha.trim()});u.success(e?.message||"验证邮件已发送,请查收"),setTimeout(()=>{g.value=!1},800)}catch(e){const o=e?.response?.data;u.error(o?.error||"发送失败"),await w()}finally{K.value=!1}}function Y(){D.push("/register")}return q(v,async a=>{a&&!x.value&&await h()}),q(g,async a=>{a&&!S.value&&await w()}),ee(async()=>{try{const a=await se();f.value=!!a?.email_enabled,N.value=!!a?.register_verify_enabled}catch{f.value=!1,N.value=!1}f.value&&await Promise.allSettled([h(),w()])}),(a,e)=>{const o=V("el-input"),c=V("el-alert"),R=V("el-form-item"),y=V("el-button"),H=V("el-form"),j=V("el-dialog");return m(),_("div",ie,[s("div",ue,[e[15]||(e[15]=s("div",{class:"login-header"},[s("span",{class:"login-badge"},"用户登录"),s("h1",null,"用户登录系统"),s("p",null,"知识管理平台")],-1)),s("div",ce,[e[11]||(e[11]=s("label",{for:"username"},"用户账号",-1)),t(o,{id:"username",modelValue:i.username,"onUpdate:modelValue":e[0]||(e[0]=l=>i.username=l),class:"login-input",placeholder:"请输入用户名",autocomplete:"username"},null,8,["modelValue"])]),s("div",de,[e[12]||(e[12]=s("label",{for:"password"},"密码",-1)),t(o,{id:"password",modelValue:i.password,"onUpdate:modelValue":e[1]||(e[1]=l=>i.password=l),class:"login-input",type:"password","show-password":"",placeholder:"请输入密码",autocomplete:"current-password",onKeyup:z(W,["enter"])},null,8,["modelValue"])]),C.value?(m(),_("div",pe,[e[13]||(e[13]=s("label",{for:"captcha"},"验证码",-1)),s("div",me,[t(o,{id:"captcha",modelValue:i.captcha,"onUpdate:modelValue":e[2]||(e[2]=l=>i.captcha=l),class:"login-input captcha-input",placeholder:"请输入验证码",onKeyup:z(W,["enter"])},null,8,["modelValue"]),B.value?(m(),_("img",{key:0,class:"captcha-img",src:B.value,alt:"验证码",title:"点击刷新",onClick:L},null,8,fe)):b("",!0),s("button",{type:"button",class:"captcha-refresh",onClick:L},"刷新")])])):b("",!0),s("button",{type:"button",class:"btn-login",disabled:E.value,onClick:W},ae(E.value?"登录中...":"登录系统"),9,ve),s("div",ge,[s("button",{type:"button",class:"link-btn",onClick:G},"忘记密码?"),A.value?(m(),_("button",{key:0,type:"button",class:"link-btn",onClick:Q},"重发验证邮件")):b("",!0)]),s("div",{class:"register-row"},[e[14]||(e[14]=s("span",null,"还没有账号?",-1)),s("button",{type:"button",class:"link-btn",onClick:Y},"立即注册")])]),t(j,{modelValue:v.value,"onUpdate:modelValue":e[6]||(e[6]=l=>v.value=l),title:"找回密码",width:"min(560px, 92vw)"},{footer:n(()=>[t(y,{onClick:e[5]||(e[5]=l=>v.value=!1)},{default:n(()=>[...e[17]||(e[17]=[k("取消",-1)])]),_:1}),t(y,{type:"primary",loading:I.value,disabled:!f.value,onClick:J},{default:n(()=>[...e[18]||(e[18]=[k(" 发送重置邮件 ",-1)])]),_:1},8,["loading","disabled"])]),default:n(()=>[f.value?(m(),O(c,{key:1,type:"info",closable:!1,title:"通过邮箱找回密码",description:"输入用户名并完成验证码,我们将向该账号绑定的邮箱发送重置链接。","show-icon":""})):(m(),O(c,{key:0,type:"warning",closable:!1,title:"邮件功能未启用",description:"无法通过邮箱找回密码,请联系管理员重置密码。","show-icon":""})),U.value?(m(),O(c,{key:2,type:"warning",closable:!1,title:"无法通过邮箱找回密码",description:U.value,"show-icon":"",class:"alert"},null,8,["description"])):b("",!0),t(H,{"label-position":"top",class:"dialog-form"},{default:n(()=>[t(R,{label:"用户名"},{default:n(()=>[t(o,{modelValue:d.username,"onUpdate:modelValue":e[3]||(e[3]=l=>d.username=l),placeholder:"请输入用户名"},null,8,["modelValue"])]),_:1}),t(R,{label:"验证码"},{default:n(()=>[s("div",he,[t(o,{modelValue:d.captcha,"onUpdate:modelValue":e[4]||(e[4]=l=>d.captcha=l),placeholder:"请输入验证码"},null,8,["modelValue"]),x.value?(m(),_("img",{key:0,class:"captcha-img",src:x.value,alt:"验证码",title:"点击刷新",onClick:h},null,8,we)):b("",!0),t(y,{onClick:h},{default:n(()=>[...e[16]||(e[16]=[k("刷新",-1)])]),_:1})])]),_:1})]),_:1})]),_:1},8,["modelValue"]),t(j,{modelValue:g.value,"onUpdate:modelValue":e[10]||(e[10]=l=>g.value=l),title:"重发验证邮件",width:"min(520px, 92vw)"},{footer:n(()=>[t(y,{onClick:e[9]||(e[9]=l=>g.value=!1)},{default:n(()=>[...e[20]||(e[20]=[k("取消",-1)])]),_:1}),t(y,{type:"primary",loading:K.value,onClick:X},{default:n(()=>[...e[21]||(e[21]=[k("发送",-1)])]),_:1},8,["loading"])]),default:n(()=>[t(c,{type:"info",closable:!1,title:"用于注册邮箱验证:请输入邮箱并完成验证码。","show-icon":""}),t(H,{"label-position":"top",class:"dialog-form"},{default:n(()=>[t(R,{label:"邮箱"},{default:n(()=>[t(o,{modelValue:p.email,"onUpdate:modelValue":e[7]||(e[7]=l=>p.email=l),placeholder:"name@example.com"},null,8,["modelValue"])]),_:1}),t(R,{label:"验证码"},{default:n(()=>[s("div",ye,[t(o,{modelValue:p.captcha,"onUpdate:modelValue":e[8]||(e[8]=l=>p.captcha=l),placeholder:"请输入验证码"},null,8,["modelValue"]),S.value?(m(),_("img",{key:0,class:"captcha-img",src:S.value,alt:"验证码",title:"点击刷新",onClick:w},null,8,_e)):b("",!0),t(y,{onClick:w},{default:n(()=>[...e[19]||(e[19]=[k("刷新",-1)])]),_:1})])]),_:1})]),_:1})]),_:1},8,["modelValue"])])}}},Ue=re(be,[["__scopeId","data-v-dc51a501"]]);export{Ue as default};
|