Files
machartaa_admin_dist/dist/assets/index-cebfab35.js
T
2026-07-16 18:05:28 +03:30

2 lines
11 KiB
JavaScript

import{_ as ee}from"./BasicMainCard-39c71fc4.js";import{_ as te}from"./BasicModal.vue_vue_type_style_index_0_lang-62717bd0.js";import{_ as ae}from"./BasicInput.vue_vue_type_style_index_0_lang-d56884d6.js";import{_ as oe,u as ne}from"./useBaseTable-a06f0b5f.js";import{_ as ie}from"./button.vue_vue_type_style_index_0_lang-1a640d2e.js";import{I as A}from"./Icon-d2ec8cda.js";import{t as le}from"./useDataTime-9ed06ff7.js";import{_ as se,G as O,d as re,g as x,o as B,c as $,b as l,w as c,a as i,e as E,H as ue,j as f,t as me,k as L,y as ce,D as v,I as de}from"./index-413b1e47.js";import{g as P}from"./convert-2ad76038.js";import{n as H}from"./textUtils-c37780ad.js";import{g as N}from"./index-61678014.js";import{M as pe}from"./index-2ebbed2a.js";import{S as _e}from"./index-2a1cc68a.js";import{C as he}from"./index-dfbe7e5c.js";import{I as ve}from"./index-06f6280e.js";import{T as z}from"./isSymbol-86ce36f2.js";import{U as fe}from"./index-ae4a1552.js";import"./index-74d36557.js";import"./index-59759ca5.js";import"./_plugin-vue_export-helper-45f37eb1.js";import"./useState-90ae9741.js";import"./vnode-66c98e4d.js";import"./useRefs-32d594a2.js";import"./_flatRest-c0f9ecce.js";import"./index-f54bdedf.js";import"./Col-151a5dc7.js";import"./styleChecker-51e38a61.js";import"./isPlainObject-e0f2efff.js";import"./usePrice-bc935b83.js";import"./updateLocale-7edd5cff.js";import"./index-7af4b7ee.js";import"./toArray-4793eb05.js";import"./FormItemContext-faddafe7.js";import"./pickAttrs-40baade3.js";import"./lodash-a9e7f026.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-5ce452ba.js";import"./index-ed8959d3.js";import"./isNumeric-3f69e2aa.js";import"./index-dd520fef.js";import"./index-d42da2d6.js";import"./DialogWrap-7069c158.js";import"./index-85f33ea5.js";import"./LeftOutlined-7f9e3805.js";import"./css-aae66f86.js";import"./index-2e29ac6c.js";const V=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:s=>s.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"عنوان ویدیو",dataIndex:"video_title",key:"video_title",customRender:s=>s.record.video_title||"-"},{title:"نمایش در صفحه اصلی",dataIndex:"show_on_home",key:"show_on_home",align:"center",width:140,customRender:s=>s.record.show_on_home?"بله":"خیر"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:s=>le(s.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function be(s){const{data:_,error:m}=await O.from("announcements").insert([s]).select();if(m)throw m;return _}async function F(s,_){const{data:m,error:h}=await O.from("announcements").update({..._,updated_at:new Date().toISOString()}).eq("id",s).select();if(h)throw h;return m}async function ge(s){const{error:_}=await O.from("announcements").delete().eq("id",s);if(_)throw _}async function we(s){const{TableEngineRequest:_}=await se(()=>import("./buildSupabaseQuery-89acf0e5.js"),["assets/buildSupabaseQuery-89acf0e5.js","assets/index-413b1e47.js","assets/index-338b63e2.css","assets/supabaseTableQuery-9069679c.js"]),m={...s};!m.sort&&!m.order&&(m.order="-id");const h=await _(m,"announcements");try{if(Array.isArray(h==null?void 0:h.rows)){const y=m.page||1,R=m.limit||20,k=(y-1)*R,T=h.rows.map((d,g)=>({...d,title:d.title??"",description:d.description??"",video_title:d.video_title??"",thumbnail:d.thumbnail??null,aparat_embed_code:d.aparat_embed_code??"",show_on_home:d.show_on_home!==!1,index:k+g}));return{...h,rows:T}}}catch(y){console.error("[getAnnouncementsTable]",y)}return h}const xe={class:"flex justify-between items-center mb-4"},ye=i("h2",null,"اطلاع‌رسانی ویدیویی",-1),ke=["src"],Ie={key:1},Te={class:"gap-2 flex justify-center"},Ce=i("span",null,"حذف",-1),Ue=i("span",null,"ویرایش",-1),Be={class:"space-y-4 relative"},$e={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},De=i("div",{class:"mb-1 text-sm text-gray-600"},"عنوان *",-1),Me=i("div",{class:"mb-1 text-sm text-gray-600"},"عنوان ویدیو",-1),Ae=i("div",{class:"mb-1 text-sm text-gray-600"},"توضیحات *",-1),Re=i("div",{class:"mb-1 text-sm text-gray-600"},"کد embed آپارات *",-1),Se=i("div",{class:"mb-1 text-sm text-gray-600"},"تامنیل",-1),Le={key:0},Pe=i("div",null,"آپلود تامنیل",-1),ze={key:0,class:"mt-1"},Oe={class:"h-2 rounded bg-gray-200 overflow-hidden"},Dt=re({__name:"index",setup(s){const{TextArea:_}=ve,m={authorization:`Bearer ${N()||localStorage.getItem("tamin_token")||""}`},[h,y]=ne(),R=x({columns:[...V.slice(0,2),{title:"تامنیل",dataIndex:"thumbnail",key:"thumbnail",slot:"thumbnail",align:"center",width:100,filterable:!1},...V.slice(2)],api:we,defaultPageLimit:20}),k=x(!1),T=x(!1),d=x(null),g=x([]),C=x(0),I=x(0),o=x({title:"",description:"",video_title:"",thumbnail:null,aparat_embed_code:"",show_on_home:!0});function W(){g.value=[],T.value=!1,d.value=null,o.value={title:"",description:"",video_title:"",thumbnail:null,aparat_embed_code:"",show_on_home:!0},k.value=!0}function q(){k.value=!1}function J(n){return n.type.startsWith("image/")?n.size/1024/1024<5?!0:(v.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(v.error("فقط فایل‌های تصویری مجاز است"),!1)}async function G(n){const{file:e,onSuccess:p,onError:r,onProgress:b}=n,D=new FormData;D.append("file",e);const S=`${de}/upload/machartaa-img`;I.value=0,C.value++,await new Promise((t,U)=>{const u=new XMLHttpRequest;u.open("POST",S);const Z=N()||localStorage.getItem("tamin_token")||"";u.setRequestHeader("Authorization",`Bearer ${Z}`),u.upload.onprogress=a=>{if(a.lengthComputable){const w=Math.round(a.loaded/a.total*100);I.value=w,b==null||b({percent:w})}},u.onload=()=>{if(I.value=100,u.status>=200&&u.status<300)try{const a=JSON.parse(u.responseText||"{}"),w=a.full_src||a.url||a.src||a.path||a.data&&(a.data.full_src||a.data.url||a.data.src||a.data.path)||"";let M=w;w!=null&&w.startsWith("http")&&(M=w.replace(/^https?:\/\/[^\/]+/,""));const j=P(M);o.value.thumbnail=M,g.value=j?[{uid:`${Date.now()}`,name:"thumbnail.jpg",status:"done",url:j,response:{path:M}}]:[],p==null||p(a,u),v.success("تامنیل با موفقیت آپلود شد!"),t()}catch(a){r==null||r(a,u),U(a)}else{const a=new Error("خطا در آپلود تصویر");r==null||r(a,u),U(a)}},u.onerror=()=>{const a=new Error("خطا در آپلود تامنیل");r==null||r(a,u),U(a)},u.onloadend=()=>{C.value=Math.max(0,C.value-1),I.value=0},u.send(D)})}function X(n){T.value=!0,d.value=n.id;let e=n.thumbnail||null;e&&e.startsWith("http")&&(e=e.replace(/^https?:\/\/[^\/]+/,"")),o.value={title:n.title||"",description:n.description||"",video_title:n.video_title||"",thumbnail:e,aparat_embed_code:n.aparat_embed_code||"",show_on_home:n.show_on_home!==!1};const p=e?P(e):null;g.value=p?[{uid:"-1",name:"thumbnail.jpg",status:"done",url:p,response:{path:e}}]:[],k.value=!0}function K(n){pe.confirm({title:"حذف اطلاع‌رسانی",content:`آیا از حذف «${n.title}» مطمئن هستید؟`,okText:"حذف",cancelText:"انصراف",onOk:async()=>{await ge(n.id),v.success("حذف شد"),y()}})}async function Q(n){const e=n.show_on_home===!1;await F(n.id,{show_on_home:e}),v.success(e?"در صفحه اصلی نمایش داده می‌شود":"از صفحه اصلی حذف شد"),y()}async function Y(){var e,p,r,b;if(!((e=o.value.title)!=null&&e.trim())){v.warning("عنوان الزامی است");return}if(!H(o.value.description)){v.warning("توضیحات الزامی است");return}if(!((p=o.value.aparat_embed_code)!=null&&p.trim())){v.warning("کد embed آپارات الزامی است");return}if(C.value>0){v.warning("لطفاً تا پایان آپلود صبر کنید");return}const n={title:o.value.title.trim(),description:H(o.value.description),video_title:((r=o.value.video_title)==null?void 0:r.trim())||"",thumbnail:((b=o.value.thumbnail)==null?void 0:b.trim())||null,aparat_embed_code:o.value.aparat_embed_code.trim(),show_on_home:o.value.show_on_home!==!1};T.value&&d.value?(await F(d.value,n),v.success("ویرایش شد")):(await be(n),v.success("افزوده شد")),q(),y()}return(n,e)=>{const p=ie,r=oe,b=ae,D=te,S=ee;return B(),$("div",null,[l(S,null,{default:c(()=>[i("div",xe,[ye,l(p,{type:"primary",onClick:W},{default:c(()=>[E("افزودن اطلاع‌رسانی")]),_:1})]),l(r,ue(R.value,{ref:"table",onRegister:f(h)}),{thumbnail:c(({record:t})=>[t.thumbnail?(B(),$("img",{key:0,src:f(P)(t.thumbnail),alt:"",class:"w-16 h-10 object-cover rounded"},null,8,ke)):(B(),$("span",Ie,"-"))]),action:c(({record:t})=>[i("div",Te,[l(f(z),{class:"cursor-pointer"},{title:c(()=>[i("span",null,me((t==null?void 0:t.show_on_home)===!1?"نمایش در صفحه اصلی":"حذف از صفحه اصلی"),1)]),default:c(()=>[l(A,{icon:(t==null?void 0:t.show_on_home)===!1?"vuesax-linear:eye":"vuesax-linear:eye-slash",color:(t==null?void 0:t.show_on_home)===!1?"#10B981":"#F59E0B",onClick:U=>Q(t)},null,8,["icon","color","onClick"])]),_:2},1024),l(f(z),{class:"cursor-pointer"},{title:c(()=>[Ce]),default:c(()=>[l(A,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:U=>K(t)},null,8,["onClick"])]),_:2},1024),l(f(z),{class:"cursor-pointer"},{title:c(()=>[Ue]),default:c(()=>[l(A,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:U=>X(t)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),l(D,{visible:k.value,"onUpdate:visible":e[6]||(e[6]=t=>k.value=t),title:T.value?"ویرایش اطلاع‌رسانی":"افزودن اطلاع‌رسانی",onOk:Y,onCancel:q,width:"80%",confirmLoading:C.value>0},{default:c(()=>[i("div",Be,[C.value>0?(B(),$("div",$e,[l(f(_e),{size:"large"})])):L("",!0),i("div",null,[De,l(b,{value:o.value.title,"onUpdate:value":e[0]||(e[0]=t=>o.value.title=t),placeholder:"عنوان اطلاع‌رسانی"},null,8,["value"])]),i("div",null,[Me,l(b,{value:o.value.video_title,"onUpdate:value":e[1]||(e[1]=t=>o.value.video_title=t),placeholder:"عنوان ویدیو"},null,8,["value"])]),i("div",null,[Ae,l(f(_),{value:o.value.description,"onUpdate:value":e[2]||(e[2]=t=>o.value.description=t),placeholder:"متن توضیحات",rows:5},null,8,["value"])]),i("div",null,[Re,l(f(_),{value:o.value.aparat_embed_code,"onUpdate:value":e[3]||(e[3]=t=>o.value.aparat_embed_code=t),placeholder:"کد embed از آپارات",rows:4},null,8,["value"])]),i("div",null,[l(f(he),{checked:o.value.show_on_home,"onUpdate:checked":e[4]||(e[4]=t=>o.value.show_on_home=t)},{default:c(()=>[E("نمایش در صفحه اصلی")]),_:1},8,["checked"])]),i("div",null,[Se,l(f(fe),{"file-list":g.value,"onUpdate:fileList":e[5]||(e[5]=t=>g.value=t),"before-upload":J,"custom-request":G,headers:m,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:c(()=>[g.value.length<1?(B(),$("div",Le,[l(A,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),Pe])):L("",!0)]),_:1},8,["file-list"]),I.value>0&&I.value<100?(B(),$("div",ze,[i("div",Oe,[i("div",{class:"h-2 bg-blue-500 transition-all",style:ce({width:`${I.value}%`})},null,4)])])):L("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{Dt as default};