2 lines
5.2 KiB
JavaScript
2 lines
5.2 KiB
JavaScript
import{e as M,r as c,j as s}from"./react-vendor-CFzzFOsg.js";import{u as F,a as L,F as P,c as l,d,e as m,b as h,f as j,o as B,s as u}from"./form-OSLy-cSS.js";import{u as R,d as U,S as W,B as o,a as f,n as i}from"./index-5C0q-ZMs.js";import{I as x}from"./input-CE0PJTgJ.js";import{B as $}from"./badge-DB-zL5ml.js";import{A as D,t as J,k as V}from"./ui-vendor-BtpOfToU.js";const q=B({nickname:u().min(1,"请输入昵称").max(64)}),H=r=>B({old_password:u().min(1,"请输入当前密码"),new_password:u().min(r,`新密码至少 ${r} 位`),confirm_password:u().min(1,"请确认新密码")}).refine(e=>e.new_password===e.confirm_password,{message:"两次输入的新密码不一致",path:["confirm_password"]});function Z(){const r=M(),{user:e,loading:g,refresh:y}=R(),[C,N]=c.useState(!1),[A,_]=c.useState(!1),[E,k]=c.useState(!1),p=c.useRef(null),{limits:v}=U(),w=F({resolver:L(q),values:{nickname:(e==null?void 0:e.nickname)??""}}),t=F({resolver:L(H(v.password_min_len)),defaultValues:{old_password:"",new_password:"",confirm_password:""}});if(c.useEffect(()=>{!g&&!e&&r("/login")},[g,e,r]),g)return s.jsx("div",{className:"flex justify-center py-16",children:s.jsx(W,{size:"lg"})});if(!e)return null;const z=async a=>{N(!0);try{await f.updateNickname(a.nickname),await y(),i.success("昵称已更新")}catch(n){i.error(n instanceof Error?n.message:"更新失败")}finally{N(!1)}},I=async a=>{_(!0);try{await f.updatePassword(a.old_password,a.new_password),i.success("密码已修改,请重新登录"),t.reset(),await f.logout(),r("/login")}catch(n){i.error(n instanceof Error?n.message:"修改失败")}finally{_(!1)}},G=async a=>{var b;const n=(b=a.target.files)==null?void 0:b[0];if(n){if(n.size>v.avatar_max_mb*1024*1024){i.error(`头像不能超过 ${v.avatar_max_mb}MB`);return}k(!0);try{await f.uploadAvatar(n),await y(),i.success("头像已更新")}catch(S){i.error(S instanceof Error?S.message:"上传失败")}finally{k(!1),p.current&&(p.current.value="")}}};return s.jsx("div",{className:"page-wrap",children:s.jsxs("div",{className:"page-inner-wide",style:{maxWidth:640},children:[s.jsxs(o,{variant:"ghost",className:"mb-3",onClick:()=>r(-1),children:[s.jsx(D,{}),"返回"]}),s.jsxs("div",{className:"profile-header",children:[s.jsx("div",{className:"profile-avatar-lg",children:e.avatar?s.jsx("img",{src:e.avatar,alt:""}):e.nickname[0]}),s.jsxs("div",{children:[s.jsx("h1",{className:"page-title",style:{marginBottom:4},children:e.nickname}),s.jsxs("div",{style:{fontSize:13,color:"var(--color-text-3)"},children:["@",e.username]}),e.role==="admin"&&s.jsx($,{variant:"green",className:"mt-1.5",children:"管理员"})]})]}),e.role==="admin"&&s.jsxs("div",{className:"section-card admin-entry-card",children:[s.jsx("div",{className:"section-card-title",children:"管理员入口"}),s.jsx("p",{style:{fontSize:13,color:"var(--color-text-3)",margin:"0 0 12px"},children:"管理板块、用户、帖子及系统设置"}),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsxs(o,{variant:"outline",onClick:()=>r("/admin/boards"),children:[s.jsx(J,{}),"管理板块"]}),s.jsxs(o,{onClick:()=>r("/admin/dashboard"),children:[s.jsx(V,{}),"进入系统后台"]})]})]}),s.jsxs("div",{className:"section-card",children:[s.jsx("div",{className:"section-card-title",children:"基本资料"}),s.jsx(P,{...w,children:s.jsxs("form",{onSubmit:w.handleSubmit(z),className:"space-y-4",children:[s.jsxs(l,{children:[s.jsx(d,{children:"用户名"}),s.jsx(m,{children:s.jsx(x,{value:e.username,disabled:!0})})]}),s.jsx(h,{control:w.control,name:"nickname",render:({field:a})=>s.jsxs(l,{children:[s.jsx(d,{children:"昵称"}),s.jsx(m,{children:s.jsx(x,{maxLength:64,placeholder:"显示名称",...a})}),s.jsx(j,{})]})}),s.jsx(o,{type:"submit",loading:C,children:"保存昵称"})]})})]}),s.jsxs("div",{className:"section-card",children:[s.jsx("div",{className:"section-card-title",children:"头像"}),s.jsx("p",{style:{fontSize:13,color:"var(--color-text-3)",margin:"0 0 12px"},children:"支持 JPG、PNG、GIF、WebP,不超过 2MB"}),s.jsx("input",{ref:p,type:"file",accept:"image/jpeg,image/png,image/gif,image/webp",style:{display:"none"},onChange:G}),s.jsx(o,{variant:"outline",loading:E,onClick:()=>{var a;return(a=p.current)==null?void 0:a.click()},children:"选择图片上传"})]}),s.jsxs("div",{className:"section-card",children:[s.jsx("div",{className:"section-card-title",children:"修改密码"}),s.jsx(P,{...t,children:s.jsxs("form",{onSubmit:t.handleSubmit(I),className:"space-y-4",children:[s.jsx(h,{control:t.control,name:"old_password",render:({field:a})=>s.jsxs(l,{children:[s.jsx(d,{children:"当前密码"}),s.jsx(m,{children:s.jsx(x,{type:"password",placeholder:"输入当前密码",...a})}),s.jsx(j,{})]})}),s.jsx(h,{control:t.control,name:"new_password",render:({field:a})=>s.jsxs(l,{children:[s.jsx(d,{children:"新密码"}),s.jsx(m,{children:s.jsx(x,{type:"password",placeholder:"至少 6 位",...a})}),s.jsx(j,{})]})}),s.jsx(h,{control:t.control,name:"confirm_password",render:({field:a})=>s.jsxs(l,{children:[s.jsx(d,{children:"确认新密码"}),s.jsx(m,{children:s.jsx(x,{type:"password",placeholder:"再次输入新密码",...a})}),s.jsx(j,{})]})}),s.jsx(o,{type:"submit",variant:"destructive",loading:A,children:"修改密码"})]})})]})]})})}export{Z as default};
|