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