码桶

发现社区成员的开源项目

geekssl /

wstats

公开
main
wstats/public/assets/Sessions-DOMTnFCs.js
Sessions-DOMTnFCs.js7 KB
import{u as W,c as G,r as n,t as _,e as g,b as X,j as s,h as f,x as Y,l as Z,z as ee,w as se,A as te,F as b,C as T,B as x,I as E,D as ae,n as $,y as R}from"./index-GWuvg2UH.js";import{B as ie}from"./index-DihvOmSo.js";import{D as ne}from"./index-DWKYNnDc.js";import{E as O}from"./index-VbOLTMR0.js";import{T as le,P as oe}from"./index-mZVFvfKe.js";import{F as re,B as de,O as ce,D as pe,S as me}from"./SessionDetail-EWkH_y26.js";import{E as ue}from"./ExportButton-ChE0FTgH.js";import"./IconTickCircle-BYgwCdAe.js";import"./object-DkPZvw8u.js";import"./slice-B6jKCnyX.js";import"./index-DIHsQVbu.js";import"./Animation-CU6YFe7Y.js";import"./_baseDifference-DopHgqVv.js";import"./index-BMbdBPA2.js";import"./index-WdvJbv7c.js";import"./index-C23zBuz1.js";import"./index-Bpyda4LF.js";import"./index-BW_2QB9V.js";function L(t,o){const i=_();return t==="today"?{start:i,end:i}:t==="yesterday"?{start:R(),end:R()}:t==="7d"?{start:g(7),end:i}:t==="30d"?{start:g(30),end:i}:$(o&&o.start,o&&o.end)||{start:g(7),end:i}}function Ee(){const{t,lang:o}=W(),{site:i}=G(),[c,I]=n.useState("today"),[r,F]=n.useState({start:g(7),end:_()}),[j,k]=n.useState(""),[l,u]=n.useState({browser:"",os:"",device:"",source:""}),[d,v]=n.useState({browser:"",os:"",device:"",source:""}),[h,A]=n.useState(1),[w,K]=n.useState(10),[M,J]=n.useState([]),[C,q]=n.useState(0),[H,z]=n.useState(!1),[B,D]=n.useState(""),S=n.useCallback(()=>({start:L(c,r).start,end:L(c,r).end,q:j.trim(),browser:d.browser.trim(),os:d.os.trim(),device:d.device,source:d.source}),[c,r,j,d]),p=n.useCallback(async(e,a)=>{if(i){z(!0);try{const m=S(),y=await X.sessions(i.id,{page:String(e||h),size:String(a||w),...m});J(y.items||[]),q(y.total||0),A(e||h),a&&K(a),D("")}catch(m){D(m.message)}finally{z(!1)}}},[i,S,h,w]),Q=`${c}|${r.start}|${r.end}|${JSON.stringify(d)}`,N=n.useRef(!0);n.useEffect(()=>{if(i){if(N.current){N.current=!1,p(1);return}p(1)}},[i,Q]);const P=Object.values(d).filter(Boolean).length,U=[{title:t("sessIdCol"),dataIndex:"session_id",width:"12%",render:(e,a)=>s.jsx(f,{content:a.session_id||a.visitor_id||"",children:s.jsx("span",{className:"sd-mono",style:{fontSize:12},children:Y(a.session_id||a.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(f,{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,a)=>{const m=a.city||a.province||e;if(!m)return s.jsx("span",{style:{color:"#c9cdd4"},children:"—"});const y=[a.country,a.province,a.city].filter(Boolean).join(" · ");return s.jsx(f,{content:y,children:s.jsxs("span",{style:{whiteSpace:"nowrap",display:"inline-flex",alignItems:"center"},children:[s.jsx(re,{country:e}),o==="zh-CN"?m:a.city||a.province||Z(e,o)]})})}},{title:t("colBrowser"),dataIndex:"browser",width:"11%",ellipsis:{showTitle:!1},render:(e,a)=>e?s.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[s.jsx(de,{name:e}),e]}):"-"},{title:t("colOs"),dataIndex:"os",width:"10%",ellipsis:{showTitle:!1},render:(e,a)=>e?s.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[s.jsx(ce,{name:e}),ee(e)]}):"-"},{title:t("colDevice"),dataIndex:"device",width:"9%",render:(e,a)=>e?s.jsxs("span",{style:{display:"inline-flex",alignItems:"center"},children:[s.jsx(pe,{name:e}),se(e)]}):"-"},{title:t("lastSeen"),dataIndex:"end_ts",width:"9%",render:e=>s.jsx(f,{content:e?new Date(e*1e3).toLocaleString():"",children:s.jsx("span",{children:e?te(e,Date.now()/1e3,t):"-"})})},{title:t("actions"),dataIndex:"id",width:"10%",render:(e,a)=>s.jsx(me,{site:i,row:a,label:a.live?`${t("detail")} · LIVE`:t("detail")})}];if(!i)return s.jsx("div",{className:"page",children:s.jsx(O,{style:{marginTop:60},title:t("noSiteHint")})});const V=s.jsxs("div",{style:{width:264,display:"flex",flexDirection:"column",gap:10,padding:4},children:[s.jsx(b,{size:"small",placeholder:t("colBrowser"),value:l.browser,onChange:e=>u({...l,browser:e})}),s.jsx(b,{size:"small",placeholder:t("colOs"),value:l.os,onChange:e=>u({...l,os:e})}),s.jsx(T,{size:"small",placeholder:t("colDevice"),clearable:!0,style:{width:"100%"},value:l.device||void 0,onChange:e=>u({...l,device:e||""}),optionList:[{value:"desktop",label:"Desktop"},{value:"mobile",label:"Mobile"},{value:"tablet",label:"Tablet"},{value:"bot",label:"Bot"}]}),s.jsx(T,{size:"small",placeholder:t("fSource"),clearable:!0,style:{width:"100%"},filter:!0,value:l.source||void 0,onChange:e=>u({...l,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(x,{size:"small",onClick:()=>{const e={browser:"",os:"",device:"",source:""};u(e),v(e)},children:t("fReset")}),s.jsx(x,{size:"small",theme:"solid",onClick:()=>v({...l}),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.jsx(b,{style:{width:200},size:"small",placeholder:t("ipPh"),prefix:s.jsx(E,{size:"small"}),value:j,onChange:k,onEnterPress:()=>p(1),showClear:!0}),s.jsx(x,{size:"small",icon:s.jsx(E,{}),onClick:()=>p(1),"aria-label":t("search")})]}),s.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center",flexWrap:"wrap"},children:[s.jsx(ue,{siteId:i==null?void 0:i.id,items:[{kind:"sessions",label:t("expSessions")}],params:()=>S()}),s.jsx(ae,{trigger:"click",position:"bottomRight",content:V,children:s.jsx(x,{size:"small",children:P?`${t("sessFilter")} · ${P}`:t("sessFilter")})}),["today","yesterday","7d","30d"].map(e=>s.jsx(x,{size:"small",theme:c===e?"solid":"borderless",onClick:()=>I(e),children:t(e==="today"?"today":e==="yesterday"?"yesterday":e==="7d"?"last7":"last30")},e)),s.jsx(ne,{type:"dateRange",size:"small",format:"yyyy-MM-dd",density:"compact",value:c==="custom"?[r.start,r.end]:void 0,placeholder:[t("customRange"),t("customRange")],onChange:e=>{if(e&&e[0]&&e[1]){const a=$(e[0],e[1]);F(a),I("custom")}},style:{width:230}})]})]}),B&&s.jsx(ie,{type:"danger",description:B,style:{marginBottom:12}}),s.jsxs("div",{className:"card",style:{padding:0,overflow:"hidden"},children:[s.jsx(le,{className:"sessions-table",columns:U,dataSource:M,rowKey:"id",loading:H,pagination:!1,empty:s.jsx(O,{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")(C)}),s.jsx(oe,{currentPage:h,pageSize:w,total:C,pageSizeOpts:[10,20,50],onPageChange:e=>p(e),onPageSizeChange:e=>p(1,e),showSizeChanger:!0,showQuickJumper:!0,style:{margin:0}})]})]})]})}export{Ee as default};