2 lines
15 KiB
JavaScript
2 lines
15 KiB
JavaScript
import{_ as G}from"./BasicMainCard-c54bb9b0.js";import{_ as H}from"./BasicModal.vue_vue_type_style_index_0_lang-81f74944.js";import{_ as K}from"./BasicTextArea.vue_vue_type_style_index_0_lang-a99d3ef0.js";import{_ as X}from"./BasicInput.vue_vue_type_style_index_0_lang-ef403492.js";import{_ as Z}from"./BaseTable.vue_vue_type_style_index_0_lang-9998cbb6.js";import{_ as ee}from"./button.vue_vue_type_style_index_0_lang-0fccfabb.js";import{a2 as te,a3 as k,d as oe,r as b,Y as ae,i as ie,o as D,c as C,b as s,w as y,a as o,e as se,a4 as ne,L as B,N as A,F as re,S as le,a0 as h}from"./index-8faf65eb.js";import{t as ce}from"./useDataTime-3ab158a8.js";import{I as T}from"./Icon-6ae98f2d.js";import{u as de}from"./useBaseTable-3aeb2499.js";import{M as ue}from"./index-d80e0fa6.js";import{S as pe}from"./index-4bd6caba.js";import{U as me}from"./index-7a7ffacc.js";import{T as Q}from"./index-873bc0b7.js";import"./_plugin-vue_export-helper-c27b6911.js";import"./index-1450fc27.js";import"./index-478507bf.js";import"./raf-c414ae0b.js";import"./colors-85157c08.js";import"./index-190b1277.js";import"./styleChecker-9e8bab95.js";import"./useState-419315b3.js";import"./Col-0090e201.js";import"./index-ded199d9.js";import"./debounce-87bd7043.js";import"./usePrefix-ed2fcde4.js";import"./index-ad541e1d.js";import"./SearchOutlined-ea23f2d8.js";import"./EyeOutlined-96e68258.js";import"./usePrice-7afab779.js";import"./index-bb9a7086.js";import"./index-a9568980.js";import"./pickAttrs-8b8fb5c4.js";import"./CheckOutlined-fd1b090a.js";import"./objectDestructuringEmpty-24e23e90.js";import"./eagerComputed-8c813d73.js";import"./index-30cb688a.js";async function ve(r){const{data:_,error:u}=await k.from("matchs").select("*").eq("id",r).single();if(u)throw u;const{data:m,error:n}=await k.from("questions").select("*").eq("match_id",r);if(n)throw n;return{..._,questions:m||[]}}async function _e(r){console.log("addMatchWithQuestions payload:",r);const{data:_,error:u}=await k.from("matchs").insert([r.match]).select().single();if(console.log("Match insert result:",{matchData:_,matchError:u}),u)throw console.error("Match insert error:",u),u;for(const m of r.questions){const{data:n,error:f}=await k.from("questions").insert([{match_id:_.id,question:m.question,options:m.options,correct_answer:m.correct_answer}]).select().single();if(f)throw f;console.log("Question created:",n)}return _}async function fe(r,_){const{error:u}=await k.from("matchs").update(_.match).eq("id",r);if(u)throw u;const{data:m}=await k.from("questions").select("id").eq("match_id",r);if(m)for(const n of m)await k.from("questions").delete().eq("id",n.id);for(const n of _.questions){const{data:f,error:g}=await k.from("questions").insert([{match_id:r,question:n.question,options:n.options,correct_answer:n.correct_answer}]).select().single();if(g)throw g;console.log("Question updated:",f)}return{id:r}}async function he(r){await k.from("questions").delete().eq("match_id",r);const{error:_}=await k.from("matchs").delete().eq("id",r);if(_)throw _}async function ge(r){const{TableEngineRequest:_}=await te(()=>import("./buildSupabaseQuery-50063746.js"),["assets/buildSupabaseQuery-50063746.js","assets/index-8faf65eb.js","assets/index-d933e911.css"]),u={...r};!u.sort&&!u.order&&(u.order="-id");const m=await _(u,"matchs");try{if(Array.isArray(m==null?void 0:m.rows)){const n=u.page||1,f=u.limit||200,g=(n-1)*f,S=m.rows.map((E,V)=>({id:E.id,title:E.title??"",description:E.description??"",created_at:E.created_at??"",index:g+V,...E}));return{...m,rows:S}}}catch(n){console.log("[getMatchTable] normalize error:",n)}return m}const xe=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",fixed:"left",customRender:r=>r.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"شرح",dataIndex:"description",key:"description"},{title:"سوالات",dataIndex:"questions",key:"questions",customRender:r=>"سوالات مسابقه"},{title:"تاریخ ایجاد",dataIndex:"created_at",key:"created_at",customRender:r=>ce(r.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],ye={class:"flex justify-between items-center mb-4"},we=o("h2",null,"مسابقات",-1),be={class:"gap-2 flex justify-center"},qe=o("span",null,"حذف",-1),ke=o("span",null,"ویرایش",-1),Ue={class:"space-y-4 relative"},Me={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},Ee=o("div",{class:"mb-1 text-sm text-gray-600"},"عنوان مسابقه",-1),De=o("div",{class:"mb-1 text-sm text-gray-600"},"شرح مسابقه",-1),Ce={class:"flex justify-center gap-10 pb-4"},$e=o("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر",-1),Ie={key:0},Le=o("div",null,"آپلود تصویر",-1),Te=o("div",{class:"mb-1 text-sm text-gray-600"},"آپلود ویدئو",-1),Be={key:0},Se=o("div",null,"آپلود ویدئو",-1),Ve=o("div",{class:"section-divider"},null,-1),Ae={class:"pt-4"},Re=o("div",{class:"mb-1 text-sm text-gray-600"},"سوالات مسابقه",-1),Qe={class:"space-y-3"},je={class:"space-y-3"},ze=o("div",{class:"mb-1 text-xs text-gray-500"},"سوال",-1),We={class:"grid grid-cols-2 gap-3"},Fe=o("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 1",-1),Pe=o("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 2",-1),Ne=o("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 3",-1),Oe=o("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 4",-1),Je=o("div",{class:"mb-1 text-xs text-gray-500"},"جواب صحیح (شماره گزینه)",-1),Ye={class:"flex justify-end"},Ge=o("span",{class:"text-[#DC2626]"},"حذف سوال",-1),He=o("span",{class:"text-gray-500"},"+ افزودن سوال",-1),Bt=oe({__name:"index",setup(r){b([]),b(!1);const _=b(null),[u,m]=de();ae();const n=b([]),f=b([]),g=b(0);function S(d){return d.type.startsWith("video/")?d.size/1024/1024<100?!0:(h.error("حجم فایل باید کمتر از 100MB باشد!"),!1):(h.error("فقط فایلهای ویدئو قابل آپلود هستند!"),!1)}async function E(d){var v,q,p,M;const{file:t,onSuccess:i,onError:U}=d;try{g.value++;const x=new FormData;x.append("file",t);const a=await fetch("https://node.machartaa.ir/upload/video",{method:"POST",body:x,headers:{Authorization:`Bearer ${localStorage.getItem("token")||""}`}});if(!a.ok)throw new Error("خطا در آپلود فایل");const e=await a.json();console.log("Video upload result:",e);const l=(e==null?void 0:e.full_src)||(e==null?void 0:e.url)||(e==null?void 0:e.src)||(e==null?void 0:e.path)||((v=e==null?void 0:e.data)==null?void 0:v.full_src)||((q=e==null?void 0:e.data)==null?void 0:q.url)||((p=e==null?void 0:e.data)==null?void 0:p.src)||((M=e==null?void 0:e.data)==null?void 0:M.path)||"";console.log("Extracted video path:",l);const w=l.startsWith("http")?l:`https://node.machartaa.ir${l}`;console.log("Full video URL:",w),c.value.video_url=w,n.value=w?[{uid:`${Date.now()}`,name:"video.mp4",status:"done",url:w,response:{path:w}}]:[],i(e),h.success("ویدئو با موفقیت آپلود شد!")}catch(x){console.error("خطا در آپلود ویدئو:",x),U(x),h.error("خطا در آپلود ویدئو!")}finally{g.value=Math.max(0,g.value-1)}}function V(d){return d.type.startsWith("image/")?d.size/1024/1024<5?!0:(h.error("حجم تصویر باید کمتر از 5MB باشد!"),!1):(h.error("فقط فایلهای تصویری قابل آپلود هستند!"),!1)}async function j(d){var v,q,p,M;const{file:t,onSuccess:i,onError:U}=d;try{g.value++;const x=new FormData;x.append("file",t);const a=await fetch("https://node.machartaa.ir/upload/machartaa-img",{method:"POST",body:x,headers:{Authorization:`Bearer ${localStorage.getItem("token")||""}`}});if(!a.ok)throw new Error("خطا در آپلود تصویر");const e=await a.json();console.log("Image upload result:",e);const l=(e==null?void 0:e.full_src)||(e==null?void 0:e.url)||(e==null?void 0:e.src)||(e==null?void 0:e.path)||((v=e==null?void 0:e.data)==null?void 0:v.full_src)||((q=e==null?void 0:e.data)==null?void 0:q.url)||((p=e==null?void 0:e.data)==null?void 0:p.src)||((M=e==null?void 0:e.data)==null?void 0:M.path)||"";console.log("Extracted path:",l);const w=l.startsWith("http")?l:`https://node.machartaa.ir${l}`;console.log("Full image URL:",w),c.value.image_url=w,f.value=w?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:w,response:{path:w}}]:[],i(e),h.success("تصویر با موفقیت آپلود شد!")}catch(x){console.error("خطا در آپلود تصویر:",x),U(x),h.error("خطا در آپلود تصویر!")}finally{g.value=Math.max(0,g.value-1)}}const z=b({columns:xe,api:ge,defaultPageLimit:20}),$=b(!1),I=b(!1),L=b(null),c=b({title:"",description:"",image_url:null,video_url:null,questions:[{id:1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""}]});async function W(){}async function F(){n.value=[],f.value=[],c.value={title:"",description:"",image_url:null,video_url:null,questions:[{id:1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""}]},I.value=!1,L.value=null,$.value=!0}function R(){$.value=!1,I.value=!1,L.value=null}async function P(){var i,U,v,q;if(!((i=c.value.title)!=null&&i.trim()))return;const d=c.value.questions.map(p=>({question:p.question,options:[p.option1,p.option2,p.option3,p.option4].filter(M=>M.trim()),correct_answer:p.correct_answer})),t={match:{title:c.value.title.trim(),description:((U=c.value.description)==null?void 0:U.trim())||"",image_url:((v=c.value.image_url)==null?void 0:v.trim())||null,video_url:((q=c.value.video_url)==null?void 0:q.trim())||null},questions:d.filter(p=>p.question.trim())};if(g.value>0){h.warning("لطفاً تا پایان آپلود ویدئوها صبر کنید.");return}console.log("Match payload:",t);try{I.value&&L.value?(await fe(L.value,t),h.success("مسابقه با موفقیت ویرایش شد!")):(await _e(t),h.success("مسابقه با موفقیت ایجاد شد!")),R(),await m()}catch(p){console.error("Error saving match:",p),h.error("خطا در ذخیره مسابقه!")}}async function N(d){try{const t=await ve(d.id);console.log("Match data loaded:",t),t.video_url?(n.value=[{uid:`video-${Date.now()}`,name:"video.mp4",status:"done",url:t.video_url,response:{path:t.video_url}}],console.log("Video file list set:",n.value)):n.value=[],t.image_url?(f.value=[{uid:`image-${Date.now()}`,name:"image.jpg",status:"done",url:t.image_url,response:{path:t.image_url}}],console.log("Image file list set:",f.value)):f.value=[],c.value={title:t.title||"",description:t.description||"",image_url:t.image_url||null,video_url:t.video_url||null,questions:t.questions&&t.questions.length>0?t.questions.map((i,U)=>({id:i.id,question:i.question||"",option1:i.options&&i.options[0]?i.options[0]:"",option2:i.options&&i.options[1]?i.options[1]:"",option3:i.options&&i.options[2]?i.options[2]:"",option4:i.options&&i.options[3]?i.options[3]:"",correct_answer:i.correct_answer||""})):[{id:1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""}]},I.value=!0,L.value=d.id,$.value=!0}catch(t){console.error("Error loading match data:",t),h.error("خطا در بارگذاری اطلاعات مسابقه!")}}function O(d){ue.confirm({title:"حذف مسابقه",content:`آیا مطمئن هستید که میخواهید مسابقه "${d.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await he(d.id),h.success("مسابقه با موفقیت حذف شد!"),await m()}catch(t){console.error("Error deleting match:",t),h.error("خطا در حذف مسابقه!")}}})}function J(){c.value.questions.push({id:c.value.questions.length+1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""})}function Y(d){c.value.questions.length>1&&(c.value.questions.splice(d,1),c.value.questions.forEach((t,i)=>{t.id=i+1}))}return ie(W),(d,t)=>{const i=ee,U=Z,v=X,q=K,p=me,M=H,x=G;return D(),C("div",null,[s(x,null,{default:y(()=>[o("div",ye,[we,s(i,{type:"primary",onClick:F},{default:y(()=>[se("افزودن مسابقه")]),_:1})]),s(U,ne(z.value,{ref_key:"table",ref:_,onRegister:B(u)}),{action:y(({record:a})=>[o("div",be,[s(B(Q),{class:"cursor-pointer"},{title:y(()=>[qe]),default:y(()=>[s(T,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:e=>O(a)},null,8,["onClick"])]),_:2},1024),s(B(Q),{class:"cursor-pointer"},{title:y(()=>[ke]),default:y(()=>[s(T,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:e=>N(a)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),s(M,{visible:$.value,"onUpdate:visible":t[4]||(t[4]=a=>$.value=a),title:I.value?"ویرایش مسابقه":"افزودن مسابقه",onOk:P,onCancel:R,width:"80%",confirmLoading:g.value>0},{default:y(()=>[o("div",Ue,[g.value>0?(D(),C("div",Me,[s(B(pe),{size:"large"})])):A("",!0),o("div",null,[Ee,s(v,{value:c.value.title,"onUpdate:value":t[0]||(t[0]=a=>c.value.title=a),placeholder:"عنوان مسابقه"},null,8,["value"])]),o("div",null,[De,s(q,{value:c.value.description,"onUpdate:value":t[1]||(t[1]=a=>c.value.description=a),placeholder:"شرح مسابقه"},null,8,["value"])]),o("div",Ce,[o("div",null,[$e,s(p,{"file-list":f.value,"onUpdate:fileList":t[2]||(t[2]=a=>f.value=a),"before-upload":V,"custom-request":j,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:y(()=>[f.value.length<1?(D(),C("div",Ie,[s(T,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),Le])):A("",!0)]),_:1},8,["file-list"])]),o("div",null,[Te,s(p,{"file-list":n.value,"onUpdate:fileList":t[3]||(t[3]=a=>n.value=a),"before-upload":S,"custom-request":E,accept:"video/*","max-count":1,"list-type":"picture-card"},{default:y(()=>[n.value.length<1?(D(),C("div",Be,[s(T,{icon:"vuesax-linear:video",class:"text-2xl mb-2"}),Se])):A("",!0)]),_:1},8,["file-list"])])]),Ve,o("div",Ae,[Re,o("div",Qe,[(D(!0),C(re,null,le(c.value.questions,(a,e)=>(D(),C("div",{key:e,class:"border rounded-lg p-3 space-y-3"},[o("div",je,[o("div",null,[ze,s(v,{value:a.question,"onUpdate:value":l=>a.question=l,placeholder:`سوال ${e+1}`},null,8,["value","onUpdate:value","placeholder"])]),o("div",We,[o("div",null,[Fe,s(v,{value:a.option1,"onUpdate:value":l=>a.option1=l,placeholder:"گزینه 1"},null,8,["value","onUpdate:value"])]),o("div",null,[Pe,s(v,{value:a.option2,"onUpdate:value":l=>a.option2=l,placeholder:"گزینه 2"},null,8,["value","onUpdate:value"])]),o("div",null,[Ne,s(v,{value:a.option3,"onUpdate:value":l=>a.option3=l,placeholder:"گزینه 3"},null,8,["value","onUpdate:value"])]),o("div",null,[Oe,s(v,{value:a.option4,"onUpdate:value":l=>a.option4=l,placeholder:"گزینه 4"},null,8,["value","onUpdate:value"])])]),o("div",null,[Je,s(v,{value:a.correct_answer,"onUpdate:value":l=>a.correct_answer=l,placeholder:"1، 2، 3 یا 4",type:"number",min:"1",max:"4"},null,8,["value","onUpdate:value"])])]),o("div",Ye,[s(i,{type:"text",danger:"",onClick:l=>Y(e),disabled:c.value.questions.length<=1},{default:y(()=>[s(T,{icon:"vuesax-linear:trash",color:"#DC2626"}),Ge]),_:2},1032,["onClick","disabled"])])]))),128)),s(i,{type:"dashed",onClick:J,class:"w-full"},{default:y(()=>[He]),_:1})])])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{Bt as default};
|