码桶

发现社区成员的开源项目

geekssl /

wstats

公开
main
wstats/public/assets/Audience-CtsUGGRA.js
Audience-CtsUGGRA.js8.3 KB
import{u as v,a as G,c as O,r as c,q as Q,b as J,j as e,B as z,T as j,f as d,g as X,v as h,t as Z,S as T}from"./index-GWuvg2UH.js";import{B as ee}from"./index-DihvOmSo.js";import{E as f}from"./index-VbOLTMR0.js";import{S as A}from"./index-BZDftoba.js";import{T as _}from"./index-mZVFvfKe.js";import{T as y}from"./index-Bpyda4LF.js";import{E as x,P as te,b as se}from"./EChart-Bps-t-O3.js";import"./IconTickCircle-BYgwCdAe.js";import"./_baseDifference-DopHgqVv.js";import"./index-DIHsQVbu.js";import"./slice-B6jKCnyX.js";import"./object-DkPZvw8u.js";import"./index-BMbdBPA2.js";import"./echarts-CEICS1Jr.js";const ae=[1,7,30],ie=["d0_10","d11_30","d31_60","d1_3","d3_10","d10m"],le=["p1","p2_3","p4_6","p7_10","p10m"],re=["f1","f2","f3_5","f6_10","f10m"];function w(s,r,l){const n=s.map(t=>({k:t,c:r&&r[t]||0})),a=n.reduce((t,b)=>t+b.c,0);return{data:n,total:a}}function S(s,r){return{color:te,tooltip:{trigger:"axis"},grid:se(),xAxis:{type:"category",data:s.map(l=>r(l.k)),axisLabel:{color:"#86909c"}},yAxis:{type:"value",splitLine:{lineStyle:{color:"#f0f1f3"}},axisLabel:{color:"#86909c"}},series:[{type:"bar",barMaxWidth:42,data:s.map(l=>l.c),itemStyle:{color:"#2a5cff",borderRadius:[3,3,0,0]}}]}}function m({data:s,total:r}){const{t:l}=v(),n=r>0?r:s.reduce((a,t)=>a+t.c,0);return e.jsx(_,{columns:[{title:l("auBucket"),dataIndex:"k",width:130,render:a=>l(a)},{title:l("auCnt"),dataIndex:"c",width:100,render:a=>d(a)},{title:l("auPct"),dataIndex:"c",render:a=>{const t=n>0?Math.min(100,a/n*100):0;return e.jsxs(T,{style:{width:"100%"},children:[e.jsx("span",{style:{width:46,textAlign:"right",fontSize:12},children:h(t)}),e.jsx("span",{style:{flex:1,height:6,background:"#f0f1f3",borderRadius:3,overflow:"hidden"},children:e.jsx("span",{style:{display:"block",height:"100%",width:`${t}%`,background:"#2a5cff"}})})]})}}],dataSource:s,rowKey:"k",pagination:!1,size:"small",empty:e.jsx(f,{description:l("analysisEmpty")})})}function B({cards:s}){return e.jsx("div",{className:"stat-grid",style:{marginBottom:16},children:s.map(r=>e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-label",children:r.label}),e.jsx("div",{className:"stat-value",children:r.value})]},r.label))})}function V({title:s,children:r}){return e.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[e.jsx("div",{className:"card-title",style:{padding:"14px 16px 6px"},children:s}),r]})}function K({title:s,items:r,base:l}){const{t:n}=v();return e.jsx(V,{title:s,children:e.jsx(_,{columns:[{title:n("auPage"),dataIndex:"name",ellipsis:{showTitle:!0},render:a=>e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:a})},{title:n("auVisits"),dataIndex:"visits",width:92,render:a=>d(a)},{title:"PV",dataIndex:"pv",width:80,render:a=>d(a)},{title:n("auPct"),dataIndex:"visits",width:170,render:a=>{const t=l>0?Math.min(100,a/l*100):0;return e.jsxs(T,{style:{width:"100%"},children:[e.jsx("span",{style:{width:44,textAlign:"right",fontSize:12},children:h(t)}),e.jsx("span",{style:{flex:1,height:6,background:"#f0f1f3",borderRadius:3,overflow:"hidden"},children:e.jsx("span",{style:{display:"block",height:"100%",width:`${t}%`,background:"#00b42a"}})})]})}}],dataSource:r||[],rowKey:(a,t)=>`${a.name}-${t}`,pagination:!1,size:"small",empty:e.jsx(f,{description:n("analysisEmpty")})})})}function u({title:s,items:r,base:l}){const{t:n}=v();return e.jsx(V,{title:s,children:e.jsx(_,{columns:[{title:s,dataIndex:"name",ellipsis:{showTitle:!0}},{title:n("auUv"),dataIndex:"c",width:92,render:a=>d(a)},{title:n("auPct"),dataIndex:"c",width:170,render:a=>{const t=l>0?Math.min(100,a/l*100):0;return e.jsxs(T,{style:{width:"100%"},children:[e.jsx("span",{style:{width:44,textAlign:"right",fontSize:12},children:h(t)}),e.jsx("span",{style:{flex:1,height:6,background:"#f0f1f3",borderRadius:3,overflow:"hidden"},children:e.jsx("span",{style:{display:"block",height:"100%",width:`${t}%`,background:"#722ed1"}})})]})}}],dataSource:r||[],rowKey:(a,t)=>`${a.name}-${t}`,pagination:!1,size:"small",empty:e.jsx(f,{description:n("analysisEmpty")})})})}function ye(){var C,I;const{t:s}=v(),r=G(),{site:l}=O(),[n,a]=c.useState(1),[t,b]=c.useState(null),[$,N]=c.useState(!1),[k,E]=c.useState(""),[L,M]=c.useState("visits"),R=c.useCallback(async()=>{if(l){N(!0);try{const{start:o,end:Y}=Q(n);b(await J.audience(l.id,o,Y)),E("")}catch(o){E(o.message)}finally{N(!1)}}},[l,n]);if(c.useEffect(()=>{R()},[R]),!l)return e.jsx("div",{className:"page",children:e.jsx(f,{style:{marginTop:60},title:e.jsx(j.Title,{heading:5,children:s("noSiteHint")}),description:s("createHint"),children:e.jsx(z,{theme:"solid",onClick:()=>r("/sites"),children:s("goSites")})})});const i=(t==null?void 0:t.totals)||{},q=i.visits>0?(i.new_visits||0)/i.visits*100:0,g=Math.max(0,(i.uv||0)-(i.uv_new||0)),{data:D,total:F}=w(ie,t==null?void 0:t.duration_dist),{data:P,total:H}=w(le,t==null?void 0:t.depth_dist),{data:U,total:W}=w(re,t==null?void 0:t.freq_dist),p={display:"grid",gridTemplateColumns:"1fr 1fr",gap:16};return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"toolbar",children:[e.jsx(j.Title,{heading:5,style:{margin:0},children:s("audience")}),e.jsx("div",{style:{display:"flex",gap:6},children:ae.map(o=>e.jsx(z,{size:"small",theme:n===o?"solid":"borderless",onClick:()=>a(o),children:s(o===1?"today":o===7?"last7":"last30")},o))})]}),k&&e.jsx(ee,{type:"danger",style:{marginBottom:12},description:e.jsx("div",{style:{whiteSpace:"pre-wrap",wordBreak:"break-all",fontFamily:"Consolas, Menlo, monospace",fontSize:12},children:k})}),$&&!t?e.jsx(A,{active:!0,placeholder:e.jsx(A.Paragraph,{rows:6}),loading:!0}):e.jsxs(y,{type:"line",activeKey:L,onChange:M,style:{background:"#fff",borderRadius:8,padding:"0 16px 16px"},children:[e.jsxs(y.TabPane,{tab:s("tabVisits"),itemKey:"visits",children:[e.jsx(B,{cards:[{label:s("auVisits"),value:d(i.visits)},{label:s("auUv"),value:d(i.uv)},{label:s("auAvgDur"),value:X(i.avg_duration)},{label:s("auAvgDepth"),value:i.avg_pv??0},{label:s("auBounce"),value:h(i.bounce_rate)},{label:s("auNewVisitRate"),value:h(q)}]}),e.jsxs("div",{style:p,children:[e.jsxs("div",{className:"chart-box",children:[e.jsx("div",{className:"card-title",children:s("auDurTitle")}),e.jsx(x,{option:S(D,s),height:260}),e.jsx(m,{data:D,total:F})]}),e.jsxs("div",{className:"chart-box",children:[e.jsx("div",{className:"card-title",children:s("auDepthTitle")}),e.jsx(x,{option:S(P,s),height:260}),e.jsx(m,{data:P,total:H})]})]}),e.jsxs("div",{style:{...p,marginBottom:16},children:[e.jsx(K,{title:s("auEntryTitle"),items:t==null?void 0:t.entries,base:i.visits}),e.jsx(K,{title:s("auExitTitle"),items:t==null?void 0:t.exits,base:i.visits})]})]}),e.jsxs(y.TabPane,{tab:s("tabVisitors"),itemKey:"visitors",children:[e.jsx(B,{cards:[{label:s("auUv"),value:d(i.uv)},{label:s("auUvNew"),value:d(i.uv_new)},{label:s("auUvReturn"),value:d(g)},{label:s("auVisitsPerUv"),value:i.visits_per_uv??0},{label:s("auPvPerUv"),value:i.pv_per_uv??0}]}),e.jsxs("div",{style:p,children:[e.jsxs("div",{className:"chart-box",children:[e.jsx("div",{className:"card-title",children:s("auFreqTitle")}),e.jsx(x,{option:S(U,s),height:260}),e.jsx(m,{data:U,total:W})]}),e.jsxs("div",{className:"chart-box",children:[e.jsxs("div",{className:"card-title",children:[s("auUvNew")," / ",s("auUvReturn")]}),e.jsx(x,{height:260,option:{color:["#2a5cff","#00b42a"],tooltip:{trigger:"item",formatter:"{b}: {c} ({d}%)"},legend:{top:0,icon:"roundRect",itemWidth:10,itemHeight:10},series:[{type:"pie",radius:["46%","70%"],center:["50%","56%"],itemStyle:{borderColor:"#fff",borderWidth:2},label:{show:!1},emphasis:{label:{show:!1}},data:[{name:s("auUvNew"),value:i.uv_new||0},{name:s("auUvReturn"),value:g}]}]}}),e.jsx(m,{data:[{k:"auUvNew",c:i.uv_new||0},{k:"auUvReturn",c:g}],total:i.uv||0})]})]}),e.jsxs("div",{style:p,children:[e.jsx(u,{title:s("auRegion"),items:t==null?void 0:t.geo,base:i.uv}),e.jsx(u,{title:s("browser"),items:t==null?void 0:t.browsers,base:i.uv}),e.jsx(u,{title:s("os"),items:t==null?void 0:t.oses,base:i.uv}),e.jsx(u,{title:s("device"),items:t==null?void 0:t.devices,base:i.uv}),e.jsx(u,{title:s("auScreen"),items:t==null?void 0:t.screens,base:i.uv}),e.jsx(u,{title:s("auLang"),items:t==null?void 0:t.langs,base:i.uv})]})]})]}),e.jsxs(j.Text,{type:"tertiary",style:{fontSize:12,display:"block",marginTop:16},children:[l.name," · ",l.domain," · ",s("range"),": ",(C=t==null?void 0:t.range)==null?void 0:C.start," ~ ",(I=t==null?void 0:t.range)==null?void 0:I.end,"(",Z(),")"]})]})}export{ye as default};