29 lines
9.6 KiB
JavaScript
29 lines
9.6 KiB
JavaScript
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BxEr63go.js","assets/index-B60u283l.css"])))=>i.map(i=>d[i]);
|
||
import{c as o,u as Z,Z as J,f as _,_ as C,r as n,g as h,j as s,E as w,B as t,$ as U,P as Y,I as z,k as ee,l as se,T as ae,m as p,a0 as te,a1 as ne,a2 as ie,a3 as re,a4 as ce,a5 as de,a6 as le,a7 as oe}from"./index-BxEr63go.js";import{C as $,a as B,b as O}from"./card-DASBiK00.js";/**
|
||
* @license lucide-react v0.475.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const xe=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],A=o("Check",xe);/**
|
||
* @license lucide-react v0.475.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const me=[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]],ue=o("Copy",me);/**
|
||
* @license lucide-react v0.475.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const he=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],pe=o("RefreshCw",he);/**
|
||
* @license lucide-react v0.475.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const ve=[["path",{d:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",key:"qn84l0"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]],je=o("TicketCheck",ve);/**
|
||
* @license lucide-react v0.475.0 - ISC
|
||
*
|
||
* This source code is licensed under the ISC license.
|
||
* See the LICENSE file in the root directory of this source tree.
|
||
*/const ye=[["path",{d:"M18 21a8 8 0 0 0-16 0",key:"3ypg7q"}],["circle",{cx:"10",cy:"8",r:"5",key:"o932ke"}],["path",{d:"M22 20c0-3.37-2-6.5-4-8a5 5 0 0 0-.45-8.3",key:"10s06x"}]],ke=o("UsersRound",ye);function be({i:c}){return c.used_by?s.jsx(p,{color:"var(--text-3)",children:"已使用"}):c.valid?s.jsx(p,{color:"var(--success)",children:"可用"}):s.jsx(p,{color:"var(--warning)",children:"已停用"})}function Ne(){var Q,K,L;const c=Z(),i=J(),E=_({queryKey:["me-admin"],queryFn:async()=>(await de(()=>import("./index-BxEr63go.js").then(a=>a.aa),__vite__mapDeps([0,1]))).serverMe(i),enabled:!!C()}),M=_({queryKey:["admin-users"],queryFn:()=>le(i),enabled:!!C()}),v=_({queryKey:["admin-invites"],queryFn:()=>oe(i),enabled:!!C()}),[I,r]=n.useState(""),[H,S]=n.useState(null),[V,j]=n.useState(!1),[x,y]=n.useState(""),[q,k]=n.useState(""),[G,d]=n.useState(null),[b,f]=n.useState(""),[l,W]=n.useState("all"),m=()=>{c.invalidateQueries({queryKey:["admin-invites"]})},u=e=>r(e.message||"操作失败"),F=h({mutationFn:()=>ne(5,i),onSuccess:e=>{m(),r(""),navigator.clipboard.writeText(e.codes.join(`
|
||
`)).catch(()=>{})},onError:u}),g=h({mutationFn:()=>ie(x.trim(),q.trim(),i),onSuccess:()=>{m(),j(!1),y(""),k(""),r("")},onError:u}),N=h({mutationFn:e=>re(e.id,e.patch,i),onSuccess:()=>{m(),d(null),r("")},onError:u}),X=h({mutationFn:e=>ce(e,i),onSuccess:()=>{m(),r("")},onError:u}),T=n.useMemo(()=>{var e;return((e=v.data)==null?void 0:e.invites)??[]},[v.data]),P=((Q=M.data)==null?void 0:Q.users)??[],R=n.useMemo(()=>T.filter(e=>l==="valid"?e.valid&&!e.used_by:l==="used"?!!e.used_by:l==="disabled"?!e.valid&&!e.used_by:!0),[T,l]);if(E.data&&!E.data.is_admin)return s.jsx(w,{title:"需要管理员账号",description:"当前登录账号不是管理员。"});const D=e=>{navigator.clipboard.writeText(e.code),S(e.id),setTimeout(()=>S(a=>a===e.id?null:a),1500)};return s.jsxs("div",{className:"mx-auto max-w-[1080px] px-6 py-5",children:[s.jsxs("div",{className:"mb-4 flex items-center justify-between",children:[s.jsx("h2",{className:"text-[15px] font-semibold text-ink-1",children:"管理"}),s.jsxs(t,{variant:"secondary",onClick:()=>{c.invalidateQueries()},children:[s.jsx(pe,{size:13})," 刷新"]})]}),I&&s.jsxs("div",{className:"mb-3 flex items-center justify-between rounded-md border border-danger/30 bg-danger-subtle px-3 py-2 text-[12px] text-danger",children:[s.jsx("span",{children:I}),s.jsx("button",{className:"rounded p-0.5 hover:bg-surface-3",onClick:()=>r(""),"aria-label":"关闭",children:s.jsx(U,{size:13})})]}),s.jsxs("div",{className:"grid grid-cols-1 gap-4 lg:grid-cols-2",children:[s.jsxs($,{children:[s.jsx(B,{title:"邀请码("+(((K=v.data)==null?void 0:K.total)??0)+")",extra:s.jsxs("div",{className:"flex gap-1.5",children:[s.jsxs(t,{size:"sm",variant:"secondary",onClick:()=>{j(e=>!e),r("")},children:[s.jsx(Y,{size:13})," 新建"]}),s.jsx(t,{size:"sm",variant:"primary",disabled:F.isPending,onClick:()=>F.mutate(),children:"批量生成 5 个"})]})}),s.jsxs(O,{className:"p-0",children:[V&&s.jsxs("div",{className:"flex flex-wrap items-end gap-2 border-b border-line bg-surface-2 px-4 py-3",children:[s.jsxs("label",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"text-[11px] font-medium text-ink-3",children:"邀请码(4-32 位字母数字-_)"}),s.jsx(z,{className:"w-[210px]",value:x,placeholder:"如 XIONG-2025",onChange:e=>y(e.target.value)})]}),s.jsxs("label",{className:"flex flex-col gap-1",children:[s.jsx("span",{className:"text-[11px] font-medium text-ink-3",children:"备注(可选)"}),s.jsx(z,{className:"w-[180px]",value:q,placeholder:"发给谁 / 用途",onChange:e=>k(e.target.value),onKeyDown:e=>{e.key==="Enter"&&x.trim()&&g.mutate()}})]}),s.jsxs("div",{className:"flex gap-1.5 pb-0.5",children:[s.jsx(t,{size:"sm",variant:"primary",disabled:!x.trim()||g.isPending,onClick:()=>g.mutate(),children:"创建"}),s.jsx(t,{size:"sm",variant:"ghost",onClick:()=>{j(!1),y(""),k("")},children:"取消"})]})]}),s.jsx("div",{className:"flex gap-1 border-b border-line px-4 py-2 text-[12px]",children:[["all","全部"],["valid","可用"],["used","已使用"],["disabled","已停用"]].map(([e,a])=>s.jsx("button",{className:"rounded-md px-2.5 py-1 transition-colors "+(l===e?"bg-brand-subtle font-medium text-brand-text":"text-ink-3 hover:bg-surface-3"),onClick:()=>W(e),children:a},e))}),R.length?s.jsx("div",{className:"divide-y divide-line max-h-[430px] overflow-y-auto",children:R.map(e=>s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 text-[12.5px]",children:[s.jsx("button",{className:"num shrink-0 cursor-pointer rounded-sm bg-surface-3 px-1.5 py-0.5 font-mono text-[12px] text-ink-1 transition-colors hover:bg-brand-subtle hover:text-brand-text",title:"点击复制",onClick:()=>D(e),children:H===e.id?s.jsxs("span",{className:"inline-flex items-center gap-1 text-success",children:[s.jsx(A,{size:11}),"已复制"]}):e.code}),s.jsx(be,{i:e}),G===e.id?s.jsxs("span",{className:"ml-1 flex min-w-0 flex-1 items-center gap-1",children:[s.jsx(z,{className:"h-7 flex-1 text-[12px]",value:b,autoFocus:!0,placeholder:"备注(64 字以内)",onChange:a=>f(a.target.value),onKeyDown:a=>{a.key==="Enter"&&N.mutate({id:e.id,patch:{remark:b}}),a.key==="Escape"&&d(null)}}),s.jsx(t,{size:"icon-sm",variant:"ghost","aria-label":"保存备注",className:"text-success",onClick:()=>N.mutate({id:e.id,patch:{remark:b}}),children:s.jsx(A,{size:13})}),s.jsx(t,{size:"icon-sm",variant:"ghost","aria-label":"取消",className:"text-ink-3",onClick:()=>d(null),children:s.jsx(U,{size:13})})]}):s.jsx("button",{className:"min-w-0 flex-1 truncate text-left text-[12px] text-ink-3 hover:text-ink-2",title:e.remark?"点击编辑备注":e.created_by_name?"由 "+e.created_by_name+" 创建 · 点击添加备注":"点击添加备注",onClick:()=>{d(e.id),f(e.remark??"")},children:e.remark||(e.created_by_name?"由 "+e.created_by_name+" 创建":s.jsx("span",{className:"opacity-60",children:"添加备注…"}))}),e.used_by_name&&s.jsxs("span",{className:"shrink-0 text-ink-3",children:["被 ",e.used_by_name," 使用于 ",ee(e.used_at)]}),s.jsxs("span",{className:"ml-auto flex shrink-0 items-center gap-0.5",children:[s.jsx(t,{size:"icon-sm",variant:"ghost","aria-label":"复制",className:"text-ink-3",onClick:()=>D(e),children:s.jsx(ue,{size:13})}),!e.used_by&&s.jsxs(s.Fragment,{children:[s.jsx(t,{size:"icon-sm",variant:"ghost","aria-label":"编辑备注",className:"text-ink-3",onClick:()=>{d(e.id),f(e.remark??"")},children:s.jsx(se,{size:13})}),s.jsx(t,{size:"sm",variant:"ghost",className:e.valid?"text-ink-3 hover:text-warning":"text-ink-3 hover:text-success",onClick:()=>N.mutate({id:e.id,patch:{valid:!e.valid}}),children:e.valid?"停用":"启用"})]}),s.jsx(t,{size:"icon-sm",variant:"ghost","aria-label":"删除",className:"text-ink-3 hover:text-danger",onClick:()=>{window.confirm("删除邀请码 "+e.code+"?此操作不可恢复。")&&X.mutate(e.id)},children:s.jsx(ae,{size:13})})]})]},e.id))}):s.jsx(w,{icon:s.jsx(je,{size:32,strokeWidth:1.5}),title:"暂无符合条件的邀请码",description:"新建自定义邀请码,或批量生成后发给需要注册的用户。"})]})]}),s.jsxs($,{children:[s.jsx(B,{title:"用户("+(((L=M.data)==null?void 0:L.total)??0)+")"}),s.jsx(O,{className:"p-0",children:P.length?s.jsx("div",{className:"divide-y divide-line max-h-[520px] overflow-y-auto",children:P.map(e=>s.jsxs("div",{className:"flex items-center gap-2 px-4 py-2.5 text-[12.5px]",children:[s.jsx("span",{className:"font-medium text-ink-1",children:e.username}),e.is_admin&&s.jsx(p,{color:"var(--brand-text)",children:"管理员"}),s.jsxs("span",{className:"num ml-auto text-ink-3",children:[e.devices," 设备 · ",e.records," 记录 · ",te(e.attachment_bytes)]})]},e.id))}):s.jsx(w,{icon:s.jsx(ke,{size:32,strokeWidth:1.5}),title:"暂无用户"})})]})]})]})}export{Ne as AdminPage};
|