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