码桶
发现社区成员的开源项目
AllSites-BbPMPeES.js5.8 KB
import{u as z,c as E,a as M,r as i,b as A,m as D,j as e,T as c,o as u,g as _,S as w,B as H,f as j,p as L}from"./index-GWuvg2UH.js";import{B as F}from"./index-DihvOmSo.js";import{S as K}from"./index-CfWZ9ycl.js";import{T as O}from"./index-mZVFvfKe.js";import{u as U}from"./useVisibilityRefresh-DRH6QDT3.js";import{I as V}from"./IconRefresh-BRkV1NtY.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";function g({today:r,yesterday:a,suffix:n=""}){const{t:o}=z(),x=Number(r)||0,l=Number(a)||0;if(l===0&&x===0)return e.jsx(u,{size:"small",color:"grey",type:"light",children:"—"});if(l===0)return e.jsxs(u,{size:"small",color:"green",type:"light",children:["↑ ",o("asNew")]});const d=(x-l)/l*100;if(Math.abs(d)<.05)return e.jsx(u,{size:"small",color:"grey",type:"light",children:"0%"});const p=d>0;return e.jsxs(u,{size:"small",color:p?"green":"red",type:"light",children:[p?"↑":"↓"," ",Math.abs(d).toFixed(1),"%",n]})}function m({today:r,yesterday:a,fmt:n=j}){return e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:n(r)}),e.jsxs("div",{style:{fontSize:12,color:"#86909c",display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{children:n(a)}),e.jsx(g,{today:r,yesterday:a})]})]})}function re(){const{t:r}=z(),{setSiteId:a}=E(),n=M(),[o,x]=i.useState(null),[l,d]=i.useState(!1),[p,b]=i.useState(""),[h,k]=i.useState(!0),[T,I]=i.useState(""),f=i.useRef(null),y=i.useCallback(async()=>{d(!0);try{const s=await A.allSites();x(s),b(""),I(new Date().toLocaleTimeString())}catch(s){b(s.message)}finally{d(!1)}},[]);i.useEffect(()=>{y()},[y]),i.useEffect(()=>(f.current&&clearInterval(f.current),h&&(f.current=setInterval(()=>{y()},3e4)),()=>clearInterval(f.current)),[h,y]),U(()=>{h&&y()});const[C,W]=D(),S=i.useCallback(s=>{a(String(s)),n("/overview")},[a,n]),B=i.useMemo(()=>[{title:r("asSite"),width:220,fixed:"left",render:(s,t)=>e.jsxs("div",{children:[e.jsx(c.Text,{link:!0,onClick:()=>S(t.site_id),style:{cursor:"pointer",fontWeight:600},children:t.name}),e.jsxs("div",{style:{fontSize:12,color:"#86909c",display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{children:t.domain}),!t.verified&&e.jsx(u,{size:"small",color:"amber",type:"light",children:r("unverified")})]})]})},{title:r("online"),width:80,sorter:(s,t)=>s.online-t.online,render:(s,t)=>t.online>0?e.jsx(u,{size:"small",color:"green",type:"light",children:t.online}):e.jsx(c.Text,{type:"tertiary",children:"0"})},{title:r("pv"),width:130,sorter:(s,t)=>s.today.pv-t.today.pv,defaultSortOrder:"descend",render:(s,t)=>e.jsx(m,{today:t.today.pv,yesterday:t.yesterday.pv})},{title:r("uv"),width:130,sorter:(s,t)=>s.today.uv-t.today.uv,render:(s,t)=>e.jsx(m,{today:t.today.uv,yesterday:t.yesterday.uv})},{title:r("visits"),width:130,sorter:(s,t)=>s.today.visits-t.today.visits,render:(s,t)=>e.jsx(m,{today:t.today.visits,yesterday:t.yesterday.visits})},{title:r("bounceRate"),width:110,sorter:(s,t)=>s.today.bounce_rate-t.today.bounce_rate,render:(s,t)=>e.jsxs("div",{children:[e.jsxs("div",{style:{fontWeight:600},children:[t.today.bounce_rate,"%"]}),e.jsxs("div",{style:{fontSize:12,color:"#86909c",display:"flex",alignItems:"center",gap:6},children:[e.jsxs("span",{children:[t.yesterday.bounce_rate,"%"]}),e.jsx(g,{today:t.today.bounce_rate,yesterday:t.yesterday.bounce_rate})]})]})},{title:r("avgDuration"),width:110,sorter:(s,t)=>s.today.avg_duration-t.today.avg_duration,render:(s,t)=>e.jsxs("div",{children:[e.jsx("div",{style:{fontWeight:600},children:_(t.today.avg_duration)}),e.jsxs("div",{style:{fontSize:12,color:"#86909c",display:"flex",alignItems:"center",gap:6},children:[e.jsx("span",{children:_(t.yesterday.avg_duration)}),e.jsx(g,{today:t.today.avg_duration,yesterday:t.yesterday.avg_duration})]})]})},{title:r("mNew"),width:130,sorter:(s,t)=>s.today.new_users-t.today.new_users,render:(s,t)=>e.jsx(m,{today:t.today.new_users,yesterday:t.yesterday.new_users})}],[r,S]),R=i.useMemo(()=>{if(!o)return[];const s=o.total||{};return[{key:"pv",label:r("pv")},{key:"uv",label:r("uv")},{key:"visits",label:r("visits")},{key:"new_users",label:r("mNew")}].map(v=>({...v,today:(s.today||{})[v.key]??0,yesterday:(s.yesterday||{})[v.key]??0}))},[o,r]),N=o&&o.items||[];return e.jsxs("div",{style:{padding:20},ref:C,children:[e.jsxs("div",{style:{display:"flex",alignItems:"center",justifyContent:"space-between",marginBottom:12,flexWrap:"wrap",gap:8},children:[e.jsxs(w,{children:[e.jsx(c.Title,{heading:4,style:{margin:0},children:r("allSites")}),e.jsx(c.Text,{type:"tertiary",style:{fontSize:12},children:r("asHint")})]}),e.jsxs(w,{children:[e.jsx(c.Text,{type:"tertiary",style:{fontSize:12},children:r("autoRefresh")}),e.jsx(K,{size:"small",checked:h,onChange:k}),e.jsx(c.Text,{type:"tertiary",style:{fontSize:12},children:T}),e.jsx(H,{icon:e.jsx(V,{}),size:"small",loading:l,onClick:y,children:r("refresh")})]})]}),p&&e.jsx(F,{type:"danger",closeIcon:null,style:{marginBottom:12},children:p}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(200px, 1fr))",gap:12,marginBottom:16},children:R.map(s=>e.jsxs("div",{style:{background:"#fff",border:"1px solid #e5e6eb",borderRadius:8,padding:"14px 16px"},children:[e.jsxs("div",{style:{fontSize:13,color:"#86909c"},children:[s.label," · ",r("asTotal")]}),e.jsxs("div",{style:{display:"flex",alignItems:"baseline",gap:8,marginTop:4,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:26,fontWeight:700,lineHeight:1.2},children:j(s.today)}),e.jsxs("span",{style:{fontSize:12,color:"#86909c"},children:[r("yesterday")," ",j(s.yesterday)]}),e.jsx(g,{today:s.today,yesterday:s.yesterday})]})]},s.key))}),e.jsx("div",{style:{background:"#fff",border:"1px solid #e5e6eb",borderRadius:8,padding:12},children:e.jsx(O,{columns:B,dataSource:N,rowKey:"site_id",size:"small",loading:l,empty:r("noSiteHint"),scroll:L(W,1080),pagination:!1})})]})}export{re as default};