Files
jiang13-forum/embed_static/static/spa/assets/AdminPostsPage-D7MOxCPU.js
freefire b451703642 完善论坛配置与发帖体验:TipTap 富文本、图片上传、修订历史、Feed 排序与后台参数管理。
同步更新 README 与 ROADMAP,反映最新功能与开发状态。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-16 04:11:38 +08:00

2 lines
5.0 KiB
JavaScript

import{e as _,r as i,j as e}from"./react-vendor-CFzzFOsg.js";import{e as P,B as n,S as z,a as m,n as r}from"./index-5C0q-ZMs.js";import{I as E}from"./input-CE0PJTgJ.js";import{B as j}from"./badge-DB-zL5ml.js";import{A as L,a as T,b as F,c as B,d as I,e as G,f as H,g as K,h as O}from"./alert-dialog-BoQ7HSUR.js";import{c as R}from"./feedCache-D2GnU_BI.js";import{i as $}from"./content-BrFHUpp8.js";import{l as q,ac as J,E as M}from"./ui-vendor-BtpOfToU.js";function N(o){const c=new Date(o);return Number.isNaN(c.getTime())?o:c.toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function se(){const o=_(),{ready:c}=P(),[u,k]=i.useState([]),[b,g]=i.useState(!0),[d,w]=i.useState(1),[x,A]=i.useState(1),[f,p]=i.useState(""),[h,v]=i.useState(""),l=(s=d,t=h)=>{g(!0),m.adminPosts({page:s,keyword:t}).then(a=>{k(a.posts??[]),w(a.page),A(a.total_pages)}).catch(a=>r.error(a.message)).finally(()=>g(!1))};i.useEffect(()=>{c&&l(1,h)},[c,h]);const D=async s=>{try{const t=await m.adminPinPost(s.id,!s.pinned);R(),window.dispatchEvent(new Event("posts-refresh")),r.success(t.message),l()}catch(t){r.error(t instanceof Error?t.message:"操作失败")}},C=async s=>{try{const t=await m.adminLockPost(s.id,!s.edit_locked);r.success(t.message),l()}catch(t){r.error(t instanceof Error?t.message:"操作失败")}},S=async s=>{try{await m.adminDeletePost(s),r.success("帖子已删除"),l()}catch(t){r.error(t instanceof Error?t.message:"删除失败")}};return c?e.jsxs("div",{className:"admin-page",children:[e.jsxs("div",{className:"admin-page-head",children:[e.jsx("h1",{children:"帖子管理"}),e.jsx("p",{children:"置顶、锁定编辑、删除帖子;支持按标题、标签或正文关键词搜索"})]}),e.jsxs("form",{className:"admin-search-bar",onSubmit:s=>{s.preventDefault(),v(f.trim())},children:[e.jsx(E,{value:f,onChange:s=>p(s.target.value),placeholder:"搜索标题、标签或正文…"}),e.jsxs(n,{type:"submit",children:[e.jsx(q,{size:16}),"搜索"]}),h&&e.jsx(n,{type:"button",variant:"outline",onClick:()=>{p(""),v("")},children:"清除"})]}),e.jsx("div",{className:"admin-card",children:b?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx(z,{size:"lg"})}):e.jsxs(e.Fragment,{children:[e.jsxs("table",{className:"admin-table",children:[e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{children:"ID"}),e.jsx("th",{children:"标题"}),e.jsx("th",{children:"板块"}),e.jsx("th",{children:"作者"}),e.jsx("th",{children:"标签"}),e.jsx("th",{children:"评论"}),e.jsx("th",{children:"置顶"}),e.jsx("th",{children:"锁定"}),e.jsx("th",{children:"点赞"}),e.jsx("th",{children:"浏览"}),e.jsx("th",{children:"时间"}),e.jsx("th",{children:"操作"})]})}),e.jsx("tbody",{children:u.map(s=>{var a,y;const t=s.updated_at&&$(s.created_at,s.updated_at);return e.jsxs("tr",{children:[e.jsx("td",{children:s.id}),e.jsxs("td",{className:"max-w-[200px] truncate",children:[e.jsx("button",{type:"button",className:"admin-text-link",onClick:()=>o(`/post/${s.id}`),children:s.title}),t&&e.jsx(j,{variant:"secondary",className:"ml-1",children:"已编辑"})]}),e.jsx("td",{children:((a=s.board)==null?void 0:a.name)??"—"}),e.jsx("td",{children:((y=s.user)==null?void 0:y.nickname)??"—"}),e.jsx("td",{className:"max-w-[120px] truncate text-muted-foreground",children:s.tags||"—"}),e.jsx("td",{children:s.comment_count??0}),e.jsx("td",{children:s.pinned?e.jsx(j,{variant:"orange",children:"是"}):"—"}),e.jsx("td",{children:s.edit_locked?e.jsx(j,{variant:"destructive",children:"是"}):"—"}),e.jsx("td",{children:s.like_count}),e.jsx("td",{children:s.view_count}),e.jsxs("td",{className:"text-sm whitespace-nowrap",children:[e.jsx("span",{children:N(s.created_at)}),t&&s.updated_at&&e.jsxs("span",{className:"block text-muted-foreground text-xs",children:["改于 ",N(s.updated_at)]})]}),e.jsx("td",{children:e.jsxs("div",{className:"flex gap-1",children:[e.jsx(n,{size:"sm",variant:"outline",onClick:()=>D(s),children:s.pinned?"取消置顶":"置顶"}),e.jsx(n,{size:"sm",variant:"outline",onClick:()=>C(s),children:s.edit_locked?e.jsxs(e.Fragment,{children:[e.jsx(J,{size:14})," 解锁"]}):e.jsxs(e.Fragment,{children:[e.jsx(M,{size:14})," 锁定"]})}),e.jsxs(L,{children:[e.jsx(T,{asChild:!0,children:e.jsx(n,{size:"sm",variant:"ghost",className:"text-destructive",children:"删除"})}),e.jsxs(F,{children:[e.jsxs(B,{children:[e.jsx(I,{children:"确定删除该帖子?"}),e.jsx(G,{children:"相关评论也将一并删除,不可恢复。"})]}),e.jsxs(H,{children:[e.jsx(K,{children:"取消"}),e.jsx(O,{onClick:()=>S(s.id),children:"删除"})]})]})]})]})})]},s.id)})})]}),u.length===0&&e.jsx("div",{className:"admin-empty",children:"没有找到帖子"}),x>1&&e.jsxs("div",{className:"admin-pagination",children:[e.jsx(n,{size:"sm",variant:"outline",disabled:d<=1,onClick:()=>l(d-1),children:"上一页"}),e.jsxs("span",{children:["第 ",d," / ",x," 页"]}),e.jsx(n,{size:"sm",variant:"outline",disabled:d>=x,onClick:()=>l(d+1),children:"下一页"})]})]})})]}):null}export{se as default};