2 lines
5.8 KiB
JavaScript
2 lines
5.8 KiB
JavaScript
import{r as n,j as e,e as M}from"./react-vendor-1fwFMt02.js";import{_ as O,Z as P,u as Z,a as G,F as V,b as u,c as g,d as b,e as y,f as N,o as q,s as C}from"./form-cra7lKcv.js";import{f as d,i as J,S as A,B as h,a as p,n as c}from"./index-CucHNnyZ.js";import{I as F}from"./input-DOedlbiC.js";import{T as K}from"./textarea-CwI-oiTC.js";import{B as Q}from"./badge-CS5odIe6.js";import{D as U,a as W,b as X,c as Y,e as $}from"./dialog-CtQqbmck.js";import{A as ee,a as se,b as ae,c as re,d as te,e as ne,f as le,g as ie,h as oe}from"./alert-dialog-D0wiVaPM.js";import{m as ce}from"./ui-vendor-Gb6mai95.js";function de(a){return O(P,a)}const S=n.forwardRef(({className:a,...r},t)=>e.jsx("div",{className:"relative w-full overflow-auto",children:e.jsx("table",{ref:t,className:d("w-full caption-bottom text-sm",a),...r})}));S.displayName="Table";const _=n.forwardRef(({className:a,...r},t)=>e.jsx("thead",{ref:t,className:d("[&_tr]:border-b",a),...r}));_.displayName="TableHeader";const B=n.forwardRef(({className:a,...r},t)=>e.jsx("tbody",{ref:t,className:d("[&_tr:last-child]:border-0",a),...r}));B.displayName="TableBody";const w=n.forwardRef(({className:a,...r},t)=>e.jsx("tr",{ref:t,className:d("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",a),...r}));w.displayName="TableRow";const i=n.forwardRef(({className:a,...r},t)=>e.jsx("th",{ref:t,className:d("h-10 px-3 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",a),...r}));i.displayName="TableHead";const o=n.forwardRef(({className:a,...r},t)=>e.jsx("td",{ref:t,className:d("p-3 align-middle [&:has([role=checkbox])]:pr-0",a),...r}));o.displayName="TableCell";const me=q({name:C().min(1,"请输入名称").max(64),description:C().max(500).optional(),sort_order:de().min(0)});function Ne(){M();const{ready:a}=J(),[r,t]=n.useState([]),[E,v]=n.useState(!0),[R,m]=n.useState(!1),[j,D]=n.useState(null),[k,T]=n.useState(!1),l=Z({resolver:G(me),defaultValues:{name:"",description:"",sort_order:1}}),f=()=>{v(!0),p.boards().then(s=>t(s.boards??[])).catch(s=>c.error(s.message)).finally(()=>v(!1))};n.useEffect(()=>{a&&f()},[a]);const H=()=>{D(null),l.reset({name:"",description:"",sort_order:r.length+1}),m(!0)},I=s=>{D(s),l.reset({name:s.name,description:s.description??"",sort_order:s.sort_order}),m(!0)},z=async s=>{T(!0);try{j?(await p.updateBoard(j.id,s),c.success("板块已更新")):(await p.createBoard(s),c.success("板块已创建")),m(!1),f(),window.dispatchEvent(new Event("boards-refresh"))}catch(x){c.error(x instanceof Error?x.message:"操作失败")}finally{T(!1)}},L=async s=>{try{await p.deleteBoard(s),c.success("板块已删除"),f(),window.dispatchEvent(new Event("boards-refresh"))}catch(x){c.error(x instanceof Error?x.message:"删除失败")}};return a?e.jsxs("div",{className:"admin-page",children:[e.jsx("div",{className:"admin-page-head",children:e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{children:[e.jsx("h1",{children:"板块管理"}),e.jsx("p",{children:"创建、编辑或删除论坛板块,用户发帖前需先有板块"})]}),e.jsxs(h,{onClick:H,children:[e.jsx(ce,{}),"新建板块"]})]})}),e.jsx("div",{className:"admin-card",children:E?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(A,{size:"lg"})}):e.jsxs(e.Fragment,{children:[e.jsxs(S,{children:[e.jsx(_,{children:e.jsxs(w,{children:[e.jsx(i,{className:"w-[60px]",children:"ID"}),e.jsx(i,{children:"名称"}),e.jsx(i,{children:"简介"}),e.jsx(i,{className:"w-[70px]",children:"排序"}),e.jsx(i,{className:"w-[80px]",children:"帖子数"}),e.jsx(i,{className:"w-[160px]",children:"操作"})]})}),e.jsx(B,{children:r.map(s=>e.jsxs(w,{children:[e.jsx(o,{children:s.id}),e.jsx(o,{children:e.jsx("strong",{children:s.name})}),e.jsx(o,{className:"max-w-[200px] truncate",children:s.description}),e.jsx(o,{children:s.sort_order}),e.jsx(o,{children:e.jsx(Q,{variant:"secondary",children:s.post_count??0})}),e.jsx(o,{children:e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(h,{variant:"ghost",size:"sm",onClick:()=>I(s),children:"编辑"}),e.jsxs(ee,{children:[e.jsx(se,{asChild:!0,children:e.jsx(h,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",children:"删除"})}),e.jsxs(ae,{children:[e.jsxs(re,{children:[e.jsx(te,{children:"确定删除该板块?"}),e.jsx(ne,{children:"删除后该板块下的帖子将无法通过板块筛选,此操作不可撤销。"})]}),e.jsxs(le,{children:[e.jsx(ie,{children:"取消"}),e.jsx(oe,{onClick:()=>L(s.id),children:"删除"})]})]})]})]})})]},s.id))})]}),r.length===0&&e.jsx("div",{className:"empty-state",children:e.jsx("p",{children:"还没有板块,点击右上角创建第一个"})})]})}),e.jsx(U,{open:R,onOpenChange:m,children:e.jsxs(W,{children:[e.jsx(X,{children:e.jsx(Y,{children:j?"编辑板块":"新建板块"})}),e.jsx(V,{...l,children:e.jsxs("form",{onSubmit:l.handleSubmit(z),className:"space-y-4",children:[e.jsx(u,{control:l.control,name:"name",render:({field:s})=>e.jsxs(g,{children:[e.jsx(b,{children:"板块名称"}),e.jsx(y,{children:e.jsx(F,{maxLength:64,placeholder:"如:技术交流",...s})}),e.jsx(N,{})]})}),e.jsx(u,{control:l.control,name:"description",render:({field:s})=>e.jsxs(g,{children:[e.jsx(b,{children:"简介"}),e.jsx(y,{children:e.jsx(K,{rows:3,maxLength:500,placeholder:"板块说明(可选)",...s})}),e.jsx(N,{})]})}),e.jsx(u,{control:l.control,name:"sort_order",render:({field:s})=>e.jsxs(g,{children:[e.jsx(b,{children:"排序"}),e.jsx(y,{children:e.jsx(F,{type:"number",min:0,...s})}),e.jsx(N,{})]})}),e.jsxs($,{children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>m(!1),children:"取消"}),e.jsx(h,{type:"submit",loading:k,children:j?"保存":"创建"})]})]})})]})})]}):e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(A,{size:"lg"})})}export{Ne as default};
|