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

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

2 lines
7.6 KiB
JavaScript

import{j as e,r as t,e as K,g as Q,i as Z,x as C}from"./react-vendor-BdyZmpPe.js";import{c as ee,B as se,u as te,p as ae,g as M,a as re,b as A,n as ne,s as oe,F as V,d as le,e as ce,f as ie}from"./index-Cp7Ff9NP.js";import{u as de}from"./virtual-vendor-rtLkLCpN.js";import{P as ue,B as fe}from"./PinnedIcon-Dc0ZpCCq.js";import{f as U}from"./content-BrFHUpp8.js";import{M as me,$ as he,U as xe,X as pe,a0 as je}from"./ui-vendor-B26O8baZ.js";function ve({post:s,sort:i="latest",onClick:d}){var g,l,c,a;const o=((l=(g=s.user)==null?void 0:g.nickname)==null?void 0:l[0])||"?",v=i==="reply"?s.last_reply_at?`${U(s.last_reply_at)} 回复`:"暂无回复":U(s.created_at),N=s.comment_count??0,m=s.like_count??0;return e.jsxs("div",{className:"post-row",onClick:d,children:[e.jsx("div",{className:"post-avatar",children:(c=s.user)!=null&&c.avatar?e.jsx("img",{src:s.user.avatar,alt:""}):o}),e.jsxs("div",{className:"post-body",children:[e.jsxs("div",{className:"post-title",children:[s.pinned&&e.jsx(ue,{className:"mr-1.5"}),s.title]}),e.jsxs("div",{className:"post-meta",children:[s.board&&e.jsx(fe,{board:s.board}),e.jsx("span",{children:((a=s.user)==null?void 0:a.nickname)||"匿名"}),e.jsx("span",{children:v})]})]}),e.jsxs("div",{className:"post-stats",children:[e.jsxs("span",{className:`post-stat${N===0?" post-stat--zero":""}`,children:[e.jsx(me,{"aria-hidden":!0}),N]}),e.jsxs("span",{className:`post-stat${m===0?" post-stat--zero":""}`,children:[e.jsx(he,{"aria-hidden":!0}),m]})]})]})}function w({className:s,...i}){return e.jsx("div",{className:ee("skeleton",s),...i})}function O({count:s=8}){return e.jsx("div",{className:"post-list-skeleton","aria-busy":"true","aria-label":"加载中",children:Array.from({length:s},(i,d)=>e.jsxs("div",{className:"post-row post-row--skeleton",children:[e.jsx(w,{className:"skeleton--avatar"}),e.jsxs("div",{className:"post-body",children:[e.jsx(w,{className:"skeleton--title",style:{width:`${55+d%4*10}%`}}),e.jsxs("div",{className:"skeleton-meta-row",children:[e.jsx(w,{className:"skeleton--badge"}),e.jsx(w,{className:"skeleton--meta"}),e.jsx(w,{className:"skeleton--meta skeleton--meta-short"})]})]}),e.jsxs("div",{className:"post-stats",children:[e.jsx(w,{className:"skeleton--stat"}),e.jsx(w,{className:"skeleton--stat"})]})]},d))})}function Ne({posts:s,sort:i="latest",loading:d,hasMore:o,canAutoLoad:v,postTotal:N,onLoadMore:m,onSelect:g,restoreScrollTop:l,resetScrollKey:c=0,onScrollTopChange:a,onScrollRestored:r}){const h=t.useRef(null),b=t.useRef(!1),x=de({count:s.length,getScrollElement:()=>h.current,estimateSize:()=>72,overscan:8}),F=o&&!v&&!d,y=!o&&s.length>0&&!d,P=d&&s.length===0,_=d&&s.length>0;return t.useLayoutEffect(()=>{if(c<=0)return;const u=h.current;u&&(u.scrollTop=0,x.scrollToOffset(0)),b.current=!0,a==null||a(0)},[c,x,a]),t.useLayoutEffect(()=>{l==null||b.current||s.length===0||(x.scrollToOffset(l),b.current=!0,r==null||r())},[l,s.length,x,r]),t.useEffect(()=>{b.current=!1},[l]),t.useEffect(()=>{const u=h.current;if(!u)return;const p=()=>{a==null||a(u.scrollTop),u.scrollTop+u.clientHeight>=u.scrollHeight-120&&v&&o&&!d&&m()};return u.addEventListener("scroll",p),()=>u.removeEventListener("scroll",p)},[v,o,d,m,a]),e.jsx("div",{className:"post-list-scroll",ref:h,children:P?e.jsx(O,{}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"content-surface",style:{height:x.getTotalSize(),position:"relative"},children:x.getVirtualItems().map(u=>{const p=s[u.index];return e.jsx("div",{style:{position:"absolute",top:0,left:0,width:"100%",transform:`translateY(${u.start}px)`},children:e.jsx(ve,{post:p,sort:i,onClick:()=>g(p.id)})},p.id)})}),_&&e.jsx(O,{count:2}),F&&e.jsxs("div",{className:"feed-list-footer feed-list-footer--history",children:[e.jsxs("p",{className:"feed-list-footer__hint",children:["已显示 ",s.length," / ",N," 条"]}),e.jsx(se,{type:"button",variant:"outline",size:"sm",onClick:m,children:"加载更多历史"})]}),y&&e.jsx("div",{className:"feed-list-footer feed-list-footer--end",children:"— 已加载全部 —"})]})})}function ge({boardId:s,keyword:i,boards:d,stats:o,postTotal:v}){const N=K(),m=d.find(c=>c.id===s),g=i?`搜索:${i}`:s&&m?m.name:"全部帖子",l=s&&m&&m.description||"";return e.jsxs("div",{className:`feed-head${i?" feed-head--solo":""}`,children:[e.jsxs("div",{className:"feed-head__title",children:[e.jsx("h2",{title:l||void 0,children:g}),!i&&o&&e.jsxs("div",{className:"feed-head__stats",children:[e.jsxs("span",{className:"feed-stat-chip",children:[e.jsx(xe,{"aria-hidden":!0}),"会员 ",e.jsx("strong",{children:o.users})]}),e.jsxs("span",{className:"feed-stat-chip",children:[e.jsx(pe,{"aria-hidden":!0}),"帖子 ",e.jsx("strong",{children:o.posts})]}),e.jsxs("span",{className:"feed-stat-chip",children:[e.jsx(je,{"aria-hidden":!0}),"板块 ",e.jsx("strong",{children:o.boards})]})]})]}),i&&e.jsx("button",{type:"button",className:"feed-head__clear",onClick:()=>N("/"),children:"清除搜索"}),i&&e.jsxs("span",{className:"feed-toolbar__count",children:["共 ",v," 条"]})]})}function Le(){const s=K(),i=Q(),[d]=Z(),o=C(),{limits:v}=te(),N=v.page_size_default,m=v.feed_max_pages,g=v.feed_max_items,l=Number(d.get("board"))||(o==null?void 0:o.boardId)||0,c=d.get("keyword")||"",a=ae(d.get("sort")),r=M(l,c,a),[h,b]=t.useState(()=>(r==null?void 0:r.posts)??[]),[x,F]=t.useState(()=>(r==null?void 0:r.postTotal)??0),[y,P]=t.useState(()=>(r==null?void 0:r.page)??1),[_,u]=t.useState(()=>(r==null?void 0:r.hasMore)??!0),[p,T]=t.useState(()=>!r),[D,z]=t.useState(()=>(r==null?void 0:r.scrollTop)??null),[G,W]=t.useState(0),R=t.useRef((r==null?void 0:r.scrollTop)??0),S=t.useRef(null),$=t.useRef(!1),X=t.useMemo(()=>_&&y<m&&h.length<g,[_,y,m,h.length,g]),B=t.useCallback(()=>{var n;z(null),R.current=0,W(f=>f+1),(n=S.current)==null||n.scrollTo(0)},[]),k=t.useCallback(()=>{$.current=!0,re(),B()},[B]),E=t.useCallback(async(n,f=!1)=>{T(!0);try{const j=await A.posts({page:n,size:N,board_id:l||"",keyword:c,sort:a==="latest"?"":a}),L=Array.isArray(j.posts)?j.posts:[];b(H=>f?L:[...H,...L]),F(j.total??0),u(!!j.has_more),P(n)}catch(j){ne.error(j instanceof Error?j.message:"加载失败"),f&&b([])}finally{T(!1)}},[l,c,a,N]),I=t.useCallback(async()=>{try{const n=await A.posts({page:1,size:N,board_id:l||"",keyword:c,sort:a==="latest"?"":a}),f=Array.isArray(n.posts)?n.posts:[],j=new Set(f.map(L=>L.id));b(L=>[...f,...L.filter(H=>!j.has(H.id))]),F(n.total??0),u(!!n.has_more)}catch{}},[l,c,a,N]),Y=t.useCallback(()=>{p||!_||E(y+1)},[p,_,y,E]);t.useEffect(()=>{var j;if((j=i.state)==null?void 0:j.refreshFeed){k(),E(1,!0);return}const f=M(l,c,a);if(f){b(f.posts),F(f.postTotal),P(f.page),u(f.hasMore),z(f.scrollTop),R.current=f.scrollTop,T(!1),I();return}z(null),R.current=0,E(1,!0)},[l,c,a,i.key,i.state,E,I,k]),t.useEffect(()=>()=>{$.current||h.length===0||oe(l,c,a,{posts:h,postTotal:x,page:y,hasMore:_,scrollTop:R.current})},[l,c,a,h,x,y,_]),t.useEffect(()=>{!p&&h.length>0&&($.current=!1)},[p,h.length]),t.useEffect(()=>{const n=()=>{k()};return window.addEventListener(V,n),()=>window.removeEventListener(V,n)},[k]),t.useEffect(()=>{const n=()=>{k(),E(1,!0)};return window.addEventListener("posts-refresh",n),()=>window.removeEventListener("posts-refresh",n)},[k,E]);const q=n=>{if(n===a){k(),E(1,!0);return}ce(s,ie(l,n))},J=!c;return e.jsx("div",{className:"page-wrap",ref:S,children:e.jsxs("div",{className:"feed-panel",children:[e.jsxs("div",{className:"feed-top",children:[e.jsx(ge,{boardId:l,keyword:c,boards:(o==null?void 0:o.boards)??[],stats:(o==null?void 0:o.stats)??null,postTotal:x}),J&&e.jsx(le,{value:a,onChange:q,postTotal:x})]}),e.jsx(Ne,{posts:h,sort:a,loading:p,hasMore:_,canAutoLoad:X,postTotal:x,onLoadMore:Y,onSelect:n=>s(`/post/${n}`),restoreScrollTop:D,resetScrollKey:G,onScrollTopChange:n=>{R.current=n},onScrollRestored:()=>z(null)})]})})}export{Le as default};