3 lines
16 KiB
JavaScript
3 lines
16 KiB
JavaScript
import{j as e,r,v as he}from"./router-zNjPR4CY.js";import{g as s,ak as U,B as x,C as $,af as ge,I as pe,ag as fe,ah as je}from"./index-CuOHsLf7.js";import{S as M,a as V,b as W,c as q,d as j}from"./select-DGqIoF9r.js";import{S as be}from"./slider-mDhSC-zv.js";import{g as te,D as we,z}from"./misc-BwRzHX8c.js";import{G as Ne,y as ve,a as se,S as ye,aG as ke,aA as Ce,v as Se,aH as Q,aw as O,C as Re,aI as J,X as ze,aJ as _e,R as Le}from"./icons-DTcdLw9j.js";import{P as X,a as Y,b as K}from"./popover-DSuRLFDH.js";import{l as R}from"./log-websocket-BnMQh0M3.js";import{f as T}from"./utils-DjBw3JGv.js";import"./radix-C-ZuImoP.js";import"./unified-ws-CBnrIqHW.js";function Z({className:u,classNames:b,showOutsideDays:n=!0,captionLayout:w="label",buttonVariant:h="ghost",formatters:N,components:v,...L}){const a=te();return e.jsx(we,{showOutsideDays:n,className:s("bg-background group/calendar p-3 [--cell-size:2rem] [[data-slot=card-content]_&]:bg-transparent [[data-slot=popover-content]_&]:bg-transparent",String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,u),captionLayout:w,formatters:{formatMonthDropdown:c=>c.toLocaleString("default",{month:"short"}),...N},classNames:{root:s("w-fit",a.root),months:s("relative flex flex-col gap-4 md:flex-row",a.months),month:s("flex w-full flex-col gap-4",a.month),nav:s("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",a.nav),button_previous:s(U({variant:h}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",a.button_previous),button_next:s(U({variant:h}),"h-[--cell-size] w-[--cell-size] select-none p-0 aria-disabled:opacity-50",a.button_next),month_caption:s("flex h-[--cell-size] w-full items-center justify-center px-[--cell-size]",a.month_caption),dropdowns:s("flex h-[--cell-size] w-full items-center justify-center gap-1.5 text-sm font-medium",a.dropdowns),dropdown_root:s("has-focus:border-ring border-input shadow-xs has-focus:ring-ring/50 has-focus:ring-[3px] relative rounded-md border",a.dropdown_root),dropdown:s("bg-popover absolute inset-0 opacity-0",a.dropdown),caption_label:s("select-none font-medium",w==="label"?"text-sm":"[&>svg]:text-muted-foreground flex h-8 items-center gap-1 rounded-md pl-2 pr-1 text-sm [&>svg]:size-3.5",a.caption_label),table:"w-full border-collapse",weekdays:s("flex",a.weekdays),weekday:s("text-muted-foreground flex-1 select-none rounded-md text-[0.8rem] font-normal",a.weekday),week:s("mt-2 flex w-full",a.week),week_number_header:s("w-[--cell-size] select-none",a.week_number_header),week_number:s("text-muted-foreground select-none text-[0.8rem]",a.week_number),day:s("group/day relative aspect-square h-full w-full select-none p-0 text-center [&:first-child[data-selected=true]_button]:rounded-l-md [&:last-child[data-selected=true]_button]:rounded-r-md",a.day),range_start:s("bg-accent rounded-l-md",a.range_start),range_middle:s("rounded-none",a.range_middle),range_end:s("bg-accent rounded-r-md",a.range_end),today:s("bg-accent text-accent-foreground rounded-md data-[selected=true]:rounded-none",a.today),outside:s("text-muted-foreground aria-selected:text-muted-foreground",a.outside),disabled:s("text-muted-foreground opacity-50",a.disabled),hidden:s("invisible",a.hidden),...b},components:{Root:({className:c,rootRef:o,...p})=>e.jsx("div",{"data-slot":"calendar",ref:o,className:s(c),...p}),Chevron:({className:c,orientation:o,...p})=>o==="left"?e.jsx(Ne,{className:s("size-4",c),...p}):o==="right"?e.jsx(ve,{className:s("size-4",c),...p}):e.jsx(se,{className:s("size-4",c),...p}),DayButton:Ie,WeekNumber:({children:c,...o})=>e.jsx("td",{...o,children:e.jsx("div",{className:"flex size-[--cell-size] items-center justify-center text-center",children:c})}),...v},...L})}function Ie({className:u,day:b,modifiers:n,...w}){const h=te(),N=r.useRef(null);return r.useEffect(()=>{n.focused&&N.current?.focus()},[n.focused]),e.jsx(x,{ref:N,variant:"ghost",size:"icon","data-day":b.date.toLocaleDateString(),"data-selected-single":n.selected&&!n.range_start&&!n.range_end&&!n.range_middle,"data-range-start":n.range_start,"data-range-end":n.range_end,"data-range-middle":n.range_middle,className:s("data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground data-[range-middle=true]:bg-accent data-[range-middle=true]:text-accent-foreground data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-ring/50 flex aspect-square h-auto w-full min-w-[--cell-size] flex-col gap-1 font-normal leading-none data-[range-end=true]:rounded-md data-[range-middle=true]:rounded-none data-[range-start=true]:rounded-md group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:ring-[3px] [&>span]:text-xs [&>span]:opacity-70",h.day,u),...w})}const _={xs:{label:"小",rowHeight:28,class:"text-[10px] sm:text-xs"},sm:{label:"中",rowHeight:36,class:"text-xs sm:text-sm"},base:{label:"大",rowHeight:44,class:"text-sm sm:text-base"}},ee={DEBUG:10,INFO:20,WARNING:30,ERROR:40,CRITICAL:50};function $e(){const[u,b]=r.useState([]),[n,w]=r.useState(""),[h,N]=r.useState("INFO"),[v,L]=r.useState("all"),[a,c]=r.useState(void 0),[o,p]=r.useState(void 0),[m,I]=r.useState(!0),[B,ae]=r.useState(!1),[D,le]=r.useState("xs"),[y,re]=r.useState(4),[E,ne]=r.useState(!1),F=r.useRef(null);r.useEffect(()=>{const t=R.getAllLogs();b(t);const l=R.onLog(()=>{b(R.getAllLogs())}),f=R.onConnectionChange(g=>{ae(g)});return()=>{l(),f()}},[]);const oe=r.useMemo(()=>{const t=new Set(u.map(l=>l.module).filter(l=>l&&l.trim()!==""));return Array.from(t).sort()},[u]),P=t=>{switch(t){case"DEBUG":return"text-muted-foreground";case"INFO":return"text-blue-500 dark:text-blue-400";case"WARNING":return"text-yellow-600 dark:text-yellow-500";case"ERROR":return"text-red-600 dark:text-red-500";case"CRITICAL":return"text-red-700 dark:text-red-400 font-bold";default:return"text-foreground"}},ce=t=>{switch(t){case"DEBUG":return"bg-gray-800/30 dark:bg-gray-800/50";case"INFO":return"bg-blue-900/20 dark:bg-blue-500/20";case"WARNING":return"bg-yellow-900/20 dark:bg-yellow-500/20";case"ERROR":return"bg-red-900/20 dark:bg-red-500/20";case"CRITICAL":return"bg-red-900/30 dark:bg-red-600/30";default:return"bg-gray-800/20 dark:bg-gray-800/30"}},de=()=>{window.location.reload()},ie=()=>{R.clearLogs(),b([])},G=()=>{const t=i.map(d=>`${d.timestamp} [${d.level.padEnd(8)}] [${d.module}] ${d.message}`).join(`
|
|
`),l=new Blob([t],{type:"text/plain;charset=utf-8"}),f=URL.createObjectURL(l),g=document.createElement("a");g.href=f,g.download=`logs-${T(new Date,"yyyy-MM-dd-HHmmss")}.txt`,g.click(),URL.revokeObjectURL(f)},xe=()=>{I(!m)},me=()=>{c(void 0),p(void 0)},i=r.useMemo(()=>u.filter(t=>{const l=n===""||t.message.toLowerCase().includes(n.toLowerCase())||t.module.toLowerCase().includes(n.toLowerCase()),f=h==="all"||ee[t.level]>=ee[h],g=v==="all"||t.module===v;let d=!0;if(a||o){const C=new Date(t.timestamp);if(a){const S=new Date(a);S.setHours(0,0,0,0),d=d&&C>=S}if(o){const S=new Date(o);S.setHours(23,59,59,999),d=d&&C<=S}}return l&&f&&g&&d}),[u,n,h,v,a,o]),ue=_[D].rowHeight+y,k=he({count:i.length,getScrollElement:()=>F.current,estimateSize:()=>ue,overscan:50}),A=r.useRef(!1),H=r.useRef(i.length);return r.useEffect(()=>{const t=F.current;if(!t)return;const l=()=>{if(A.current)return;const{scrollTop:f,scrollHeight:g,clientHeight:d}=t,C=g-f-d;C>100&&m?I(!1):C<50&&!m&&I(!0)};return t.addEventListener("scroll",l,{passive:!0}),()=>t.removeEventListener("scroll",l)},[m]),r.useEffect(()=>{const t=i.length>H.current;H.current=i.length,m&&i.length>0&&t&&(A.current=!0,k.scrollToIndex(i.length-1,{align:"end",behavior:"auto"}),requestAnimationFrame(()=>{requestAnimationFrame(()=>{A.current=!1})}))},[i.length,m,k]),e.jsxs("div",{className:"h-full flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex-shrink-0 space-y-2 sm:space-y-3 p-2 sm:p-3 lg:p-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-lg sm:text-xl lg:text-2xl font-bold",children:"日志查看器"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5 hidden sm:block",children:"实时查看和分析麦麦运行日志"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:s("h-2 w-2 sm:h-2.5 sm:w-2.5 rounded-full",B?"bg-green-500 animate-pulse":"bg-red-500")}),e.jsx("span",{className:"text-xs text-muted-foreground",children:B?"已连接":"未连接"})]})]}),e.jsx($,{className:"p-2 sm:p-3",children:e.jsx(ge,{open:E,onOpenChange:ne,children:e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"flex-1 relative min-w-0",children:[e.jsx(ye,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),e.jsx(pe,{placeholder:"搜索日志...",value:n,onChange:t=>w(t.target.value),className:"pl-8 h-8 text-xs sm:text-sm"})]}),e.jsxs("div",{className:"flex gap-1 flex-shrink-0",children:[e.jsxs(x,{variant:m?"default":"outline",size:"sm",onClick:xe,className:"h-8 px-2",title:m?"自动滚动":"已暂停",children:[m?e.jsx(ke,{className:"h-3.5 w-3.5"}):e.jsx(Ce,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden sm:inline",children:m?"滚动":"暂停"})]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:ie,className:"h-8 px-2",title:"清空日志",children:[e.jsx(Se,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden md:inline",children:"清空"})]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:G,className:"h-8 px-2 hidden sm:flex",title:"导出日志",children:[e.jsx(Q,{className:"h-3.5 w-3.5"}),e.jsx("span",{className:"ml-1 text-xs hidden lg:inline",children:"导出"})]}),e.jsx(fe,{asChild:!0,children:e.jsxs(x,{variant:"outline",size:"sm",className:"h-8 px-2",title:E?"收起筛选":"展开筛选",children:[e.jsx(O,{className:"h-3.5 w-3.5"}),E?e.jsx(Re,{className:"h-3.5 w-3.5 ml-1"}):e.jsx(se,{className:"h-3.5 w-3.5 ml-1"})]})})]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground text-center sm:text-right -mt-1",children:[e.jsxs("span",{className:"font-mono",children:[i.length," / ",u.length]}),e.jsx("span",{className:"ml-1",children:"条日志"})]}),e.jsxs(je,{className:"space-y-2",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(M,{value:h,onValueChange:t=>N(t),children:[e.jsxs(V,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(O,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(W,{placeholder:"最低级别"})]}),e.jsxs(q,{children:[e.jsx(j,{value:"all",children:"全部级别"}),e.jsx(j,{value:"DEBUG",children:"DEBUG 及以上"}),e.jsx(j,{value:"INFO",children:"INFO 及以上"}),e.jsx(j,{value:"WARNING",children:"WARNING 及以上"}),e.jsx(j,{value:"ERROR",children:"ERROR 及以上"}),e.jsx(j,{value:"CRITICAL",children:"CRITICAL"})]})]}),e.jsxs(M,{value:v,onValueChange:L,children:[e.jsxs(V,{className:"w-full sm:flex-1 h-8 text-xs",children:[e.jsx(O,{className:"h-3.5 w-3.5 mr-1.5"}),e.jsx(W,{placeholder:"模块"})]}),e.jsxs(q,{children:[e.jsx(j,{value:"all",children:"全部模块"}),oe.map(t=>e.jsx(j,{value:t,children:t},t))]})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:gap-2",children:[e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsxs(x,{variant:"outline",size:"sm",className:s("w-full sm:flex-1 justify-start text-left font-normal h-8",!a&&"text-muted-foreground"),children:[e.jsx(J,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:a?T(a,"PP",{locale:z}):"开始日期"})]})}),e.jsx(K,{className:"w-auto p-0",align:"start",children:e.jsx(Z,{mode:"single",selected:a,onSelect:c,initialFocus:!0,locale:z})})]}),e.jsxs(X,{children:[e.jsx(Y,{asChild:!0,children:e.jsxs(x,{variant:"outline",size:"sm",className:s("w-full sm:flex-1 justify-start text-left font-normal h-8",!o&&"text-muted-foreground"),children:[e.jsx(J,{className:"mr-1.5 h-3.5 w-3.5"}),e.jsx("span",{className:"text-xs",children:o?T(o,"PP",{locale:z}):"结束日期"})]})}),e.jsx(K,{className:"w-auto p-0",align:"start",children:e.jsx(Z,{mode:"single",selected:o,onSelect:p,initialFocus:!0,locale:z})})]}),(a||o)&&e.jsxs(x,{variant:"outline",size:"sm",onClick:me,className:"w-full sm:w-auto h-8",children:[e.jsx(ze,{className:"h-3.5 w-3.5 sm:mr-1"}),e.jsx("span",{className:"text-xs",children:"清除"})]})]}),e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-3 pt-2 border-t border-border/50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[e.jsx(_e,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:"字号"})]}),e.jsx("div",{className:"flex gap-1",children:Object.keys(_).map(t=>e.jsx(x,{variant:D===t?"default":"outline",size:"sm",onClick:()=>le(t),className:"h-6 px-2 text-xs",children:_[t].label},t))})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-1 max-w-[200px]",children:[e.jsx("span",{className:"text-xs text-muted-foreground whitespace-nowrap",children:"行距"}),e.jsx(be,{value:[y],onValueChange:([t])=>re(t),min:0,max:12,step:2,className:"flex-1"}),e.jsxs("span",{className:"text-xs text-muted-foreground w-7",children:[y,"px"]})]}),e.jsxs("div",{className:"flex gap-2 sm:hidden",children:[e.jsxs(x,{variant:"outline",size:"sm",onClick:de,className:"flex-1 h-8",children:[e.jsx(Le,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"刷新"})]}),e.jsxs(x,{variant:"outline",size:"sm",onClick:G,className:"flex-1 h-8",children:[e.jsx(Q,{className:"h-3.5 w-3.5 mr-1"}),e.jsx("span",{className:"text-xs",children:"导出"})]})]})]})]})]})})})]}),e.jsx("div",{className:"flex-1 min-h-0 px-2 sm:px-3 lg:px-4 pb-2 sm:pb-3 lg:pb-4",children:e.jsx($,{className:"bg-black dark:bg-gray-950 border-gray-800 dark:border-gray-900 h-full overflow-hidden",children:e.jsx("div",{ref:F,className:s("h-full overflow-auto","[&::-webkit-scrollbar]:w-2.5","[&::-webkit-scrollbar-track]:bg-transparent","[&::-webkit-scrollbar-thumb]:bg-border [&::-webkit-scrollbar-thumb]:rounded-full","[&::-webkit-scrollbar-thumb:hover]:bg-border/80"),children:e.jsx("div",{className:s("p-2 sm:p-3 font-mono relative",_[D].class),style:{height:`${k.getTotalSize()}px`},children:i.length===0?e.jsx("div",{className:"text-gray-500 dark:text-gray-600 text-center py-8 text-xs sm:text-sm",children:"暂无日志数据"}):k.getVirtualItems().map(t=>{const l=i[t.index];return e.jsxs("div",{"data-index":t.index,ref:k.measureElement,className:s("absolute top-0 left-0 w-full px-2 sm:px-3 rounded hover:bg-white/5 transition-colors",ce(l.level)),style:{transform:`translateY(${t.start}px)`,paddingTop:`${y/2}px`,paddingBottom:`${y/2}px`},children:[e.jsxs("div",{className:"flex flex-col gap-0.5 sm:hidden",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 text-[10px]",children:l.timestamp}),e.jsxs("span",{className:s("font-semibold text-[10px]",P(l.level)),children:["[",l.level,"]"]})]}),e.jsx("div",{className:"text-cyan-400 dark:text-cyan-500 truncate text-[10px]",children:l.module}),e.jsx("div",{className:"text-gray-300 dark:text-gray-400 whitespace-pre-wrap break-words text-[10px]",children:l.message})]}),e.jsxs("div",{className:"hidden sm:flex gap-2 items-start",children:[e.jsx("span",{className:"text-gray-500 dark:text-gray-600 flex-shrink-0 w-[130px] lg:w-[160px]",children:l.timestamp}),e.jsxs("span",{className:s("flex-shrink-0 w-[65px] lg:w-[75px] font-semibold",P(l.level)),children:["[",l.level,"]"]}),e.jsx("span",{className:"text-cyan-400 dark:text-cyan-500 flex-shrink-0 w-[100px] lg:w-[130px] truncate",children:l.module}),e.jsx("span",{className:"text-gray-300 dark:text-gray-400 flex-1 whitespace-pre-wrap break-words",children:l.message})]})]},t.key)})})})})})]})}export{$e as LogViewerPage};
|