2 lines
5.1 KiB
JavaScript
2 lines
5.1 KiB
JavaScript
import{e as G,r as t,j as s}from"./react-vendor-CgzNJrV9.js";import{u as _,a as F,F as L,c as l,d,e as m,I as x,b as j,f as h,o as P,s as u}from"./form-BzHbu9bJ.js";import{u as M,B as c,o as R,a as f}from"./index-474mTIgd.js";import{B as D}from"./badge-CsEfIQQ2.js";import{S as U}from"./spinner-DH1syOsQ.js";import{n as i}from"./notify-Zesh5czd.js";import{A as W,j as J,k as V}from"./ui-vendor-CdH1UOKW.js";const q=P({nickname:u().min(1,"请输入昵称").max(64)}),H=P({old_password:u().min(1,"请输入当前密码"),new_password:u().min(6,"新密码至少 6 位"),confirm_password:u().min(1,"请确认新密码")}).refine(n=>n.new_password===n.confirm_password,{message:"两次输入的新密码不一致",path:["confirm_password"]});function $(){const n=G(),{user:a,loading:g,refresh:v}=M(),[A,y]=t.useState(!1),[B,N]=t.useState(!1),[C,k]=t.useState(!1),p=t.useRef(null),w=_({resolver:F(q),values:{nickname:(a==null?void 0:a.nickname)??""}}),o=_({resolver:F(H),defaultValues:{old_password:"",new_password:"",confirm_password:""}});if(t.useEffect(()=>{!g&&!a&&n("/login")},[g,a,n]),g)return s.jsx("div",{className:"flex justify-center py-16",children:s.jsx(U,{size:"lg"})});if(!a)return null;const E=async e=>{y(!0);try{await f.updateNickname(e.nickname),await v(),i.success("昵称已更新")}catch(r){i.error(r instanceof Error?r.message:"更新失败")}finally{y(!1)}},z=async e=>{N(!0);try{await f.updatePassword(e.old_password,e.new_password),i.success("密码已修改,请重新登录"),o.reset(),await f.logout(),n("/login")}catch(r){i.error(r instanceof Error?r.message:"修改失败")}finally{N(!1)}},I=async e=>{var b;const r=(b=e.target.files)==null?void 0:b[0];if(r){if(r.size>2*1024*1024){i.error("头像不能超过 2MB");return}k(!0);try{await f.uploadAvatar(r),await v(),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(c,{variant:"ghost",className:"mb-3",onClick:()=>n(-1),children:[s.jsx(W,{}),"返回"]}),s.jsxs("div",{className:"profile-header",children:[s.jsx("div",{className:"profile-avatar-lg",children:a.avatar?s.jsx("img",{src:a.avatar,alt:""}):a.nickname[0]}),s.jsxs("div",{children:[s.jsx("h1",{className:"page-title",style:{marginBottom:4},children:a.nickname}),s.jsxs("div",{style:{fontSize:13,color:"var(--color-text-3)"},children:["@",a.username]}),a.role==="admin"&&s.jsx(D,{variant:"green",className:"mt-1.5",children:"管理员"})]})]}),a.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(c,{variant:"outline",onClick:()=>n("/boards"),children:[s.jsx(J,{}),"管理板块"]}),s.jsxs(c,{onClick:R,children:[s.jsx(V,{}),"进入系统后台"]})]})]}),s.jsxs("div",{className:"section-card",children:[s.jsx("div",{className:"section-card-title",children:"基本资料"}),s.jsx(L,{...w,children:s.jsxs("form",{onSubmit:w.handleSubmit(E),className:"space-y-4",children:[s.jsxs(l,{children:[s.jsx(d,{children:"用户名"}),s.jsx(m,{children:s.jsx(x,{value:a.username,disabled:!0})})]}),s.jsx(j,{control:w.control,name:"nickname",render:({field:e})=>s.jsxs(l,{children:[s.jsx(d,{children:"昵称"}),s.jsx(m,{children:s.jsx(x,{maxLength:64,placeholder:"显示名称",...e})}),s.jsx(h,{})]})}),s.jsx(c,{type:"submit",loading:A,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:I}),s.jsx(c,{variant:"outline",loading:C,onClick:()=>{var e;return(e=p.current)==null?void 0:e.click()},children:"选择图片上传"})]}),s.jsxs("div",{className:"section-card",children:[s.jsx("div",{className:"section-card-title",children:"修改密码"}),s.jsx(L,{...o,children:s.jsxs("form",{onSubmit:o.handleSubmit(z),className:"space-y-4",children:[s.jsx(j,{control:o.control,name:"old_password",render:({field:e})=>s.jsxs(l,{children:[s.jsx(d,{children:"当前密码"}),s.jsx(m,{children:s.jsx(x,{type:"password",placeholder:"输入当前密码",...e})}),s.jsx(h,{})]})}),s.jsx(j,{control:o.control,name:"new_password",render:({field:e})=>s.jsxs(l,{children:[s.jsx(d,{children:"新密码"}),s.jsx(m,{children:s.jsx(x,{type:"password",placeholder:"至少 6 位",...e})}),s.jsx(h,{})]})}),s.jsx(j,{control:o.control,name:"confirm_password",render:({field:e})=>s.jsxs(l,{children:[s.jsx(d,{children:"确认新密码"}),s.jsx(m,{children:s.jsx(x,{type:"password",placeholder:"再次输入新密码",...e})}),s.jsx(h,{})]})}),s.jsx(c,{type:"submit",variant:"destructive",loading:B,children:"修改密码"})]})})]})]})})}export{$ as default};
|