2 lines
14 KiB
JavaScript
2 lines
14 KiB
JavaScript
import{_ as z}from"./BasicShowContext.vue_vue_type_script_setup_true_lang-548d4cc8.js";import{_ as V,u as A}from"./useBaseTable-8cba60ae.js";import{_ as J}from"./button.vue_vue_type_style_index_0_lang-e2b25b37.js";import{g as O,a as G,s as Q,b as W,c as X,d as Y}from"./pushNotification-2f621083.js";import{t as j}from"./useDataTime-8b5c8616.js";import{M as Z}from"./index-83a7641b.js";import{I as K}from"./index-e101c0bd.js";import{d as F,g as p,h as N,v as ee,o as b,c as g,a as e,b as a,j as S,w as r,e as c,t as i,k as w,H as E,D as R,F as te,i as se}from"./index-ac7066b4.js";import{_ as ae}from"./BasicModal.vue_vue_type_style_index_0_lang-02d666ae.js";import{I as oe}from"./Icon-7978fe0f.js";import{B as le}from"./index-802e18b7.js";import{D as ne,_ as re}from"./index-cf8c5e44.js";import{S as ie}from"./index-a074700a.js";import{T as de}from"./isSymbol-666d5768.js";import{_ as ue,T as ce}from"./index-29b429a8.js";import"./updateLocale-199556b5.js";import"./_plugin-vue_export-helper-4339814c.js";import"./vnode-ef8e6ff6.js";import"./useState-277f1e57.js";import"./useMemo-51fb250b.js";import"./FormItemContext-8e774be4.js";import"./lodash-875c0571.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-4839fd2a.js";import"./index-25ae81e5.js";import"./Badge-fcb9007c.js";import"./isNumeric-3f69e2aa.js";import"./index-7f62cf48.js";import"./index-74186c79.js";import"./index-fa378035.js";import"./styleChecker-8fccceee.js";import"./index-b18fec22.js";import"./index-5ae727af.js";import"./DialogWrap-4b820301.js";import"./pickAttrs-73e6cb05.js";import"./css-aae66f86.js";import"./index-ff2f09c7.js";import"./toArray-518515e2.js";import"./SearchOutlined-36fcc6f3.js";import"./isMobile-e2e89480.js";import"./index-f0d8ad9c.js";import"./isPlainObject-a4fa2df5.js";import"./useRefs-a8a1b35f.js";import"./_flatRest-843ce72e.js";const _e=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,customRender:t=>{var x;const o=((x=t==null?void 0:t.record)==null?void 0:x.record)??(t==null?void 0:t.record)??t;return(typeof(o==null?void 0:o.index)=="number"?o.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 _;const o=((_=t==null?void 0:t.record)==null?void 0:_.record)??(t==null?void 0:t.record)??t;return o!=null&&o.has_push?"✓ فعال":"—"}},{title:"زمان ثبتنام",dataIndex:"created_at",key:"created_at",type:"Date",filterable:!0,customRender:t=>{var _;const o=((_=t==null?void 0:t.record)==null?void 0:_.record)??(t==null?void 0:t.record)??t;return o!=null&&o.created_at?j(o.created_at):"-"}}],me={class:"space-y-4"},pe={class:"grid grid-cols-1 xl:grid-cols-3 gap-4"},fe={class:"xl:col-span-2 space-y-4"},ve=e("div",{class:"mb-1 text-sm text-gray-600"},"عنوان نوتیفیکیشن *",-1),be=e("div",{class:"mb-1 text-sm text-gray-600"},"متن نوتیفیکیشن *",-1),ge=e("div",{class:"mb-1 text-sm text-gray-600"},"لینک (اختیاری)",-1),he={class:"flex flex-wrap gap-2"},ye={class:"bg-gray-50 rounded-lg p-4 border border-gray-200 space-y-2 text-sm"},xe=e("div",{class:"font-semibold text-gray-700 mb-2"},"آمار اعلانها",-1),ke={class:"grid grid-cols-1 gap-2"},$e={class:"flex justify-between items-center bg-white rounded-md px-3 py-2 border border-gray-100"},we=e("span",{class:"text-gray-600"},"کاربران با اعلان فعال",-1),Se={class:"text-green-700"},Ie={class:"flex justify-between items-center bg-white rounded-md px-3 py-2 border border-gray-100"},Pe=e("span",{class:"text-gray-600"},"کل اشتراک push",-1),Re=e("div",{class:"font-semibold text-gray-700 mb-2 pt-2"},"راهنما",-1),Te=e("p",{class:"text-gray-600 leading-6 m-0"}," فقط کاربرانی که اعلان را در اپ فعال کردهاند، نوتیف دریافت میکنند. ",-1),Be=e("p",{class:"text-gray-600 leading-6 m-0"}," از فیلتر «اعلان فعال» میتوانید فقط کاربران با اعلان روشن یا خاموش را ببینید. ",-1),Ce=e("p",{class:"text-gray-600 leading-6 m-0"}," برای ارسال محدود، کاربران را از جدول پایین انتخاب کنید. ",-1),De={key:0,class:"pt-2 border-t border-gray-200"},Le=e("div",{class:"font-medium mb-1"},"آخرین ارسال:",-1),Ne={key:0,class:"text-amber-700 mb-1"},Ue={key:1},Me={key:2},qe={key:3},Ke={key:4},je={class:"border-t border-gray-200 pt-4"},Fe=e("div",{class:"mb-2 text-sm text-gray-600"}," کاربران را جستجو کنید و برای ارسال محدود، آنها را انتخاب کنید. ",-1),Ve=F({__name:"PushSendPanel",emits:["sent"],setup(t,{emit:o}){const{TextArea:_}=K,[x]=A(),l=p({title:"ماچارتا",body:"",url:"/"}),m=p(!1),s=p([]),d=p(null),h=p({uniqueUsers:0,totalSubscriptions:0}),I=p(!1),T=N(()=>({selectedRowKeys:s.value,onChange:n=>{s.value=n.map(String)},preserveSelectedRowKeys:!0}));async function C(){I.value=!0;try{h.value=await G()}finally{I.value=!1}}ee(()=>{C()});const D=p({columns:_e,api:O,defaultPageLimit:20,height:"45vh"}),L=N(()=>{var n,u;return!!((n=l.value.title)!=null&&n.trim()&&((u=l.value.body)!=null&&u.trim()))});function k(){var n,u;return(n=l.value.title)!=null&&n.trim()?(u=l.value.body)!=null&&u.trim()?!0:(R.error("لطفاً متن نوتیفیکیشن را وارد کنید"),!1):(R.error("لطفاً عنوان نوتیفیکیشن را وارد کنید"),!1)}async function B(n){if(!k())return;if(n==="selected"&&!s.value.length){R.warning("حداقل یک کاربر انتخاب کنید");return}const u=n==="selected"?`آیا از ارسال نوتیفیکیشن به ${s.value.length} کاربر انتخابشده مطمئن هستید؟`:"آیا از ارسال نوتیفیکیشن به همه کاربران مطمئن هستید؟";Z.confirm({title:"تأیید ارسال نوتیفیکیشن",content:u,okText:"بله، ارسال کن",cancelText:"انصراف",centered:!0,onOk:async()=>{var $,P,f;m.value=!0;try{const v={title:l.value.title.trim(),body:l.value.body.trim(),url:(($=l.value.url)==null?void 0:$.trim())||"/"},y=n==="selected"?await Q(v.title,v.body,s.value,v.url):await W(v.title,v.body,v.url);if(d.value=y,y.queued){const q=y.subscribed!=null?` (${y.subscribed} اشتراک)`:"";R.success(y.message||`نوتیفیکیشن در صف ارسال قرار گرفت${q}. نتیجه در سوابق ثبت میشود.`)}else{const q=y.subscribed!=null?` — ${y.subscribed} نفر اشتراک push دارند`:"";R.success(`نوتیفیکیشن ارسال شد (${y.sent} موفق، ${y.failed} ناموفق${q})`)}o("sent"),C(),n==="all"&&(l.value.body="")}catch(v){R.error(((f=(P=v==null?void 0:v.response)==null?void 0:P.data)==null?void 0:f.error)||v.message||"خطا در ارسال نوتیفیکیشن")}finally{m.value=!1}}})}function U(){return B("all")}function M(){return B("selected")}return(n,u)=>{const $=J,P=V;return b(),g("div",me,[e("div",pe,[e("div",fe,[e("div",null,[ve,a(S(K),{value:l.value.title,"onUpdate:value":u[0]||(u[0]=f=>l.value.title=f),placeholder:"مثلاً: اطلاعیه مهم"},null,8,["value"])]),e("div",null,[be,a(S(_),{value:l.value.body,"onUpdate:value":u[1]||(u[1]=f=>l.value.body=f),placeholder:"متن دلخواه برای کاربران",rows:4,maxlength:500,"show-count":""},null,8,["value"])]),e("div",null,[ge,a(S(K),{value:l.value.url,"onUpdate:value":u[2]||(u[2]=f=>l.value.url=f),placeholder:"/shop یا /matches"},null,8,["value"])]),e("div",he,[a($,{type:"primary",loading:m.value,disabled:!L.value,onClick:U},{default:r(()=>[c(" ارسال به همه کاربران ")]),_:1},8,["loading","disabled"]),a($,{type:"primary",ghost:"",loading:m.value,disabled:!L.value||!s.value.length,onClick:M},{default:r(()=>[c(" ارسال به انتخابشدهها ("+i(s.value.length)+") ",1)]),_:1},8,["loading","disabled"])])]),e("div",ye,[xe,e("div",ke,[e("div",$e,[we,e("strong",Se,i(h.value.uniqueUsers)+" نفر",1)]),e("div",Ie,[Pe,e("strong",null,i(h.value.totalSubscriptions),1)])]),Re,Te,Be,Ce,d.value?(b(),g("div",De,[Le,d.value.queued?(b(),g("div",Ne,"در صف ارسال (دستهای)")):w("",!0),d.value.queued?w("",!0):(b(),g("div",Ue,[c("موفق: "),e("strong",null,i(d.value.sent),1)])),d.value.queued?w("",!0):(b(),g("div",Me,[c("ناموفق: "),e("strong",null,i(d.value.failed),1)])),d.value.targeted!=null?(b(),g("div",qe,[c(" انتخابشده: "),e("strong",null,i(d.value.targeted),1)])):w("",!0),d.value.subscribed!=null?(b(),g("div",Ke,[c(" دارای اشتراک push: "),e("strong",null,i(d.value.subscribed),1)])):w("",!0)])):w("",!0)])]),e("div",je,[Fe,a(P,E(D.value,{"row-selection":T.value,onRegister:S(x)}),null,16,["row-selection","onRegister"])])])}}}),H={custom:"همه کاربران",custom_selected:"کاربران انتخابشده",story:"قصه جدید",book:"کتاب صوتی",product:"محصول جدید",match:"مسابقه جدید"},Ae=[{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 o=t.record.title||"";return o.length>40?`${o.slice(0,40)}...`:o}},{title:"نوع ارسال",dataIndex:"type",key:"type",filterable:!1,customRender:t=>H[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?j(t.record.created_at):"-"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];function Ee(t){return H[t]||t}const He={class:"gap-2 flex justify-center"},ze=e("span",null,"جزئیات ارسال",-1),Je={class:"whitespace-pre-wrap text-sm"},Oe={class:"grid grid-cols-1 sm:grid-cols-3 gap-3 mb-4"},Ge={class:"rounded-lg border border-green-200 bg-green-50 p-4 text-center"},Qe={class:"text-2xl font-bold text-green-600"},We=e("div",{class:"text-sm text-gray-600 mt-1"},"ارسال موفق",-1),Xe={class:"rounded-lg border border-red-200 bg-red-50 p-4 text-center"},Ye={class:"text-2xl font-bold text-red-600"},Ze=e("div",{class:"text-sm text-gray-600 mt-1"},"ارسال ناموفق",-1),et={class:"rounded-lg border border-gray-200 bg-gray-50 p-4 text-center"},tt={class:"text-2xl font-bold text-gray-700"},st=e("div",{class:"text-sm text-gray-600 mt-1"},"مجموع تلاشها",-1),at={key:0,class:"text-sm text-gray-600"},ot={class:"text-green-600"},lt={class:"text-green-600"},nt={class:"text-red-600"},rt={key:1,class:"text-sm text-gray-500"},it=F({__name:"PushHistoryPanel",setup(t,{expose:o}){const[_,x]=A(),l=p(!1),m=p(!1),s=p(null),d=p({columns:Ae,api:X,defaultPageLimit:20,height:"55vh"}),h=N(()=>s.value?(s.value.sent_count||0)+(s.value.failed_count||0):0),I=N(()=>!h.value||!s.value?0:Math.round(s.value.sent_count/h.value*100));function T(k){return k?j(k):"-"}async function C(k){l.value=!0,m.value=!0,s.value=null;try{s.value=await Y(k.id)}finally{m.value=!1}}function D(){l.value=!1,s.value=null}function L(){x()}return o({reload:L}),(k,B)=>{const U=V,M=le,n=ne,u=re,$=ie,P=ae;return b(),g("div",null,[a(U,E(d.value,{onRegister:S(_)}),{action:r(({record:f})=>[e("div",He,[a(S(de),{class:"cursor-pointer"},{title:r(()=>[ze]),default:r(()=>[a(oe,{icon:"vuesax-linear:eye",color:"#1D4ED8",onClick:v=>C(f)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),a(P,{visible:l.value,"onUpdate:visible":B[0]||(B[0]=f=>l.value=f),title:"جزئیات نوتیفیکیشن ارسالی","custom-footer":"",width:"720px",onClose:D},{footer:r(()=>[a(M,{onClick:D},{default:r(()=>[c("بستن")]),_:1})]),default:r(()=>[a($,{spinning:m.value},{default:r(()=>[s.value?(b(),g(te,{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(S(Ee)(s.value.type)),1)]),_:1}),a(n,{label:"تاریخ ارسال"},{default:r(()=>[c(i(T(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",Je,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",Ge,[e("div",Qe,i(s.value.sent_count),1),We]),e("div",Xe,[e("div",Ye,i(s.value.failed_count),1),Ze]),e("div",et,[e("div",tt,i(h.value),1),st])]),h.value>0?(b(),g("div",at,[c(" نرخ موفقیت: "),e("strong",ot,i(I.value)+"%",1),c(" — "),e("span",lt,i(s.value.sent_count)+" موفق",1),c(" / "),e("span",nt,i(s.value.failed_count)+" ناموفق",1)])):(b(),g("div",rt," هیچ اشتراک push فعالی برای ارسال یافت نشد. "))],64)):w("",!0)]),_:1},8,["spinning"])]),_:1},8,["visible"])])}}}),dt=e("div",{class:"flex justify-between items-center mb-4"},[e("h2",null,"نوتیفیکیشن Push")],-1),Zt=F({__name:"index",setup(t){const o=p("send"),_=p(null);function x(){var m;(m=_.value)==null||m.reload()}function l(m){var s;m==="history"&&((s=_.value)==null||s.reload())}return(m,s)=>{const d=ue,h=ce,I=z;return b(),se(I,null,{default:r(()=>[dt,a(h,{activeKey:o.value,"onUpdate:activeKey":s[0]||(s[0]=T=>o.value=T),onChange:l},{default:r(()=>[a(d,{key:"send",tab:"ارسال نوتیفیکیشن"},{default:r(()=>[a(Ve,{onSent:x})]),_:1}),a(d,{key:"history",tab:"سوابق ارسالی"},{default:r(()=>[a(it,{ref_key:"historyPanelRef",ref:_},null,512)]),_:1})]),_:1},8,["activeKey"])]),_:1})}}});export{Zt as default};
|