码桶

发现社区成员的开源项目

geekssl /

wstats

公开
main
wstats/public/assets/Goals-yvePkYh_.js
Goals-yvePkYh_.js7.1 KB
import{u as te,a as ae,c as se,r as l,b as h,q as ne,j as e,B as x,T as ie,C as le,o as z,f as N,F as A}from"./index-GWuvg2UH.js";import{B as H}from"./index-DihvOmSo.js";import{C as oe}from"./index-BVKuUSRW.js";import{E as V}from"./index-VbOLTMR0.js";import{M as q}from"./Modal-08QhW3n9.js";import{R as w,a as j}from"./index-DIHsQVbu.js";import{S}from"./index-BZDftoba.js";import{T as P}from"./index-BW_2QB9V.js";import{E as re}from"./EChart-Bps-t-O3.js";import{I as J}from"./IconPlus-Dkwh5Gs5.js";import{I as ce}from"./IconEdit-CHNNVEq9.js";import{I as de}from"./IconDelete-CdbtfS3z.js";import"./IconTickCircle-BYgwCdAe.js";import"./_baseDifference-DopHgqVv.js";import"./echarts-CEICS1Jr.js";const me=[1,7,30],ge=["prefix","contains","exact"],pe={name:"",type:"page",target:"",match_type:"contains"};function Pe(){var M,O,$;const{t:a}=te(),K=ae(),{site:r}=se(),C=(r==null?void 0:r.role)==="viewer",[T,Q]=l.useState(7),[y,_]=l.useState(null),[m,u]=l.useState(""),[o,k]=l.useState(null),[U,B]=l.useState(!1),[I,E]=l.useState(""),[i,c]=l.useState(null),[X,D]=l.useState(!1),[F,p]=l.useState(""),v=l.useCallback(async()=>{if(r)try{const t=await h.goals(r.id);_(t.items||[]),u(s=>{const d=(t.items||[]).map(g=>String(g.id));return s&&d.includes(String(s))?s:d[0]||""})}catch(t){E(t.message)}},[r]);l.useEffect(()=>{_(null),k(null),u(""),v()},[v]);const G=l.useCallback(async()=>{if(!(!r||!m)){B(!0);try{const{start:t,end:s}=ne(T);k(await h.goalData(m,r.id,t,s)),E("")}catch(t){E(t.message)}finally{B(!1)}}},[r,m,T]);if(l.useEffect(()=>{G()},[G]),!r)return e.jsx("div",{className:"page",children:e.jsx(V,{style:{marginTop:60},title:a("noSiteHint"),children:e.jsx(x,{theme:"solid",onClick:()=>K("/sites"),children:a("goSites")})})});const n=(y||[]).find(t=>String(t.id)===String(m))||null,R=()=>{p(""),c({id:0,...pe})},Y=()=>{n&&(p(""),c({id:n.id,name:n.name,type:n.type,target:n.target,match_type:n.match_type}))},Z=async()=>{const t=i,s=t.name.trim(),d=t.target.trim();if(!s){p(a("goalName"));return}if(!d){p(t.type==="page"?a("goalTargetPage"):a("goalTargetEvent"));return}D(!0);try{const g={site_id:r.id,name:s,type:t.type,target:d,match_type:t.match_type};t.id?await h.updateGoal(t.id,g):await h.createGoal(g),c(null),await v(),P.success(a("goalSaved"))}catch(g){p(g.message)}finally{D(!1)}},ee=()=>{n&&q.confirm({title:a("goalDel"),content:a("goalDelConfirm"),onOk:async()=>{try{await h.deleteGoal(n.id),P.success(a("goalDelOk")),u(""),await v()}catch(t){P.error(t.message)}}})},b=(o==null?void 0:o.trend)||[],W=b.length?{tooltip:{trigger:"axis"},grid:{left:42,right:16,top:20,bottom:24},xAxis:{type:"category",data:b.map(t=>t.day)},yAxis:{type:"value",minInterval:1},series:[{type:"bar",name:a("goalConversions"),barMaxWidth:26,itemStyle:{color:"#2a5cff",borderRadius:[3,3,0,0]},data:b.map(t=>t.conversions)}]}:null,L={prefix:a("matchPrefix"),contains:a("matchContains"),exact:a("matchExact")},f=(t,s,d)=>e.jsxs(oe,{bodyStyle:{padding:"14px 18px"},style:{flex:1,minWidth:150},children:[e.jsx("div",{style:{fontSize:13,color:"#86909c",marginBottom:6},children:t}),e.jsx("div",{style:{fontSize:26,fontWeight:600,lineHeight:1.2},children:s}),d&&e.jsx("div",{style:{fontSize:12,color:"#86909c",marginTop:4},children:d})]});return e.jsxs("div",{className:"page",children:[e.jsxs("div",{className:"toolbar",children:[e.jsx(ie.Title,{heading:5,style:{margin:0},children:a("goal")}),e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:10},children:[e.jsx(w,{type:"button",buttonSize:"small",value:T,onChange:t=>Q(Number(t.target.value)),children:me.map(t=>e.jsxs(j,{value:t,children:[t,"D"]},t))}),!C&&e.jsx(x,{size:"small",icon:e.jsx(J,{}),theme:"solid",onClick:R,children:a("goalNew")})]})]}),I&&e.jsx(H,{type:"danger",description:I,style:{marginBottom:12}}),y===null?e.jsx("div",{className:"card",children:e.jsx(S,{active:!0,placeholder:e.jsx(S.Paragraph,{rows:6}),loading:!0})}):y.length===0?e.jsx("div",{className:"card",children:e.jsx(V,{style:{margin:"40px 0"},description:a("goalEmpty"),children:!C&&e.jsx(x,{theme:"solid",icon:e.jsx(J,{}),onClick:R,children:a("goalNew")})})}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"card",style:{padding:"10px 16px",marginBottom:14,display:"flex",alignItems:"center",gap:10,flexWrap:"wrap"},children:[e.jsx("span",{style:{fontSize:13,color:"#86909c"},children:a("goalPick")}),e.jsx(le,{size:"small",style:{minWidth:220},value:m?String(m):void 0,onChange:t=>u(t),optionList:y.map(t=>({value:String(t.id),label:t.name}))}),n&&e.jsxs(e.Fragment,{children:[e.jsx(z,{size:"small",color:n.type==="event"?"purple":"blue",children:n.type==="event"?a("goalTypeEvent"):a("goalTypePage")}),e.jsx(z,{size:"small",style:{fontFamily:"monospace"},children:n.target}),n.type==="page"&&e.jsx(z,{size:"small",children:L[n.match_type]||n.match_type}),e.jsx("span",{style:{flex:1}}),!C&&e.jsxs(e.Fragment,{children:[e.jsx(x,{size:"small",icon:e.jsx(ce,{}),onClick:Y,children:a("goalEdit")}),e.jsx(x,{size:"small",type:"danger",icon:e.jsx(de,{}),onClick:ee,children:a("goalDel")})]})]})]}),U&&!o?e.jsx("div",{className:"card",children:e.jsx(S,{active:!0,placeholder:e.jsx(S.Paragraph,{rows:5}),loading:!0})}):o?e.jsxs(e.Fragment,{children:[e.jsxs("div",{style:{display:"flex",gap:12,flexWrap:"wrap",marginBottom:14},children:[f(a("goalVisits"),N(o.visits),`${(M=o.range)==null?void 0:M.start} ~ ${(O=o.range)==null?void 0:O.end}`),f(a("goalConversions"),N(o.conversions)),f(a("goalConvertedVisitors"),N(o.converted_visitors)),f(a("goalRate"),`${o.rate}%`)]}),W&&e.jsxs("div",{className:"chart-box",children:[e.jsxs("div",{className:"card-title",children:[a("goalTrend")," · ",($=o.goal)==null?void 0:$.name]}),e.jsx(re,{option:W,height:280})]})]}):null]}),e.jsx(q,{title:i!=null&&i.id?a("goalEdit"):a("goalNew"),visible:i!==null,onCancel:()=>c(null),onOk:Z,okButtonProps:{loading:X},width:520,children:i&&e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:14,paddingTop:6},children:[F&&e.jsx(H,{type:"danger",description:F}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,marginBottom:6},children:a("goalName")}),e.jsx(A,{placeholder:a("goalNamePh"),value:i.name,onChange:t=>c(s=>({...s,name:t}))})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,marginBottom:6},children:a("goalType")}),e.jsxs(w,{type:"button",buttonSize:"small",value:i.type,onChange:t=>c(s=>({...s,type:t.target.value,match_type:t.target.value==="event"?"exact":s.match_type})),children:[e.jsx(j,{value:"page",children:a("goalTypePage")}),e.jsx(j,{value:"event",children:a("goalTypeEvent")})]}),e.jsx("div",{style:{fontSize:12,color:"#86909c",marginTop:6},children:a("goalTypeTip")})]}),e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,marginBottom:6},children:i.type==="page"?a("goalTargetPage"):a("goalTargetEvent")}),e.jsx(A,{placeholder:i.type==="page"?a("goalTargetPagePh"):a("goalTargetEventPh"),value:i.target,style:{fontFamily:"monospace"},onChange:t=>c(s=>({...s,target:t}))})]}),i.type==="page"&&e.jsxs("div",{children:[e.jsx("div",{style:{fontSize:13,marginBottom:6},children:a("goalMatch")}),e.jsx(w,{type:"button",buttonSize:"small",value:i.match_type,onChange:t=>c(s=>({...s,match_type:t.target.value})),children:ge.map(t=>e.jsx(j,{value:t,children:L[t]},t))})]})]})})]})}export{Pe as default};