import{ut as e}from"./vue.runtime.esm-bundler-DS0mm12S.js";import{M as t,P as n,ht as r}from"./index-aDrlI3dP.js";import{t as i}from"./monisuo-admin.api-CkHxxpNg.js";function a(){let a=n(),o=t(),{isLogin:s,adminInfo:c}=r(o),l=e(!1),u=e(null),d=i();function f(){o.logout(),a.push({path:`/auth/sign-in`})}function p(){a.push({path:`/monisuo/dashboard`})}async function m(e,t){l.value=!0,u.value=null;try{let n=await d.mutateAsync({username:e,password:t});if(console.log(`Login result:`,n),n.code===`0000`&&n.data){console.log(`Setting token and adminInfo...`),o.setToken(n.data.token),o.setAdminInfo(n.data.adminInfo),console.log(`isLogin after setToken:`,o.isLogin);let e=a.currentRoute.value.query.redirect;console.log(`Redirecting to:`,e||`/monisuo/dashboard`),!e||e.startsWith(`//`)?p():a.push(e)}else console.log(`Login failed:`,n.code,n.msg),u.value=n.msg||`登录失败`}catch(e){console.error(`Login error:`,e),u.value=e.response?.data?.msg||`网络错误，请稍后重试`}finally{l.value=!1}}return{loading:l,error:u,isLogin:s,adminInfo:c,logout:f,login:m}}export{a as t};