Geo-mfzyT0lE.js10.7 KB
import{u as me,b as ue,e as he,r as o,t as P,g as E,c as ve,o as $,h as m,j as e,d as xe,T as z,n as te,x as ye,S as fe,y as Q}from"./index-DS2B3OLK.js";import{B as D}from"./index-BNK0Nj_J.js";import{D as je}from"./index-3kr5QjM4.js";import{E as S}from"./index-dKmdA2E0.js";import{R as Y,a as v}from"./index-CElfosix.js";import{S as T}from"./index-Bj7oeOfx.js";import{T as M}from"./index-b2iqXj_X.js";import{T as w}from"./index-BkQnUDM_.js";import{e as be}from"./echarts-CEICS1Jr.js";import{E as Se,P as Ce}from"./EChart-DcWCF1N5.js";import"./IconTickCircle-Bbh_c2jr.js";import"./object-DvQZmkoP.js";import"./slice-s3-7cpgr.js";import"./Animation-BXPC60cz.js";import"./_baseDifference-D1QxGNC2.js";import"./index-R4PZyHYh.js";function Z(t,r){const d=P();return t==="today"?{start:d,end:d}:t==="yesterday"?{start:Q(),end:Q()}:t==="7d"?{start:E(7),end:d}:t==="30d"?{start:E(30),end:d}:te(r==null?void 0:r.start,r==null?void 0:r.end)}const ee={};let _=null;function se(t){return String(t||"").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(t){return ee[t]?Promise.resolve():fetch(`/geo/${t}.json`).then(r=>{if(!r.ok)throw new Error(`HTTP ${r.status}`);return r.json()}).then(r=>{if(t==="china"){_={};for(const d of r.features||[]){const c=d&&d.properties&&d.properties.name;c&&(_[se(c)]=c)}}be.registerMap(t==="china"?"wstat-china":"wstat-world",r),ee[t]=!0})}function ke(){var q,J;const{t,lang:r}=me(),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,s=(i==null?void 0:i.geo_status)||null,l=[];s?(s.driver==="none"||s.configured==="none"?(l.push(t("geoR1Driver").replace("{driver}",String(s.configured||s.driver))),s.xdb_exists||(l.push(t("geoR2NoFile").replace("{path}",String(s.xdb_path||"server/data/ip2region.xdb"))),(s.xdb_candidates||[]).length>0&&l.push(t("geoR3Mismatch").replace("{files}",(s.xdb_candidates||[]).join(", "))))):!s.xdb_exists&&s.driver!=="http"?(l.push(t("geoR2NoFile").replace("{path}",String(s.xdb_path||"server/data/ip2region.xdb"))),(s.xdb_candidates||[]).length>0&&l.push(t("geoR3Mismatch").replace("{files}",(s.xdb_candidates||[]).join(", ")))):(s.events_geo||0)===0&&(s.events_total||0)>0?l.push(t("geoR4NoResolve").replace("{n}",String(s.events_total)).replace("{g}",String(s.events_geo))):l.push(t("geoR5OldData").replace("{n}",String(b))),s.driver!=="http"&&(s.xdb6_exists?(s.events_ipv6||0)>0&&(s.events_ipv6_geo||0)===0&&l.push(t("geoR6Ipv6").replace("{n}",String(s.events_ipv6))):l.push(t("geoR2NoFile6").replace("{path}",String(s.xdb6_path||"server/data/ip2region_v6.xdb"))))):l.push(t("geoEmpty"));const G=a=>Math.round((a||0)/1048576*10)/10+" MB",H=s?`${t("geoDiagDriver")} ${s.driver||"-"} · ${t("geoDiagXdb")} ${s.xdb_exists?G(s.xdb_size):"-"} · ${t("geoDiagXdb6")} ${s.xdb6_exists?G(s.xdb6_size):"-"} · ${t("geoDiagEvents")} ${s.events_geo||0}/${s.events_total||0}`+(s.events_ipv6?` · ${t("geoDiagEvents6")} ${s.events_ipv6_geo||0}/${s.events_ipv6}`:"")+` · ${t("geoDiagSessions")} ${s.sessions_geo||0}/${s.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 g of a){const h=Re[g.country]||g.country,R=n.get(h)||{visits:0,pv:0,uv:0,raw:g.country};R.visits+=Number(g.visits)||0,R.pv+=Number(g.pv)||0,R.uv+=Number(g.uv)||0,n.set(h,R)}y=[...n.entries()].map(([g,h])=>({name:g,disp:g==="China"?$("China",r):$(h.raw,r),visits:h.visits,pv:h.pv,uv:h.uv}))}else y=p.map(n=>({name:_&&_[se(n.province)]||n.province,disp:n.province,visits:Number(n.visits)||0,pv:Number(n.pv)||0,uv:Number(n.uv)||0}));const ge=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/>${t("visits")}: ${m(n.data.visits)} · PV ${m(n.data.pv)} · UV ${m(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:ge}]}},[B,u,i,r,t]);if(!c)return e.jsx("div",{className:"page",children:e.jsx(S,{style:{marginTop:60},title:t("noSiteHint"),children:e.jsx(xe,{theme:"solid",onClick:()=>d("/sites"),children:t("goSites")})})});const x=(a,p)=>({title:a,dataIndex:p,width:74,render:y=>e.jsx("span",{style:{fontVariantNumeric:"tabular-nums"},children:m(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(t("srcColPv"),"pv"),x("UV","uv"),x(t("visits"),"visits")],X=[{title:t("geoColRegion"),dataIndex:u==="world"?"country":"province",ellipsis:{showTitle:!0}},x(t("visits"),"visits"),x(t("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:t("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:t("today")}),e.jsx(v,{value:"yesterday",children:t("yesterday")}),e.jsx(v,{value:"7d",children:t("last7")}),e.jsx(v,{value:"30d",children:t("last30")}),e.jsx(v,{value:"custom",children:t("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(te(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:t("geoTotal")}),e.jsx("div",{className:"stat-value",children:m(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:t("geoResolved")}),e.jsx("div",{className:"stat-value",style:{color:"#00b42a"},children:m(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:t("geoCountries")}),e.jsx("div",{className:"stat-value",children:m(N.length)}),e.jsxs("div",{className:"stat-sub",children:[t("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:t("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:"var(--wstat-mono)"},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:t("geoWorld")}),e.jsx(v,{value:"china",children:t("geoChina")})]}),e.jsxs(z.Text,{type:"tertiary",size:"small",children:[t("geoTotal")," ",m(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(w,{activeKey:le,onChange:de,type:"line",children:[e.jsxs(w.TabPane,{tab:t("geoTabIp"),itemKey:"ip",children:[e.jsx("div",{style:{padding:"4px 0 6px",fontSize:12,opacity:.75},children:t("geoIpTotal").replace("{n}",m(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:t("noData")})})]}),e.jsx(w.TabPane,{tab:t("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:t("noData")})})}),e.jsx(w.TabPane,{tab:t("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:t("noData")})})})]})})]}),e.jsxs(z.Text,{type:"tertiary",style:{fontSize:12,display:"block",marginTop:4},children:[c.name," · ",c.domain," · ",t("range"),": ",i.range.start," ~ ",i.range.end,"(",P(),") · sessions.country / province / ip"]})]}):e.jsx(S,{description:t("noData"),style:{margin:"40px 0"}})]})}export{ke as default};