码桶
发现社区成员的开源项目
Profile-CP6W0yYd.js6.8 KB
import{E as M,r as a,u as Z,b as u,O as H,j as e,o as g,T as n,S as d,F as m,C as K,aZ as J,B as x,s as Y}from"./index-GWuvg2UH.js";import{B as y}from"./index-DihvOmSo.js";import{E as $}from"./index-VbOLTMR0.js";import{S as E}from"./index-BZDftoba.js";import{T as G}from"./index-mZVFvfKe.js";import{T as l}from"./index-BW_2QB9V.js";import"./IconTickCircle-BYgwCdAe.js";import"./_baseDifference-DopHgqVv.js";import"./index-DIHsQVbu.js";import"./slice-B6jKCnyX.js";import"./object-DkPZvw8u.js";import"./index-BMbdBPA2.js";function Q(s){return a.createElement("svg",Object.assign({viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",focusable:!1,"aria-hidden":!0},s),a.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12 2a6.5 6.5 0 0 0-6.5 6.5V10H5a2 2 0 0 0-2 2v8c0 1.1.9 2 2 2h14a2 2 0 0 0 2-2v-8a2 2 0 0 0-2-2h-.5V8.5A6.5 6.5 0 0 0 12 2Zm3.5 8V8.5a3.5 3.5 0 1 0-7 0V10h7Z",fill:"currentColor"}))}const W=M(Q,"lock"),X={login:"opLogin",logout:"opLogout",profile_update:"opProfileUpdate",password_change:"opPasswordChange",password_reset:"opPasswordReset",user_create:"opUserCreate",user_update:"opUserUpdate",user_disable:"opUserDisable",user_enable:"opUserEnable",user_delete:"opUserDelete",user_reset_password:"opUserResetPwd"},ee={login:"green",logout:"grey",profile_update:"blue",password_change:"purple",password_reset:"purple",user_create:"cyan",user_update:"blue",user_disable:"red",user_enable:"green",user_delete:"red",user_reset_password:"red"};function me(){const{t:s,lang:I,setLang:O}=Z(),[i,j]=a.useState(null),[P,f]=a.useState(""),[h,S]=a.useState("zh-CN"),[U,v]=a.useState(!1),[w,_]=a.useState(""),[c,C]=a.useState(""),[b,L]=a.useState(""),[R,T]=a.useState(!1),[r,D]=a.useState({items:[],total:0,page:1,page_size:20,logs_table:!0}),[q,z]=a.useState(!1),[N,k]=a.useState(""),B=a.useCallback(async()=>{try{const t=await u.profile();j(t),f(t.nickname||""),S(t.lang||"zh-CN"),k("")}catch(t){k(t.message)}},[]),p=a.useCallback(async(t=1)=>{z(!0);try{const o=await u.profileLogs({page:t,page_size:20});D(o)}catch{}finally{z(!1)}},[]);a.useEffect(()=>{B(),p(1)},[B,p]);const A=async()=>{v(!0);try{const t=await u.profileSave({nickname:P.trim(),lang:h});j(t),f(t.nickname||""),h!==I&&O(h),l.success(s("profileSaved")),p(1)}catch(t){l.error(t.message)}finally{v(!1)}},F=async()=>{if(!w){l.warning(s("profileOldPwdPh"));return}if(c.length<8||c.length>72){l.warning(s("profilePwdLen"));return}if(c!==b){l.warning(s("profilePwdMismatch"));return}T(!0);try{const o=await u.profilePassword(w,c);o&&o.token&&Y(o.token),_(""),C(""),L(""),l.success(s("profilePwdChanged")),p(1)}catch(o){l.error(o.message)}finally{T(!1)}},V=[{title:s("opTime"),dataIndex:"created_at",width:150,render:t=>t?H(t):"-"},{title:s("opAction"),dataIndex:"action",width:130,render:t=>e.jsx(g,{color:ee[t]||"grey",size:"small",children:s(X[t])||t})},{title:s("opDetail"),dataIndex:"detail",render:t=>t?e.jsx(n.Text,{style:{fontSize:13},children:t}):"—"},{title:s("opIp"),dataIndex:"ip",width:130,render:t=>e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:t||"-"})}];return N&&!i?e.jsx("div",{className:"page",children:e.jsx(y,{type:"danger",description:N})}):e.jsxs("div",{className:"page",children:[e.jsx("div",{className:"toolbar",children:e.jsx(n.Title,{heading:5,style:{margin:0},children:s("profile")})}),e.jsxs("div",{className:"card",style:{marginBottom:16},children:[e.jsx("div",{className:"card-title",children:s("profileInfo")}),i?e.jsxs(e.Fragment,{children:[e.jsxs(d,{wrap:!0,spacing:16,align:"center",style:{marginBottom:12},children:[e.jsx(n.Text,{type:"tertiary",style:{fontSize:12},children:s("email")}),e.jsx(m,{value:i.email,disabled:!0,style:{width:300}}),e.jsx(n.Text,{type:"tertiary",style:{fontSize:12},children:s("profileEmailReadonly")})]}),e.jsxs(d,{wrap:!0,spacing:16,align:"center",style:{marginBottom:12},children:[e.jsx(n.Text,{type:"tertiary",style:{fontSize:12},children:s("profileNickname")}),e.jsx(m,{value:P,onChange:f,maxlength:30,showClear:!0,style:{width:300},placeholder:s("profileNicknamePh")})]}),e.jsxs(d,{wrap:!0,spacing:16,align:"center",style:{marginBottom:12},children:[e.jsx(n.Text,{type:"tertiary",style:{fontSize:12},children:s("profileLang")}),e.jsx(K,{value:h,style:{width:180},onChange:S,optionList:[{value:"zh-CN",label:"简体中文"},{value:"en-US",label:"English"}]})]}),e.jsxs(d,{wrap:!0,spacing:12,align:"center",style:{marginBottom:4},children:[i.is_admin?e.jsx(g,{color:"red",size:"small",children:s("roleAdmin")}):null,e.jsxs(g,{color:"green",size:"small",children:[s("profileJoined")," ",i.created_at?J(i.created_at):"-"]}),e.jsxs(g,{color:"blue",size:"small",children:[s("profileSitesOwned"),": ",i.sites_owned??0]}),e.jsxs(g,{color:"cyan",size:"small",children:[s("profileSitesShared"),": ",i.sites_shared??0]})]}),e.jsx("div",{children:e.jsx(x,{theme:"solid",loading:U,onClick:A,children:s("save")})})]}):e.jsx(E,{active:!0,placeholder:e.jsx(E.Paragraph,{rows:3}),loading:!0})]}),e.jsxs("div",{className:"card",style:{marginBottom:16},children:[e.jsx("div",{className:"card-title",children:e.jsxs(d,{spacing:6,children:[e.jsx(W,{size:"small"}),s("profilePwdTitle")]})}),e.jsx(y,{type:"info",description:s("profilePwdHint"),style:{marginBottom:12}}),e.jsxs(d,{wrap:!0,spacing:16,align:"center",style:{marginBottom:12},children:[e.jsx(m,{mode:"password",value:w,onChange:_,style:{width:260},placeholder:s("profileOldPwdPh")}),e.jsx(m,{mode:"password",value:c,onChange:C,style:{width:260},placeholder:s("profileNewPwdPh")}),e.jsx(m,{mode:"password",value:b,onChange:L,style:{width:260},placeholder:s("profileNewPwd2Ph")}),e.jsx(x,{theme:"solid",loading:R,onClick:F,children:s("profilePwdBtn")})]})]}),e.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[e.jsxs("div",{className:"card-title",style:{padding:"14px 16px 6px"},children:[s("profileLogs"),r.total?` · ${r.total}`:""]}),r.logs_table===!1&&e.jsx("div",{style:{padding:"0 16px 12px"},children:e.jsx(y,{type:"warning",description:e.jsxs("div",{children:[e.jsx("div",{children:s("profileLogsNoTable")}),r.db?e.jsxs("div",{style:{marginTop:6,fontSize:12},children:[s("profileLogsDbNow"),e.jsx("code",{style:{marginLeft:4},children:r.db})]}):null,r.err?e.jsxs("div",{style:{marginTop:4,fontSize:12,wordBreak:"break-all"},children:[s("profileLogsErr"),e.jsx("code",{style:{marginLeft:4},children:r.err})]}):null,r.sql?e.jsx(x,{size:"small",theme:"borderless",style:{marginTop:6,paddingLeft:0},onClick:async()=>{try{await navigator.clipboard.writeText(r.sql),l.success(s("profileLogsSqlCopied"))}catch{l.error(s("profileLogsSqlCopyFail"))}},children:s("profileLogsCopySql")}):null]})})}),e.jsx(G,{columns:V,dataSource:r.items||[],rowKey:"id",size:"small",loading:q,empty:e.jsx($,{description:s("profileLogsEmpty")}),pagination:{currentPage:r.page,pageSize:r.page_size,total:r.total,onPageChange:t=>p(t)}})]})]})}export{me as default};