2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
import{_ as Z}from"./BasicMainCard-f06c4dad.js";import{_ as ee}from"./BasicModal.vue_vue_type_style_index_0_lang-7cc4ab5d.js";import{_ as te}from"./BasicInput.vue_vue_type_style_index_0_lang-ebcbbe1b.js";import{_ as ae,u as oe}from"./useBaseTable-01dc558f.js";import{_ as ie}from"./button.vue_vue_type_style_index_0_lang-86273660.js";import{I as $}from"./Icon-cc126d0d.js";import{t as ne}from"./useDataTime-5a09f654.js";import{_ as le,G as se,H as re,I as ue,d as me,g as y,o as A,c as B,b as l,w as m,a as n,e as E,J as ce,j as v,t as de,k as L,y as pe,D as _,K as _e}from"./index-d718011e.js";import{g as P}from"./convert-2ad76038.js";import{n as H}from"./textUtils-c37780ad.js";import{g as N}from"./index-18640d9e.js";import{M as he}from"./index-eb860757.js";import{S as ve}from"./index-5ade1644.js";import{C as fe}from"./index-6fc61bbd.js";import{I as ge}from"./index-ba4d9879.js";import{T as z}from"./isSymbol-e219d64b.js";import{U as be}from"./index-c895ada9.js";import"./Grid-162208a5.js";import"./index-68cba126.js";import"./_plugin-vue_export-helper-0ed48b96.js";import"./shallowequal-c9e151d3.js";import"./index-5b828516.js";import"./vnode-0b482026.js";import"./index-7eae579c.js";import"./useState-d226846a.js";import"./useRefs-373e2aeb.js";import"./_flatRest-e8ea393e.js";import"./isMobile-e2e89480.js";import"./omit-86fc1094.js";import"./index-44f8c87e.js";import"./Col-7aad654b.js";import"./styleChecker-351d08aa.js";import"./isPlainObject-63126d02.js";import"./usePrice-bc935b83.js";import"./updateLocale-dac04afb.js";import"./index-12b8b726.js";import"./useMemo-9e09b0c8.js";import"./FormItemContext-6bb05345.js";import"./lodash-02d12c59.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-e23cf95b.js";import"./index-cbb71dc1.js";import"./Badge-bf61afe1.js";import"./isNumeric-3f69e2aa.js";import"./index-9747fd4d.js";import"./index-4e5c2990.js";import"./toArray-02b8a08a.js";import"./SearchOutlined-31f9ef0b.js";import"./pickAttrs-49bc9c67.js";import"./index-7a44352f.js";import"./DialogWrap-944b6cdf.js";import"./index-59898946.js";import"./css-aae66f86.js";import"./index-7a1bd658.js";import"./index-a2e0d559.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=>ne(s.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function we(s){const h=await se("announcements",s);return Array.isArray(h)?h:[h]}async function q(s,h){const c=await re("announcements",s,{...h,updated_at:new Date().toISOString()});return Array.isArray(c)?c:[c]}async function ye(s){await ue("announcements",s)}async function xe(s){const{TableEngineRequest:h}=await le(()=>import("./buildSupabaseQuery-ad024d1e.js"),["assets/buildSupabaseQuery-ad024d1e.js","assets/index-d718011e.js","assets/index-a54d32f7.css"]),c={...s};!c.sort&&!c.order&&(c.order="-id");const g=await h(c,"announcements");try{if(Array.isArray(g==null?void 0:g.rows)){const x=c.page||1,M=c.limit||20,k=(x-1)*M,T=g.rows.map((d,b)=>({...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+b}));return{...g,rows:T}}}catch(x){console.error("[getAnnouncementsTable]",x)}return g}const ke={class:"flex justify-between items-center mb-4"},Ie=n("h2",null,"اطلاعرسانی ویدیویی",-1),Te=["src"],Ce={key:1},Ue={class:"gap-2 flex justify-center"},Ae=n("span",null,"حذف",-1),Be=n("span",null,"ویرایش",-1),Re={class:"space-y-4 relative"},De={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},$e=n("div",{class:"mb-1 text-sm text-gray-600"},"عنوان *",-1),Me=n("div",{class:"mb-1 text-sm text-gray-600"},"عنوان ویدیو",-1),Se=n("div",{class:"mb-1 text-sm text-gray-600"},"توضیحات *",-1),Le=n("div",{class:"mb-1 text-sm text-gray-600"},"کد embed آپارات *",-1),Pe=n("div",{class:"mb-1 text-sm text-gray-600"},"تامنیل",-1),ze={key:0},je=n("div",null,"آپلود تامنیل",-1),Oe={key:0,class:"mt-1"},Ee={class:"h-2 rounded bg-gray-200 overflow-hidden"},Ht=me({__name:"index",setup(s){const{TextArea:h}=ge,c={authorization:`Bearer ${N()||localStorage.getItem("tamin_token")||""}`},[g,x]=oe(),M=y({columns:[...V.slice(0,2),{title:"تامنیل",dataIndex:"thumbnail",key:"thumbnail",slot:"thumbnail",align:"center",width:100,filterable:!1},...V.slice(2)],api:xe,defaultPageLimit:20}),k=y(!1),T=y(!1),d=y(null),b=y([]),C=y(0),I=y(0),o=y({title:"",description:"",video_title:"",thumbnail:null,aparat_embed_code:"",show_on_home:!0});function F(){b.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 j(){k.value=!1}function J(i){return i.type.startsWith("image/")?i.size/1024/1024<5?!0:(_.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(_.error("فقط فایلهای تصویری مجاز است"),!1)}async function W(i){const{file:e,onSuccess:p,onError:r,onProgress:f}=i,R=new FormData;R.append("file",e);const S=`${_e}/upload/machartaa-img`;I.value=0,C.value++,await new Promise((t,U)=>{const u=new XMLHttpRequest;u.open("POST",S);const Y=N()||localStorage.getItem("tamin_token")||"";u.setRequestHeader("Authorization",`Bearer ${Y}`),u.upload.onprogress=a=>{if(a.lengthComputable){const w=Math.round(a.loaded/a.total*100);I.value=w,f==null||f({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 D=w;w!=null&&w.startsWith("http")&&(D=w.replace(/^https?:\/\/[^\/]+/,""));const O=P(D);o.value.thumbnail=D,b.value=O?[{uid:`${Date.now()}`,name:"thumbnail.jpg",status:"done",url:O,response:{path:D}}]:[],p==null||p(a,u),_.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(R)})}function G(i){T.value=!0,d.value=i.id;let e=i.thumbnail||null;e&&e.startsWith("http")&&(e=e.replace(/^https?:\/\/[^\/]+/,"")),o.value={title:i.title||"",description:i.description||"",video_title:i.video_title||"",thumbnail:e,aparat_embed_code:i.aparat_embed_code||"",show_on_home:i.show_on_home!==!1};const p=e?P(e):null;b.value=p?[{uid:"-1",name:"thumbnail.jpg",status:"done",url:p,response:{path:e}}]:[],k.value=!0}function K(i){he.confirm({title:"حذف اطلاعرسانی",content:`آیا از حذف «${i.title}» مطمئن هستید؟`,okText:"حذف",cancelText:"انصراف",onOk:async()=>{await ye(i.id),_.success("حذف شد"),x()}})}async function X(i){const e=i.show_on_home===!1;await q(i.id,{show_on_home:e}),_.success(e?"در صفحه اصلی نمایش داده میشود":"از صفحه اصلی حذف شد"),x()}async function Q(){var e,p,r,f;if(!((e=o.value.title)!=null&&e.trim())){_.warning("عنوان الزامی است");return}if(!H(o.value.description)){_.warning("توضیحات الزامی است");return}if(!((p=o.value.aparat_embed_code)!=null&&p.trim())){_.warning("کد embed آپارات الزامی است");return}if(C.value>0){_.warning("لطفاً تا پایان آپلود صبر کنید");return}const i={title:o.value.title.trim(),description:H(o.value.description),video_title:((r=o.value.video_title)==null?void 0:r.trim())||"",thumbnail:((f=o.value.thumbnail)==null?void 0:f.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 q(d.value,i),_.success("ویرایش شد")):(await we(i),_.success("افزوده شد")),j(),x()}return(i,e)=>{const p=ie,r=ae,f=te,R=ee,S=Z;return A(),B("div",null,[l(S,null,{default:m(()=>[n("div",ke,[Ie,l(p,{type:"primary",onClick:F},{default:m(()=>[E("افزودن اطلاعرسانی")]),_:1})]),l(r,ce(M.value,{ref:"table",onRegister:v(g)}),{thumbnail:m(({record:t})=>[t.thumbnail?(A(),B("img",{key:0,src:v(P)(t.thumbnail),alt:"",class:"w-16 h-10 object-cover rounded"},null,8,Te)):(A(),B("span",Ce,"-"))]),action:m(({record:t})=>[n("div",Ue,[l(v(z),{class:"cursor-pointer"},{title:m(()=>[n("span",null,de((t==null?void 0:t.show_on_home)===!1?"نمایش در صفحه اصلی":"حذف از صفحه اصلی"),1)]),default:m(()=>[l($,{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=>X(t)},null,8,["icon","color","onClick"])]),_:2},1024),l(v(z),{class:"cursor-pointer"},{title:m(()=>[Ae]),default:m(()=>[l($,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:U=>K(t)},null,8,["onClick"])]),_:2},1024),l(v(z),{class:"cursor-pointer"},{title:m(()=>[Be]),default:m(()=>[l($,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:U=>G(t)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),l(R,{visible:k.value,"onUpdate:visible":e[6]||(e[6]=t=>k.value=t),title:T.value?"ویرایش اطلاعرسانی":"افزودن اطلاعرسانی",onOk:Q,onCancel:j,width:"80%",confirmLoading:C.value>0},{default:m(()=>[n("div",Re,[C.value>0?(A(),B("div",De,[l(v(ve),{size:"large"})])):L("",!0),n("div",null,[$e,l(f,{value:o.value.title,"onUpdate:value":e[0]||(e[0]=t=>o.value.title=t),placeholder:"عنوان اطلاعرسانی"},null,8,["value"])]),n("div",null,[Me,l(f,{value:o.value.video_title,"onUpdate:value":e[1]||(e[1]=t=>o.value.video_title=t),placeholder:"عنوان ویدیو"},null,8,["value"])]),n("div",null,[Se,l(v(h),{value:o.value.description,"onUpdate:value":e[2]||(e[2]=t=>o.value.description=t),placeholder:"متن توضیحات",rows:5},null,8,["value"])]),n("div",null,[Le,l(v(h),{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"])]),n("div",null,[l(v(fe),{checked:o.value.show_on_home,"onUpdate:checked":e[4]||(e[4]=t=>o.value.show_on_home=t)},{default:m(()=>[E("نمایش در صفحه اصلی")]),_:1},8,["checked"])]),n("div",null,[Pe,l(v(be),{"file-list":b.value,"onUpdate:fileList":e[5]||(e[5]=t=>b.value=t),"before-upload":J,"custom-request":W,headers:c,accept:"image/jpeg,image/png,image/webp,image/gif,image/heic,image/heif,.jpg,.jpeg,.png,.webp,.gif,.heic,.heif","max-count":1,"list-type":"picture-card"},{default:m(()=>[b.value.length<1?(A(),B("div",ze,[l($,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),je])):L("",!0)]),_:1},8,["file-list"]),I.value>0&&I.value<100?(A(),B("div",Oe,[n("div",Ee,[n("div",{class:"h-2 bg-blue-500 transition-all",style:pe({width:`${I.value}%`})},null,4)])])):L("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{Ht as default};
|