2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
import{d as U,o as g,c as h,a as e,t as i,J as z,g as m,h as N,v as G,b as a,j as k,w as r,e as c,k as L,G as V,D as T,F as H,i as O}from"./index-229ba0a3.js";import{_ as A,u as q}from"./useBaseTable-9961a393.js";import{_ as Q,B as W}from"./button.vue_vue_type_style_index_0_lang-08cdb61a.js";import{g as X,a as Y,s as Z,b as ee,c as te,d as se}from"./pushNotification-87eb05bb.js";import{t as F}from"./useDataTime-024ee901.js";import{M as ae}from"./index-e82d9954.js";import{I as j}from"./index-83597ea6.js";import{_ as le}from"./BasicModal.vue_vue_type_style_index_0_lang-8927c0a8.js";import{I as oe}from"./Icon-b73f0ccd.js";import{D as ne,_ as re}from"./index-ed1024fe.js";import{S as ie}from"./index-939f3031.js";import{T as de}from"./shallowequal-e16473e7.js";import{_ as ue,T as ce}from"./index-a7c49db8.js";import"./fa_IR-3a494b17.js";import"./toArray-2b8ac8d2.js";import"./vnode-29431c52.js";import"./FormItemContext-d2efc581.js";import"./pickAttrs-a633b394.js";import"./useState-5d84a598.js";import"./_plugin-vue_export-helper-5c7e4561.js";import"./lodash-6658ee3b.js";import"./css-ddfc5c90.js";import"./DialogWrap-81e16685.js";import"./index-fbe56609.js";import"./styleChecker-4d6469c9.js";import"./isPlainObject-17ad1cae.js";import"./useRefs-97fcf834.js";import"./_flatRest-fbf51dda.js";const _e={class:"py-2 pr-3 w-full h-full relative"},pe={class:"text-black font-bold"},me={class:"mt-5 overflow-y-auto p-2 h-[96%]"},fe=U({__name:"BasicShowContext",props:{title:{}},setup(t){const l=t;return(d,$)=>(g(),h("div",_e,[e("div",pe,i(l.title),1),e("div",me,[z(d.$slots,"default")])]))}}),ve=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,customRender:t=>{var d;return((t==null?void 0:t.index)??((d=t==null?void 0:t.record)==null?void 0:d.index)??0)+1}},{title:"نام",dataIndex:"first_name",key:"first_name",filterable:!0},{title:"نام خانوادگی",dataIndex:"last_name",key:"last_name",filterable:!0},{title:"شماره همراه",dataIndex:"phone",key:"phone",filterable:!0},{title:"اعلان فعال",dataIndex:"has_push",key:"has_push",filterField:"has_push",type:"Select",filterable:!0,filterComponentProps:{options:[{label:"فعال",value:"1"},{label:"غیرفعال",value:"0"}]},customRender:t=>{var d;const l=((d=t==null?void 0:t.record)==null?void 0:d.record)??(t==null?void 0:t.record)??t;return l!=null&&l.has_push?"✓ فعال":"—"}},{title:"زمان ثبتنام",dataIndex:"created_at",key:"created_at",type:"Date",filterable:!0,customRender:t=>{var d;const l=((d=t==null?void 0:t.record)==null?void 0:d.record)??(t==null?void 0:t.record)??t;return l!=null&&l.created_at?F(l.created_at):"-"}}],be={class:"space-y-4"},ge={class:"grid grid-cols-1 xl:grid-cols-3 gap-4"},he={class:"xl:col-span-2 space-y-4"},ye=e("div",{class:"mb-1 text-sm text-gray-600"},"عنوان نوتیفیکیشن *",-1),xe=e("div",{class:"mb-1 text-sm text-gray-600"},"متن نوتیفیکیشن *",-1),ke=e("div",{class:"mb-1 text-sm text-gray-600"},"لینک (اختیاری)",-1),$e={class:"flex flex-wrap gap-2"},we={class:"bg-gray-50 rounded-lg p-4 border border-gray-200 space-y-2 text-sm"},Se=e("div",{class:"font-semibold text-gray-700 mb-2"},"آمار اعلانها",-1),Ie={class:"grid grid-cols-1 gap-2"},Pe={class:"flex justify-between items-center bg-white rounded-md px-3 py-2 border border-gray-100"},Re=e("span",{class:"text-gray-600"},"کاربران با اعلان فعال",-1),Te={class:"text-green-700"},Be={class:"flex justify-between items-center bg-white rounded-md px-3 py-2 border border-gray-100"},Ce=e("span",{class:"text-gray-600"},"کل اشتراک push",-1),De=e("div",{class:"font-semibold text-gray-700 mb-2 pt-2"},"راهنما",-1),Le=e("p",{class:"text-gray-600 leading-6 m-0"}," فقط کاربرانی که اعلان را در اپ فعال کردهاند، نوتیف دریافت میکنند. ",-1),Ne=e("p",{class:"text-gray-600 leading-6 m-0"}," از فیلتر «اعلان فعال» میتوانید فقط کاربران با اعلان روشن یا خاموش را ببینید. ",-1),Ue=e("p",{class:"text-gray-600 leading-6 m-0"}," برای ارسال محدود، کاربران را از جدول پایین انتخاب کنید. ",-1),Me={key:0,class:"pt-2 border-t border-gray-200"},Ke=e("div",{class:"font-medium mb-1"},"آخرین ارسال:",-1),je={key:0},Fe={key:1},Ve={class:"border-t border-gray-200 pt-4"},Ae=e("div",{class:"mb-2 text-sm text-gray-600"}," کاربران را جستجو کنید و برای ارسال محدود، آنها را انتخاب کنید. ",-1),qe=U({__name:"PushSendPanel",emits:["sent"],setup(t,{emit:l}){const{TextArea:d}=j,[$]=q(),o=m({title:"ماچارتا",body:"",url:"/"}),_=m(!1),s=m([]),p=m(null),b=m({uniqueUsers:0,totalSubscriptions:0}),w=m(!1),I=N(()=>({selectedRowKeys:s.value,onChange:n=>{s.value=n.map(String)},preserveSelectedRowKeys:!0}));async function B(){w.value=!0;try{b.value=await Y()}finally{w.value=!1}}G(()=>{B()});const C=m({columns:ve,api:X,defaultPageLimit:20,height:"45vh"}),D=N(()=>{var n,u;return!!((n=o.value.title)!=null&&n.trim()&&((u=o.value.body)!=null&&u.trim()))});function y(){var n,u;return(n=o.value.title)!=null&&n.trim()?(u=o.value.body)!=null&&u.trim()?!0:(T.error("لطفاً متن نوتیفیکیشن را وارد کنید"),!1):(T.error("لطفاً عنوان نوتیفیکیشن را وارد کنید"),!1)}async function P(n){if(!y())return;if(n==="selected"&&!s.value.length){T.warning("حداقل یک کاربر انتخاب کنید");return}const u=n==="selected"?`آیا از ارسال نوتیفیکیشن به ${s.value.length} کاربر انتخابشده مطمئن هستید؟`:"آیا از ارسال نوتیفیکیشن به همه کاربران مطمئن هستید؟";ae.confirm({title:"تأیید ارسال نوتیفیکیشن",content:u,okText:"بله، ارسال کن",cancelText:"انصراف",centered:!0,onOk:async()=>{var x,S,f;_.value=!0;try{const v={title:o.value.title.trim(),body:o.value.body.trim(),url:((x=o.value.url)==null?void 0:x.trim())||"/"},R=n==="selected"?await Z(v.title,v.body,s.value,v.url):await ee(v.title,v.body,v.url);p.value=R;const J=R.subscribed!=null?` — ${R.subscribed} نفر اشتراک push دارند`:"";T.success(`نوتیفیکیشن ارسال شد (${R.sent} موفق، ${R.failed} ناموفق${J})`),l("sent"),B(),n==="all"&&(o.value.body="")}catch(v){T.error(((f=(S=v==null?void 0:v.response)==null?void 0:S.data)==null?void 0:f.error)||v.message||"خطا در ارسال نوتیفیکیشن")}finally{_.value=!1}}})}function M(){return P("all")}function K(){return P("selected")}return(n,u)=>{const x=Q,S=A;return g(),h("div",be,[e("div",ge,[e("div",he,[e("div",null,[ye,a(k(j),{value:o.value.title,"onUpdate:value":u[0]||(u[0]=f=>o.value.title=f),placeholder:"مثلاً: اطلاعیه مهم"},null,8,["value"])]),e("div",null,[xe,a(k(d),{value:o.value.body,"onUpdate:value":u[1]||(u[1]=f=>o.value.body=f),placeholder:"متن دلخواه برای کاربران",rows:4,maxlength:500,"show-count":""},null,8,["value"])]),e("div",null,[ke,a(k(j),{value:o.value.url,"onUpdate:value":u[2]||(u[2]=f=>o.value.url=f),placeholder:"/shop یا /matches"},null,8,["value"])]),e("div",$e,[a(x,{type:"primary",loading:_.value,disabled:!D.value,onClick:M},{default:r(()=>[c(" ارسال به همه کاربران ")]),_:1},8,["loading","disabled"]),a(x,{type:"primary",ghost:"",loading:_.value,disabled:!D.value||!s.value.length,onClick:K},{default:r(()=>[c(" ارسال به انتخابشدهها ("+i(s.value.length)+") ",1)]),_:1},8,["loading","disabled"])])]),e("div",we,[Se,e("div",Ie,[e("div",Pe,[Re,e("strong",Te,i(b.value.uniqueUsers)+" نفر",1)]),e("div",Be,[Ce,e("strong",null,i(b.value.totalSubscriptions),1)])]),De,Le,Ne,Ue,p.value?(g(),h("div",Me,[Ke,e("div",null,[c("موفق: "),e("strong",null,i(p.value.sent),1)]),e("div",null,[c("ناموفق: "),e("strong",null,i(p.value.failed),1)]),p.value.targeted!=null?(g(),h("div",je,[c(" انتخابشده: "),e("strong",null,i(p.value.targeted),1)])):L("",!0),p.value.subscribed!=null?(g(),h("div",Fe,[c(" دارای اشتراک push: "),e("strong",null,i(p.value.subscribed),1)])):L("",!0)])):L("",!0)])]),e("div",Ve,[Ae,a(S,V(C.value,{"row-selection":I.value,onRegister:k($)}),null,16,["row-selection","onRegister"])])])}}}),E={custom:"همه کاربران",custom_selected:"کاربران انتخابشده",story:"قصه جدید",book:"کتاب صوتی",product:"محصول جدید",match:"مسابقه جدید"},Ee=[{title:"ردیف",dataIndex:"id",key:"row_index",filterable:!1,customRender:t=>t.index+1},{title:"شناسه",dataIndex:"id",key:"id",filterable:!1},{title:"عنوان",dataIndex:"title",key:"title",filterable:!1,customRender:t=>{const l=t.record.title||"";return l.length>40?`${l.slice(0,40)}...`:l}},{title:"نوع ارسال",dataIndex:"type",key:"type",filterable:!1,customRender:t=>E[t.record.type]||t.record.type},{title:"موفق",dataIndex:"sent_count",key:"sent_count",filterable:!1,customRender:t=>t.record.sent_count??0},{title:"ناموفق",dataIndex:"failed_count",key:"failed_count",filterable:!1,customRender:t=>t.record.failed_count??0},{title:"تاریخ",dataIndex:"created_at",key:"created_at",filterable:!1,customRender:t=>t.record.created_at?F(t.record.created_at):"-"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];function Je(t){return E[t]||t}const ze={class:"gap-2 flex justify-center"},Ge=e("span",null,"جزئیات ارسال",-1),He={class:"whitespace-pre-wrap text-sm"},Oe={class:"grid grid-cols-1 sm:grid-cols-3 gap-3 mb-4"},Qe={class:"rounded-lg border border-green-200 bg-green-50 p-4 text-center"},We={class:"text-2xl font-bold text-green-600"},Xe=e("div",{class:"text-sm text-gray-600 mt-1"},"ارسال موفق",-1),Ye={class:"rounded-lg border border-red-200 bg-red-50 p-4 text-center"},Ze={class:"text-2xl font-bold text-red-600"},et=e("div",{class:"text-sm text-gray-600 mt-1"},"ارسال ناموفق",-1),tt={class:"rounded-lg border border-gray-200 bg-gray-50 p-4 text-center"},st={class:"text-2xl font-bold text-gray-700"},at=e("div",{class:"text-sm text-gray-600 mt-1"},"مجموع تلاشها",-1),lt={key:0,class:"text-sm text-gray-600"},ot={class:"text-green-600"},nt={class:"text-green-600"},rt={class:"text-red-600"},it={key:1,class:"text-sm text-gray-500"},dt=U({__name:"PushHistoryPanel",setup(t,{expose:l}){const[d,$]=q(),o=m(!1),_=m(!1),s=m(null),p=m({columns:Ee,api:te,defaultPageLimit:20,height:"55vh"}),b=N(()=>s.value?(s.value.sent_count||0)+(s.value.failed_count||0):0),w=N(()=>!b.value||!s.value?0:Math.round(s.value.sent_count/b.value*100));function I(y){return y?F(y):"-"}async function B(y){o.value=!0,_.value=!0,s.value=null;try{s.value=await se(y.id)}finally{_.value=!1}}function C(){o.value=!1,s.value=null}function D(){$()}return l({reload:D}),(y,P)=>{const M=A,K=W,n=ne,u=re,x=ie,S=le;return g(),h("div",null,[a(M,V(p.value,{onRegister:k(d)}),{action:r(({record:f})=>[e("div",ze,[a(k(de),{class:"cursor-pointer"},{title:r(()=>[Ge]),default:r(()=>[a(oe,{icon:"vuesax-linear:eye",color:"#1D4ED8",onClick:v=>B(f)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),a(S,{visible:o.value,"onUpdate:visible":P[0]||(P[0]=f=>o.value=f),title:"جزئیات نوتیفیکیشن ارسالی","custom-footer":"",width:"720px",onClose:C},{footer:r(()=>[a(K,{onClick:C},{default:r(()=>[c("بستن")]),_:1})]),default:r(()=>[a(x,{spinning:_.value},{default:r(()=>[s.value?(g(),h(H,{key:0},[a(u,{bordered:"",column:2,size:"small",class:"mb-4"},{default:r(()=>[a(n,{label:"شناسه"},{default:r(()=>[c("#"+i(s.value.id),1)]),_:1}),a(n,{label:"نوع ارسال"},{default:r(()=>[c(i(k(Je)(s.value.type)),1)]),_:1}),a(n,{label:"تاریخ ارسال"},{default:r(()=>[c(i(I(s.value.created_at)),1)]),_:1}),a(n,{label:"ارسالکننده"},{default:r(()=>[c(i(s.value.admin_name||"-"),1)]),_:1}),a(n,{label:"عنوان",span:2},{default:r(()=>[c(i(s.value.title),1)]),_:1}),a(n,{label:"متن",span:2},{default:r(()=>[e("div",He,i(s.value.body),1)]),_:1}),a(n,{label:"لینک",span:2},{default:r(()=>[c(i(s.value.url||"/"),1)]),_:1})]),_:1}),e("div",Oe,[e("div",Qe,[e("div",We,i(s.value.sent_count),1),Xe]),e("div",Ye,[e("div",Ze,i(s.value.failed_count),1),et]),e("div",tt,[e("div",st,i(b.value),1),at])]),b.value>0?(g(),h("div",lt,[c(" نرخ موفقیت: "),e("strong",ot,i(w.value)+"%",1),c(" — "),e("span",nt,i(s.value.sent_count)+" موفق",1),c(" / "),e("span",rt,i(s.value.failed_count)+" ناموفق",1)])):(g(),h("div",it," هیچ اشتراک push فعالی برای ارسال یافت نشد. "))],64)):L("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),ut=e("div",{class:"flex justify-between items-center mb-4"},[e("h2",null,"نوتیفیکیشن Push")],-1),Ft=U({__name:"index",setup(t){const l=m("send"),d=m(null);function $(){var _;(_=d.value)==null||_.reload()}function o(_){var s;_==="history"&&((s=d.value)==null||s.reload())}return(_,s)=>{const p=ue,b=ce,w=fe;return g(),O(w,null,{default:r(()=>[ut,a(b,{activeKey:l.value,"onUpdate:activeKey":s[0]||(s[0]=I=>l.value=I),onChange:o},{default:r(()=>[a(p,{key:"send",tab:"ارسال نوتیفیکیشن"},{default:r(()=>[a(qe,{onSent:$})]),_:1}),a(p,{key:"history",tab:"سوابق ارسالی"},{default:r(()=>[a(dt,{ref_key:"historyPanelRef",ref:d},null,512)]),_:1})]),_:1},8,["activeKey"])]),_:1})}}});export{Ft as default};
|