import{d as R,r as g,H as E,z as k,c as q,a as s,w as a,aZ as N,B as _,a_ as z,a$ as D,b as t,a5 as M,t as i,b1 as O,h as C,O as T,J as H,K as J,L as K,i as L,bn as Z,C as u,o as $}from"./index-DqVhJ65C.js";/* empty css               *//* empty css                  *//* empty css                *//* empty css                   *//* empty css               *//* empty css                  */const G={class:"p-6"},Q={class:"flex flex-col items-center py-4"},W={class:"text-2xl"},X={class:"text-lg font-bold"},Y={class:"text-gray-500 text-sm"},ee={class:"text-sm text-gray-500 space-y-2"},se={class:"flex justify-between"},ae={class:"flex justify-between"},te={class:"flex justify-between"},_e=R({__name:"AdminProfile",setup(oe){const y=g(),c=g(!1),d=g({username:"",email:"",role:"admin",last_login_time:"",last_login_ip:"",create_time:""}),l=E({old_password:"",new_password:"",confirm_password:""}),p=E({two_factor:!1,login_notify:!1}),P={old_password:[{required:!0,message:"请输入当前密码",trigger:"blur"}],new_password:[{required:!0,message:"请输入新密码",trigger:"blur"},{min:6,message:"密码长度不能少于6位",trigger:"blur"}],confirm_password:[{required:!0,message:"请确认新密码",trigger:"blur"},{validator:(o,e,r)=>{e!==l.new_password?r(new Error("两次输入的密码不一致")):r()},trigger:"blur"}]},S=async()=>{try{const o=await _.get("/admin/profile");o.code===0&&(d.value=o.data)}catch(o){console.error(o)}},U=async()=>{try{const o=await _.get("/admin/security");o.code===0&&Object.assign(p,o.data)}catch(o){console.error(o)}},B=async()=>{var e;if(await((e=y.value)==null?void 0:e.validate().catch(()=>!1))){c.value=!0;try{const r=await _.post("/admin/change_password",l);r.code===0?(u({message:"密码修改成功",type:"success",plain:!0}),l.old_password="",l.new_password="",l.confirm_password=""):u({message:r.message,type:"error",plain:!0})}catch(r){u({message:r.message||"修改失败",type:"error",plain:!0})}finally{c.value=!1}}},v=async()=>{try{await _.post("/admin/security",p),u({message:"设置已更新",type:"success",plain:!0})}catch(o){u({message:o.message||"保存失败",type:"error",plain:!0})}};return k(()=>{S(),U()}),(o,e)=>{const r=M,F=O,I=T,f=D,x=z,w=K,m=J,j=L,b=H,h=Z,A=N;return $(),q("div",G,[s(A,{gutter:20},{default:a(()=>[s(x,{span:8},{default:a(()=>[s(f,{shadow:"hover"},{default:a(()=>[t("div",Q,[s(r,{size:80,class:"mb-4"},{default:a(()=>{var n,V;return[t("span",W,i((V=(n=d.value.username)==null?void 0:n.charAt(0))==null?void 0:V.toUpperCase()),1)]}),_:1}),t("h3",X,i(d.value.username),1),t("p",Y,i(d.value.email),1),s(F,{class:"mt-2",type:"primary"},{default:a(()=>[C(i(d.value.role==="admin"?"超级管理员":"管理员"),1)]),_:1})]),s(I),t("div",ee,[t("div",se,[e[5]||(e[5]=t("span",null,"上次登录",-1)),t("span",null,i(d.value.last_login_time||"-"),1)]),t("div",ae,[e[6]||(e[6]=t("span",null,"登录 IP",-1)),t("span",null,i(d.value.last_login_ip||"-"),1)]),t("div",te,[e[7]||(e[7]=t("span",null,"注册时间",-1)),t("span",null,i(d.value.create_time||"-"),1)])])]),_:1})]),_:1}),s(x,{span:16},{default:a(()=>[s(f,{shadow:"hover"},{header:a(()=>[...e[8]||(e[8]=[t("span",{class:"font-medium"},"修改密码",-1)])]),default:a(()=>[s(b,{model:l,rules:P,ref_key:"passFormRef",ref:y,"label-width":"100px",class:"max-w-md"},{default:a(()=>[s(m,{label:"当前密码",prop:"old_password"},{default:a(()=>[s(w,{modelValue:l.old_password,"onUpdate:modelValue":e[0]||(e[0]=n=>l.old_password=n),type:"password","show-password":""},null,8,["modelValue"])]),_:1}),s(m,{label:"新密码",prop:"new_password"},{default:a(()=>[s(w,{modelValue:l.new_password,"onUpdate:modelValue":e[1]||(e[1]=n=>l.new_password=n),type:"password","show-password":""},null,8,["modelValue"])]),_:1}),s(m,{label:"确认密码",prop:"confirm_password"},{default:a(()=>[s(w,{modelValue:l.confirm_password,"onUpdate:modelValue":e[2]||(e[2]=n=>l.confirm_password=n),type:"password","show-password":""},null,8,["modelValue"])]),_:1}),s(m,null,{default:a(()=>[s(j,{type:"primary",onClick:B,loading:c.value},{default:a(()=>[...e[9]||(e[9]=[C("修改密码",-1)])]),_:1},8,["loading"])]),_:1})]),_:1},8,["model"])]),_:1}),s(f,{shadow:"hover",class:"mt-4"},{header:a(()=>[...e[10]||(e[10]=[t("span",{class:"font-medium"},"安全设置",-1)])]),default:a(()=>[s(b,{"label-width":"120px",class:"max-w-md"},{default:a(()=>[s(m,{label:"双因素认证"},{default:a(()=>[s(h,{modelValue:p.two_factor,"onUpdate:modelValue":e[3]||(e[3]=n=>p.two_factor=n),onChange:v},null,8,["modelValue"]),e[11]||(e[11]=t("span",{class:"ml-4 text-xs text-gray-400"},"开启后登录需要验证码",-1))]),_:1}),s(m,{label:"登录提醒"},{default:a(()=>[s(h,{modelValue:p.login_notify,"onUpdate:modelValue":e[4]||(e[4]=n=>p.login_notify=n),onChange:v},null,8,["modelValue"]),e[12]||(e[12]=t("span",{class:"ml-4 text-xs text-gray-400"},"新设备登录时发送邮件提醒",-1))]),_:1})]),_:1})]),_:1})]),_:1})]),_:1})])}}});export{_e as default};
