2 lines
12 KiB
JavaScript
2 lines
12 KiB
JavaScript
import{_ as K}from"./BasicMainCard-b6d3a742.js";import{M as Z,_ as ee}from"./BasicModal.vue_vue_type_style_index_0_lang-2af0515b.js";import{_ as te}from"./BasicTextArea.vue_vue_type_style_index_0_lang-e6dc6664.js";import{_ as oe}from"./BasicInput.vue_vue_type_style_index_0_lang-b6ba0813.js";import{_ as ae}from"./index-3b98377f.js";import{_ as le}from"./button.vue_vue_type_style_index_0_lang-06e5b584.js";import{b as ie,u as se,c as ne,d as re,e as ue}from"./competition-59b42287.js";import{t as de}from"./useDataTime-1975c6da.js";import{I as S}from"./Icon-d4177b3f.js";import{u as ce}from"./useBaseTable-3aeb2499.js";import{d as pe,r as v,Y as me,i as ve,o as y,c as b,b as s,w as m,a as t,e as _e,a2 as fe,L as D,N as L,X as ge,O as he,F as xe,S as ye,a0 as _,a4 as Q}from"./index-87709b34.js";import{_ as be}from"./TextPreview.vue_vue_type_script_setup_true_lang-65db399b.js";import{S as we}from"./index-cd93622d.js";import{U as Ue}from"./index-f0cfc260.js";import{T as W}from"./styleChecker-196e7653.js";import"./_plugin-vue_export-helper-52cf77f2.js";import"./index-5379f56d.js";import"./useState-9f80f738.js";import"./vnode-73bc4aca.js";import"./Col-797226f3.js";import"./index-23a38418.js";import"./usePrice-7afab779.js";import"./index-ae3216a5.js";const ke=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:w=>w.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"شرح",dataIndex:"description",key:"description",slot:"description"},{title:"سوالات",dataIndex:"questions",key:"questions",customRender:w=>"سوالات مسابقه"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:w=>de(w.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],Me={class:"flex justify-between items-center mb-4"},Ce=t("h2",null,"مسابقات",-1),$e={class:"gap-2 flex justify-center"},Ie=t("span",null,"حذف",-1),Be=t("span",null,"ویرایش",-1),Se={class:"space-y-4 relative"},De={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},Le=t("div",{class:"mb-1 text-sm text-gray-600"},"عنوان مسابقه",-1),Te=t("div",{class:"mb-1 text-sm text-gray-600"},"شرح مسابقه",-1),Re=t("div",{class:"mb-1 text-sm text-gray-600"},"عنوان ویدئو قرعه کشی",-1),Ae=t("div",{class:"mb-1 text-sm text-gray-600"},"حداقل امتیاز شرکت در قرعه کشی",-1),Ne=t("div",{class:"mb-1 text-sm text-gray-600"},"آدرس ویدئو",-1),Qe={class:"flex justify-center gap-10 pb-4"},We=t("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر",-1),je={key:0},ze=t("div",null,"آپلود تصویر",-1),Ee={key:0,class:"text-xs text-gray-500 mt-1 text-center"},Oe={class:"h-2 rounded bg-gray-200 overflow-hidden"},Pe={class:"text-xs text-gray-700 font-semibold text-center mt-1"},Fe=t("div",{class:"section-divider"},null,-1),Ve={class:"pt-4"},qe=t("div",{class:"mb-1 text-sm text-gray-600"},"سوالات مسابقه",-1),He={class:"space-y-3"},Je={class:"space-y-3"},Xe=t("div",{class:"mb-1 text-xs text-gray-500"},"سوال",-1),Ye={class:"grid grid-cols-2 gap-3"},Ge=t("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 1",-1),Ke=t("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 2",-1),Ze=t("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 3",-1),et=t("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 4",-1),tt=t("div",{class:"mb-1 text-xs text-gray-500"},"جواب صحیح (شماره گزینه)",-1),ot={class:"flex justify-end"},at=t("span",{class:"text-[#DC2626]"},"حذف سوال",-1),lt=t("span",{class:"text-gray-500"},"+ افزودن سوال",-1),It=pe({__name:"index",setup(w){v([]),v(!1);const j=v(null),[z,T]=ce();me();const f=v([]),x=v(0),g=v(0);function E(r){return r.type.startsWith("image/")?r.size/1024/1024<5?!0:(_.error("حجم تصویر باید کمتر از 5MB باشد!"),!1):(_.error("فقط فایلهای تصویری قابل آپلود هستند!"),!1)}async function O(r){const{file:o,onSuccess:i,onError:d,onProgress:u}=r,h=new FormData;h.append("file",o);const p=`${Q}/upload/machartaa-img`;g.value=0,x.value++,await new Promise((C,$)=>{const e=new XMLHttpRequest;e.open("POST",p),e.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("token")||""}`),e.upload.onprogress=c=>{if(c.lengthComputable){const n=Math.round(c.loaded/c.total*100);g.value=n,u==null||u({percent:n})}},e.onload=()=>{var c,n,A,N;if(g.value=100,e.status>=200&&e.status<300)try{const a=JSON.parse(e.responseText||"{}"),I=(a==null?void 0:a.full_src)||(a==null?void 0:a.url)||(a==null?void 0:a.src)||(a==null?void 0:a.path)||((c=a==null?void 0:a.data)==null?void 0:c.full_src)||((n=a==null?void 0:a.data)==null?void 0:n.url)||((A=a==null?void 0:a.data)==null?void 0:A.src)||((N=a==null?void 0:a.data)==null?void 0:N.path)||"",B=I!=null&&I.startsWith("http")?I:`${Q}${I}`;l.value.image_url=B||null,f.value=B?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:B,response:{path:B}}]:[],i==null||i(a,e),_.success("تصویر با موفقیت آپلود شد!"),C()}catch(a){d==null||d(a,e),$(a)}else{const a=new Error("خطا در آپلود تصویر");d==null||d(a,e),$(a)}},e.onerror=()=>{const c=new Error("خطا در آپلود تصویر!");d==null||d(c,e),$(c)},e.onloadend=()=>{x.value=Math.max(0,x.value-1),g.value=0},e.send(h)})}function P(r){return{width:`${Math.max(0,Math.min(100,r))}%`}}const F=v({columns:ke,api:ie,defaultPageLimit:20}),U=v(!1),k=v(!1),M=v(null),l=v({title:"",description:"",image_url:null,video_url:null,title_video_result:null,minimum_score:null,questions:[{id:1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""}]});async function V(){}async function q(){f.value=[],l.value={title:"",description:"",image_url:null,video_url:null,title_video_result:null,minimum_score:null,questions:[{id:1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""}]},k.value=!1,M.value=null,U.value=!0}function R(){U.value=!1,k.value=!1,M.value=null}async function H(){var i,d,u,h;if(!((i=l.value.title)!=null&&i.trim()))return;const r=l.value.questions.map(p=>({question:p.question,options:[p.option1,p.option2,p.option3,p.option4].filter(C=>C.trim()),correct_answer:p.correct_answer})),o={match:{title:l.value.title.trim(),description:((d=l.value.description)==null?void 0:d.trim())||"",image_url:((u=l.value.image_url)==null?void 0:u.trim())||null,video_url:((h=l.value.video_url)==null?void 0:h.trim())||null,title_video_result:l.value.title_video_result?String(l.value.title_video_result).trim():null,minimum_score:l.value.minimum_score?String(l.value.minimum_score).trim():null},questions:r.filter(p=>p.question.trim())};if(x.value>0){_.warning("لطفاً تا پایان آپلود ویدئوها صبر کنید.");return}console.log("Match payload:",o);try{k.value&&M.value?(await se(M.value,o),_.success("مسابقه با موفقیت ویرایش شد!")):(await ne(o),_.success("مسابقه با موفقیت ایجاد شد!")),R(),await T()}catch(p){console.error("Error saving match:",p),_.error("خطا در ذخیره مسابقه!")}}async function J(r){try{const o=await re(r.id);console.log("Match data loaded:",o),o.image_url?(f.value=[{uid:`image-${Date.now()}`,name:"image.jpg",status:"done",url:o.image_url,response:{path:o.image_url}}],console.log("Image file list set:",f.value)):f.value=[],l.value={title:o.title||"",description:o.description||"",image_url:o.image_url||null,video_url:o.video_url||null,title_video_result:o.title_video_result?String(o.title_video_result):null,minimum_score:o.minimum_score?String(o.minimum_score):null,questions:o.questions&&o.questions.length>0?o.questions.map((i,d)=>({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:""}]},k.value=!0,M.value=r.id,U.value=!0}catch(o){console.error("Error loading match data:",o),_.error("خطا در بارگذاری اطلاعات مسابقه!")}}function X(r){Z.confirm({title:"حذف مسابقه",content:`آیا مطمئن هستید که میخواهید مسابقه "${r.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await ue(r.id),_.success("مسابقه با موفقیت حذف شد!"),await T()}catch(o){console.error("Error deleting match:",o),_.error("خطا در حذف مسابقه!")}}})}function Y(){l.value.questions.push({id:l.value.questions.length+1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""})}function G(r){l.value.questions.length>1&&(l.value.questions.splice(r,1),l.value.questions.forEach((o,i)=>{o.id=i+1}))}return ve(V),(r,o)=>{const i=le,d=ae,u=oe,h=te,p=Ue,C=ee,$=K;return y(),b("div",null,[s($,null,{default:m(()=>[t("div",Me,[Ce,s(i,{type:"primary",onClick:q},{default:m(()=>[_e("افزودن مسابقه")]),_:1})]),s(d,fe(F.value,{ref_key:"table",ref:j,onRegister:D(z)}),{description:m(({record:e})=>[s(be,{text:e.description},null,8,["text"])]),action:m(({record:e})=>[t("div",$e,[s(D(W),{class:"cursor-pointer"},{title:m(()=>[Ie]),default:m(()=>[s(S,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:c=>X(e)},null,8,["onClick"])]),_:2},1024),s(D(W),{class:"cursor-pointer"},{title:m(()=>[Be]),default:m(()=>[s(S,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:c=>J(e)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),s(C,{visible:U.value,"onUpdate:visible":o[6]||(o[6]=e=>U.value=e),title:k.value?"ویرایش مسابقه":"افزودن مسابقه",onOk:H,onCancel:R,width:"80%",confirmLoading:x.value>0},{default:m(()=>[t("div",Se,[x.value>0?(y(),b("div",De,[s(D(we),{size:"large"})])):L("",!0),t("div",null,[Le,s(u,{value:l.value.title,"onUpdate:value":o[0]||(o[0]=e=>l.value.title=e),placeholder:"عنوان مسابقه"},null,8,["value"])]),t("div",null,[Te,s(h,{value:l.value.description,"onUpdate:value":o[1]||(o[1]=e=>l.value.description=e),placeholder:"شرح مسابقه"},null,8,["value"])]),t("div",null,[Re,s(u,{value:l.value.title_video_result,"onUpdate:value":o[2]||(o[2]=e=>l.value.title_video_result=e),placeholder:"عنوان ویدئو قرعه کشی"},null,8,["value"])]),t("div",null,[Ae,s(u,{value:l.value.minimum_score,"onUpdate:value":o[3]||(o[3]=e=>l.value.minimum_score=e),placeholder:"حداقل امتیاز شرکت در قرعه کشی"},null,8,["value"])]),t("div",null,[Ne,s(u,{value:l.value.video_url,"onUpdate:value":o[4]||(o[4]=e=>l.value.video_url=e),placeholder:"آدرس URL ویدئو"},null,8,["value"])]),t("div",Qe,[t("div",null,[We,s(p,{"file-list":f.value,"onUpdate:fileList":o[5]||(o[5]=e=>f.value=e),"before-upload":E,"custom-request":O,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:m(()=>[f.value.length<1?(y(),b("div",je,[s(S,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),ze])):L("",!0)]),_:1},8,["file-list"]),g.value>0&&g.value<100?(y(),b("div",Ee,[t("div",Oe,[t("div",{class:"h-2 bg-blue-500 transition-all",style:ge(P(g.value))},null,4)]),t("div",Pe,he(g.value)+"%",1)])):L("",!0)])]),Fe,t("div",Ve,[qe,t("div",He,[(y(!0),b(xe,null,ye(l.value.questions,(e,c)=>(y(),b("div",{key:c,class:"border rounded-lg p-3 space-y-3"},[t("div",Je,[t("div",null,[Xe,s(u,{value:e.question,"onUpdate:value":n=>e.question=n,placeholder:`سوال ${c+1}`},null,8,["value","onUpdate:value","placeholder"])]),t("div",Ye,[t("div",null,[Ge,s(u,{value:e.option1,"onUpdate:value":n=>e.option1=n,placeholder:"گزینه 1"},null,8,["value","onUpdate:value"])]),t("div",null,[Ke,s(u,{value:e.option2,"onUpdate:value":n=>e.option2=n,placeholder:"گزینه 2"},null,8,["value","onUpdate:value"])]),t("div",null,[Ze,s(u,{value:e.option3,"onUpdate:value":n=>e.option3=n,placeholder:"گزینه 3"},null,8,["value","onUpdate:value"])]),t("div",null,[et,s(u,{value:e.option4,"onUpdate:value":n=>e.option4=n,placeholder:"گزینه 4"},null,8,["value","onUpdate:value"])])]),t("div",null,[tt,s(u,{value:e.correct_answer,"onUpdate:value":n=>e.correct_answer=n,placeholder:"1، 2، 3 یا 4",type:"number",min:"1",max:"4"},null,8,["value","onUpdate:value"])])]),t("div",ot,[s(i,{type:"text",danger:"",onClick:n=>G(c),disabled:l.value.questions.length<=1},{default:m(()=>[s(S,{icon:"vuesax-linear:trash",color:"#DC2626"}),at]),_:2},1032,["onClick","disabled"])])]))),128)),s(i,{type:"dashed",onClick:Y,class:"w-full"},{default:m(()=>[lt]),_:1})])])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{It as default};
|