码桶

发现社区成员的开源项目

geekssl /

wstats

公开
main
wstats/public/assets/Geo-BFgcvm3p.js
Geo-BFgcvm3p.js10.7 KB
import{u as ge,a as ue,c as he,r as o,t as P,e as E,b as ve,l as $,f as g,j as e,B as xe,T as z,n as se,v as ye,S as fe,y as Q}from"./index-GWuvg2UH.js";import{B as D}from"./index-DihvOmSo.js";import{D as je}from"./index-DWKYNnDc.js";import{E as S}from"./index-VbOLTMR0.js";import{R as Y,a as v}from"./index-DIHsQVbu.js";import{S as T}from"./index-BZDftoba.js";import{T as M}from"./index-mZVFvfKe.js";import{T as _}from"./index-Bpyda4LF.js";import{e as be}from"./echarts-CEICS1Jr.js";import{E as Se,P as Ce}from"./EChart-Bps-t-O3.js";import"./IconTickCircle-BYgwCdAe.js";import"./object-DkPZvw8u.js";import"./slice-B6jKCnyX.js";import"./Animation-CU6YFe7Y.js";import"./_baseDifference-DopHgqVv.js";import"./index-BMbdBPA2.js";function Z(s,r){const d=P();return s==="today"?{start:d,end:d}:s==="yesterday"?{start:Q(),end:Q()}:s==="7d"?{start:E(7),end:d}:s==="30d"?{start:E(30),end:d}:se(r==null?void 0:r.start,r==null?void 0:r.end)}const ee={};let w=null;function te(s){return String(s||"").replace(/(维吾尔|回族|壮族)?自治区$|特别行政区$|省$|市$/,"")}const Re={中国:"China",China:"China",中国台湾:"China",Taiwan:"China","Taiwan, China":"China",中国香港:"China","Hong Kong":"China","Hong Kong, China":"China",中国澳门:"China",Macao:"China",Macau:"China","Macao, China":"China","United States":"United States",US:"United States",USA:"United States","United States of America":"United States","United Kingdom":"United Kingdom",UK:"United Kingdom","Great Britain":"United Kingdom",Russia:"Russia","Russian Federation":"Russia","South Korea":"Korea",Korea:"Korea","Republic of Korea":"Korea","North Korea":"Dem. Rep. Korea","Dem. Rep. Korea":"Dem. Rep. Korea",Laos:"Lao PDR","Lao PDR":"Lao PDR",Burma:"Myanmar",Myanmar:"Myanmar","Czech Republic":"Czech Rep.",Czechia:"Czech Rep.","Ivory Coast":"Côte d'Ivoire","Côte d'Ivoire":"Côte d'Ivoire","East Timor":"Timor-Leste","Timor-Leste":"Timor-Leste","Viet Nam":"Vietnam",Vietnam:"Vietnam","Brunei Darussalam":"Brunei",Swaziland:"Swaziland",Macedonia:"Macedonia"};function Te(s){return ee[s]?Promise.resolve():fetch(`/geo/${s}.json`).then(r=>{if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()}).then(r=>{if(s==="china"){w={};for(const d of r.features||[]){const c=d&&d.properties&&d.properties.name;c&&(w[te(c)]=c)}}be.registerMap(s==="china"?"wstat-china":"wstat-world",r),ee[s]=!0})}function ke(){var q,J;const{t:s,lang:r}=ge(),d=ue(),{site:c}=he(),[f,ae]=o.useState("7d"),[j,ie]=o.useState({start:E(7),end:P()}),[i,ne]=o.useState(null),[re,I]=o.useState(!1),[U,L]=o.useState(""),[u,oe]=o.useState("world"),[B,V]=o.useState(!1),[O,k]=o.useState(""),[le,de]=o.useState("ip");Z(f,j);const A=o.useCallback(async()=>{if(c){I(!0);try{const a=Z(f,j);ne(await ve.geo(c.id,a.start,a.end)),L("")}catch(a){L(a.message)}finally{I(!1)}}},[c,f,j]);o.useEffect(()=>{A()},[A]),o.useEffect(()=>{V(!1),k(""),Te(u).then(()=>V(!0)).catch(a=>k(String(a.message||a)))},[u]);const N=(i==null?void 0:i.countries)||[],F=(i==null?void 0:i.provinces)||[],K=(i==null?void 0:i.ips)||[],ce=Number((i==null?void 0:i.ip_total)??K.length),b=(i==null?void 0:i.total_visits)||0,C=(i==null?void 0:i.geo_visits)||0,t=(i==null?void 0:i.geo_status)||null,l=[];t?(t.driver==="none"||t.configured==="none"?(l.push(s("geoR1Driver").replace("{driver}",String(t.configured||t.driver))),t.xdb_exists||(l.push(s("geoR2NoFile").replace("{path}",String(t.xdb_path||"server/data/ip2region.xdb"))),(t.xdb_candidates||[]).length>0&&l.push(s("geoR3Mismatch").replace("{files}",(t.xdb_candidates||[]).join(", "))))):!t.xdb_exists&&t.driver!=="http"?(l.push(s("geoR2NoFile").replace("{path}",String(t.xdb_path||"server/data/ip2region.xdb"))),(t.xdb_candidates||[]).length>0&&l.push(s("geoR3Mismatch").replace("{files}",(t.xdb_candidates||[]).join(", ")))):(t.events_geo||0)===0&&(t.events_total||0)>0?l.push(s("geoR4NoResolve").replace("{n}",String(t.events_total)).replace("{g}",String(t.events_geo))):l.push(s("geoR5OldData").replace("{n}",String(b))),t.driver!=="http"&&(t.xdb6_exists?(t.events_ipv6||0)>0&&(t.events_ipv6_geo||0)===0&&l.push(s("geoR6Ipv6").replace("{n}",String(t.events_ipv6))):l.push(s("geoR2NoFile6").replace("{path}",String(t.xdb6_path||"server/data/ip2region_v6.xdb"))))):l.push(s("geoEmpty"));const G=a=>Math.round((a||0)/1048576*10)/10+" MB",H=t?`${s("geoDiagDriver")} ${t.driver||"-"} · ${s("geoDiagXdb")} ${t.xdb_exists?G(t.xdb_size):"-"} · ${s("geoDiagXdb6")} ${t.xdb6_exists?G(t.xdb6_size):"-"} · ${s("geoDiagEvents")} ${t.events_geo||0}/${t.events_total||0}`+(t.events_ipv6?` · ${s("geoDiagEvents6")} ${t.events_ipv6_geo||0}/${t.events_ipv6}`:"")+` · ${s("geoDiagSessions")} ${t.sessions_geo||0}/${t.sessions_total||0}`:"",W=o.useMemo(()=>{if(!B||!i)return null;const a=i.countries||[],p=i.provinces||[];let y;if(u==="world"){const n=new Map;for(const m of a){const h=Re[m.country]||m.country,R=n.get(h)||{visits:0,pv:0,uv:0,raw:m.country};R.visits+=Number(m.visits)||0,R.pv+=Number(m.pv)||0,R.uv+=Number(m.uv)||0,n.set(h,R)}y=[...n.entries()].map(([m,h])=>({name:m,disp:m==="China"?$("China",r):$(h.raw,r),visits:h.visits,pv:h.pv,uv:h.uv}))}else y=p.map(n=>({name:w&&w[te(n.province)]||n.province,disp:n.province,visits:Number(n.visits)||0,pv:Number(n.pv)||0,uv:Number(n.uv)||0}));const me=y.filter(n=>n.name).map(n=>({...n,value:n.visits,itemStyle:{areaColor:"#2e7d32"}}));return{tooltip:{trigger:"item",formatter:n=>n.data&&n.data.visits?`${n.data.disp}<br/>${s("visits")}: ${g(n.data.visits)} · PV ${g(n.data.pv)} · UV ${g(n.data.uv)}`:n.name},series:[{type:"map",map:u==="world"?"wstat-world":"wstat-china",roam:!0,selectedMode:!1,scaleLimit:{min:.7,max:8},itemStyle:{areaColor:"#f2f3f5",borderColor:"#ffffff",borderWidth:.6},emphasis:{label:{show:!0,color:"#1d2129",fontSize:11},itemStyle:{areaColor:"#66bb6a"}},data:me}]}},[B,u,i,r,s]);if(!c)return e.jsx("div",{className:"page",children:e.jsx(S,{style:{marginTop:60},title:s("noSiteHint"),children:e.jsx(xe,{theme:"solid",onClick:()=>d("/sites"),children:s("goSites")})})});const x=(a,p)=>({title:a,dataIndex:p,width:74,render:y=>e.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:g(y)})}),pe=[{title:"IP",dataIndex:"ip",render:a=>e.jsx("span",{className:"sd-mono",style:{background:"transparent",padding:0,color:"#0a8f4c"},title:a,children:a})},x(s("srcColPv"),"pv"),x("UV","uv"),x(s("visits"),"visits")],X=[{title:s("geoColRegion"),dataIndex:u==="world"?"country":"province",ellipsis:{showTitle:!0}},x(s("visits"),"visits"),x(s("srcColPv"),"pv"),x("UV","uv")];return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"toolbar",children:[e.jsx(z.Title,{heading:5,style:{margin:0},children:s("geo")}),e.jsxs("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[e.jsxs(Y,{type:"button",buttonSize:"small",value:f,onChange:a=>ae(a.target.value),children:[e.jsx(v,{value:"today",children:s("today")}),e.jsx(v,{value:"yesterday",children:s("yesterday")}),e.jsx(v,{value:"7d",children:s("last7")}),e.jsx(v,{value:"30d",children:s("last30")}),e.jsx(v,{value:"custom",children:s("customRange")})]}),f==="custom"&&e.jsx(je,{type:"dateRange",size:"small",format:"yyyy-MM-dd",value:[j.start,j.end],onChange:a=>{a&&a[0]&&a[1]&&ie(se(a[0],a[1]))},style:{width:240}})]})]}),U&&e.jsx(D,{type:"danger",description:U,style:{marginBottom:12}}),e.jsxs("div",{className:"stat-grid",children:[e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-label",children:s("geoTotal")}),e.jsx("div",{className:"stat-value",children:g(b)}),e.jsxs("div",{className:"stat-sub",children:[(q=i==null?void 0:i.range)==null?void 0:q.start," ~ ",(J=i==null?void 0:i.range)==null?void 0:J.end]})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-label",children:s("geoResolved")}),e.jsx("div",{className:"stat-value",style:{color:"#00b42a"},children:g(C)}),e.jsx("div",{className:"stat-sub",children:ye(b>0?C/b*100:0)})]}),e.jsxs("div",{className:"stat-card",children:[e.jsx("div",{className:"stat-label",children:s("geoCountries")}),e.jsx("div",{className:"stat-value",children:g(N.length)}),e.jsxs("div",{className:"stat-sub",children:[s("geoColRegion")," TOP40"]})]})]}),re&&!i?e.jsx(T,{active:!0,placeholder:e.jsx(T.Paragraph,{rows:8}),loading:!0}):i?e.jsxs(e.Fragment,{children:[b>0&&C===0&&e.jsx(D,{type:"warning",title:s("geoEmptyTitle"),style:{marginBottom:12},description:e.jsxs("div",{children:[e.jsx("ul",{style:{margin:"4px 0 0 18px",padding:0},children:l.map((a,p)=>e.jsx("li",{style:{marginBottom:2},children:a},p))}),H&&e.jsx("div",{style:{marginTop:6,fontSize:12,opacity:.85,fontFamily:"Consolas, Menlo, monospace"},children:H})]})}),e.jsxs("div",{style:{display:"grid",gridTemplateColumns:"minmax(0, 1.5fr) minmax(0, 1fr)",gap:16,marginBottom:16},children:[e.jsxs("div",{className:"card",style:{padding:12},children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:4},children:[e.jsxs(Y,{type:"button",buttonSize:"small",value:u,onChange:a=>oe(a.target.value),children:[e.jsx(v,{value:"world",children:s("geoWorld")}),e.jsx(v,{value:"china",children:s("geoChina")})]}),e.jsxs(z.Text,{type:"tertiary",size:"small",children:[s("geoTotal")," ",g(C)]})]}),O?e.jsx(D,{type:"warning",description:O,style:{margin:"12px 0"}}):W?e.jsx(Se,{option:W,height:470}):e.jsx(T,{active:!0,placeholder:e.jsx(T.Paragraph,{rows:10}),loading:!0,style:{paddingTop:16}})]}),e.jsx("div",{className:"card",style:{padding:"4px 12px 12px",overflow:"hidden"},children:e.jsxs(_,{activeKey:le,onChange:de,type:"line",children:[e.jsxs(_.TabPane,{tab:s("geoTabIp"),itemKey:"ip",children:[e.jsx("div",{style:{padding:"4px 0 6px",fontSize:12,opacity:.75},children:s("geoIpTotal").replace("{n}",g(ce))}),e.jsx(M,{columns:pe,dataSource:K,rowKey:"ip",pagination:K.length>12?{pageSize:12,size:"small"}:!1,size:"small",empty:e.jsx(S,{description:s("noData")})})]}),e.jsx(_.TabPane,{tab:s("geoTabCountry"),itemKey:"country",children:e.jsx(M,{columns:X.map(a=>a.dataIndex==="country"?{...a,render:(p,y)=>e.jsxs(fe,{children:[e.jsx("span",{style:{display:"inline-block",width:8,height:8,borderRadius:"50%",background:Ce[3],marginRight:2}}),$(p,r)]})}:a),dataSource:N,rowKey:"country",pagination:N.length>12?{pageSize:12,size:"small"}:!1,size:"small",empty:e.jsx(S,{description:s("noData")})})}),e.jsx(_.TabPane,{tab:s("geoTabProvince"),itemKey:"province",children:e.jsx(M,{columns:X.map(a=>a.dataIndex==="country"?{...a,dataIndex:"province",render:p=>e.jsx("span",{style:{display:"inline-block",paddingLeft:14},children:p})}:a),dataSource:F,rowKey:"province",pagination:F.length>12?{pageSize:12,size:"small"}:!1,size:"small",empty:e.jsx(S,{description:s("noData")})})})]})})]}),e.jsxs(z.Text,{type:"tertiary",style:{fontSize:12,display:"block",marginTop:4},children:[c.name," · ",c.domain," · ",s("range"),": ",i.range.start," ~ ",i.range.end,"(",P(),") · sessions.country / province / ip"]})]}):e.jsx(S,{description:s("noData"),style:{margin:"40px 0"}})]})}export{ke as default};