geekssl /

wstats

公开
main
wstats/public/assets/Sessions-BicrQU3h.js
Sessions-BicrQU3h.js11.1 KB
import{j as s,u as de,e as ce,r,t as X,g as z,c as N,l as j,D as pe,o as he,E as xe,C as ue,z as G,k as Y,F as T,G as J,d as w,I as U,H as me,n as Z,y as Q,R,T as E}from"./index-DS2B3OLK.js";import{B as fe}from"./index-BNK0Nj_J.js";import{D as ye}from"./index-3kr5QjM4.js";import{E as L}from"./index-dKmdA2E0.js";import{T as O,P as je}from"./index-b2iqXj_X.js";import{F as we,B as ge,O as Se,D as Ie,S as ee}from"./SessionDetail-X71sgOyP.js";import{E as ve}from"./ExportButton-CoqnqODF.js";import"./IconTickCircle-Bbh_c2jr.js";import"./object-DvQZmkoP.js";import"./slice-s3-7cpgr.js";import"./index-CElfosix.js";import"./Animation-BXPC60cz.js";import"./_baseDifference-D1QxGNC2.js";import"./index-R4PZyHYh.js";import"./index-JBcYhKgc.js";import"./index-gNmiyIm9.js";import"./index-BkQnUDM_.js";import"./index-DhB1Ls4S.js";function be(t,l,i){const a=[];return t&&a.push(t),l&&l!==t&&a.push(l),i&&i!==l&&a.push(i),a.join(" · ")}function Ce({r:t,maxWidth:l=150}){const i=t&&t.ip||"",a=be(t&&t.country,t&&t.province,t&&t.city),d={color:"#c9cdd4"};return!i&&!a?s.jsx("span",{style:d,children:"—"}):s.jsxs("div",{style:{lineHeight:1.6,minWidth:0},title:[i,a].filter(Boolean).join(" · "),children:[s.jsx("div",{className:"sd-mono",style:{fontSize:12,color:i?void 0:d.color},children:i||"—"}),s.jsx("div",{style:{fontSize:12,color:a?void 0:d.color,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",maxWidth:l},children:a||"—"})]})}function B(t,l){const i=X();return t==="today"?{start:i,end:i}:t==="yesterday"?{start:Q(),end:Q()}:t==="7d"?{start:z(7),end:i}:t==="30d"?{start:z(30),end:i}:Z(l&&l.start,l&&l.end)||{start:z(7),end:i}}const se={direct:"chDirect",search:"chSearch",social:"chSocial",link:"chLink",paid:"chPaid",utm:"chUtm",internal:"chInternal"};function ze({site:t,ip:l,range:i,t:a}){const[d,h]=R.useState(null),[S,c]=R.useState("");if(R.useEffect(()=>{let o=!0;return N.sessions(t.id,{start:i.start,end:i.end,q:l,page:"1",size:"20"}).then(u=>{o&&h(u.items||[])}).catch(u=>{o&&c(u.message)}),()=>{o=!1}},[t.id,l,i.start,i.end]),S)return s.jsx(E.Text,{type:"danger",children:S});if(!d)return s.jsx(E.Text,{type:"tertiary",children:"…"});const D=[{title:a("lastSeen"),dataIndex:"start_ts",width:120,render:o=>s.jsx("span",{style:{fontSize:12},children:o?new Date(o*1e3).toLocaleString():"-"})},{title:a("colEntry"),dataIndex:"entry_url",ellipsis:{showTitle:!0},render:o=>s.jsx("span",{className:"sd-mono",style:{fontSize:12},children:o||"-"})},{title:a("fSource"),dataIndex:"source",width:90,render:o=>a(se[o]||"chOther")},{title:a("visits"),dataIndex:"pageviews",width:70},{title:a("colDuration"),dataIndex:"duration",width:90,render:o=>Y(o||0)},{title:a("actions"),dataIndex:"id",width:80,render:(o,u)=>s.jsx(ee,{site:t,row:u,label:u.live?`${a("detail")} · LIVE`:a("detail")})}];return s.jsx("div",{style:{padding:"4px 8px 8px 40px"},children:d.length===0?s.jsx(E.Text,{type:"tertiary",children:a("noData")}):s.jsx(O,{columns:D,dataSource:d,rowKey:"id",pagination:!1,size:"small"})})}function Me(){const{t,lang:l}=de(),{site:i}=ce(),[a,d]=r.useState("sessions"),[h,S]=r.useState("today"),[c,D]=r.useState({start:z(7),end:X()}),[o,u]=r.useState(""),[x,I]=r.useState({browser:"",os:"",device:"",source:""}),[m,P]=r.useState({browser:"",os:"",device:"",source:""}),[v,te]=r.useState(1),[C,ie]=r.useState(10),[k,$]=r.useState([]),[F,A]=r.useState(0),[V,K]=r.useState(!1),[q,H]=r.useState(""),_=r.useCallback(()=>({start:B(h,c).start,end:B(h,c).end,q:o.trim(),browser:m.browser.trim(),os:m.os.trim(),device:m.device,source:m.source}),[h,c,o,m]),g=r.useCallback(async(e,n,f)=>{if(!i)return;const y=f||a;K(!0);try{const p=_();if(y==="iptrace"){const b=await N.iptrace(i.id,{page:String(e||v),size:String(n||C),start:p.start,end:p.end,q:p.q});$(b.items||[]),A(b.total||0)}else{const b=await N.sessions(i.id,{page:String(e||v),size:String(n||C),...p});$(b.items||[]),A(b.total||0)}te(e||v),n&&ie(n),H("")}catch(p){H(p.message)}finally{K(!1)}},[i,_,v,C,a]),ne=`${h}|${c.start}|${c.end}|${JSON.stringify(m)}|${a}`,M=r.useRef(!0);r.useEffect(()=>{if(i){if(M.current){M.current=!1,g(1);return}g(1)}},[i,ne]);const W=Object.values(m).filter(Boolean).length,ae=[{title:t("sessIdCol"),dataIndex:"session_id",width:"12%",render:(e,n)=>s.jsx(j,{content:n.session_id||n.visitor_id||"",children:s.jsx("span",{className:"sd-mono",style:{fontSize:12},children:pe(n.session_id||n.visitor_id)||"-"})})},{title:"IP",dataIndex:"ip",width:"10%",render:e=>e?s.jsx("span",{className:"sd-mono",style:{fontSize:12,color:"#00b42a"},title:e,children:e}):s.jsx("span",{style:{color:"#c9cdd4"},children:"—"})},{title:t("sessUserCol"),dataIndex:"end_user",width:"10%",render:e=>e?s.jsx(j,{content:e,children:s.jsx("span",{className:"sd-mono",style:{fontSize:12},children:e})}):s.jsx("span",{style:{color:"#c9cdd4"},children:"—"})},{title:t("visits"),dataIndex:"pageviews",width:"8%"},{title:t("colLoc"),dataIndex:"country",width:"11%",ellipsis:{showTitle:!1},render:(e,n)=>{const f=n.city||n.province||e;if(!f)return s.jsx("span",{style:{color:"#c9cdd4"},children:"—"});const y=[n.country,n.province,n.city].filter(Boolean).join(" · ");return s.jsx(j,{content:y,children:s.jsxs("span",{style:{whiteSpace:"nowrap",display:"inline-flex",alignItems:"center"},children:[s.jsx(we,{country:e}),l==="zh-CN"?f:n.city||n.province||he(e,l)]})})}},{title:t("colBrowser"),dataIndex:"browser",width:"11%",ellipsis:{showTitle:!1},render:(e,n)=>e?s.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[s.jsx(ge,{name:e}),e]}):"-"},{title:t("colOs"),dataIndex:"os",width:"10%",ellipsis:{showTitle:!1},render:(e,n)=>e?s.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[s.jsx(Se,{name:e}),xe(e)]}):"-"},{title:t("colDevice"),dataIndex:"device",width:"9%",render:(e,n)=>e?s.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[s.jsx(Ie,{name:e}),ue(e)]}):"-"},{title:t("lastSeen"),dataIndex:"end_ts",width:"9%",render:e=>s.jsx(j,{content:e?new Date(e*1e3).toLocaleString():"",children:s.jsx("span",{children:e?G(e,Date.now()/1e3,t):"-"})})},{title:t("actions"),dataIndex:"id",width:"10%",render:(e,n)=>s.jsx(ee,{site:i,row:n,label:n.live?`${t("detail")} · LIVE`:t("detail")})}],le=[{title:"IP",dataIndex:"ip",width:"13%",render:(e,n)=>s.jsx(Ce,{r:n,maxWidth:170})},{title:t("ipColFrom"),dataIndex:"source_mix",ellipsis:{showTitle:!1},render:(e,n)=>{if((!e||Object.keys(e).length===0)&&!n.top_ref_host)return s.jsx("span",{style:{color:"#c9cdd4"},children:"—"});const f=Object.entries(e||{}).sort((y,p)=>p[1]-y[1]).slice(0,2).map(([y,p])=>`${t(se[y]||"chOther")}×${p}`);return s.jsx(j,{content:f.join(" / "),children:s.jsxs("span",{style:{fontSize:12,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",display:"block"},children:[f.join(" / "),n.top_ref_host?s.jsxs("span",{style:{color:"#86909c"},children:[" · ",n.top_ref_host]}):null]})})}},{title:t("ipColSessions"),dataIndex:"sessions",width:"8%"},{title:t("srcColPv"),dataIndex:"pv",width:"8%"},{title:t("ipColVisitors"),dataIndex:"visitors",width:"8%"},{title:t("ipColAvgDur"),dataIndex:"avg_duration",width:"9%",render:e=>Y(e||0)},{title:t("ipColFirst"),dataIndex:"first_ts",width:"12%",render:e=>s.jsx(j,{content:e?new Date(e*1e3).toLocaleString():"",children:s.jsx("span",{style:{fontSize:12},children:e?new Date(e*1e3).toLocaleString():"-"})})},{title:t("lastSeen"),dataIndex:"last_ts",width:"10%",render:e=>s.jsx(j,{content:e?new Date(e*1e3).toLocaleString():"",children:s.jsx("span",{children:e?G(e,Date.now()/1e3,t):"-"})})}],oe=B(h,c);if(!i)return s.jsx("div",{className:"page",children:s.jsx(L,{style:{marginTop:60},title:t("noSiteHint")})});const re=s.jsxs("div",{style:{width:264,display:"flex",flexDirection:"column",gap:10,padding:4},children:[s.jsx(T,{size:"small",placeholder:t("colBrowser"),value:x.browser,onChange:e=>I({...x,browser:e})}),s.jsx(T,{size:"small",placeholder:t("colOs"),value:x.os,onChange:e=>I({...x,os:e})}),s.jsx(J,{size:"small",placeholder:t("colDevice"),clearable:!0,style:{width:"100%"},value:x.device||void 0,onChange:e=>I({...x,device:e||""}),optionList:[{value:"desktop",label:"Desktop"},{value:"mobile",label:"Mobile"},{value:"tablet",label:"Tablet"},{value:"bot",label:"Bot"}]}),s.jsx(J,{size:"small",placeholder:t("fSource"),clearable:!0,style:{width:"100%"},filter:!0,value:x.source||void 0,onChange:e=>I({...x,source:e||""}),optionList:["direct","search","social","link","paid","utm","internal"].map(e=>({value:e,label:e}))}),s.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",gap:8},children:[s.jsx(w,{size:"small",onClick:()=>{const e={browser:"",os:"",device:"",source:""};I(e),P(e)},children:t("fReset")}),s.jsx(w,{size:"small",theme:"solid",onClick:()=>P({...x}),children:t("fApply")})]})]});return s.jsxs("div",{className:"page",children:[s.jsxs("div",{className:"toolbar",style:{justifyContent:"space-between"},children:[s.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[s.jsxs("div",{style:{display:"inline-flex",gap:4,marginRight:4},children:[s.jsx(w,{size:"small",theme:a==="sessions"?"solid":"borderless",onClick:()=>d("sessions"),children:t("sessViewSessions")}),s.jsx(w,{size:"small",theme:a==="iptrace"?"solid":"borderless",onClick:()=>d("iptrace"),children:t("sessViewIp")})]}),s.jsx(T,{style:{width:200},size:"small",placeholder:t(a==="iptrace"?"ipPhTrace":"ipPh"),prefix:s.jsx(U,{size:"small"}),value:o,onChange:u,onEnterPress:()=>g(1),showClear:!0}),s.jsx(w,{size:"small",icon:s.jsx(U,{}),onClick:()=>g(1),"aria-label":t("search")})]}),s.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[a==="sessions"&&s.jsx(ve,{siteId:i==null?void 0:i.id,items:[{kind:"sessions",label:t("expSessions")}],params:()=>_()}),a==="sessions"&&s.jsx(me,{trigger:"click",position:"bottomRight",content:re,children:s.jsx(w,{size:"small",children:W?`${t("sessFilter")} · ${W}`:t("sessFilter")})}),["today","yesterday","7d","30d"].map(e=>s.jsx(w,{size:"small",theme:h===e?"solid":"borderless",onClick:()=>S(e),children:t(e==="today"?"today":e==="yesterday"?"yesterday":e==="7d"?"last7":"last30")},e)),s.jsx(ye,{type:"dateRange",size:"small",format:"yyyy-MM-dd",density:"compact",value:h==="custom"?[c.start,c.end]:void 0,placeholder:[t("customRange"),t("customRange")],onChange:e=>{if(e&&e[0]&&e[1]){const n=Z(e[0],e[1]);D(n),S("custom")}},style:{width:230}})]})]}),q&&s.jsx(fe,{type:"danger",description:q,style:{marginBottom:12}}),s.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[a==="iptrace"?s.jsx(O,{className:"sessions-table",columns:le,dataSource:k,rowKey:"ip",loading:V,pagination:!1,empty:s.jsx(L,{description:t("noData")}),size:"middle",expandedRowRender:e=>s.jsx(ze,{site:i,ip:e.ip,range:oe,t})}):s.jsx(O,{className:"sessions-table",columns:ae,dataSource:k,rowKey:"id",loading:V,pagination:!1,empty:s.jsx(L,{description:t("noData")}),size:"middle"}),s.jsxs("div",{style:{display:"flex",justifyContent:"flex-end",alignItems:"center",gap:12,padding:"10px 16px",borderTop:"1px solid #f0f1f3"},children:[s.jsx("span",{style:{color:"#86909c",fontSize:13},children:t("totalN")(F)}),s.jsx(je,{currentPage:v,pageSize:C,total:F,pageSizeOpts:[10,20,50],onPageChange:e=>g(e),onPageSizeChange:e=>g(1,e),showSizeChanger:!0,showQuickJumper:!0,style:{margin:0}})]})]})]})}export{Me as default};