Files
machartaa_admin_dist/dist/assets/index-7c89b1e4.js
T
2026-07-08 14:38:52 +03:30

2 lines
18 KiB
JavaScript

import{_ as xe}from"./BasicMainCard-c26f589a.js";import{_ as we}from"./BasicModal.vue_vue_type_style_index_0_lang-36072897.js";import{_ as be}from"./BasicTextArea.vue_vue_type_style_index_0_lang-e3e796a9.js";import{_ as Se,a as Ie,u as Q}from"./useBaseTable-d491ffe5.js";import{_ as ke}from"./BasicInput.vue_vue_type_style_index_0_lang-d5948597.js";import{_ as Ce}from"./button.vue_vue_type_style_index_0_lang-3a790820.js";import{H as y,_ as Ue,d as Te,g as A,A as Me,o as $,c as B,b as c,w as m,j as S,a as s,e as z,G as Y,t as V,k as W,y as Re,F as Ae,n as qe,D as C,L as Pe,M as $e,I as Be}from"./index-ffafd876.js";import{f as Z,b as Ee,c as De,d as Le,e as Fe,t as Oe,M as ne,g as Ne}from"./supabaseTableQuery-95762ff3.js";import{t as K}from"./useDataTime-f9f596b1.js";import{I as O}from"./Icon-58829394.js";import{e as ee,g as te}from"./convert-67c23be8.js";import{T as se}from"./index-1a5da99e.js";import{M as je}from"./index-93c9f6b7.js";import{S as ze}from"./index-40f87837.js";import{S as ae}from"./fa_IR-b2b727da.js";import{T as H}from"./shallowequal-ca58cb6e.js";import{U as Ve}from"./index-48409291.js";import{_ as We}from"./_plugin-vue_export-helper-e7197a51.js";import"./index-cb12f6fe.js";import"./index-437fa868.js";import"./Col-3ad70221.js";import"./styleChecker-b4f2d4f9.js";import"./vnode-0b63e783.js";import"./isPlainObject-d7ef5141.js";import"./index-1e605be8.js";import"./FormItemContext-390ff43d.js";import"./useState-41f6d092.js";import"./lodash-ab9f2acd.js";import"./css-b16a4085.js";import"./DialogWrap-b6912a28.js";import"./pickAttrs-dfe23605.js";import"./index-0bd19c4c.js";import"./toArray-ae59f6f3.js";import"./usePrice-bc935b83.js";import"./useRefs-7c3186e8.js";import"./_flatRest-914a1e1b.js";import"./index-834c4847.js";function re(e,i){return i.map((o,n)=>({challenge_id:e,step_order:n+1,description:o.description,duration_seconds:Math.max(1,Math.round(Number(o.duration_minutes)*60)),aparat_embed_code:o.aparat_embed_code||null,punishment_description:o.punishment_description,requires_photo_upload:!!o.requires_photo_upload}))}async function He(e){const{data:i,error:o}=await y.from("step_challenges").select("*").eq("id",e).single();if(o)throw o;const{data:n,error:u}=await y.from("step_challenge_steps").select("*").eq("challenge_id",e).order("step_order",{ascending:!0});if(u)throw u;return{...i,steps:(n||[]).map(l=>({...l,duration_minutes:Math.round((l.duration_seconds||60)/60)}))}}async function Ke(e,i){const{data:o,error:n}=await y.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:i||null}]).select().single();if(n)throw n;const u=re(o.id,e.steps),{error:l}=await y.from("step_challenge_steps").insert(u);if(l)throw l;return o}async function Ge(e,i){const{error:o}=await y.from("step_challenges").update({title:i.title,character_image_url:i.character_image_url,show:i.show??!1,access_type:i.access_type??"free",sort_order:i.sort_order??0,updated_at:new Date().toISOString()}).eq("id",e);if(o)throw o;const{error:n}=await y.from("step_challenge_steps").delete().eq("challenge_id",e);if(n)throw n;const u=re(e,i.steps),{error:l}=await y.from("step_challenge_steps").insert(u);if(l)throw l;return{id:e}}async function Je(e){const{error:i}=await y.from("step_challenges").delete().eq("id",e);if(i)throw i}async function Xe(e,i){const{data:o,error:n}=await y.from("step_challenges").update({...i,updated_at:new Date().toISOString()}).eq("id",e).select();if(n)throw n;return o}async function Qe(e){const{TableEngineRequest:i}=await Ue(()=>import("./buildSupabaseQuery-53b6d4bf.js"),["assets/buildSupabaseQuery-53b6d4bf.js","assets/index-ffafd876.js","assets/index-210d4b6a.css","assets/supabaseTableQuery-95762ff3.js"]),o={...e};!o.sort&&!o.order&&(o.order="-id");const n=await i(o,"step_challenges");try{if(Array.isArray(n==null?void 0:n.rows)){const u=n.rows,l=u.map(I=>I.id).filter(Boolean);let U={};if(l.length>0){const{data:I}=await y.from("step_challenge_steps").select("id, challenge_id, step_order, duration_seconds").in("challenge_id",l);U=(I||[]).reduce((x,v)=>(x[v.challenge_id]||(x[v.challenge_id]=[]),x[v.challenge_id].push(v),x),{})}const T=o.page||1,R=o.limit||20,d=(T-1)*R,r=u.map((I,x)=>{const v=U[I.id]||[],q=v.reduce((M,E)=>M+Math.round((E.duration_seconds||0)/60),0);return{...I,index:d+x,steps_count:v.length,total_minutes:q}});return{...n,rows:r}}}catch(u){console.log("[getStepChallengesTable] normalize error:",u)}return n}const Ye=new Set(["status","current_step_order","started_at","completed_at","created_at","challenge_id"]);async function oe(e){const i=e.trim();if(!i)return[];const{data:o,error:n}=await y.from("step_challenges").select("id").ilike("title",Oe(i)).limit(ne);if(n)throw n;return(o||[]).map(u=>u.id)}function Ze(e,i,o){const n=Ne(["status"],e,i).split(","),u=[...new Set(o)].slice(0,ne);return u.length&&n.push(`challenge_id.in.(${u.join(",")})`),n.join(",")}async function et(e){const{limit:i=20,page:o=1,search:n,filters:u}=e;let l=y.from("user_step_challenges").select("*, step_challenges(title), users(name, phone, first_name, last_name)",{count:"exact"});if(n!=null&&n.trim()){const[d,r]=await Promise.all([Z(y,n),oe(n)]);l=l.or(Ze(n,d,r))}if(u!=null&&u.length){for(const d of u)if(!(d.hidden||!d.field)){if(d.field==="challenge_title"){if(["eq","has","like"].includes(d.op)){const r=await oe(String(d.value));r.length?l=l.in("challenge_id",r):l=l.eq("challenge_id",-1)}continue}if(d.field==="user_name"||d.field==="user_phone"){if(["eq","has","like"].includes(d.op)){const r=await Z(y,String(d.value));r.length?l=l.in("user_id",r):l=l.eq("user_id","00000000-0000-0000-0000-000000000000")}continue}Ye.has(d.field)&&(l=Ee(l,d))}}l=De(l,e,"-created_at",["created_at","status","current_step_order"]),l=Le(l,o,i);const{data:U,error:T,count:R}=await l;if(T)throw T;return Fe(U,R,e,d=>{const r=Array.isArray(d.users)?d.users[0]:d.users,I=Array.isArray(d.step_challenges)?d.step_challenges[0]:d.step_challenges;let x="نامشخص";return r!=null&&r.name?x=r.name:r!=null&&r.first_name||r!=null&&r.last_name?x=`${r.first_name||""} ${r.last_name||""}`.trim():r!=null&&r.phone&&(x=r.phone),{...d,challenge_title:(I==null?void 0:I.title)||"",user_name:x,user_phone:(r==null?void 0:r.phone)||""}})}const tt=[{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 i=e.record.steps_count||0,o=e.record.total_minutes||0;return i?`${i} مرحله / ${o} دقیقه`:"-"}},{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=>K(e.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],st={in_progress:"در حال انجام",completed:"تکمیل شده",abandoned:"رها شده"},at=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:e=>e.record.index+1},{title:"چالش",dataIndex:"challenge_title",key:"challenge_title",filterField:"challenge_title"},{title:"کاربر",dataIndex:"user_name",key:"user_name",filterField:"user_name"},{title:"موبایل",dataIndex:"user_phone",key:"user_phone",filterField:"user_phone"},{title:"وضعیت",dataIndex:"status",key:"status",customRender:e=>st[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=>K(e.record.started_at)},{title:"پایان",dataIndex:"completed_at",key:"completed_at",customRender:e=>e.record.completed_at?K(e.record.completed_at):"-"}],h=e=>(Pe("data-v-a2451c8c"),e=e(),$e(),e),ot={class:"flex justify-between items-center mb-4"},nt=h(()=>s("h2",null,"چالش‌های مرحله‌ای",-1)),rt={class:"gap-2 flex justify-center"},lt=h(()=>s("span",null,"حذف",-1)),it=h(()=>s("span",null,"ویرایش",-1)),ct=h(()=>s("div",{class:"mb-4"},[s("h2",null,"پیشرفت کاربران در چالش‌ها")],-1)),dt={class:"space-y-4 relative"},ut={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},_t=h(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"عنوان چالش",-1)),pt={class:"grid grid-cols-1 sm:grid-cols-3 gap-4"},mt=h(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"ترتیب نمایش",-1)),ht=h(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"وضعیت نمایش",-1)),ft={class:"flex items-center gap-2 mt-2"},gt={class:"text-sm text-gray-600"},vt=h(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"نوع دسترسی",-1)),yt={class:"flex justify-center pb-2"},xt=h(()=>s("div",{class:"mb-1 text-sm text-gray-600"},"عکس کاراکتر (کارت لیست)",-1)),wt={key:0},bt=h(()=>s("div",null,"آپلود تصویر",-1)),St={key:0,class:"mt-1"},It={class:"h-2 rounded bg-gray-200 overflow-hidden"},kt=h(()=>s("div",{class:"section-divider"},null,-1)),Ct={class:"pt-2"},Ut=h(()=>s("div",{class:"mb-2 text-sm text-gray-600 font-semibold"},"مراحل چالش",-1)),Tt={class:"space-y-3"},Mt={class:"font-semibold text-gray-700"},Rt=h(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"توضیحات مرحله",-1)),At={class:"grid grid-cols-2 gap-3"},qt=h(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"زمان حل (دقیقه)",-1)),Pt={class:"flex items-end pb-1"},$t={class:"flex items-center gap-2"},Bt=h(()=>s("span",{class:"text-sm text-gray-600"},"نیاز به بارگذاری عکس",-1)),Et=h(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"کد embed آپارات",-1)),Dt=h(()=>s("div",{class:"mb-1 text-xs text-gray-500"},"توضیح مجازات",-1)),Lt={class:"flex justify-end"},Ft=h(()=>s("span",{class:"text-[#DC2626]"},"حذف مرحله",-1)),Ot=h(()=>s("span",{class:"text-gray-500"},"+ افزودن مرحله",-1)),Nt=Te({__name:"index",setup(e){const i=se,o=se.TabPane,n=ae,u=ae.Option,l=A("challenges"),U=A(!1),T=A(!1),R=A(null),[d,r]=Q(),[I]=Q(),x=Me(),v=A([]),q=A(0),M=A(0),E=()=>({description:"",duration_minutes:5,aparat_embed_code:"",punishment_description:"",requires_photo_upload:!1}),_=A({title:"",character_image_url:null,show:!1,access_type:"free",sort_order:0,steps:[E()]}),le={columns:tt,api:Qe,defaultPageLimit:20},ie={columns:at,api:et,defaultPageLimit:20};function ce(p){return{width:`${Math.max(0,Math.min(100,p))}%`}}function G(){_.value={title:"",character_image_url:null,show:!1,access_type:"free",sort_order:0,steps:[E()]},v.value=[]}function de(){T.value=!1,R.value=null,G(),U.value=!0}function J(){U.value=!1,G()}function ue(){_.value.steps.push(E())}function _e(p){_.value.steps.length<=1||_.value.steps.splice(p,1)}function pe(p){return p.type.startsWith("image/")?p.size/1024/1024<5?!0:(C.error("حجم تصویر باید کمتر از 5MB باشد!"),!1):(C.error("فقط فایل‌های تصویری قابل آپلود هستند!"),!1)}async function me(p){const{file:a,onSuccess:f,onError:k,onProgress:P}=p,D=new FormData;D.append("file",a);const L=`${Be}/upload/machartaa-img`;M.value=0,q.value++,await new Promise((N,F)=>{const t=new XMLHttpRequest;t.open("POST",L),t.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("token")||""}`),t.upload.onprogress=w=>{if(w.lengthComputable){const g=Math.round(w.loaded/w.total*100);M.value=g,P==null||P({percent:g})}},t.onload=()=>{var w,g;if(M.value=100,t.status>=200&&t.status<300)try{const b=JSON.parse(t.responseText||"{}"),ye=b.full_src||b.url||b.src||b.path||((w=b.data)==null?void 0:w.full_src)||((g=b.data)==null?void 0:g.url)||"",j=ee(ye),X=te(j);_.value.character_image_url=j,v.value=X?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:X,response:{path:j}}]:[],f==null||f(b,t),C.success("تصویر با موفقیت آپلود شد!"),N()}catch(b){k==null||k(b,t),F(b)}else{const b=new Error("خطا در آپلود تصویر");k==null||k(b,t),F(b)}},t.onerror=()=>{k==null||k(new Error("خطا در آپلود تصویر!"),t),F(new Error("خطا در آپلود تصویر!"))},t.onloadend=()=>{q.value=Math.max(0,q.value-1),M.value=0},t.send(D)})}async function he(p){try{const a=await He(p.id);T.value=!0,R.value=p.id,_.value={title:a.title,character_image_url:ee(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(f=>({id:f.id,description:f.description,duration_minutes:f.duration_minutes||Math.round((f.duration_seconds||60)/60),aparat_embed_code:f.aparat_embed_code||"",punishment_description:f.punishment_description||"",requires_photo_upload:!!f.requires_photo_upload}))},a.character_image_url&&(v.value=[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:te(a.character_image_url)}]),U.value=!0}catch(a){C.error(a.message||"خطا در بارگذاری چالش")}}async function fe(p){je.confirm({title:"حذف چالش",content:"آیا از حذف این چالش مطمئن هستید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{await Je(p.id),C.success("چالش حذف شد"),r()}})}async function ge(p){await Xe(p.id,{show:!p.show}),C.success(p.show?"چالش مخفی شد":"چالش نمایش داده می‌شود"),r()}async function ve(){var p;if(!_.value.title.trim()){C.error("عنوان چالش الزامی است");return}if(_.value.steps.some(a=>!a.description.trim())){C.error("توضیحات همه مراحل الزامی است");return}if(_.value.steps.some(a=>!a.punishment_description.trim())){C.error("توضیح مجازات همه مراحل الزامی است");return}try{const a={..._.value,sort_order:Number(_.value.sort_order)||0};T.value&&R.value?(await Ge(R.value,a),C.success("چالش ویرایش شد")):(await Ke(a,(p=x.userInfo)==null?void 0:p.id),C.success("چالش اضافه شد")),J(),r()}catch(a){C.error(a.message||"خطا در ذخیره چالش")}}return(p,a)=>{const f=Ce,k=Se,P=ke,D=Ie,L=be,N=we,F=xe;return $(),B("div",null,[c(F,null,{default:m(()=>[c(S(i),{activeKey:l.value,"onUpdate:activeKey":a[0]||(a[0]=t=>l.value=t)},{default:m(()=>[c(S(o),{key:"challenges",tab:"مدیریت چالش‌ها"},{default:m(()=>[s("div",ot,[nt,c(f,{type:"primary",onClick:de},{default:m(()=>[z("افزودن چالش")]),_:1})]),c(k,Y(le,{ref:"table",onRegister:S(d)}),{action:m(({record:t})=>[s("div",rt,[c(S(H),{class:"cursor-pointer"},{title:m(()=>[s("span",null,V(t.show?"مخفی کردن":"نمایش"),1)]),default:m(()=>[c(O,{icon:t.show?"vuesax-linear:eye-slash":"vuesax-linear:eye",color:t.show?"#F59E0B":"#16A34A",onClick:w=>ge(t)},null,8,["icon","color","onClick"])]),_:2},1024),c(S(H),{class:"cursor-pointer"},{title:m(()=>[lt]),default:m(()=>[c(O,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:w=>fe(t)},null,8,["onClick"])]),_:2},1024),c(S(H),{class:"cursor-pointer"},{title:m(()=>[it]),default:m(()=>[c(O,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:w=>he(t)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"])]),_:1}),c(S(o),{key:"progress",tab:"پیشرفت کاربران"},{default:m(()=>[ct,c(k,Y(ie,{onRegister:S(I)}),null,16,["onRegister"])]),_:1})]),_:1},8,["activeKey"]),c(N,{visible:U.value,"onUpdate:visible":a[6]||(a[6]=t=>U.value=t),title:T.value?"ویرایش چالش":"افزودن چالش",onOk:ve,onCancel:J,width:"85%",confirmLoading:q.value>0},{default:m(()=>[s("div",dt,[q.value>0?($(),B("div",ut,[c(S(ze),{size:"large"})])):W("",!0),s("div",null,[_t,c(P,{value:_.value.title,"onUpdate:value":a[1]||(a[1]=t=>_.value.title=t),placeholder:"عنوان چالش"},null,8,["value"])]),s("div",pt,[s("div",null,[mt,c(P,{value:_.value.sort_order,"onUpdate:value":a[2]||(a[2]=t=>_.value.sort_order=t),type:"number",placeholder:"0"},null,8,["value"])]),s("div",null,[ht,s("div",ft,[c(D,{value:_.value.show,"onUpdate:value":a[3]||(a[3]=t=>_.value.show=t)},null,8,["value"]),s("span",gt,V(_.value.show?"نمایش":"مخفی"),1)])]),s("div",null,[vt,c(S(n),{value:_.value.access_type,"onUpdate:value":a[4]||(a[4]=t=>_.value.access_type=t),class:"w-full"},{default:m(()=>[c(S(u),{value:"free"},{default:m(()=>[z("رایگان (همه کاربران)")]),_:1}),c(S(u),{value:"subscription"},{default:m(()=>[z("اشتراکی (فقط اشتراک فعال)")]),_:1})]),_:1},8,["value"])])]),s("div",yt,[s("div",null,[xt,c(S(Ve),{"file-list":v.value,"onUpdate:fileList":a[5]||(a[5]=t=>v.value=t),"before-upload":pe,"custom-request":me,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:m(()=>[v.value.length<1?($(),B("div",wt,[c(O,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),bt])):W("",!0)]),_:1},8,["file-list"]),M.value>0&&M.value<100?($(),B("div",St,[s("div",It,[s("div",{class:"h-2 bg-blue-500 transition-all",style:Re(ce(M.value))},null,4)])])):W("",!0)])]),kt,s("div",Ct,[Ut,s("div",Tt,[($(!0),B(Ae,null,qe(_.value.steps,(t,w)=>($(),B("div",{key:w,class:"border rounded-lg p-4 space-y-3"},[s("div",Mt,"مرحله "+V(w+1),1),s("div",null,[Rt,c(L,{value:t.description,"onUpdate:value":g=>t.description=g,placeholder:"توضیحات مرحله",rows:2},null,8,["value","onUpdate:value"])]),s("div",At,[s("div",null,[qt,c(P,{value:t.duration_minutes,"onUpdate:value":g=>t.duration_minutes=g,type:"number",min:"1",placeholder:"5"},null,8,["value","onUpdate:value"])]),s("div",Pt,[s("div",$t,[c(D,{value:t.requires_photo_upload,"onUpdate:value":g=>t.requires_photo_upload=g},null,8,["value","onUpdate:value"]),Bt])])]),s("div",null,[Et,c(L,{value:t.aparat_embed_code,"onUpdate:value":g=>t.aparat_embed_code=g,placeholder:"کد embed ویدیو آپارات",rows:3},null,8,["value","onUpdate:value"])]),s("div",null,[Dt,c(L,{value:t.punishment_description,"onUpdate:value":g=>t.punishment_description=g,placeholder:"مجازات در صورت انجام ندادن",rows:2},null,8,["value","onUpdate:value"])]),s("div",Lt,[c(f,{type:"text",danger:"",onClick:g=>_e(w),disabled:_.value.steps.length<=1},{default:m(()=>[c(O,{icon:"vuesax-linear:trash",color:"#DC2626"}),Ft]),_:2},1032,["onClick","disabled"])])]))),128)),c(f,{type:"dashed",onClick:ue,class:"w-full"},{default:m(()=>[Ot]),_:1})])])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});const ks=We(Nt,[["__scopeId","data-v-a2451c8c"]]);export{ks as default};