PageSourceSearch

https://roborobo.top/assets/BlogDetailPage-ae7ec2c.D-Bio_Fh.js

js roborobo.top collected 2026-10-07 21:04:05 UTC 17,388 bytes, 5 lines download raw bytes

1import{u as fe,j as t,n as A,b as R,B as v,F as be}from"./index-ae7ec2c.BSswS0a9.js";import{a as l}from"./monaco-ae7ec2c.DBaGHQ0n.js";import{M as ye}from"./MarkdownRenderer-ae7ec2c.DzNP55xY.js";import{F as ve,B as we}from"./BlogShareModal-ae7ec2c.DMZSLdVw.js";function je(n){return n.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/!\[([^\]]*)\]\(((?:https?:\/\/|data:image\/|\/uploads\/)[^\s)]+)\)/g,(S,w,p)=>{const B=String(w).replace(/"/g,"&quot;");return`<img src="${p}" alt="${B}" style="max-width:100%;height:auto;border-radius:10px;margin:8px 0" loading="lazy">`}).replace(/\n/g,"<br>")}function Ce({user:n,blogId:c,commentId:S,onNavigate:w,onUserUpdate:p}){const{themeData:B}=fe(),i=B.isLight,[o,F]=l.useState(null),[j,f]=l.useState([]),[b,C]=l.useState(""),[g,I]=l.useState(null),[y,N]=l.useState(""),[q,P]=l.useState(null),[ie,J]=l.useState(!0),[D,E]=l.useState(!1),[le,M]=l.useState(0),[z,W]=l.useState(!1),[oe,H]=l.useState(0),[K,V]=l.useState(!1),[Y,G]=l.useState(!1),[Q,r]=l.useState(null),[X,L]=l.useState(!1),[T,Z]=l.useState(!1),[de,O]=l.useState(!1),[k,ee]=l.useState(null),ce=async()=>{J(!0);try{const e=await v.get(c);if(e?.code===200&&e.data){const s=e.data;F(s),f((s.comments?.list||[]).map(a=>({id:a.id,content:a.content,createdAt:a.createdAt,parentId:a.parentId||null,replyToUser:a.replyToUser||null,replies:(a.replies||[]).map(d=>({id:d.id,content:d.content,createdAt:d.createdAt,parentId:d.parentId,replyToUser:d.replyToUser||null,user:d.author||d.user||{nickname:"匿名",avatar:"👤"}})),user:a.author||a.user||{nickname:"匿名",avatar:"👤"}}))),M(s.likeCount||s._count?.likes||0),E(s.isLiked||!1),W(s.isFavorited||!1),H(s.favoriteCount||s._count?.favorites||0)}}catch{const s=JSON.parse(localStorage.getItem("oi_blogs")||"[]").find(a=>a.id===c);s&&(F(s),f((s.comments||[]).map(a=>({...a,user:a.user||{nickname:"匿名",avatar:"👤"}}))))}finally{J(!1)}};l.useEffect(()=>{ce()},[c]),l.useEffect(()=>{if(!S)return;let e=0;const s=()=>{const a=document.getElementById(`comment-${S}`);if(a){a.scrollIntoView({behavior:"smooth",block:"center"}),a.classList.add("ring-2","ring-purple-400","rounded-xl","transition-shadow"),setTimeout(()=>a.classList.remove("ring-2","ring-purple-400","rounded-xl","transition-shadow"),2500);return}e++<40&&setTimeout(s,100)};s()},[S,j]);const me=async()=>{if(!n){window.dispatchEvent(new CustomEvent("oi_guest_require_login"));return}if(!D){try{const e=await v.like(c);if(e?.code===200&&e.data)if(E(e.data.liked),M(e.data.likeCount),e.data.liked){const s=JSON.parse(localStorage.getItem("oi_liked_blogs")||"[]");s.includes(c)||(s.push(c),localStorage.setItem("oi_liked_blogs",JSON.stringify(s))),r("❤️ 点赞成功,+5积分已奖励给作者")}else{const s=JSON.parse(localStorage.getItem("oi_liked_blogs")||"[]");localStorage.setItem("oi_liked_blogs",JSON.stringify(s.filter(a=>a!==c))),r("已取消点赞")}}catch{E(!0),M(e=>e+1)}setTimeout(()=>r(null),3e3)}},_=()=>o?.isFeatured&&o?.featuredType==="auto",ue=async()=>{if(!n){window.dispatchEvent(new CustomEvent("oi_guest_require_login"));return}if(!K){V(!0);try{const e=await v.favorite(c);e?.code===200&&e.data?(W(e.data.favorited),H(e.data.favoriteCount),r(e.data.favorited?"🔖 已收藏":"已取消收藏")):r(e?.message||"操作失败,请重试")}catch(e){r(e?.message||"操作失败,请重试")}finally{V(!1),setTimeout(()=>r(null),3e3)}}},xe=async()=>{if(!n){window.dispatchEvent(new CustomEvent("oi_guest_require_login"));return}if(!(T||_())){Z(!0);try{const e=await v.feature(c);e?.code===200?(F(s=>s&&{...s,isFeatured:!0,featuredType:"auto",featuredAt:e.data?.featuredAt||new Date().toISOString(),featuredUntil:e.data?.featuredUntil||null}),r("⭐ 加精成功,已置顶展示 24 小时(消耗 200 积分)"),p?.({...n,points:Math.max(0,(n.points||0)-200)})):r(e?.message||"加精失败,请重试")}catch(e){r(e?.message||"加精失败,请重试")}finally{Z(!1),setTimeout(()=>r(null),3e3)}}},pe=async()=>{O(!1),await xe()},ge=async()=>{if(!n){window.dispatchEvent(new CustomEvent("oi_guest_require_login"));return}if(b.trim()){G(!0);try{const e=await v.comment(c,b.trim());if(e?.code===201&&e.data){const s=e.data.comment;f(a=>[...a,{id:s.id,content:s.content,createdAt:s.createdAt,parentId:s.parentId||null,replyToUser:s.replyToUser||null,replies:[],user:{...s.author||s.user||{},nickname:(s.author||s.user||{}).nickname||n.nickname,avatar:(s.author||s.user||{}).avatar||n.avatar,stageId:(s.author||s.user||{}).stageId||n.stageId}}]),C(""),r("💬 评论成功,+10积分"),p({...n,points:(n.points||0)+(e.data.pointsEarned||10)})}}catch(e){r(e?.message||"评论失败,请重试"),f(s=>[...s,{id:Date.now().toString(),content:b.trim(),createdAt:new Date().toISOString(),parentId:null,replyToUser:null,replies:[],user:{nickname:n.nickname,avatar:n.avatar,stageId:n.stageId}}]),C(""),p({...n,points:(n.points||0)+10})}finally{G(!1),setTimeout(()=>r(null),3e3)}}},te=async e=>{if(!n){window.dispatchEvent(new CustomEvent("oi_guest_require_login"));return}if(y.trim()){P(e);try{const s=await v.comment(c,y.trim(),e);
1if(s?.code===201&&s.data){const a=s.data.comment;f(d=>d.map(u=>u.id===e?{...u,replies:[...u.replies||[],{id:a.id,content:a.content,createdAt:a.createdAt,parentId:a.parentId,replyToUser:a.replyToUser||null,user:{...a.author||a.user||{},nickname:(a.author||a.user||{}).nickname||n.nickname,avatar:(a.author||a.user||{}).avatar||n.avatar,stageId:(a.author||a.user||{}).stageId||n.stageId}}]}:u)),N(""),I(null),r("💬 回复成功,+10积分"),p?.({...n,points:(n.points||0)+(s.data.pointsEarned||10)})}else console.error("回复失败:",s),r(s?.message||"回复失败,请重试")}catch{f(s=>s.map(a=>a.id===e?{...a,replies:[...a.replies||[],{id:Date.now().toString(),content:y.trim(),createdAt:new Date().toISOString(),parentId:e,replyToUser:g?{id:"",nickname:g.nickname}:null,user:{nickname:n.nickname,avatar:n.avatar,stageId:n.stageId}}]}:a)),N(""),I(null),p({...n,points:(n.points||0)+10})}finally{P(null),setTimeout(()=>r(null),3e3)}}},he=(e,s)=>{if(!e.type.startsWith("image/")){r("仅支持图片文件"),setTimeout(()=>r(null),3e3);return}if(e.size>5*1024*1024){r("图片大小不能超过 5MB"),setTimeout(()=>r(null),3e3);return}L(!0);const a=new FileReader;a.onload=async()=>{try{const d=a.result,u=await be.uploadImage(d);if(u?.code===200&&u.data?.url){const ne=`![](${u.data.url})`;s(re=>re?`${re}
2${ne}`:ne)}else r(u?.message||"图片上传失败"),setTimeout(()=>r(null),3e3)}catch{r("图片上传失败,请重试"),setTimeout(()=>r(null),3e3)}finally{L(!1)}},a.onerror=()=>{L(!1),r("读取图片失败"),setTimeout(()=>r(null),3e3)},a.readAsDataURL(e)},ae=e=>s=>{s.preventDefault(),s.stopPropagation();const a=Array.from(s.dataTransfer.files).filter(d=>d.type.startsWith("image/"));if(a.length!==0){if(a.length>1){r("一次只能上传一张图片"),setTimeout(()=>r(null),3e3);return}he(a[0],e)}},U=e=>{const s=new Date(e);return`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")} ${String(s.getHours()).padStart(2,"0")}:${String(s.getMinutes()).padStart(2,"0")}`},$=i?"bg-white border-gray-200":"glass-card border-white/10",h=i?"text-gray-900":"text-white",m=i?"text-gray-500":"text-white/50",se=i?"bg-gray-50 border-gray-200 focus:border-purple-400":"bg-white/5 border-white/10 focus:border-purple-500";if(ie)return t.jsx("div",{className:"max-w-5xl mx-auto px-4 py-6",children:t.jsxs("div",{className:`animate-pulse p-6 rounded-xl ${$}`,children:[t.jsx("div",{className:`h-6 w-3/4 rounded mb-4 ${i?"bg-gray-200":"bg-white/10"}`}),t.jsx("div",{className:`h-4 w-full rounded mb-2 ${i?"bg-gray-100":"bg-white/5"}`}),t.jsx("div",{className:`h-4 w-2/3 rounded ${i?"bg-gray-100":"bg-white/5"}`})]})});if(!o)return t.jsxs("div",{className:"max-w-5xl mx-auto px-4 py-20 text-center",children:[t.jsx("div",{className:"text-5xl mb-4",children:"😕"}),t.jsx("p",{className:m,children:"博客不存在或已被删除"}),t.jsx("button",{onClick:()=>w("blog"),className:"mt-4 text-purple-400 hover:text-purple-300 text-sm",children:"返回博客广场"})]});const x=o.author||o.user||{nickname:"匿名",avatar:"👤"};return t.jsxs("div",{className:"max-w-5xl mx-auto px-4 py-6",children:[t.jsx("style",{children:`
3        @keyframes featuredBlink { 0%,100% { opacity: 1 } 50% { opacity: .5 } }
4        .featured-blink { animation: featuredBlink 1.1s ease-in-out infinite; }
5      `}),t.jsx("button",{onClick:()=>w("blog"),className:`mb-4 px-2 py-1 rounded-lg text-sm ${i?"hover:bg-gray-100 text-gray-600":"hover:bg-white/5 text-white/60"}`,children:"← 返回博客广场"}),Q&&t.jsx("div",{className:`mb-4 p-3 rounded-lg text-sm animate-in slide-in-from-top ${i?"bg-green-50 text-green-700":"bg-green-500/10 text-green-400"}`,children:Q}),t.jsxs("div",{className:`p-6 rounded-xl border ${$}`,children:[t.jsxs("div",{className:"flex items-center gap-3 mb-4 flex-wrap",children:[o.isFeatured&&o.featuredType==="official"&&t.jsx("span",{className:"featured-blink inline-flex items-center gap-1 px-3 py-0.5 rounded-full text-xs font-bold bg-gradient-to-r from-amber-400 to-yellow-500 text-white shadow",children:"⭐ 官方精选"}),o.isFeatured&&o.featuredType==="auto"&&t.jsx("span",{className:"featured-blink inline-flex items-center gap-1 px-3 py-0.5 rounded-full text-xs font-bold bg-gradient-to-r from-orange-500 to-red-500 text-white shadow",children:"🔥 精选"}),t.jsx("h1",{className:`text-2xl font-bold ${h}`,children:o.title}),t.jsx("button",{onClick:()=>ee(o),className:`ml-auto flex items-center gap-1 px-3 py-1 rounded-full text-xs font-medium transition-colors ${i?"bg-green-50 text-green-600 hover:bg-green-100":"bg-green-500/10 text-green-300 hover:bg-green-500/20"}`,title:"分享这篇博客",children:"🔗 分享"})]}),t.jsxs("div",{className:"flex items-center gap-3 mb-6 pb-4 border-b border-gray-200/10",children:[t.jsx("span",{className:"text-2xl",children:t.jsx(A,{value:x.avatar,fallback:"👤"})}),t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center gap-2",children:[x.stageId&&(()=>{const e=R(x.stageId);return t.jsxs("span",{className:`text-xs px-2 py-0.5 rounded-full ${i?"bg-gray-100":"bg-white/10"} ${e.color}`,children:[e.emoji," ",e.name]})})(),t.jsx("span",{className:`font-medium ${h}`,children:x.nickname||"匿名"}),x.id&&t.jsx("button",{onClick:()=>w("blogMy",x.id===n?.id?void 0:{viewUserId:x.id}),className:`ml-1 px-2.5 py-0.5 rounded-full text-[11px] font-medium transition-colors ${i?"bg-purple-100 text-purple-700 hover:bg-purple-200":"bg-purple-500/20 text-purple-300 hover:bg-purple-500/30"}`,children:x.id===n?.id?"📚 我的博客":"📚 去看 TA 的博客"})]}),t.jsxs("div",{className:`text-xs ${m}`,children:[U(o.createdAt)," · 👁 ",o.viewCount||0]})]})]}),o.tags&&t.jsx("div",{className:"flex gap-2 mb-4 flex-wrap",children:o.tags.split(",").filter(
5Boolean).map(e=>t.jsx("span",{className:`px-2.5 py-1 rounded-full text-xs ${i?"bg-purple-50 text-purple-600":"bg-purple-500/10 text-purple-400"}`,children:e.trim()},e))}),o.content&&t.jsx("div",{className:`leading-relaxed text-sm ${m}`,dangerouslySetInnerHTML:{__html:je(o.content)}}),o.contentMd&&t.jsxs("div",{className:"mt-5 pt-5 border-t border-gray-200/10",children:[t.jsx("div",{className:`mb-2 text-xs font-medium ${m}`,children:"📝 Markdown 正文"}),t.jsx(ye,{isLight:i,children:o.contentMd})]}),t.jsxs("div",{className:"flex items-center gap-4 mt-6 pt-4 border-t border-gray-200/10",children:[t.jsxs("button",{onClick:me,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm transition-all ${D?"bg-red-500/20 text-red-400":i?"hover:bg-gray-100 text-gray-500":"hover:bg-white/5 text-white/50"}`,children:[D?"❤️":"🤍"," ",le]}),t.jsxs("button",{onClick:ue,disabled:K,className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm transition-all disabled:opacity-50 ${z?"bg-yellow-500/20 text-yellow-400":i?"hover:bg-gray-100 text-gray-500":"hover:bg-white/5 text-white/50"}`,children:[z?"★":"☆"," ",oe]}),t.jsxs("span",{className:`flex items-center gap-1.5 text-sm ${m}`,children:["💬 ",j.length]}),t.jsx("button",{onClick:()=>O(!0),disabled:T||_(),className:`flex items-center gap-1.5 px-3 py-1.5 rounded-lg text-sm transition-all ${_()?"bg-amber-500/20 text-amber-400":i?"hover:bg-gray-100 text-amber-600":"hover:bg-white/5 text-amber-200/70"} disabled:opacity-50`,children:T?"加精中...":_()?"⭐ 已加精":"⭐ 加精(−200)"})]})]}),t.jsxs("div",{className:"mt-6",children:[t.jsxs("h3",{className:`text-lg font-semibold mb-4 ${h}`,children:["💬 评论 (",j.length,")"]}),n?t.jsxs("div",{className:`flex gap-3 mb-6 p-4 rounded-xl border ${$}`,children:[t.jsx("span",{className:"text-xl shrink-0",children:t.jsx(A,{value:n.avatar})}),t.jsxs("div",{className:"flex-1",children:[t.jsx("textarea",{value:b,onChange:e=>C(e.target.value),onDrop:ae(C),onDragOver:e=>e.preventDefault(),placeholder:"写下你的评论...(支持拖拽图片上传)",rows:2,maxLength:1e3,className:`w-full px-3 py-2 rounded-lg border text-sm outline-none resize-none transition-colors ${se} ${h}`}),t.jsxs("div",{className:"flex justify-between items-center mt-2",children:[t.jsxs("span",{className:`text-xs ${m}`,children:[b.length,"/1000 ",X&&"· 图片上传中..."]}),t.jsx("div",{className:"flex items-center gap-2",children:t.jsx("button",{onClick:ge,disabled:!b.trim()||Y||X,className:"px-4 py-1.5 rounded-lg bg-purple-500 hover:bg-purple-600 text-white text-xs font-medium transition-colors disabled:opacity-40",children:Y?"发送中...":"发表评论"})})]})]})]}):t.jsx("div",{className:`mb-6 p-4 rounded-xl border ${$} text-center`,children:t.jsx("button",{onClick:()=>window.dispatchEvent(new CustomEvent("oi_guest_require_login")),className:"text-purple-400 hover:text-purple-300 text-sm font-medium",children:"登录 / 注册 后参与评论"})}),j.length===0?t.jsx("div",{className:`text-center py-8 text-sm ${m}`,children:"暂无评论,来抢沙发吧~"}):t.jsx("div",{className:"space-y-4",children:j.map(e=>{const s=e.replies?.length||0;return t.jsxs("div",{id:`comment-${e.id}`,className:`rounded-xl border ${$} overflow-hidden`,children:[t.jsxs("div",{className:"flex gap-3 p-4",children:[t.jsx("span",{className:"text-lg shrink-0",children:t.jsx(A,{value:e.user?.avatar,fallback:"👤"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.user?.stageId&&(()=>{const a=R(e.user.stageId);return t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${i?"bg-gray-100":"bg-white/10"} ${a.color}`,children:[a.emoji," ",a.name]})})(),t.jsx("span",{className:`text-sm font-medium ${h}`,children:e.user?.nickname||"匿名"}),t.jsx("span",{className:`text-xs ${m}`,children:U(e.createdAt)})]}),t.jsx("p",{className:`text-sm ${m}`,children:e.content}),t.jsx("button",{onClick:()=>I(g?.commentId===e.id?null:{commentId:e.id,nickname:e.user?.nickname||"匿名"}),className:`mt-1 text-xs transition-colors ${g?.commentId===e.id?"text-purple-400":i?"text-gray-400 hover:text-gray-600":"text-white/30 hover:text-white/50"}`,children:g?.commentId===e.id?"取消回复":"回复"})]})]}),g?.commentId===e.id&&t.jsx("div",{className:"px-4 pb-3 ml-10",children:t.jsxs("div",{className:"flex gap-2",children:[t.jsx("input",{type:"text",value:y,onChange:a=>N(a.target.value),onDrop:ae(N),onDragOver:a=>a.preventDefault(),onKeyDown:a=>a.key==="Enter"&&y.trim()&&te(e.id),placeholder:`回复 ${g.nickname}...(可拖拽图片)`,maxLength:500,className:`flex-1 px-3 py-2 rounded-lg border text-sm outline-none ${se} ${h}`,autoFocus:!0}),t.jsx("button",{onClick:()=>te(e.id),disabled:!y.trim()||q===e.id,className:"px-3 py-2 rounded-lg bg-purple-500 hover:bg-purple-600 text-white text-xs font-medium transition-colors disabled:opacity-40",children:q===e.id?"...":"发送"})]})}),s>0&&t.jsx("div",{className:`ml-10 border-t ${i?"border-gray-100":"border-white/5"}`,children:e.replies.map(a=>t.jsxs("div",{id:`comment-${a.id}`,className:`flex gap-3 px-4 py-3 ${i?"bg-gray-50/50":"bg-white/[0.02]"}`,children:[t.jsx("span",{className:"text-sm shrink-0 mt-0.5",children:t.jsx(A,{value:a.user?.avatar,fallback:"👤"})}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-0.5",children:[a.user?.stageId&&(()=>{const d=R(a.user.stageId);return t.jsxs("span",{className:`text-[10px] px-1.5 py-0.5 rounded-full ${i?"bg-gray-100":"bg-white/10"} ${d.color}`,children:[d.emoji," ",d.name]})})(),t.jsx("span",{className:`text-sm font-medium ${h}`,children:a.user?.nickname||"匿名"}),a.replyToUser&&t.jsxs("span",{className:`text-xs ${m}`,children:["回复 ",t.jsx("span",{className:"text-purple-400",children:a.replyToUser.nickname})]}),t.jsx("span",{className:`text-xs ${m}`,children:U(a.createdAt)})]}),t.jsx("p",{className:`text-sm ${m}`,children:a.content}),t.jsx("button",{onClick:()=>{I({commentId:e.id,nickname:a.user?.nickname||"匿名"}),N(`@${a.user?.nickname||"匿名"} `)},className:`mt-1 text-xs transition-colors ${i?"text-gray-400 hover:text-gray-600":"text-white/30 hover:text-white/50"}`,children:"回复"})]})]},a.id))})]},e.id)})})]}),t.jsx(ve,{open:de,cost:200,points:n?.points||0,busy:T,onConfirm:pe,onCancel:()=>O(!1)}),k&&t.jsx(we,{open:!!k,onClose:()=>ee(null),blog:k,isMine:k.author?.id===n?.id||k.user?.id===n?.id})]})}export{Ce as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.