1 line
10 KiB
JavaScript
1 line
10 KiB
JavaScript
import{C as e,G as t,J as n,L as r,N as i,O as a,S as o,U as s,V as c,_ as l,a as ee,c as u,g as d,i as f,j as p,n as m,p as h,r as g,t as _,x as v,z as y}from"./ui-BjxGELcM.js";import{t as b}from"./arrow-right-CxQiebL9.js";import{t as x}from"./globe-Cy3sFr4f.js";import{n as S,r as C,t as te}from"./users-D75l7xkO.js";import{t as w}from"./radio-tower-Dfdb9MI0.js";import{i as T,t as ne}from"./index-BsK239Bd.js";var E=[[`path`,{d:`M11 20H2`,key:`nlcfvz`}],[`path`,{d:`M11 4.562v16.157a1 1 0 0 0 1.242.97L19 20V5.562a2 2 0 0 0-1.515-1.94l-4-1A2 2 0 0 0 11 4.561z`,key:`au4z13`}],[`path`,{d:`M11 4H8a2 2 0 0 0-2 2v14`,key:`74r1mk`}],[`path`,{d:`M14 12h.01`,key:`1jfl7z`}],[`path`,{d:`M22 20h-3`,key:`vhrsz`}]],re=e=>r(l,t(e,{iconNode:E,name:`door-open`})),D=[[`path`,{d:`m21 21-4.34-4.34`,key:`14j7rj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}]],O=e=>r(l,t(e,{iconNode:D,name:`search`})),k=a(`<div><p class="mono-label text-muted-foreground">rooms / registry</p><h1 class="display mt-2 text-4xl sm:text-5xl">房间</h1><p class="mt-3 max-w-xl text-sm text-muted-foreground">创建或进入房间。已接入新分页查询(<code class=font-mono>/api/rooms/query</code>)与管理面创建(<code class=font-mono>/api/manage/rooms</code>),支持搜索、公开度与成员统计。`),A=a(`<input class="h-8 flex-1 border border-line bg-background px-2 text-xs outline-none"placeholder=描述(可选)>`),j=a(`<label class="flex items-center gap-1.5 text-xs"><input type=checkbox>`),M=a(`<div class="flex flex-wrap items-center gap-3 border-t border-line/50 pt-3"><label class="flex items-center gap-2 text-xs"><input type=checkbox>高级`),N=a(`<div class="relative max-w-3xl border border-line bg-card/60 p-3 sm:p-4"><div class="flex flex-col gap-3"><div class="flex flex-col gap-2 sm:flex-row"><div class="flex h-10 flex-1 items-center gap-2.5 border border-line bg-background/70 px-3 transition-colors focus-within:border-ring"><input class="field-mono h-full w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground/50"placeholder="新房间名,如 live-demo"aria-label=房间名>`),ie=a(`<span class="mono-label animate-pulse text-muted-foreground">loading…`),ae=a(`<div class="flex items-center justify-between gap-3 border-b border-line pb-3"><h2 class="flex items-center gap-2 font-semibold">房间列表`),oe=a(`<div class=space-y-2>`),se=a(`<div class="mx-auto max-w-[1400px] space-y-8 px-4 py-8 sm:px-6 sm:py-10"><div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"><div class="flex flex-1 items-center gap-2"><div class="flex h-9 flex-1 max-w-sm items-center gap-2 border border-line bg-background px-3"><input class="h-full w-full bg-transparent text-sm outline-none placeholder:text-muted-foreground/50"placeholder="搜索房间名 / 展示名"></div></div><div class="flex items-center gap-2 text-xs text-muted-foreground"><span class=font-mono> rooms · 第 <!>/<!> 页</span></div></div><section class=space-y-3>`),ce=a(`<div class="flex flex-col items-center gap-3 border border-dashed border-line px-6 py-12 text-center"><span class="flex size-10 items-center justify-center border border-line bg-card text-muted-foreground"></span><div><p class=font-medium>暂无房间</p><p class="mt-1 text-sm text-muted-foreground">`),le=a(`<span class="font-mono text-xs text-muted-foreground">/`),ue=a(`<span class=truncate>· `),de=a(`<div class="group relative border border-line/70 bg-card/40 px-4 py-4 transition-colors hover:border-line hover:bg-accent/30 sm:px-5"><div class="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"><div class="flex min-w-0 flex-1 items-start gap-3"><div class="min-w-0 flex-1"><div class="flex flex-wrap items-center gap-2"><p class="display truncate text-xl sm:text-2xl"></p></div><div class="mt-1 flex flex-wrap items-center gap-3 text-xs text-muted-foreground"><span class="flex items-center gap-1"></span><span class="flex items-center gap-1"> 成员</span><span class=font-mono> 路分发</span></div></div></div><div class="flex shrink-0 items-center gap-2">`),P=()=>{let t=T(),[a,l]=s([]),[v,E]=s(0),[D,P]=s(1),[F,I]=s(``),[L,R]=s(``),[z,B]=s(``),[V,H]=s(!1),[U,W]=s(``),[fe,G]=s(!1),[K,q]=s(``),[J,pe]=s(!0),[Y,me]=s(!1),X=async()=>{G(!0),W(``);try{if(h.isAdminOrAbove())try{let e=((await d.manageRooms()).rooms||[]).map(e=>({name:e.room.name,display_name:e.room.display_name,description:e.room.description,creator:e.room.creator,is_public:e.room.is_public,status:e.room.status,member_count:e.member_count,targets:e.targets,live:e.live,created_at:e.room.created_at})),t=F().trim().toLowerCase();t&&(e=e.filter(e=>e.name.toLowerCase().includes(t)||e.display_name&&e.display_name.toLowerCase().includes(t))),E(e.length);let n=(D()-1)*12;l(e.slice(n,n+12));return}catch{}try{let e=await d.queryRooms({page:D(),page_size:12,search:F().trim()||void 0}),t=(e.rooms||[]).map(e=>({name:e.name,display_name:e.display_name,description:e.description,creator:e.creator,is_public:e.is_public,status:e.status,member_count:e.member_count??0,targets:[],live:!1,created_at:e.created_at}));try{let e=await d.listRooms(),n=new Map((e.rooms||[]).map(e=>[e.name,(e.targets?.length??0)>0?e.targets:[]]));for(let e of t){let t=n.get(e.name);t&&(e.targets=t,e.live=t.length>0)}}catch{}l(t),E(e.total??t.length);return}catch{}let e=((await d.listRooms()).rooms||[]).map(e=>({name:e.name,display_name:e.name,description:``,creator:``,is_public:!0,status:`active`,member_count:0,targets:e.targets||[],live:(e.targets?.length??0)>0})),t=F().trim().toLowerCase();t&&(e=e.filter(e=>e.name.toLowerCase().includes(t))),E(e.length);let n=(D()-1)*12;l(e.slice(n,n+12))}catch(e){W(String(e?.message||e))}finally{G(!1)}};y(()=>{h.isAuthed()&&X()}),y(()=>{D(),F(),h.isAuthed()&&X()}),n(()=>h.isAuthed()&&X());let Z=()=>{I(L().trim()),P(1)},Q=async()=>{let e=z().trim();if(e){H(!0),W(``);try{if(h.isAdminOrAbove()&&Y())await d.manageCreateRoom({name:e,display_name:e,description:K().trim()||void 0,is_public:J(),require_approval:!1,max_members:100});else try{await d.manageCreateRoom({name:e,display_name:e,description:K().trim()||void 0,is_public:J()})}catch{await d.createRoom(e)}B(``),q(``),await X(),t({to:`/room`,search:{room:e}})}catch(e){W(String(e?.message||e))}finally{H(!1)}}},he=e=>t({to:`/room`,search:{room:e}}),$=()=>Math.max(1,Math.ceil(v()/12));return(()=>{var t=se(),n=t.firstChild,s=n.firstChild,l=s.firstChild,d=l.firstChild,y=s.nextSibling,T=y.firstChild,E=T.firstChild,H=E.nextSibling,W=H.nextSibling.nextSibling;W.nextSibling;var G=n.nextSibling;return o(t,r(u,{get children(){return k()}}),n),o(t,r(i,{get when(){return U()},get children(){return r(_,{tone:`error`,get children(){return U()}})}}),n),o(t,r(u,{delay:1,get children(){var t=N(),n=t.firstChild,a=n.firstChild,s=a.firstChild,l=s.firstChild;return o(t,r(f,{}),n),o(s,r(S,{class:`size-4 shrink-0 text-muted-foreground`}),l),l.$$keydown=e=>{e.key===`Enter`&&Q()},l.$$input=e=>B(e.currentTarget.value),o(a,r(g,{class:`h-10 shrink-0`,onClick:Q,get disabled(){return V()||!z().trim()},get children(){return[r(b,{class:`size-4`}),`创建并进入`]}}),null),o(n,r(i,{get when(){return h.isAdminOrAbove()},get children(){var t=M(),n=t.firstChild.firstChild;return n.addEventListener(`change`,e=>me(e.target.checked)),o(t,r(i,{get when(){return Y()},get children(){return[(()=>{var e=A();return e.$$input=e=>q(e.currentTarget.value),c(()=>e.value=K()),e})(),(()=>{var t=j(),n=t.firstChild;return n.addEventListener(`change`,e=>pe(e.target.checked)),o(t,(()=>{var t=e(()=>!!J());return()=>t()?r(x,{class:`size-3`}):r(C,{class:`size-3`})})(),null),o(t,()=>J()?`公开`:`私密`,null),c(()=>n.checked=J()),t})()]}}),null),c(()=>n.checked=Y()),t}}),null),c(()=>l.value=z()),t}}),n),o(l,r(O,{class:`size-4 text-muted-foreground`}),d),d.$$keydown=e=>{e.key===`Enter`&&Z()},d.$$input=e=>R(e.currentTarget.value),o(s,r(g,{variant:`outline`,class:`h-9`,onClick:Z,children:`搜索`}),null),o(s,r(i,{get when(){return F()},get children(){return r(g,{variant:`ghost`,class:`h-9`,onClick:()=>{R(``),I(``),P(1)},children:`清除`})}}),null),o(T,v,E),o(T,D,H),o(T,$,W),o(y,r(g,{variant:`outline`,class:`h-7 px-2 text-xs`,get disabled(){return D()<=1},onClick:()=>P(e=>Math.max(1,e-1)),children:`上一页`}),null),o(y,r(g,{variant:`outline`,class:`h-7 px-2 text-xs`,get disabled(){return D()>=$()},onClick:()=>P(e=>e+1),children:`下一页`}),null),o(G,r(u,{get children(){var e=ae(),t=e.firstChild,n=t.firstChild;return o(t,r(w,{class:`size-4 text-muted-foreground`}),n),o(e,r(i,{get when(){return fe()},get children(){return ie()}}),null),e}}),null),o(G,r(i,{get when(){return a().length>0},get fallback(){return(()=>{var t=ce(),n=t.firstChild,i=n.nextSibling.firstChild.nextSibling;return o(n,r(re,{class:`size-5`})),o(i,(()=>{var t=e(()=>!!F());return()=>t()?`无匹配 "${F()}" 的房间`:`创建一个房间后,分发拓扑会在这里出现。`})()),t})()},get children(){var t=oe();return o(t,r(p,{get each(){return a()},children:(t,n)=>r(u,{get delay(){return Math.min(n()+1,6)},get children(){var n=de(),a=n.firstChild,s=a.firstChild,c=s.firstChild,l=c.firstChild,u=l.firstChild,d=l.nextSibling,p=d.firstChild,h=p.nextSibling,_=h.firstChild,v=h.nextSibling,y=v.firstChild,S=s.nextSibling;return o(n,r(f,{}),a),o(s,r(ee,{get active(){return!!t.live}}),c),o(u,()=>t.display_name||t.name),o(l,r(i,{get when(){return t.name!==t.display_name},get children(){var e=le();return e.firstChild,o(e,()=>t.name,null),e}}),null),o(l,r(m,{get variant(){return t.live?`success`:`muted`},class:`text-[10px]`,get children(){return t.live?`LIVE`:`IDLE`}}),null),o(l,r(m,{variant:`outline`,class:`gap-1 text-[10px]`,get children(){return[e(()=>e(()=>t.is_public===!1)()?r(C,{class:`size-3`}):r(x,{class:`size-3`})),e(()=>t.is_public===!1?`私密`:`公开`)]}}),null),o(l,r(i,{get when(){return e(()=>!!t.status)()&&t.status!==`active`},get children(){return r(m,{variant:`outline`,class:`border-destructive/40 text-destructive text-[10px]`,get children(){return t.status}})}}),null),o(p,r(ne,{class:`size-3`}),null),o(p,()=>t.creator||`-`,null),o(h,r(te,{class:`size-3`}),_),o(h,()=>t.member_count??0,_),o(v,()=>t.targets?.length??0,y),o(d,r(i,{get when(){return t.description},get children(){var e=ue();return e.firstChild,o(e,()=>t.description,null),e}}),null),o(S,r(g,{variant:`outline`,class:`h-9`,onClick:()=>he(t.name),get children(){return[`进入房间`,r(b,{class:`size-4`})]}})),n}})})),t}}),null),c(()=>d.value=L()),t})()};v([`input`,`keydown`]);export{P as Rooms}; |