Files
jiang13-forum/embed_static/static/spa/assets/AdminPostsPage-Boh0BdYW.js
freefire 55c256654b 支持板块图标与主题色自定义,并优化列表加载与未保存离开提示。
新增后端图标校验与色槽规范化,前端展示 BoardBadge/骨架屏,发帖与板块管理页增加未保存确认。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-28 17:13:32 +08:00

2 lines
4.9 KiB
JavaScript

import{e as _,r as i,j as e}from"./react-vendor-BdyZmpPe.js";import{m as P,B as n,S as z,b as x,n as r,a as E}from"./index-Cp7Ff9NP.js";import{I as L}from"./input-y6vZyHhN.js";import{B as j}from"./badge-xzbTTsRq.js";import{A as T,g as F,a as B,b as I,c as G,d as H,e as K,f as O,h as R}from"./alert-dialog-C2PKamsV.js";import{i as $}from"./content-BrFHUpp8.js";import{E as q,aC as J,aa as M}from"./ui-vendor-B26O8baZ.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 ee(){const o=_(),{ready:c}=P(),[u,k]=i.useState([]),[b,g]=i.useState(!0),[d,w]=i.useState(1),[m,A]=i.useState(1),[f,p]=i.useState(""),[h,v]=i.useState(""),l=(s=d,t=h)=>{g(!0),x.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 x.adminPinPost(s.id,!s.pinned);E(),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 x.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 x.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(L,{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(T,{children:[e.jsx(F,{asChild:!0,children:e.jsx(n,{size:"sm",variant:"ghost",className:"text-destructive",children:"删除"})}),e.jsxs(B,{children:[e.jsxs(I,{children:[e.jsx(G,{children:"确定删除该帖子?"}),e.jsx(H,{children:"相关评论也将一并删除,不可恢复。"})]}),e.jsxs(K,{children:[e.jsx(O,{children:"取消"}),e.jsx(R,{onClick:()=>S(s.id),children:"删除"})]})]})]})]})})]},s.id)})})]}),u.length===0&&e.jsx("div",{className:"admin-empty",children:"没有找到帖子"}),m>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," / ",m," 页"]}),e.jsx(n,{size:"sm",variant:"outline",disabled:d>=m,onClick:()=>l(d+1),children:"下一页"})]})]})})]}):null}export{ee as default};