Profile-DdrWU4D2.js6.8 KB
import{J as M,r as a,u as H,c as u,V as J,j as e,q as g,T as n,S as d,F as m,G as K,b0 as Z,d as x,s as G}from"./index-DS2B3OLK.js";import{B as y}from"./index-BNK0Nj_J.js";import{E as Y}from"./index-dKmdA2E0.js";import{S as E}from"./index-Bj7oeOfx.js";import{T as $}from"./index-b2iqXj_X.js";import{T as l}from"./index-DhB1Ls4S.js";import"./IconTickCircle-Bbh_c2jr.js";import"./_baseDifference-D1QxGNC2.js";import"./index-CElfosix.js";import"./slice-s3-7cpgr.js";import"./object-DvQZmkoP.js";import"./index-R4PZyHYh.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}=H(),[i,j]=a.useState(null),[v,f]=a.useState(""),[h,P]=a.useState("zh-CN"),[U,S]=a.useState(!1),[w,_]=a.useState(""),[c,C]=a.useState(""),[b,L]=a.useState(""),[R,T]=a.useState(!1),[r,q]=a.useState({items:[],total:0,page:1,page_size:20,logs_table:!0}),[D,z]=a.useState(!1),[N,k]=a.useState(""),B=a.useCallback(async()=>{try{const t=await u.profile();j(t),f(t.nickname||""),P(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});q(o)}catch{}finally{z(!1)}},[]);a.useEffect(()=>{B(),p(1)},[B,p]);const A=async()=>{S(!0);try{const t=await u.profileSave({nickname:v.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{S(!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&&G(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?J(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:"var(--wstat-mono)",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:v,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:P,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?Z(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($,{columns:V,dataSource:r.items||[],rowKey:"id",size:"small",loading:D,empty:e.jsx(Y,{description:s("profileLogsEmpty")}),pagination:{currentPage:r.page,pageSize:r.page_size,total:r.total,onPageChange:t=>p(t)}})]})]})}export{me as default};