Files
machartaa_admin_dist/dist/assets/index-e7be31b0.js
T
2026-06-09 17:09:57 +03:30

2 lines
17 KiB
JavaScript

import{_ as ge}from"./BasicMainCard-235024f3.js";import{_ as ve}from"./BasicModal.vue_vue_type_style_index_0_lang-b3ec83ab.js";import{_ as ye}from"./BasicTextArea.vue_vue_type_style_index_0_lang-71f5f6af.js";import{_ as xe,a as we,u as Q}from"./useBaseTable-c172fcda.js";import{_ as be}from"./BasicInput.vue_vue_type_style_index_0_lang-6499c59b.js";import{_ as Se}from"./button.vue_vue_type_style_index_0_lang-ac3928e1.js";import{H as T,_ as ke,d as Ce,g as M,z as Ie,o as R,c as B,b as r,w as _,j as b,a as s,e as j,E as Y,t as V,k as W,y as Ue,F as Te,n as Me,C,I as qe,J as Ae,G as $e}from"./index-5cd0dc27.js";import{t as J}from"./useDataTime-dd940a73.js";import{I as O}from"./Icon-cd5db3c7.js";import{e as Z,g as ee}from"./convert-67c23be8.js";import{T as te}from"./index-610f5e48.js";import{M as Le}from"./index-303cddc1.js";import{S as Re}from"./index-19deb164.js";import{S as se}from"./fa_IR-0446fdd0.js";import{T as H}from"./shallowequal-55f47fed.js";import{U as Be}from"./index-6eb27b7e.js";import{_ as Pe}from"./_plugin-vue_export-helper-a1eb32e1.js";import"./index-35b70f12.js";import"./Col-c0746d46.js";import"./vnode-e95c7631.js";import"./isPlainObject-db8a979e.js";import"./index-f4a7a776.js";import"./FormItemContext-890ed032.js";import"./useState-9fb4d9c6.js";import"./lodash-6d31cf29.js";import"./index-906ffe0c.js";import"./pickAttrs-52814cf1.js";import"./toArray-a619b364.js";import"./usePrice-7afab779.js";import"./useRefs-72ceeba3.js";import"./index-5eb50e4a.js";function ae(e,l){return l.map((n,i)=>({challenge_id:e,step_order:i+1,description:n.description,duration_seconds:Math.max(1,Math.round(Number(n.duration_minutes)*60)),aparat_embed_code:n.aparat_embed_code||null,punishment_description:n.punishment_description,requires_photo_upload:!!n.requires_photo_upload}))}async function De(e){const{data:l,error:n}=await T.from("step_challenges").select("*").eq("id",e).single();if(n)throw n;const{data:i,error:h}=await T.from("step_challenge_steps").select("*").eq("challenge_id",e).order("step_order",{ascending:!0});if(h)throw h;return{...l,steps:(i||[]).map(f=>({...f,duration_minutes:Math.round((f.duration_seconds||60)/60)}))}}async function Ee(e,l){const{data:n,error:i}=await T.from("step_challenges").insert([{title:e.title,character_image_url:e.character_image_url,show:e.show??!1,access_type:e.access_type??"free",sort_order:e.sort_order??0,owner_id:l||null}]).select().single();if(i)throw i;const h=ae(n.id,e.steps),{error:f}=await T.from("step_challenge_steps").insert(h);if(f)throw f;return n}async function ze(e,l){const{error:n}=await T.from("step_challenges").update({title:l.title,character_image_url:l.character_image_url,show:l.show??!1,access_type:l.access_type??"free",sort_order:l.sort_order??0,updated_at:new Date().toISOString()}).eq("id",e);if(n)throw n;const{error:i}=await T.from("step_challenge_steps").delete().eq("challenge_id",e);if(i)throw i;const h=ae(e,l.steps),{error:f}=await T.from("step_challenge_steps").insert(h);if(f)throw f;return{id:e}}async function Oe(e){const{error:l}=await T.from("step_challenges").delete().eq("id",e);if(l)throw l}async function Fe(e,l){const{data:n,error:i}=await T.from("step_challenges").update({...l,updated_at:new Date().toISOString()}).eq("id",e).select();if(i)throw i;return n}async function Ne(e){const{TableEngineRequest:l}=await ke(()=>import("./buildSupabaseQuery-8603a814.js"),["assets/buildSupabaseQuery-8603a814.js","assets/index-5cd0dc27.js","assets/index-5d811526.css"]),n={...e};!n.sort&&!n.order&&(n.order="-id");const i=await l(n,"step_challenges");try{if(Array.isArray(i==null?void 0:i.rows)){const h=i.rows,f=h.map(c=>c.id).filter(Boolean);let I={};if(f.length>0){const{data:c}=await T.from("step_challenge_steps").select("id, challenge_id, step_order, duration_seconds").in("challenge_id",f);I=(c||[]).reduce((m,o)=>(m[o.challenge_id]||(m[o.challenge_id]=[]),m[o.challenge_id].push(o),m),{})}const q=n.page||1,S=n.limit||20,A=(q-1)*S,L=h.map((c,m)=>{const o=I[c.id]||[],U=o.reduce((y,P)=>y+Math.round((P.duration_seconds||0)/60),0);return{...c,index:A+m,steps_count:o.length,total_minutes:U}});return{...i,rows:L}}}catch(h){console.log("[getStepChallengesTable] normalize error:",h)}return i}async function je(e){const{limit:l=20,page:n=1,search:i}=e;let h=T.from("user_step_challenges").select("*, step_challenges(title), users(name, phone, first_name, last_name)",{count:"exact"}).order("created_at",{ascending:!1});const{data:f,error:I,count:q}=await h;if(I)throw I;let S=(f||[]).map((c,m)=>{const o=Array.isArray(c.users)?c.users[0]:c.users,U=Array.isArray(c.step_challenges)?c.step_challenges[0]:c.step_challenges;let y="نامشخص";return o!=null&&o.name?y=o.name:o!=null&&o.first_name||o!=null&&o.last_name?y=`${o.first_name||""} ${o.last_name||""}`.trim():o!=null&&o.phone&&(y=o.phone),{...c,index:m,challenge_title:(U==null?void 0:U.title)||"",user_name:y,user_phone:(o==null?void 0:o.phone)||""}});if(i){const c=i.toLowerCase();S=S.filter(m=>(m.challenge_title||"").toLowerCase().includes(c)||(m.user_name||"").toLowerCase().includes(c)||(m.user_phone||"").toLowerCase().includes(c)||(m.status||"").toLowerCase().includes(c))}const A=(n-1)*l;return{rows:S.slice(A,A+l).map((c,m)=>({...c,index:A+m})),total:S.length,query:{...e,total:S.length,page:n,limit:l}}}const Ve=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:e=>e.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"مراحل",dataIndex:"steps_count",key:"steps_count",customRender:e=>{const l=e.record.steps_count||0,n=e.record.total_minutes||0;return l?`${l} مرحله / ${n} دقیقه`:"-"}},{title:"نمایش",dataIndex:"show",key:"show",customRender:e=>e.record.show?"فعال":"مخفی"},{title:"نوع",dataIndex:"access_type",key:"access_type",width:100,align:"center",customRender:e=>e.record.access_type==="subscription"?"اشتراکی":"رایگان"},{title:"ترتیب",dataIndex:"sort_order",key:"sort_order",width:80,align:"center"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:e=>J(e.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],We={in_progress:"در حال انجام",completed:"تکمیل شده",abandoned:"رها شده"},He=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:e=>e.record.index+1},{title:"چالش",dataIndex:"challenge_title",key:"challenge_title"},{title:"کاربر",dataIndex:"user_name",key:"user_name"},{title:"موبایل",dataIndex:"user_phone",key:"user_phone"},{title:"وضعیت",dataIndex:"status",key:"status",customRender:e=>We[e.record.status]||e.record.status},{title:"مرحله فعلی",dataIndex:"current_step_order",key:"current_step_order",align:"center"},{title:"شروع",dataIndex:"started_at",key:"started_at",customRender:e=>J(e.record.started_at)},{title:"پایان",dataIndex:"completed_at",key:"completed_at",customRender:e=>e.record.completed_at?J(e.record.completed_at):"-"}],p=e=>(qe("data-v-a2451c8c"),e=e(),Ae(),e),Je={class:"flex justify-between items-center mb-4"},Ke=p(()=>s("h2",null,"چالش‌های مرحله‌ای",-1)),Ge={class:"gap-2 flex justify-center"},Xe=p(()=>s("span",null,"حذف",-1)),Qe=p(()=>s("span",null,"ویرایش",-1)),Ye=p(()=>s("div",{class:"mb-4"},[s("h2",null,"پیشرفت کاربران در چالش‌ها")],-1)),Ze={class:"space-y-4 relative"},et={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},tt=p(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"عنوان چالش",-1)),st={class:"grid grid-cols-1 sm:grid-cols-3 gap-4"},at=p(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"ترتیب نمایش",-1)),ot=p(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"وضعیت نمایش",-1)),nt={class:"flex items-center gap-2 mt-2"},rt={class:"text-sm text-gray-600"},lt=p(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"نوع دسترسی",-1)),it={class:"flex justify-center pb-2"},ct=p(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"عکس کاراکتر (کارت لیست)",-1)),dt={key:0},ut=p(()=>s("div",null,"آپلود تصویر",-1)),_t={key:0,class:"mt-1"},pt={class:"h-2 rounded bg-gray-200 overflow-hidden"},mt=p(()=>s("div",{class:"section-divider"},null,-1)),ht={class:"pt-2"},ft=p(()=>s("div",{class:"mb-2 text-sm text-gray-600 font-semibold"},"مراحل چالش",-1)),gt={class:"space-y-3"},vt={class:"font-semibold text-gray-700"},yt=p(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"توضیحات مرحله",-1)),xt={class:"grid grid-cols-2 gap-3"},wt=p(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"زمان حل (دقیقه)",-1)),bt={class:"flex items-end pb-1"},St={class:"flex items-center gap-2"},kt=p(()=>s("span",{class:"text-sm text-gray-600"},"نیاز به بارگذاری عکس",-1)),Ct=p(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"کد embed آپارات",-1)),It=p(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"توضیح مجازات",-1)),Ut={class:"flex justify-end"},Tt=p(()=>s("span",{class:"text-[#DC2626]"},"حذف مرحله",-1)),Mt=p(()=>s("span",{class:"text-gray-500"},"+ افزودن مرحله",-1)),qt=Ce({__name:"index",setup(e){const l=te,n=te.TabPane,i=se,h=se.Option,f=M("challenges"),I=M(!1),q=M(!1),S=M(null),[A,L]=Q(),[c]=Q(),m=Ie(),o=M([]),U=M(0),y=M(0),P=()=>({description:"",duration_minutes:5,aparat_embed_code:"",punishment_description:"",requires_photo_upload:!1}),d=M({title:"",character_image_url:null,show:!1,access_type:"free",sort_order:0,steps:[P()]}),oe={columns:Ve,api:Ne,defaultPageLimit:20},ne={columns:He,api:je,defaultPageLimit:20};function re(u){return{width:`${Math.max(0,Math.min(100,u))}%`}}function K(){d.value={title:"",character_image_url:null,show:!1,access_type:"free",sort_order:0,steps:[P()]},o.value=[]}function le(){q.value=!1,S.value=null,K(),I.value=!0}function G(){I.value=!1,K()}function ie(){d.value.steps.push(P())}function ce(u){d.value.steps.length<=1||d.value.steps.splice(u,1)}function de(u){return u.type.startsWith("image/")?u.size/1024/1024<5?!0:(C.error("حجم تصویر باید کمتر از 5MB باشد!"),!1):(C.error("فقط فایل‌های تصویری قابل آپلود هستند!"),!1)}async function ue(u){const{file:a,onSuccess:g,onError:k,onProgress:$}=u,D=new FormData;D.append("file",a);const E=`${$e}/upload/machartaa-img`;y.value=0,U.value++,await new Promise((F,z)=>{const t=new XMLHttpRequest;t.open("POST",E),t.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("token")||""}`),t.upload.onprogress=x=>{if(x.lengthComputable){const v=Math.round(x.loaded/x.total*100);y.value=v,$==null||$({percent:v})}},t.onload=()=>{var x,v;if(y.value=100,t.status>=200&&t.status<300)try{const w=JSON.parse(t.responseText||"{}"),fe=w.full_src||w.url||w.src||w.path||((x=w.data)==null?void 0:x.full_src)||((v=w.data)==null?void 0:v.url)||"",N=Z(fe),X=ee(N);d.value.character_image_url=N,o.value=X?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:X,response:{path:N}}]:[],g==null||g(w,t),C.success("تصویر با موفقیت آپلود شد!"),F()}catch(w){k==null||k(w,t),z(w)}else{const w=new Error("خطا در آپلود تصویر");k==null||k(w,t),z(w)}},t.onerror=()=>{k==null||k(new Error("خطا در آپلود تصویر!"),t),z(new Error("خطا در آپلود تصویر!"))},t.onloadend=()=>{U.value=Math.max(0,U.value-1),y.value=0},t.send(D)})}async function _e(u){try{const a=await De(u.id);q.value=!0,S.value=u.id,d.value={title:a.title,character_image_url:Z(a.character_image_url),show:!!a.show,access_type:a.access_type==="subscription"?"subscription":"free",sort_order:a.sort_order||0,steps:(a.steps||[]).map(g=>({id:g.id,description:g.description,duration_minutes:g.duration_minutes||Math.round((g.duration_seconds||60)/60),aparat_embed_code:g.aparat_embed_code||"",punishment_description:g.punishment_description||"",requires_photo_upload:!!g.requires_photo_upload}))},a.character_image_url&&(o.value=[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:ee(a.character_image_url)}]),I.value=!0}catch(a){C.error(a.message||"خطا در بارگذاری چالش")}}async function pe(u){Le.confirm({title:"حذف چالش",content:"آیا از حذف این چالش مطمئن هستید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{await Oe(u.id),C.success("چالش حذف شد"),L()}})}async function me(u){await Fe(u.id,{show:!u.show}),C.success(u.show?"چالش مخفی شد":"چالش نمایش داده می‌شود"),L()}async function he(){var u;if(!d.value.title.trim()){C.error("عنوان چالش الزامی است");return}if(d.value.steps.some(a=>!a.description.trim())){C.error("توضیحات همه مراحل الزامی است");return}if(d.value.steps.some(a=>!a.punishment_description.trim())){C.error("توضیح مجازات همه مراحل الزامی است");return}try{const a={...d.value,sort_order:Number(d.value.sort_order)||0};q.value&&S.value?(await ze(S.value,a),C.success("چالش ویرایش شد")):(await Ee(a,(u=m.userInfo)==null?void 0:u.id),C.success("چالش اضافه شد")),G(),L()}catch(a){C.error(a.message||"خطا در ذخیره چالش")}}return(u,a)=>{const g=Se,k=xe,$=be,D=we,E=ye,F=ve,z=ge;return R(),B("div",null,[r(z,null,{default:_(()=>[r(b(l),{activeKey:f.value,"onUpdate:activeKey":a[0]||(a[0]=t=>f.value=t)},{default:_(()=>[r(b(n),{key:"challenges",tab:"مدیریت چالش‌ها"},{default:_(()=>[s("div",Je,[Ke,r(g,{type:"primary",onClick:le},{default:_(()=>[j("افزودن چالش")]),_:1})]),r(k,Y(oe,{ref:"table",onRegister:b(A)}),{action:_(({record:t})=>[s("div",Ge,[r(b(H),{class:"cursor-pointer"},{title:_(()=>[s("span",null,V(t.show?"مخفی کردن":"نمایش"),1)]),default:_(()=>[r(O,{icon:t.show?"vuesax-linear:eye-slash":"vuesax-linear:eye",color:t.show?"#F59E0B":"#16A34A",onClick:x=>me(t)},null,8,["icon","color","onClick"])]),_:2},1024),r(b(H),{class:"cursor-pointer"},{title:_(()=>[Xe]),default:_(()=>[r(O,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:x=>pe(t)},null,8,["onClick"])]),_:2},1024),r(b(H),{class:"cursor-pointer"},{title:_(()=>[Qe]),default:_(()=>[r(O,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:x=>_e(t)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"])]),_:1}),r(b(n),{key:"progress",tab:"پیشرفت کاربران"},{default:_(()=>[Ye,r(k,Y(ne,{onRegister:b(c)}),null,16,["onRegister"])]),_:1})]),_:1},8,["activeKey"]),r(F,{visible:I.value,"onUpdate:visible":a[6]||(a[6]=t=>I.value=t),title:q.value?"ویرایش چالش":"افزودن چالش",onOk:he,onCancel:G,width:"85%",confirmLoading:U.value>0},{default:_(()=>[s("div",Ze,[U.value>0?(R(),B("div",et,[r(b(Re),{size:"large"})])):W("",!0),s("div",null,[tt,r($,{value:d.value.title,"onUpdate:value":a[1]||(a[1]=t=>d.value.title=t),placeholder:"عنوان چالش"},null,8,["value"])]),s("div",st,[s("div",null,[at,r($,{value:d.value.sort_order,"onUpdate:value":a[2]||(a[2]=t=>d.value.sort_order=t),type:"number",placeholder:"0"},null,8,["value"])]),s("div",null,[ot,s("div",nt,[r(D,{value:d.value.show,"onUpdate:value":a[3]||(a[3]=t=>d.value.show=t)},null,8,["value"]),s("span",rt,V(d.value.show?"نمایش":"مخفی"),1)])]),s("div",null,[lt,r(b(i),{value:d.value.access_type,"onUpdate:value":a[4]||(a[4]=t=>d.value.access_type=t),class:"w-full"},{default:_(()=>[r(b(h),{value:"free"},{default:_(()=>[j("رایگان (همه کاربران)")]),_:1}),r(b(h),{value:"subscription"},{default:_(()=>[j("اشتراکی (فقط اشتراک فعال)")]),_:1})]),_:1},8,["value"])])]),s("div",it,[s("div",null,[ct,r(b(Be),{"file-list":o.value,"onUpdate:fileList":a[5]||(a[5]=t=>o.value=t),"before-upload":de,"custom-request":ue,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:_(()=>[o.value.length<1?(R(),B("div",dt,[r(O,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),ut])):W("",!0)]),_:1},8,["file-list"]),y.value>0&&y.value<100?(R(),B("div",_t,[s("div",pt,[s("div",{class:"h-2 bg-blue-500 transition-all",style:Ue(re(y.value))},null,4)])])):W("",!0)])]),mt,s("div",ht,[ft,s("div",gt,[(R(!0),B(Te,null,Me(d.value.steps,(t,x)=>(R(),B("div",{key:x,class:"border rounded-lg p-4 space-y-3"},[s("div",vt,"مرحله "+V(x+1),1),s("div",null,[yt,r(E,{value:t.description,"onUpdate:value":v=>t.description=v,placeholder:"توضیحات مرحله",rows:2},null,8,["value","onUpdate:value"])]),s("div",xt,[s("div",null,[wt,r($,{value:t.duration_minutes,"onUpdate:value":v=>t.duration_minutes=v,type:"number",min:"1",placeholder:"5"},null,8,["value","onUpdate:value"])]),s("div",bt,[s("div",St,[r(D,{value:t.requires_photo_upload,"onUpdate:value":v=>t.requires_photo_upload=v},null,8,["value","onUpdate:value"]),kt])])]),s("div",null,[Ct,r(E,{value:t.aparat_embed_code,"onUpdate:value":v=>t.aparat_embed_code=v,placeholder:"کد embed ویدیو آپارات",rows:3},null,8,["value","onUpdate:value"])]),s("div",null,[It,r(E,{value:t.punishment_description,"onUpdate:value":v=>t.punishment_description=v,placeholder:"مجازات در صورت انجام ندادن",rows:2},null,8,["value","onUpdate:value"])]),s("div",Ut,[r(g,{type:"text",danger:"",onClick:v=>ce(x),disabled:d.value.steps.length<=1},{default:_(()=>[r(O,{icon:"vuesax-linear:trash",color:"#DC2626"}),Tt]),_:2},1032,["onClick","disabled"])])]))),128)),r(g,{type:"dashed",onClick:ie,class:"w-full"},{default:_(()=>[Mt]),_:1})])])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});const is=Pe(qt,[["__scopeId","data-v-a2451c8c"]]);export{is as default};