码桶
发现社区成员的开源项目
PageDetail-DL9AaAh-.js10.8 KB
import{E as se,r as c,u as P,a as te,c as ie,d as le,q as ne,b as re,j as e,B as S,S as ae,o as oe,T,f as d,g as F,v as C,O as N,k as R,w as K,z as ce,bi as de,l as V,h as I,x as pe,A as me}from"./index-GWuvg2UH.js";import{B as O}from"./index-DihvOmSo.js";import{E as f}from"./index-VbOLTMR0.js";import{S as U}from"./index-BZDftoba.js";import{T as w}from"./index-mZVFvfKe.js";import{T as g}from"./index-Bpyda4LF.js";import{P as j,b as L,a as H,E as G,c as M}from"./EChart-Bps-t-O3.js";import{B as W,O as xe,F as he,D as ye,S as ue}from"./SessionDetail-EWkH_y26.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";import"./index-WdvJbv7c.js";import"./Animation-CU6YFe7Y.js";import"./index-C23zBuz1.js";import"./index-BW_2QB9V.js";function ge(t){return c.createElement("svg",Object.assign({viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",width:"1em",height:"1em",focusable:!1,"aria-hidden":!0},t),c.createElement("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M23 12c0 .83-.67 1.5-1.5 1.5H6.12l6.44 6.44a1.5 1.5 0 0 1-2.12 2.12l-9-9a1.5 1.5 0 0 1 0-2.12l9-9a1.5 1.5 0 0 1 2.12 2.12L6.12 10.5H21.5c.83 0 1.5.67 1.5 1.5Z",fill:"currentColor"}))}const je=se(ge,"arrow_left"),fe=[1,7,30];function m({title:t,items:x,empty:u,renderName:o}){const{t:a}=P(),h=x.reduce((n,p)=>n+p.pv,0);return e.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[e.jsx("div",{className:"card-title",style:{padding:"14px 16px 6px"},children:t}),e.jsx(w,{columns:[{title:a("colName"),dataIndex:"name",ellipsis:{showTitle:!0},render:n=>e.jsx("span",{style:{fontFamily:"monospace",fontSize:12},children:o?o(n):n||"-"})},{title:a("colPv"),dataIndex:"pv",width:80,render:n=>d(n)},{title:a("colPct"),dataIndex:"pv",width:70,render:n=>e.jsx("span",{style:{color:"#86909c",fontSize:12},children:h>0?C(n/h*100):"0%"})}],dataSource:x,rowKey:(n,p)=>`${n.name}-${p}`,pagination:!1,size:"small",empty:e.jsx(f,{description:u||a("noData")})})]})}function q({title:t,items:x,onPick:u}){const{t:o}=P();return e.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[e.jsx("div",{className:"card-title",style:{padding:"14px 16px 6px"},children:t}),e.jsx(w,{columns:[{title:o("url"),dataIndex:"url",ellipsis:{showTitle:!0},render:a=>e.jsx("a",{href:`/page?url=${encodeURIComponent(a)}`,onClick:h=>{h.preventDefault(),u(a)},style:{fontFamily:"monospace",fontSize:12},children:a})},{title:o("pdCount"),dataIndex:"count",width:80,render:a=>d(a)}],dataSource:x,rowKey:(a,h)=>`${a.url}-${h}`,pagination:!1,size:"small",empty:e.jsx(f,{description:o("pdNoFlow")})})]})}function Ke(){var A,$;const{t,lang:x}=P(),u=te(),{site:o}=ie(),[a,h]=le(),n=a.get("url")||"",p=a.get("match")==="prefix"?"prefix":"exact",[b,Z]=c.useState(7),[s,J]=c.useState(null),[Q,k]=c.useState(!1),[E,B]=c.useState(""),D=c.useCallback(async()=>{if(!(!o||!n)){k(!0);try{const{start:i,end:l}=ne(b);J(await re.pageDetail(o.id,n,i,l,p)),B("")}catch(i){B(i.message)}finally{k(!1)}}},[o,n,b,p]);c.useEffect(()=>{D()},[D]);const _=c.useCallback(i=>{h({url:i,match:p},{replace:!1})},[h,p]),r=(s==null?void 0:s.summary)||{},X=c.useMemo(()=>{const i=M();return{tooltip:H(),grid:L(),legend:{data:["PV","UV"],right:8,top:4,textStyle:{color:"#86909c"}},xAxis:{...i.xAxis,data:((s==null?void 0:s.trend)||[]).map(l=>l.day)},yAxis:i.yAxis,series:[{name:"PV",type:"line",smooth:!0,showSymbol:!1,data:((s==null?void 0:s.trend)||[]).map(l=>l.pv),lineStyle:{color:j[0]},itemStyle:{color:j[0]},areaStyle:{opacity:.08,color:j[0]}},{name:"UV",type:"line",smooth:!0,showSymbol:!1,data:((s==null?void 0:s.trend)||[]).map(l=>l.uv),lineStyle:{color:j[1]},itemStyle:{color:j[1]}}]}},[s]),Y=c.useMemo(()=>{const i=M(),l={};((s==null?void 0:s.hourly)||[]).forEach(y=>{l[y.hour]=y.pv});const v=Array.from({length:24},(y,ee)=>ee);return{tooltip:H(),grid:L(),xAxis:{...i.xAxis,boundaryGap:!0,data:v.map(y=>`${y}:00`)},yAxis:i.yAxis,series:[{name:"PV",type:"bar",barMaxWidth:18,data:v.map(y=>l[y]||0),itemStyle:{color:j[5],borderRadius:[3,3,0,0]}}]}},[s]);if(!o)return e.jsx("div",{className:"page",children:e.jsx(f,{style:{marginTop:60},title:t("noSiteHint")})});if(!n)return e.jsx("div",{className:"page",children:e.jsx(f,{style:{marginTop:60},title:t("pdNoUrl"),description:t("analysis"),children:e.jsx(S,{theme:"solid",onClick:()=>u("/analysis"),children:t("pdBack")})})});const z=n.length>90?n.slice(0,90)+"…":n;return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"toolbar",style:{justifyContent:"space-between",alignItems:"flex-start"},children:[e.jsxs("div",{style:{minWidth:0,flex:1},children:[e.jsxs(ae,{children:[e.jsx(S,{size:"small",icon:e.jsx(je,{}),onClick:()=>u("/analysis"),children:t("pdBack")}),e.jsx(oe,{size:"small",color:p==="prefix"?"violet":"blue",children:t(p==="prefix"?"matchPrefix":"matchExact")})]}),e.jsx(T.Title,{heading:6,style:{margin:"10px 0 2px",wordBreak:"break-all"},ellipsis:{showTooltip:!0,rows:2},children:(s==null?void 0:s.title)||z}),e.jsx(T.Text,{type:"tertiary",style:{fontSize:12,fontFamily:"monospace",wordBreak:"break-all"},children:z})]}),e.jsx("div",{style:{display:"flex",gap:6,flexShrink:0},children:fe.map(i=>e.jsx(S,{size:"small",theme:b===i?"solid":"borderless",onClick:()=>Z(i),children:t(i===1?"today":i===7?"last7":"last30")},i))})]}),E&&e.jsx(O,{type:"danger",description:E,style:{marginBottom:12}}),(s==null?void 0:s.partial)&&e.jsx(O,{type:"warning",description:t("pdPartial"),style:{marginBottom:12}}),Q&&!s?e.jsx(U,{active:!0,placeholder:e.jsx(U.Paragraph,{rows:8}),loading:!0}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"stat-grid",style:{marginBottom:16},children:[{l:t("colPv"),v:d(r.pv)},{l:t("totalUV"),v:d(r.uv)},{l:t("totalIP"),v:d(r.ipc)},{l:t("pdVisits"),v:d(r.sessions)},{l:t("pdEntries"),v:d(r.entries)},{l:t("pdExits"),v:d(r.exits)},{l:t("pdAvgDur"),v:F(r.avg_duration)},{l:t("bounceRate"),v:C(r.bounce_rate)},{l:t("pdPvPerVisit"),v:Number(r.pv_per_visit||0).toFixed(2)},{l:t("pdClicks"),v:d(r.clicks)},{l:t("pdScroll"),v:r.avg_scroll!=null?C(r.avg_scroll):"—"}].map(i=>e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-label",children:i.l}),e.jsx("div",{className:"stat-value",children:i.v})]},i.l))}),e.jsxs(T.Text,{type:"tertiary",style:{fontSize:12,display:"block",marginBottom:12},children:[t("range"),": ",(A=s==null?void 0:s.range)==null?void 0:A.start," ~ ",($=s==null?void 0:s.range)==null?void 0:$.end,r.first_ts>0&&` · ${t("pdFirst")}: ${N(r.first_ts)}`,r.last_ts>0&&` · ${t("pdLast")}: ${N(r.last_ts)}`]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1.6fr 1fr",gap:16,marginBottom:16},children:[e.jsxs("div",{className:"card",children:[e.jsx("div",{className:"card-title",children:t("pdTrend")}),e.jsx(G,{option:X,height:260})]}),e.jsxs("div",{className:"card",children:[e.jsx("div",{className:"card-title",children:t("pdHour")}),e.jsx(G,{option:Y,height:260})]})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16,marginBottom:16},children:[e.jsx(q,{title:t("pdPrev"),items:(s==null?void 0:s.prev_pages)||[],onPick:_}),e.jsx(q,{title:t("pdNext"),items:(s==null?void 0:s.next_pages)||[],onPick:_})]}),e.jsxs(g,{type:"line",style:{background:"#fff",borderRadius:8,padding:"0 16px 16px"},children:[e.jsxs(g.TabPane,{tab:t("pdSource"),itemKey:"src",children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsx(m,{title:t("colChannel"),items:(s==null?void 0:s.channels)||[],renderName:i=>R(i)==="-"?"-":`${i} · ${R(i)}`}),e.jsx(m,{title:t("colRefHost"),items:(s==null?void 0:s.referrers)||[]})]}),!!((s==null?void 0:s.campaigns)||[]).length&&e.jsx("div",{style:{marginTop:16},children:e.jsx(m,{title:t("campaign"),items:s.campaigns})})]}),e.jsxs(g.TabPane,{tab:t("pdEnv"),itemKey:"env",children:[e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:16},children:[e.jsx(m,{title:t("device"),items:(s==null?void 0:s.devices)||[],renderName:i=>K(i)}),e.jsx(m,{title:t("colBrowser"),items:(s==null?void 0:s.browsers)||[],renderName:i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[e.jsx(W,{name:i}),i]})}),e.jsx(m,{title:t("colOs"),items:(s==null?void 0:s.oses)||[],renderName:i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[e.jsx(xe,{name:i}),ce(i)]})})]}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16,marginTop:16},children:[e.jsx(m,{title:t("auScreen"),items:(s==null?void 0:s.screens)||[]}),e.jsx(m,{title:t("lang"),items:(s==null?void 0:s.langs)||[]})]})]}),e.jsx(g.TabPane,{tab:t("pdGeo"),itemKey:"geo",children:e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:16},children:[e.jsx(m,{title:t("colCountry"),items:(s==null?void 0:s.countries)||[],renderName:i=>e.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[de(i)," ",x==="zh-CN"?V(i,x):i]})}),e.jsx(m,{title:t("colProvince"),items:(s==null?void 0:s.provinces)||[]})]})}),e.jsx(g.TabPane,{tab:t("pdEvents"),itemKey:"events",children:e.jsx(w,{columns:[{title:t("pdEventName"),dataIndex:"name",ellipsis:{showTitle:!0}},{title:t("pdCount"),dataIndex:"count",width:110,render:i=>d(i)},{title:t("totalUV"),dataIndex:"uv",width:110,render:i=>d(i)}],dataSource:(s==null?void 0:s.events)||[],rowKey:(i,l)=>`${i.name}-${l}`,pagination:!1,size:"small",empty:e.jsx(f,{description:t("pdNoEvents")})})}),e.jsx(g.TabPane,{tab:t("pdSessions"),itemKey:"sessions",children:e.jsx(w,{className:"sessions-table",columns:[{title:t("sessIdCol"),dataIndex:"session_id",width:170,render:(i,l)=>e.jsx(I,{content:i,children:e.jsx("span",{className:"sd-mono",style:{fontSize:12},children:pe(i)})})},{title:t("visits"),dataIndex:"pageviews",width:70},{title:t("duration"),dataIndex:"duration",width:90,render:i=>F(i)},{title:t("colLoc"),dataIndex:"country",width:130,ellipsis:{showTitle:!1},render:(i,l)=>{const v=l.city||l.province||i;return v?e.jsx(I,{content:[l.country,l.province,l.city].filter(Boolean).join(" · "),children:e.jsxs("span",{style:{whiteSpace:"nowrap"},children:[e.jsx(he,{country:i}),x==="zh-CN"?v:l.city||l.province||V(i,x)]})}):e.jsx("span",{style:{color:"#c9cdd4"},children:"—"})}},{title:t("colBrowser"),dataIndex:"browser",width:130,ellipsis:{showTitle:!1},render:i=>i?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[e.jsx(W,{name:i}),i]}):"-"},{title:t("colDevice"),dataIndex:"device",width:90,render:i=>i?e.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[e.jsx(ye,{name:i}),K(i)]}):"-"},{title:t("lastSeen"),dataIndex:"end_ts",width:110,render:i=>i?e.jsx(I,{content:N(i),children:e.jsx("span",{children:me(i,Date.now()/1e3,t)})}):"-"},{title:t("actions"),dataIndex:"id",width:90,render:(i,l)=>e.jsx(ue,{site:o,row:l,label:t("detail")})}],dataSource:(s==null?void 0:s.recent_sessions)||[],rowKey:"id",pagination:!1,size:"middle",empty:e.jsx(f,{description:t("noData")})})})]})]})]})}export{Ke as default};