2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{r as d,j as e,R as j}from"./react-vendor-jWT2yUdV.js";import{b as y,u as k,k as N,c as f,a as W,d as Q,A as _,P as G,s as J}from"./index-DiaaLdUu.js";import{c as V,b as X,a as P}from"./chunk-B75B6XQK-aFCr8AK6.js";import{c as Y}from"./chunk-NAV3ZXLI-ChbUTMf0.js";import{i as M}from"./chunk-MLPFQTYO-DSnBqIsb.js";import{t as B}from"./chunk-6LIX6LVT-B246pOuK.js";import{M as Z,a as $,b as ee,c as te,d as re,e as ae,f as se}from"./index-DE7yoXMZ.js";import{d as ne}from"./chunk-IHO36JMK-DJPUeGG0.js";import{I as oe}from"./index-DvErMbt6.js";import{l as A}from"./logo-kBMoCJob.js";import{u as T}from"./use-dialog-CRIMuzeE.js";import{u as D,b as O,m as R,O as ie}from"./react-router-dom-C6k78GT4.js";import{m as w}from"./proxy-BsRmjYPH.js";import{s as le,P as ce,w as de}from"./process_utils-Bjmp-2dU.js";import{Q as F}from"./qq_manager-BfRTEAby.js";import"./qface-BZLvZXJ8.js";import"./react-hot-toast-cGcFZPSt.js";import"./usePress-BrNwsdVw.js";import"./useFocusable-DA5Croun.js";import"./chunk-FGM523TA-CgSvUh2a.js";import"./chunk-M3MASYO7-B4fjH-eW.js";import"./index-BsnVex0g.js";import"./chunk-WQVQ7P2I-BJd1EiqP.js";import"./useHover-DC1o5-bm.js";import"./chunk-UX7UMZL5-CMHjUaC_.js";import"./iconBase-B7bT1FlI.js";import"./chunk-RJKRL3AU-CjtrMR1U.js";import"./chunk-AXSF7SRE-Cr4elNVq.js";import"./gestures-BHfQC-M8.js";import"./layout-Buao20KT.js";import"./index-BBhZPeTB.js";const ue=d.createContext(null),S={didCatch:!1,error:null};class fe extends d.Component{constructor(r){super(r),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=S}static getDerivedStateFromError(r){return{didCatch:!0,error:r}}resetErrorBoundary(){const{error:r}=this.state;if(r!==null){for(var t,a,s=arguments.length,n=new Array(s),o=0;o<s;o++)n[o]=arguments[o];(t=(a=this.props).onReset)===null||t===void 0||t.call(a,{args:n,reason:"imperative-api"}),this.setState(S)}}componentDidCatch(r,t){var a,s;(a=(s=this.props).onError)===null||a===void 0||a.call(s,r,t)}componentDidUpdate(r,t){const{didCatch:a}=this.state,{resetKeys:s}=this.props;if(a&&t.error!==null&&me(r.resetKeys,s)){var n,o;(n=(o=this.props).onReset)===null||n===void 0||n.call(o,{next:s,prev:r.resetKeys,reason:"keys"}),this.setState(S)}}render(){const{children:r,fallbackRender:t,FallbackComponent:a,fallback:s}=this.props,{didCatch:n,error:o}=this.state;let c=r;if(n){const h={error:o,resetErrorBoundary:this.resetErrorBoundary};if(typeof t=="function")c=t(h);else if(a)c=d.createElement(a,h);else if(s!==void 0)c=s;else throw o}return d.createElement(ue.Provider,{value:{didCatch:n,error:o,resetErrorBoundary:this.resetErrorBoundary}},c)}}function me(){let i=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return i.length!==r.length||i.some((t,a)=>!Object.is(t,r[a]))}function he({error:i,resetErrorBoundary:r}){return e.jsxs("div",{className:"pt-32 flex flex-col justify-center items-center",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx(Z,{className:"mr-2",color:"red",size:30}),e.jsx("h1",{className:"text-2xl",children:"出错了"})]}),e.jsxs("div",{className:"my-6 flex flex-col justify-center items-center",children:[e.jsx("p",{className:"mb-2",children:"错误信息"}),e.jsx(V,{children:i.message})]}),e.jsx(y,{color:"primary",size:"md",onPress:r,children:"重试"})]})}const q=(i,r=!1)=>i==null?void 0:i.map(t=>{var b;const a=D(),s=O(),[n,o]=j.useState(!!t.autoOpen),c=j.useMemo(()=>t.items&&t.items.length>0,[t.items]),[h]=k(N.backgroundImage,""),[m]=k(N.customIcons,{}),u=j.useMemo(()=>t.href?!!R(t.href,s.pathname):!1,[t.href,s.pathname]),E=C=>{a(C)};j.useEffect(()=>{t.items&&t.items.some(g=>(g==null?void 0:g.href)&&!!R(g.href,s.pathname))&&o(!0)},[t.items,s.pathname]);const p=j.useRef(null);return e.jsxs("div",{children:[e.jsx(y,{className:f("group relative flex items-center w-full h-10 text-left justify-start rounded-xl px-3","transition-all duration-200",u?"bg-primary-500/[0.12] text-primary-600 dark:bg-primary-500/[0.16] dark:text-primary-300 font-semibold shadow-sm shadow-primary-500/10":"text-default-600 hover:bg-default-100/70 hover:text-default-900 dark:text-default-300 dark:hover:bg-white/[0.06]",h&&!u&&"text-white/85 hover:bg-white/15 hover:text-white",u&&"before:absolute before:left-0 before:top-1/2 before:-translate-y-1/2 before:h-5 before:w-[3px] before:rounded-full before:bg-primary-500"),color:"default",disableRipple:!0,endContent:c?e.jsx("div",{className:f("ml-auto relative w-3 h-3 transition-transform duration-300",n&&"transform rotate-180",u?"text-primary-500":"text-default-300 dark:text-white/40","before:rounded-full",'before:content-[""]',"before:block","before:absolute","before:w-3","before:h-[4.5px]","before:bg-current","before:top-1/2","before:-left-[3px]","before:transform","before:-translate-y-1/2","before:rotate-45","after:rounded-full",'after:content-[""]',"after:block","after:absolute","after:w-3","after:h-[4.5px]","after:bg-current","after:top-1/2","after:left-[3px]","after:transform","after:-translate-y-1/2","after:-rotate-45")}):e.jsx("div",{className:f("ml-auto rounded-full transition-all duration-300",u?"w-1.5 h-1.5 bg-primary-500":"w-1 h-1 bg-default-300 dark:bg-white/25 group-hover:bg-primary-300"),"aria-hidden":"true"}),startContent:m[t.label]?e.jsx(M,{radius:"none",src:m[t.label],alt:t.label,className:"w-[18px] h-[18px] flex-shrink-0"}):e.jsx("span",{className:f("flex-shrink-0 transition-transform duration-200 group-hover:scale-110",u?"text-primary-500":"opacity-80"),children:t.icon}),variant:"light",onPress:()=>{t.href?u||E(t.href):c&&o(!n)},children:e.jsx("span",{className:"text-sm",children:t.label})}),e.jsx("div",{ref:p,className:"ml-4 overflow-hidden transition-all duration-300",style:{height:n?(b=p.current)==null?void 0:b.scrollHeight:0},children:t.items&&q(t.items,!0)})]},t.href+t.label)}),xe=i=>{const{items:r}=i;return e.jsx("div",{className:"flex flex-col justify-content-center flex-1 gap-2",children:q(r)})},pe=i=>{const{open:r,items:t,onClose:a}=i,{toggleTheme:s,isDark:n}=W(),{revokeAuth:o}=Q(),c=T(),[h]=k(N.backgroundImage,""),m=!!h,u=()=>{c.confirm({title:"退出登录",content:"确定要退出登录吗?",onConfirm:o})};return e.jsxs(e.Fragment,{children:[e.jsx(_,{initial:!1,children:r&&e.jsx(w.div,{className:"fixed inset-y-0 left-64 right-0 bg-black/20 backdrop-blur-[1px] z-40 md:hidden","aria-hidden":"true",onClick:a,initial:{opacity:0},animate:{opacity:1},exit:{opacity:0,transition:{duration:.15}},transition:{duration:.2,delay:.15}})}),e.jsx(w.div,{className:f("overflow-hidden fixed top-0 left-0 h-full z-50 md:static md:shadow-none rounded-r-2xl md:rounded-none",m?"bg-black/25 backdrop-blur-xl":"bg-white/55 dark:bg-white/[0.03] backdrop-blur-2xl border-r border-white/60 dark:border-white/[0.06] shadow-[8px_0_30px_-24px_rgba(15,23,42,0.35)]","md:border-r-0 md:shadow-none"),initial:{width:0},animate:{width:r?"16rem":0},transition:{type:r?"spring":"tween",stiffness:150,damping:r?15:10},style:{overflow:"hidden"},children:e.jsxs(w.div,{className:"w-64 flex flex-col items-stretch h-full transition-transform duration-300 ease-in-out z-30 relative float-right p-3",children:[e.jsxs("div",{className:"flex items-center justify-start gap-3 px-2 my-5 ml-1",children:[e.jsxs("div",{className:"relative flex-shrink-0",children:[e.jsx("div",{className:f("absolute inset-0 rounded-xl blur-md opacity-70",m?"bg-white/40":"bg-primary-300/50")}),e.jsx(M,{src:A,alt:"SnowCat",width:34,height:34,className:"relative flex-shrink-0 rounded-xl"})]}),e.jsxs("div",{className:"flex flex-col min-w-0",children:[e.jsx("div",{className:f("text-lg font-bold tracking-wide select-none leading-tight",m?"text-white":"text-default-900 dark:text-white"),children:"SnowCat"}),e.jsx("div",{className:f("text-tiny select-none leading-tight tracking-[0.18em]",m?"text-white/60":"text-default-400"),children:"雪猫控制台"})]})]}),e.jsx(ne,{className:"opacity-20 mb-1"}),e.jsxs("div",{className:"overflow-y-auto flex flex-col flex-1 px-1 pt-2 hide-scrollbar",children:[e.jsx(xe,{items:t}),e.jsxs("div",{className:"mt-auto mb-8 md:mb-2 space-y-2 px-1",children:[e.jsx(y,{className:f("w-full font-medium transition-all duration-300 rounded-xl justify-start px-3",m?"bg-white/10 text-white hover:bg-white/20":"bg-default-100/60 text-default-600 hover:bg-default-200/70 dark:bg-white/[0.06] dark:text-default-300"),variant:"flat",onPress:s,startContent:n?e.jsx(ee,{size:17}):e.jsx($,{size:17}),children:n?"切换浅色":"切换深色"}),e.jsx(y,{className:f("w-full mb-2 font-medium transition-all duration-300 rounded-xl justify-start px-3",m?"bg-danger-500/20 text-white hover:bg-danger-500/30":"bg-danger-50/70 text-danger-500 hover:bg-danger-100/80 dark:bg-danger-900/20 dark:text-danger-300"),variant:"flat",onPress:u,startContent:e.jsx(oe,{size:17}),children:"退出登录"})]})]})]})})]})},L=le.navItems,H=(i,r)=>{const t=[];if(r){for(const a of i)if(a.href===r)t.push(a.label);else if(a.items){const s=H(a.items,r);s.length>0&&(t.push(a.label),t.push(...s))}}return t},be=({children:i})=>{const r=O(),t=d.useRef(null),[a,s]=k(N.sideBarOpen,!0),[n]=k(N.backgroundImage,""),o=D(),{isAuth:c,revokeAuth:h}=Q(),m=T(),u=d.useRef(!0),[E,p]=d.useState(!1),[b,C]=d.useState(!1);d.useEffect(()=>{const l=()=>C(!!document.fullscreenElement);return document.addEventListener("fullscreenchange",l),()=>document.removeEventListener("fullscreenchange",l)},[]);const g=d.useCallback(async()=>{try{document.fullscreenElement?await document.exitFullscreen():await document.documentElement.requestFullscreen()}catch{}},[]);d.useEffect(()=>{if(!c)return;const l=async()=>{const z=r.pathname;if(!(z==="/qq_login"||z==="/web_login"))try{const x=await F.getQQLoginInfo();(x==null?void 0:x.online)===!1&&u.current===!0?(u.current=!1,m.confirm({title:"账号已离线",content:"您的 QQ 账号已掉线,是否重启进程以重新登录?",confirmText:"重启进程",cancelText:"退出账户",onConfirm:async()=>{p(!0);try{await ce.restartProcess()}catch{}await de(15e3,()=>{p(!1),window.location.reload()},()=>{p(!1),m.alert({title:"启动超时",content:"后端在 15 秒内未响应,请检查 SnowCat 运行日志或手动重启。"})})},onCancel:()=>{h(),o("/web_login")}})):(x==null?void 0:x.online)===!0&&(u.current=!0)}catch{}},v=setInterval(l,5e3);return l(),()=>clearInterval(v)},[c,r.pathname]);const K=async()=>{try{const l=await F.checkQQLoginStatus();l.isOffline?u.current=!1:l.isLogin||(c?o("/qq_login",{replace:!0}):o("/web_login",{replace:!0}))}catch{o("/web_login",{replace:!0})}};d.useEffect(()=>{var l,v;(v=(l=t==null?void 0:t.current)==null?void 0:l.scrollTo)==null||v.call(l,{top:0,behavior:"smooth"})},[r.pathname]),d.useEffect(()=>{c&&K()},[c]);const I=d.useMemo(()=>H(L,r.pathname),[r.pathname]),U=r.pathname==="/";return e.jsxs("div",{className:"h-screen relative flex items-stretch overflow-hidden",style:{backgroundImage:n?`url(${n})`:void 0,backgroundSize:"cover",backgroundPosition:"center"},children:[e.jsx(G,{loading:E}),e.jsx(pe,{items:L,open:a,onClose:()=>s(!1)}),e.jsxs(w.div,{layout:!0,ref:t,initial:{opacity:0,scale:.98},animate:{opacity:1,scale:1},transition:{duration:.4},className:f("flex-1 overflow-y-auto overflow-x-hidden","transition-all duration-300 ease-in-out","pb-10 md:pb-0"),children:[e.jsxs("header",{className:f("sticky top-0 z-30 h-14 px-3 md:px-6 flex items-center gap-3","border-b border-white/50 dark:border-white/[0.06]","shadow-[0_1px_24px_-16px_rgba(15,23,42,0.4)]",n?"bg-black/25 backdrop-blur-xl":"bg-white/60 dark:bg-white/[0.03] backdrop-blur-2xl"),children:[e.jsx(y,{isIconOnly:!0,radius:"full",variant:"light",size:"sm","aria-label":"切换侧边栏",onPress:()=>s(!a),className:"text-default-500 hover:text-primary",children:a?e.jsx(te,{size:22}):e.jsx(re,{size:22})}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx(M,{src:A,alt:"SnowCat",width:24,height:24,className:"hidden sm:block flex-shrink-0 rounded-md"}),e.jsx("span",{className:f("font-bold tracking-tight text-[15px] hidden sm:inline",n?"text-white":"text-default-800 dark:text-white"),children:"SnowCat"}),e.jsx(Y,{size:"sm",variant:"flat",color:"primary",className:"hidden md:inline-flex h-6 text-[11px] tracking-wider",children:"雪猫控制台"})]}),e.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:e.jsxs(X,{size:"sm",classNames:{list:"flex-nowrap"},children:[U&&e.jsx(P,{children:e.jsx("span",{className:"font-semibold",children:"总览"})},"home"),I==null?void 0:I.map((l,v)=>e.jsx(P,{children:e.jsx(_,{mode:"wait",children:e.jsx(w.div,{initial:{opacity:0,y:-8},animate:{opacity:1,y:0},exit:{opacity:0,y:8},transition:{duration:.25},className:"font-semibold whitespace-nowrap",children:l},l)})},v))]})}),e.jsx(B,{content:"WebSocket / HTTP 双调试台在「接口调试」与「实时调试」",placement:"bottom",children:e.jsx("span",{className:"hidden xl:inline text-tiny text-default-400 whitespace-nowrap",children:"OneBot v11 · 融合自持版"})}),e.jsx(B,{content:b?"退出全屏":"全屏显示",placement:"bottom",children:e.jsx(y,{isIconOnly:!0,radius:"full",variant:"light",size:"sm","aria-label":b?"退出全屏":"全屏显示",onPress:g,className:"text-default-500 hover:text-primary",children:b?e.jsx(ae,{size:22}):e.jsx(se,{size:22})})})]}),e.jsx(fe,{fallbackRender:he,children:i})]})]})};function Xe(){const i=O();return e.jsx(be,{children:e.jsx(d.Suspense,{fallback:e.jsx("div",{className:"flex justify-center px-10",children:e.jsx(J,{})}),children:e.jsx(_,{mode:"wait",children:e.jsx(w.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{type:"tween",ease:"easeInOut"},children:e.jsx(ie,{})},i.pathname)})})})}export{Xe as default};
|