码桶
发现社区成员的开源项目
MobileBoard-CFceBMIM.js13.9 KB
import{u as z,a as M,r as c,b as T,j as e,T as W,G as B,B as L,f as b,g as N,t as A,l as H,k as P,A as V,y as R,e as O}from"./index-GWuvg2UH.js";import{B as G}from"./index-DihvOmSo.js";import{E as $}from"./index-VbOLTMR0.js";import{S as _}from"./index-BZDftoba.js";import{E as D}from"./EChart-Bps-t-O3.js";import{u as C}from"./useVisibilityRefresh-DRH6QDT3.js";import"./IconTickCircle-BYgwCdAe.js";import"./echarts-CEICS1Jr.js";const g={background:"#fff",borderRadius:10,padding:"12px 14px",boxShadow:"0 1px 2px rgba(0,0,0,0.04)"};function I(t){const s=A();return t==="yesterday"?{start:R(),end:R()}:t==="7d"?{start:O(7),end:s}:t==="30d"?{start:O(30),end:s}:{start:s,end:s}}function U({v:t}){if(t==null)return null;const s=t>=0;return e.jsxs("span",{className:s?"delta-pill delta-up":"delta-pill delta-down",children:[s?"▲":"▼"," ",Math.abs(t),"%"]})}function F({value:t,onChange:s,t:i}){const a=["today","yesterday","7d","30d"],p={today:i("today"),yesterday:i("yesterday"),"7d":i("last7"),"30d":i("last30")};return e.jsx("div",{style:{display:"flex",gap:6,overflowX:"auto",padding:"2px 0"},children:a.map(f=>e.jsx("button",{type:"button",onClick:()=>s(f),style:{flex:"0 0 auto",border:"1px solid "+(t===f?"#2a5cff":"#e5e6eb"),background:t===f?"#eaf0ff":"#fff",color:t===f?"#2a5cff":"#4e5969",borderRadius:999,padding:"4px 12px",fontSize:12,lineHeight:"18px"},children:p[f]},f))})}function k({err:t}){return t?e.jsx(G,{type:"danger",description:t,style:{marginBottom:10}}):null}function S({rows:t=5}){return e.jsx("div",{style:g,children:e.jsx(_,{active:!0,placeholder:e.jsx(_.Paragraph,{rows:t}),loading:!0})})}function E({rows:t,fmt:s,t:i,max:a=30}){const p=(t||[]).slice(0,a);if(!p.length)return e.jsx("div",{style:{padding:"18px 0",textAlign:"center",color:"#86909c",fontSize:13},children:i("noData")});const f=p[0].pv||0;return e.jsx("div",{style:{display:"flex",flexDirection:"column"},children:p.map((l,y)=>{const u=f>0?Math.max(4,(l.pv||0)/f*100):0;return e.jsxs("div",{style:{padding:"8px 0",borderBottom:y<p.length-1?"1px solid #f0f1f3":"none"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:10,marginBottom:4},children:[e.jsx("span",{style:{fontSize:13,color:"#1d2129",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:l.name,children:s?s(l.name):l.name}),e.jsx("span",{style:{flex:"0 0 auto",fontSize:13,fontWeight:600,color:"#1d2129"},children:b(l.pv||0)})]}),e.jsx("div",{style:{height:4,borderRadius:2,background:"#f0f1f3",overflow:"hidden"},children:e.jsx("div",{style:{width:`${u}%`,height:"100%",borderRadius:2,background:"#2a5cff"}})})]},y)})})}function X({site:t,rangeKey:s}){var m;const{t:i}=z(),[a,p]=c.useState(null),[f,l]=c.useState(""),y=c.useRef(null),u=I(s),x=c.useCallback(async()=>{if(t)try{const r=I(s);p(await T.overview(t.id,r.start,r.end)),l("")}catch(r){l(r.message)}},[t,s]);if(c.useEffect(()=>(x(),clearInterval(y.current),y.current=setInterval(()=>{document.visibilityState!=="hidden"&&x()},15e3),()=>clearInterval(y.current)),[x]),C(()=>x()),f&&!a)return e.jsx(S,{rows:6});if(!a)return e.jsx(S,{rows:6});const h=a.totals||{},v=a.deltas||{},d=a.live||{},j=u.start===u.end,o=j&&((m=a.hourly)!=null&&m.length)?a.hourly.map(r=>({k:r.hour,pv:r.pv,uv:r.uv})):(a.trend||[]).map(r=>({k:r.day,pv:r.pv,uv:r.uv})),n=o.length?{color:["#2a5cff","#00b42a"],tooltip:{trigger:"axis"},legend:{bottom:0,itemWidth:12,itemHeight:8,textStyle:{color:"#86909c",fontSize:11}},grid:{left:8,right:12,top:14,bottom:34,containLabel:!0},xAxis:{type:"category",boundaryGap:!1,data:o.map(r=>r.k),axisLabel:{color:"#86909c",fontSize:10},axisLine:{lineStyle:{color:"#e5e6eb"}},axisTick:{show:!1}},yAxis:{type:"value",splitLine:{lineStyle:{color:"#f0f1f3"}},axisLabel:{color:"#86909c",fontSize:10}},series:[{name:"PV",type:"line",smooth:!0,symbol:"none",data:o.map(r=>r.pv),areaStyle:{opacity:.08}},{name:"UV",type:"line",smooth:!0,symbol:"none",data:o.map(r=>r.uv)}]}:null,w=[{k:"pv",label:i("mPv")},{k:"uv",label:i("mUv")},{k:"ipc",label:i("mIp")},{k:"bounce_rate",label:i("mBounce"),pct:!0},{k:"avg_duration",label:i("mDur"),dur:!0},{k:"new_users",label:i("mNew")}];return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx(k,{err:f}),e.jsxs("div",{role:"button",tabIndex:0,onClick:()=>window.dispatchEvent(new CustomEvent("mb-goto",{detail:"live"})),style:{...g,display:"flex",alignItems:"center",justifyContent:"space-between",cursor:"pointer"},children:[e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:12,color:"#86909c"},children:i("onlineNow")}),e.jsx("div",{style:{fontSize:26,fontWeight:700,color:"#00b42a",lineHeight:1.2},children:b(d.online10??d.online??0)}),e.jsx("div",{style:{fontSize:11,color:"#86909c"},children:(d.online10??d.online??0)>0?`${i("online")} ${b(d.online??0)}`:i("noLiveHint")})]}),e.jsx("span",{style:{color:"#86909c",fontSize:18},children:"›"})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:10},children:w.map(r=>e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:12,color:"#86909c"},children:r.label}),e.jsx("div",{style:{display:"flex",alignItems:"baseline",gap:6,marginTop:2},children:e.jsx("span",{style:{fontSize:20,fontWeight:700,color:"#1d2129"},children:r.dur?N(h[r.k]||0):r.pct?`${Number(h[r.k]||0).toFixed(1)}%`:b(h[r.k]||0)})}),e.jsx("div",{style:{marginTop:2},children:e.jsx(U,{v:v[r.k]})})]},r.k))}),n&&e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#1d2129",marginBottom:6},children:i(j?"liveTitle":"trendTitle")}),e.jsx(D,{option:n,height:210})]})]})}function q({site:t}){var o;const{t:s,lang:i}=z(),[a,p]=c.useState(null),[f,l]=c.useState(""),y=c.useRef(null),u=c.useCallback(async()=>{if(t)try{p(await T.realtime(t.id,{day:A(),scope:"all",page:"1",page_size:"20"})),l("")}catch(n){l(n.message)}},[t]);if(c.useEffect(()=>(u(),clearInterval(y.current),y.current=setInterval(()=>{document.visibilityState!=="hidden"&&u()},5e3),()=>clearInterval(y.current)),[u]),C(()=>u()),f&&!a)return e.jsx(S,{rows:6});if(!a)return e.jsx(S,{rows:6});const x=a.today||{},h=((o=a.list)==null?void 0:o.items)||[],v=a.now||Date.now()/1e3,d=x.series||[],j=d.length?{color:["#00b42a"],tooltip:{trigger:"axis"},grid:{left:8,right:12,top:14,bottom:8,containLabel:!0},xAxis:{type:"category",boundaryGap:!1,data:d.map(n=>n.min),axisLabel:{color:"#86909c",fontSize:10,interval:9},axisLine:{lineStyle:{color:"#e5e6eb"}},axisTick:{show:!1}},yAxis:{type:"value",splitLine:{lineStyle:{color:"#f0f1f3"}},axisLabel:{color:"#86909c",fontSize:10}},series:[{type:"line",smooth:!0,symbol:"none",data:d.map(n=>n.pv),areaStyle:{opacity:.15}}]}:null;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx(k,{err:f}),e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:12,color:"#86909c"},children:s("onlineNow")}),e.jsx("div",{style:{fontSize:34,fontWeight:700,color:"#00b42a",lineHeight:1.2},children:b(a.online??0)}),e.jsx("div",{style:{fontSize:11,color:"#86909c"},children:s("onlineScope")})]}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:10},children:[{label:`PV · ${s("today")}`,v:b(x.pv??0)},{label:s("totalUV"),v:b(x.uv??0)},{label:s("totalIP"),v:b(x.ipc??0)}].map(n=>e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:11,color:"#86909c"},children:n.label}),e.jsx("div",{style:{fontSize:18,fontWeight:700,color:"#1d2129"},children:n.v})]},n.label))}),j&&e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#1d2129",marginBottom:6},children:s("liveTitle")}),e.jsx(D,{option:j,height:190})]}),e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#1d2129",marginBottom:4},children:s("mbLiveVisitors")}),h.length===0?e.jsx($,{description:s("emptyOnline"),style:{padding:"18px 0"}}):h.map((n,w)=>{const m=[n.city,n.province!==n.city?n.province:"",H(n.country,i)].filter(Boolean)[0]||"-",r=n.ref_host||P(n.source)||"-";return e.jsxs("div",{style:{padding:"9px 0",borderBottom:w<h.length-1?"1px solid #f0f1f3":"none"},children:[e.jsxs("div",{style:{display:"flex",justifyContent:"space-between",gap:8},children:[e.jsxs("span",{style:{fontSize:13,fontWeight:600,color:n.online?"#00b42a":"#86909c"},children:[n.online?"● ":"○ ",m]}),e.jsx("span",{style:{fontSize:12,color:"#86909c"},children:V(n.last_ts,v,s)})]}),e.jsx("div",{style:{fontSize:12,color:"#4e5969",marginTop:3,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},title:n.entry_url,children:n.entry_url||"-"}),e.jsxs("div",{style:{display:"flex",gap:12,fontSize:11,color:"#86909c",marginTop:3},children:[e.jsx("span",{children:r}),e.jsxs("span",{children:[s("colStay")," ",N(n.duration||0)]}),e.jsxs("span",{children:["PV ",n.pageviews??0]})]})]},n.id||w)})]})]})}function J({site:t,rangeKey:s}){const{t:i,lang:a}=z(),[p,f]=c.useState(null),[l,y]=c.useState(""),u=c.useRef(null),x=c.useCallback(async()=>{if(t)try{const d=I(s);f(await T.analysis(t.id,d.start,d.end)),y("")}catch(d){y(d.message)}},[t,s]);if(c.useEffect(()=>(x(),clearInterval(u.current),()=>clearInterval(u.current)),[x]),C(()=>x()),!p)return l?e.jsx(k,{err:l}):e.jsx(S,{rows:7});const h=(p.channels||[]).map(d=>({name:P(d.name)||d.name,value:d.pv||0})),v=h.length?{color:["#2a5cff","#00b42a","#ff7d00","#f53f3f","#722ed1","#00b2ff","#86909c"],tooltip:{trigger:"item"},legend:{bottom:0,itemWidth:12,itemHeight:8,textStyle:{color:"#86909c",fontSize:11}},series:[{type:"pie",radius:["42%","66%"],center:["50%","42%"],data:h,label:{show:!1}}]}:null;return e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx(k,{err:l}),v?e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#1d2129",marginBottom:6},children:i("mbChannels")}),e.jsx(D,{option:v,height:240})]}):null,e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#1d2129",marginBottom:4},children:i("mbTopRefs")}),e.jsx(E,{rows:p.referrers,t:i})]}),e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#1d2129",marginBottom:4},children:i("mbTopRegions")}),e.jsx(E,{rows:p.countries,t:i,fmt:d=>H(d,a)})]})]})}function Q({site:t,rangeKey:s}){const{t:i}=z(),[a,p]=c.useState(null),[f,l]=c.useState(""),y=c.useRef(null),u=c.useCallback(async()=>{if(t)try{const x=I(s);p(await T.analysis(t.id,x.start,x.end)),l("")}catch(x){l(x.message)}},[t,s]);return c.useEffect(()=>(u(),clearInterval(y.current),()=>clearInterval(y.current)),[u]),C(()=>u()),e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:10},children:[e.jsx(k,{err:f}),e.jsxs("div",{style:g,children:[e.jsx("div",{style:{fontSize:13,fontWeight:600,color:"#1d2129",marginBottom:4},children:i("mbTopPages")}),a?e.jsx(E,{rows:a.pages,t:i,max:50}):e.jsx(S,{rows:6})]})]})}function oe(){const{t}=z(),s=M(),[i,a]=c.useState(null),[p,f]=c.useState(localStorage.getItem("wstat_site")||""),[l,y]=c.useState("overview"),[u,x]=c.useState("today");c.useEffect(()=>{let o=!0;return T.sites().then(n=>{if(!o)return;if(a(n),!(n||[]).some(m=>String(m.id)===String(p))&&n&&n.length>0){const m=String(n[0].id);localStorage.setItem("wstat_site",m),f(m)}}).catch(()=>a([])),()=>{o=!1}},[]),c.useEffect(()=>{const o=n=>y(n.detail||"overview");return window.addEventListener("mb-goto",o),()=>window.removeEventListener("mb-goto",o)},[]);const h=(i||[]).find(o=>String(o.id)===String(p))||null,v=o=>{localStorage.setItem("wstat_site",String(o)),f(String(o))},d=[{key:"overview",label:t("mbTabOverview")},{key:"live",label:t("mbTabRealtime")},{key:"sources",label:t("mbTabSources")},{key:"pages",label:t("mbTabPages")}];c.useEffect(()=>{const o=d.find(n=>n.key===l);document.title=`${o&&o.label||t("mbTabOverview")} · ${t("appName")||"WebStats"}`},[l,t]);const j=l==="overview"||l==="sources"||l==="pages";return e.jsxs("div",{style:{minHeight:"100vh",background:"#f5f6f8",display:"flex",flexDirection:"column"},children:[e.jsxs("div",{style:{position:"sticky",top:0,zIndex:10,background:"#fff",borderBottom:"1px solid #e5e6eb",padding:"10px 14px 8px",display:"flex",alignItems:"center",justifyContent:"space-between",gap:8},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:8,minWidth:0},children:[e.jsx("div",{className:"logo-badge",style:{width:26,height:26,fontSize:13},children:"W"}),i===null?e.jsx(W.Text,{type:"tertiary",children:t("loading")}):h?e.jsx(B,{trigger:"click",position:"bottomLeft",render:e.jsx(B.Menu,{children:(i||[]).map(o=>e.jsx(B.Item,{active:String(o.id)===String(p),onClick:()=>v(o.id),children:`${o.name}(${o.domain})`},o.id))}),children:e.jsxs("span",{style:{display:"flex",alignItems:"center",gap:4,cursor:"pointer",minWidth:0},children:[e.jsx("span",{style:{fontSize:14,fontWeight:600,color:"#1d2129",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:h.name}),e.jsx("span",{style:{color:"#86909c",fontSize:10},children:"▼"})]})}):e.jsx(W.Text,{type:"tertiary",children:t("noSiteHint")})]}),e.jsx(L,{size:"small",theme:"borderless",type:"tertiary",onClick:()=>s("/overview"),children:t("mbDesktop")})]}),j&&h&&e.jsx("div",{style:{padding:"10px 14px 0"},children:e.jsx(F,{value:u,onChange:x,t})}),e.jsx("div",{style:{flex:1,padding:"10px 14px calc(76px + env(safe-area-inset-bottom))"},children:h?e.jsxs(e.Fragment,{children:[l==="overview"&&e.jsx(X,{site:h,rangeKey:u}),l==="live"&&e.jsx(q,{site:h}),l==="sources"&&e.jsx(J,{site:h,rangeKey:u}),l==="pages"&&e.jsx(Q,{site:h,rangeKey:u})]}):i===null?e.jsx(S,{rows:6}):e.jsx($,{style:{marginTop:80},title:t("noSiteHint"),children:e.jsx(L,{theme:"solid",onClick:()=>s("/sites"),children:t("goSites")})})}),e.jsx("div",{style:{position:"fixed",left:0,right:0,bottom:0,zIndex:20,background:"#fff",borderTop:"1px solid #e5e6eb",display:"flex",paddingBottom:"env(safe-area-inset-bottom)"},children:d.map(o=>{const n=l===o.key;return e.jsxs("button",{type:"button",onClick:()=>y(o.key),style:{flex:1,height:52,border:"none",background:"transparent",cursor:"pointer",display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",gap:2,color:n?"#2a5cff":"#86909c",fontSize:11},children:[e.jsx("span",{style:{width:20,height:3,borderRadius:2,background:n?"#2a5cff":"transparent"}}),o.label]},o.key)})})]})}export{oe as default};