Files
machartaa_admin_dist/dist/assets/index-7f470b29.js
T
2026-07-22 17:08:59 +03:30

2 lines
15 KiB
JavaScript

import{_ as ae}from"./BasicMainCard-abd17be1.js";import{_ as le}from"./BasicModal.vue_vue_type_style_index_0_lang-a23efd75.js";import{_ as ie}from"./BaseSwitch.vue_vue_type_script_setup_true_lang-2e8a6602.js";import{_ as se}from"./BasicTextArea.vue_vue_type_style_index_0_lang-76c247eb.js";import{_ as ne}from"./BasicInput.vue_vue_type_style_index_0_lang-e68ff48c.js";import{_ as re,u as ue}from"./useBaseTable-eabb6e73.js";import{_ as ce}from"./button.vue_vue_type_style_index_0_lang-58c562e7.js";import{g as de,u as pe,a as me,b as ve,c as _e,d as he}from"./competition-465f058f.js";import{t as fe}from"./useDataTime-a9a38277.js";import{I as B}from"./Icon-2ca0951c.js";import{d as ge,g as h,A as xe,v as ye,o as b,c as k,b as s,w as m,a as e,e as we,H as be,j as S,t as L,k as A,y as ke,F as Ue,n as Ce,D as _,I as Me}from"./index-02897754.js";import{e as R,g as Q}from"./convert-2ad76038.js";import{_ as $e}from"./TextPreview.vue_vue_type_script_setup_true_lang-c7e75dc6.js";import{M as z}from"./index-4652c849.js";import{S as Ie}from"./index-644e91ea.js";import{U as Be}from"./index-fd46be7d.js";import{T as P}from"./isSymbol-792a2a97.js";import"./index-c1d1bf6d.js";import"./index-9f87c1a7.js";import"./_plugin-vue_export-helper-2dea18d7.js";import"./useState-4419625c.js";import"./vnode-65917850.js";import"./useRefs-44db43e1.js";import"./_flatRest-bac800e2.js";import"./index-a2c53d90.js";import"./Col-880c700f.js";import"./styleChecker-ce90d19e.js";import"./isPlainObject-6a522913.js";import"./index-b0c72faa.js";import"./FormItemContext-0ec501fb.js";import"./usePrice-bc935b83.js";import"./updateLocale-ed1a4c67.js";import"./index-1d9cca6c.js";import"./toArray-b84867a5.js";import"./pickAttrs-66d27c5c.js";import"./lodash-f280de5a.js";import"./index-9a9a9cd2.js";import"./isNumeric-3f69e2aa.js";import"./index-f459a9b9.js";import"./index-4cf251d4.js";import"./index-834ba08a.js";import"./LeftOutlined-0f3263d7.js";import"./css-aae66f86.js";import"./DialogWrap-b41f46aa.js";import"./index-066e71ee.js";import"./textUtils-c37780ad.js";import"./index-a571a3ce.js";const Se=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:g=>g.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"شرح",dataIndex:"description",key:"description",slot:"description"},{title:"سوالات",dataIndex:"questions",key:"questions",customRender:g=>"سوالات مسابقه"},{title:"وضعیت نمایش",dataIndex:"show",key:"show",type:"Boolean",filterable:!0,align:"center",customRender:g=>g.record.show?"نمایش":"مخفی"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:g=>fe(g.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],Te={class:"flex justify-between items-center mb-4"},De=e("h2",null,"مسابقات",-1),Le={class:"gap-2 flex justify-center"},Ae=e("span",null,"حذف",-1),Re=e("span",null,"ویرایش",-1),Pe={class:"space-y-4 relative"},Ee={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},je=e("div",{class:"mb-1 text-sm text-gray-600"},"عنوان مسابقه",-1),Fe=e("div",{class:"mb-1 text-sm text-gray-600"},"شرح مسابقه",-1),Qe=e("div",{class:"mb-1 text-sm text-gray-600"},"عنوان ویدئو قرعه کشی",-1),ze=e("div",{class:"mb-1 text-sm text-gray-600"},"حداقل امتیاز شرکت در قرعه کشی",-1),Ne=e("div",{class:"mb-1 text-sm text-gray-600"},"آدرس ویدئو",-1),Oe=e("div",{class:"mb-1 text-sm text-gray-600"},"وضعیت نمایش",-1),Ve={class:"flex items-center gap-2"},We={class:"text-sm text-gray-600"},He={class:"flex justify-center gap-10 pb-4"},qe=e("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر",-1),Je={key:0},Xe=e("div",null,"آپلود تصویر",-1),Ge={key:0,class:"text-xs text-gray-500 mt-1 text-center"},Ke={class:"h-2 rounded bg-gray-200 overflow-hidden"},Ye={class:"text-xs text-gray-700 font-semibold text-center mt-1"},Ze=e("div",{class:"section-divider"},null,-1),et={class:"pt-4"},tt=e("div",{class:"mb-1 text-sm text-gray-600"},"سوالات مسابقه",-1),ot={class:"space-y-3"},at={class:"space-y-3"},lt=e("div",{class:"mb-1 text-xs text-gray-500"},"سوال",-1),it={class:"grid grid-cols-2 gap-3"},st=e("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 1",-1),nt=e("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 2",-1),rt=e("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 3",-1),ut=e("div",{class:"mb-1 text-xs text-gray-500"},"گزینه 4",-1),ct=e("div",{class:"mb-1 text-xs text-gray-500"},"جواب صحیح (شماره گزینه)",-1),dt={class:"flex justify-end"},pt=e("span",{class:"text-[#DC2626]"},"حذف سوال",-1),mt=e("span",{class:"text-gray-500"},"+ افزودن سوال",-1),no=ge({__name:"index",setup(g){h([]),h(!1);const N=h(null),[O,T]=ue();xe();const x=h([]),w=h(0),f=h(0);function V(n){return n.type.startsWith("image/")?n.size/1024/1024<5?!0:(_.error("حجم تصویر باید کمتر از 5MB باشد!"),!1):(_.error("فقط فایل‌های تصویری قابل آپلود هستند!"),!1)}async function W(n){const{file:t,onSuccess:l,onError:d,onProgress:r}=n,y=new FormData;y.append("file",t);const p=`${Me}/upload/machartaa-img`;f.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);f.value=v,r==null||r({percent:v})}},u.onload=()=>{var o,v,c,j;if(f.value=100,u.status>=200&&u.status<300)try{const i=JSON.parse(u.responseText||"{}"),oe=(i==null?void 0:i.full_src)||(i==null?void 0:i.url)||(i==null?void 0:i.src)||(i==null?void 0:i.path)||((o=i==null?void 0:i.data)==null?void 0:o.full_src)||((v=i==null?void 0:i.data)==null?void 0:v.url)||((c=i==null?void 0:i.data)==null?void 0:c.src)||((j=i==null?void 0:i.data)==null?void 0:j.path)||"",D=R(oe),F=Q(D);a.value.image_url=D||null,x.value=F?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:F,response:{path:D}}]:[],l==null||l(i,u),_.success("تصویر با موفقیت آپلود شد!"),$()}catch(i){d==null||d(i,u),I(i)}else{const i=new Error("خطا در آپلود تصویر");d==null||d(i,u),I(i)}},u.onerror=()=>{const o=new Error("خطا در آپلود تصویر!");d==null||d(o,u),I(o)},u.onloadend=()=>{w.value=Math.max(0,w.value-1),f.value=0},u.send(y)})}function H(n){return{width:`${Math.max(0,Math.min(100,n))}%`}}const q=h({columns:Se,api:de,defaultPageLimit:20}),U=h(!1),C=h(!1),M=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 J(){}async function X(){x.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:""}]},C.value=!1,M.value=null,U.value=!0}function E(){U.value=!1,C.value=!1,M.value=null}async function G(){var l,d,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})),t={match:{title:a.value.title.trim(),description:((d=a.value.description)==null?void 0:d.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}try{C.value&&M.value?(await pe(M.value,t),_.success("مسابقه با موفقیت ویرایش شد!")):(await me(t),_.success("مسابقه با موفقیت ایجاد شد!")),E(),await T()}catch(p){console.error("Error saving match:",p),_.error("خطا در ذخیره مسابقه!")}}async function K(n){try{const t=await ve(n.id);if(t.image_url){const l=R(t.image_url);x.value=[{uid:`image-${Date.now()}`,name:"image.jpg",status:"done",url:Q(l),response:{path:l}}]}else x.value=[];a.value={title:t.title||"",description:t.description||"",image_url:R(t.image_url)||null,video_url:t.video_url||null,title_video_result:t.title_video_result?String(t.title_video_result):null,minimum_score:t.minimum_score?String(t.minimum_score):null,show:t.show??!0,questions:t.questions&&t.questions.length>0?t.questions.map(l=>({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:""}]},C.value=!0,M.value=n.id,U.value=!0}catch(t){console.error("Error loading match data:",t),_.error("خطا در بارگذاری اطلاعات مسابقه!")}}async function Y(n){const t=!n.show;z.confirm({title:"تغییر وضعیت نمایش",content:t?`آیا مطمئن هستید که می‌خواهید مسابقه "${n.title}" را نمایش دهید؟`:`آیا مطمئن هستید که می‌خواهید مسابقه "${n.title}" را مخفی کنید؟`,okText:"بله",cancelText:"خیر",onOk:async()=>{try{await _e(n.id,{show:t}),_.success(t?"مسابقه با موفقیت نمایش داده شد!":"مسابقه با موفقیت مخفی شد!"),await T()}catch(l){console.error("Error toggling show:",l),_.error("خطا در تغییر وضعیت نمایش!")}}})}function Z(n){z.confirm({title:"حذف مسابقه",content:`آیا مطمئن هستید که می‌خواهید مسابقه "${n.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await he(n.id),_.success("مسابقه با موفقیت حذف شد!"),await T()}catch(t){console.error("Error deleting match:",t),_.error("خطا در حذف مسابقه!")}}})}function ee(){a.value.questions.push({id:a.value.questions.length+1,question:"",option1:"",option2:"",option3:"",option4:"",correct_answer:""})}function te(n){a.value.questions.length>1&&(a.value.questions.splice(n,1),a.value.questions.forEach((t,l)=>{t.id=l+1}))}return ye(J),(n,t)=>{const l=ce,d=re,r=ne,y=se,p=ie,$=Be,I=le,u=ae;return b(),k("div",null,[s(u,null,{default:m(()=>[e("div",Te,[De,s(l,{type:"primary",onClick:X},{default:m(()=>[we("افزودن مسابقه")]),_:1})]),s(d,be(q.value,{ref_key:"table",ref:N,onRegister:S(O)}),{description:m(({record:o})=>[s($e,{text:o.description},null,8,["text"])]),action:m(({record:o})=>[e("div",Le,[s(S(P),{class:"cursor-pointer"},{title:m(()=>[e("span",null,L(o.show?"مخفی کردن":"نمایش"),1)]),default:m(()=>[s(B,{icon:o.show?"vuesax-linear:eye-slash":"vuesax-linear:eye",color:o.show?"#F59E0B":"#16A34A",onClick:v=>Y(o)},null,8,["icon","color","onClick"])]),_:2},1024),s(S(P),{class:"cursor-pointer"},{title:m(()=>[Ae]),default:m(()=>[s(B,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:v=>Z(o)},null,8,["onClick"])]),_:2},1024),s(S(P),{class:"cursor-pointer"},{title:m(()=>[Re]),default:m(()=>[s(B,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:v=>K(o)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),s(I,{visible:U.value,"onUpdate:visible":t[7]||(t[7]=o=>U.value=o),title:C.value?"ویرایش مسابقه":"افزودن مسابقه",onOk:G,onCancel:E,width:"80%",confirmLoading:w.value>0},{default:m(()=>[e("div",Pe,[w.value>0?(b(),k("div",Ee,[s(S(Ie),{size:"large"})])):A("",!0),e("div",null,[je,s(r,{value:a.value.title,"onUpdate:value":t[0]||(t[0]=o=>a.value.title=o),placeholder:"عنوان مسابقه"},null,8,["value"])]),e("div",null,[Fe,s(y,{value:a.value.description,"onUpdate:value":t[1]||(t[1]=o=>a.value.description=o),placeholder:"شرح مسابقه"},null,8,["value"])]),e("div",null,[Qe,s(r,{value:a.value.title_video_result,"onUpdate:value":t[2]||(t[2]=o=>a.value.title_video_result=o),placeholder:"عنوان ویدئو قرعه کشی"},null,8,["value"])]),e("div",null,[ze,s(r,{value:a.value.minimum_score,"onUpdate:value":t[3]||(t[3]=o=>a.value.minimum_score=o),placeholder:"حداقل امتیاز شرکت در قرعه کشی"},null,8,["value"])]),e("div",null,[Ne,s(r,{value:a.value.video_url,"onUpdate:value":t[4]||(t[4]=o=>a.value.video_url=o),placeholder:"آدرس URL ویدئو"},null,8,["value"])]),e("div",null,[Oe,e("div",Ve,[s(p,{value:a.value.show,"onUpdate:value":t[5]||(t[5]=o=>a.value.show=o)},null,8,["value"]),e("span",We,L(a.value.show?"نمایش":"مخفی"),1)])]),e("div",He,[e("div",null,[qe,s($,{"file-list":x.value,"onUpdate:fileList":t[6]||(t[6]=o=>x.value=o),"before-upload":V,"custom-request":W,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:m(()=>[x.value.length<1?(b(),k("div",Je,[s(B,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),Xe])):A("",!0)]),_:1},8,["file-list"]),f.value>0&&f.value<100?(b(),k("div",Ge,[e("div",Ke,[e("div",{class:"h-2 bg-blue-500 transition-all",style:ke(H(f.value))},null,4)]),e("div",Ye,L(f.value)+"%",1)])):A("",!0)])]),Ze,e("div",et,[tt,e("div",ot,[(b(!0),k(Ue,null,Ce(a.value.questions,(o,v)=>(b(),k("div",{key:v,class:"border rounded-lg p-3 space-y-3"},[e("div",at,[e("div",null,[lt,s(r,{value:o.question,"onUpdate:value":c=>o.question=c,placeholder:`سوال ${v+1}`},null,8,["value","onUpdate:value","placeholder"])]),e("div",it,[e("div",null,[st,s(r,{value:o.option1,"onUpdate:value":c=>o.option1=c,placeholder:"گزینه 1"},null,8,["value","onUpdate:value"])]),e("div",null,[nt,s(r,{value:o.option2,"onUpdate:value":c=>o.option2=c,placeholder:"گزینه 2"},null,8,["value","onUpdate:value"])]),e("div",null,[rt,s(r,{value:o.option3,"onUpdate:value":c=>o.option3=c,placeholder:"گزینه 3"},null,8,["value","onUpdate:value"])]),e("div",null,[ut,s(r,{value:o.option4,"onUpdate:value":c=>o.option4=c,placeholder:"گزینه 4"},null,8,["value","onUpdate:value"])])]),e("div",null,[ct,s(r,{value:o.correct_answer,"onUpdate:value":c=>o.correct_answer=c,placeholder:"1، 2، 3 یا 4",type:"number",min:"1",max:"4"},null,8,["value","onUpdate:value"])])]),e("div",dt,[s(l,{type:"text",danger:"",onClick:c=>te(v),disabled:a.value.questions.length<=1},{default:m(()=>[s(B,{icon:"vuesax-linear:trash",color:"#DC2626"}),pt]),_:2},1032,["onClick","disabled"])])]))),128)),s(l,{type:"dashed",onClick:ee,class:"w-full"},{default:m(()=>[mt]),_:1})])])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{no as default};