PageSourceSearch

https://kuaipao.ai/assets/index-DRd2vXWH.js

js kuaipao.ai collected 2026-10-05 14:38:06 UTC 8,691 bytes, 1 lines download raw bytes

1import{j as s,F as O,f as P,S as z,l as L,W as B,X as J,B as R,p as U,Y as H,r as y}from"./semi-ui-DaREz2Dk.js";import{r as c,R as F,e as K,d as V}from"./react-core-CbTnFS3E.js";import{U as G}from"./index-DIEzcWSf.js";import{M as W}from"./index-DwbdS1R8.js";import{r as X,a as Y}from"./index-LW9wZsud.js";import{D as q}from"./docs-CXt4DivS.js";import"./i18n-Bx9xRaoE.js";import"./tools-C_1hZ9u4.js";import"./react-components-BCk5goEb.js";import"./icons-B20TY-5b.js";import"./index-xDewR2Kz.js";function Q({categories:e=[],articles:r=[],activeArticleId:p,onSelectArticle:u,className:d=""}){const[m,b]=c.useState(""),[l,N]=c.useState({});F.useEffect(()=>{if(e.length>0){const a={},i=t=>{t.forEach(o=>{a[o.id]=!0,o.children&&o.children.length>0&&i(o.children)})};i(e),N(a)}},[e]);const v=c.useMemo(()=>{const a={};return r.forEach(i=>{const t=i.category_id||0;a[t]||(a[t]=[]),a[t].push(i)}),a},[r]),x=c.useMemo(()=>{if(!m.trim())return r;const a=m.toLowerCase();return r.filter(i=>i.title.toLowerCase().includes(a)||i.summary&&i.summary.toLowerCase().includes(a))},[r,m]),f=a=>{N(i=>({...i,[a]:!i[a]}))},g=a=>{const i=l[a.id],t=m.trim()?x.filter(o=>o.category_id===a.id):v[a.id]||[];return m.trim()&&t.length===0&&(!a.children||a.children.length===0)?null:s.jsxs("div",{className:"docs-sidebar-category",children:[s.jsxs("div",{className:"docs-sidebar-category-title",onClick:()=>f(a.id),children:[s.jsx("span",{className:"docs-sidebar-category-name",children:a.name}),s.jsx("span",{className:`docs-sidebar-arrow ${i?"expanded":""}`,children:"›"})]}),i&&s.jsxs("div",{className:"docs-sidebar-article-list",children:[t.map(o=>s.jsx("div",{className:`docs-sidebar-article ${p===o.id?"active":""}`,onClick:()=>u(o),title:o.title,children:o.title},o.id)),a.children&&a.children.map(o=>g(o))]})]},a.id)},j=m.trim()?x.filter(a=>!a.category_id):v[0]||[];return s.jsxs("div",{className:`docs-sidebar ${d}`,children:[s.jsx("div",{className:"docs-sidebar-search",children:s.jsx(O,{prefix:s.jsx(P,{}),placeholder:"搜索文档...",value:m,onChange:b,showClear:!0,size:"small"})}),s.jsxs("div",{className:"docs-sidebar-tree",children:[e.map(a=>g(a)),j.length>0&&s.jsxs("div",{className:"docs-sidebar-category",children:[s.jsxs("div",{className:"docs-sidebar-category-title",onClick:()=>f(0),children:[s.jsx("span",{className:"docs-sidebar-category-name",children:"其他"}),s.jsx("span",{className:`docs-sidebar-arrow ${l[0]?"expanded":""}`,children:"›"})]}),l[0]!==!1&&s.jsx("div",{className:"docs-sidebar-article-list",children:j.map(a=>s.jsx("div",{className:`docs-sidebar-article ${p===a.id?"active":""}`,onClick:()=>u(a),title:a.title,children:a.title},a.id))})]})]})]})}function Z(e){if(!e)return"";const r=new Date(e*1e3),u=new Date-r,d=Math.floor(u/(1e3*60*60*24));return d===0?"今天":d===1?"昨天":d<30?`${d} 天前`:`修改于 ${r.toLocaleDateString("zh-CN")}`}function ss({article:e,loading:r=!1,canEdit:p=!1,onEdit:u,articles:d=[],onSelectArticle:m}){const[b,l]=c.useState(0),[N,v]=c.useState(!1),x=c.useRef(null),{prevArticle:f,nextArticle:g}=c.useMemo(()=>{if(!e||!d.length)return{prevArticle:null,nextArticle:null};const t=d.findIndex(o=>o.id===e.id);return{prevArticle:t>0?d[t-1]:null,nextArticle:t>=0&&t<d.length-1?d[t+1]:null}},[e,d]),j=c.useCallback(()=>{const t=x.current;if(!t)return;const o=t.scrollTop,w=t.scrollHeight-t.clientHeight;w>0&&l(Math.min(o/w*100,100)),v(o>300)},[]);c.useEffect(()=>{const t=x.current;if(t&&e)return t.addEventListener("scroll",j,{passive:!0}),t.scrollTop=0,l(0),v(!1),()=>t.removeEventListener("scroll",j)},[e,j]);const a=()=>{var t;(t=x.current)==null||t.scrollTo({top:0,behavior:"smooth"})},i=t=>{t&&m&&m(t)};return r?s.jsx("div",{className:"docs-content-scroll",children:s.jsx("div",{className:"docs-empty",children:s.jsx(z,{size:"large"})})}):e?s.jsxs("div",{className:"docs-content-scroll",ref:x,children:[s.jsx("div",{className:"docs-progress-bar",children:s.jsx("div",{className:"docs-progress-bar-fill",style:{width:`${b}%`}})}),s.jsxs("div",{className:"docs-content",children:[s.jsxs("div",{className:"docs-breadcrumb",children:[s.jsx("a",{onClick:()=>window.location.href="/docs",children:"文档中心"}),s.jsx("span",{className:"separator",children:"›"}),s.jsx("span",{children:e.title})]}),s.jsxs("div",{className:"docs-content-header",children:[s.jsx("h1",{className:"docs-content-title",children:e.title}),s.jsxs("div",{className:"docs-content-meta",children:[e.content_type&&s.jsx(L,{size:"small",color:"blue",style:{borderRadius:12},children:e.content_type==="openapi"?"API 文档":"Markdown"}),s.jsxs("span",{children:[s.jsx(B,{size:"small"}),Z(e.updated_at||e.created_at)]}),s.jsxs("span",{children:[s.jsx(J,{size:"small"}),e.view_count||e.views||0," 次浏览"]})]}),p&&u&&s.jsx("div",{className:"docs-content-actions",children:s.jsx(R,{icon:s.jsx(U,{}),size:"small",theme:"light",onClick:()=>u(e),children:"编辑"})})]}),e.content_type==="openapi"?s.jsx("div",{className:"docs-markdown-body",children:s.jsx("pre",{children:s.jsx("code",{children:e.content})})}):s.jsx("div",{className:"docs-markdown-body",children:s.jsx(W,{remarkPlugins:[H,Y],rehypePlugins:[X],children:e.content||""})}),(f||g)&&s.jsxs("div",{className:"docs-page-nav",children:[f?s.jsxs("div",{className:"docs-page-nav-item prev",onClick:()=>i(f),children:[s.jsx("span",{className:"docs-page-nav-arrow",children:"←"}),s.jsxs("div",{className:"docs-page-nav-info",children:[s.jsx("span",{className:"docs-page-nav-label",children:"上一页"}),s.jsx("span",{className:"docs-page-nav-title",children:f.title})]})]}):s.jsx("div",{className:"docs-page-nav-placeholder"}),g?s.jsxs("div",{className:"docs-page-nav-item next",onClick:()=>i(g),children:[s.jsxs("div",{className:"docs-page-nav-info",children:[s.jsx("span",{className:"docs-page-nav-label",children:"下一页"}),s.jsx("span",{className:"docs-page-nav-title",children:g.title})]}),s.jsx("span",{className:"docs-page-nav-arrow",children:"→"})]}):s.jsx("div",{className:"docs-page-nav-placeholder"})]})]}),s.jsx("button",{className:`docs-back-to-top ${N?"visible":""}`,onClick:a,title:"回到顶部",children:"↑"})]}):s.jsx("div",{className:"docs-content-scroll",children:s.jsxs("div",{className:"docs-empty",children:[s.jsx("div",{className:"docs-empty-icon",children:"📖"}),s.jsx("div",{className:"docs-empty-text",children:"选择左侧文档开始阅读"})]})})}const C="/api/docs";async function T(e){return(await fetch(e)).json()}async function es(e,r){const p=localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")).id:0;return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json","New-Api-User":String(p)},body:JSON.stringify(r)})).json()}async function as(e,r){const p=localStorage.getItem("user")?JSON.parse(localStorage.getItem("user")).id:0;return(await fetch(e,{method:"PUT",headers:{"Content-Type":"application/json","New-Api-User":String(p)},body:JSON.stringify(r)})).json()}function us(){var E,$,I;const[e]=c.useContext(G);K();const[r,p]=V(),[u,d]=c.useState([]),[m,b]=c.useState([]),[l,N]=c.useState(null),[v,x]=c.useState(!1),[f,g]=c.useState(!1),[j,a]=c.useState(!1),[i,t]=c.useState(null),o=!!((E=e==null?void 0:e.user)!=null&&E.username),w=(($=e==null?void 0:e.user)==null?void 0:$.role)>=10,S=c.useCallback(async()=>{try{const n=await T(`${C}/sidebar`);if(n.success&&(d(n.data.categories||[]),b(n.data.articles||[]),!r.get("id")&&n.data.articles&&n.data.articles.length>0)){const M=n.data.articles[0];p({id:M.id},{replace:!0})}}catch(n){console.error("加载侧边栏数据失败:",n)}},[]),k=c.useCallback(async n=>{x(!0);try{const h=await T(`${C}/articles/${n}`);h.success?N(h.data):y.error(h.message||"加载文档失败")}catch{y.error("加载文档失败")}finally{x(!1)}},[]);c.useEffect(()=>{S()},[S]),c.useEffect(()=>{const n=r.get("id");n&&k(Number(n))},[r,k]);const A=n=>{p({id:n.id}),g(!1)},_=n=>{t(n),a(!0)},D=async n=>{try{let h;n.id?h=await as(`${C}/articles/${n.id}`,n):h=await es(`${C}/articles`,n),h.success?(y.success(h.message||"保存成功"),a(!1),t(null),S(),n.id&&(l==null?void 0:l.id)===n.id&&k(n.id)):y.error(h.message||"保存失败")}catch(h){y.error("保存失败: "+h.message)}};return s.jsxs("div",{className:"docs-page",children:[s.jsx(Q,{categories:u,articles:m,activeArticleId:l==null?void 0:l.id,onSelectArticle:A,className:f?"mobile-open":""}),s.jsx(ss,{article:l,loading:v,canEdit:w||o&&(l==null?void 0:l.author_id)===((I=e==null?void 0:e.user)==null?void 0:I.id),onEdit:_,articles:m,onSelectArticle:A}),s.jsx("button",{className:"docs-mobile-toggle",onClick:()=>g(!f),children:f?"✕":"☰"}
1),s.jsx(q,{visible:j,article:i,categories:u,onSave:D,onClose:()=>{a(!1),t(null)}})]})}export{us 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.