Files
machartaa_admin_dist/dist/assets/index-7fb19cf6.js
T

2 lines
14 KiB
JavaScript

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