2 lines
8.6 KiB
JavaScript
2 lines
8.6 KiB
JavaScript
import{_ as J}from"./BasicMainCard-bf671953.js";import{_ as G}from"./BasicModal.vue_vue_type_style_index_0_lang-407efba3.js";import{_ as X}from"./BasicInput.vue_vue_type_style_index_0_lang-1d385434.js";import{_ as K,u as Q}from"./useBaseTable-24f4f2e2.js";import{_ as Y}from"./button.vue_vue_type_style_index_0_lang-27efd666.js";import{I as P}from"./Icon-6341c6d7.js";import{t as Z}from"./useDataTime-7ae4955d.js";import{_ as ee,I as S,d as te,g as b,o as D,c as $,b as r,w as f,a as o,e as ae,G as oe,j as B,k as R,y as se,t as ie,D as g,H as le}from"./index-1bce333c.js";import{g as A}from"./convert-67c23be8.js";import{_ as ne}from"./TextPreview.vue_vue_type_script_setup_true_lang-2f7c25ba.js";import{M as re}from"./index-5c225384.js";import{S as ce}from"./index-7d6b4818.js";import{I as ue}from"./index-88c28232.js";import{T as E}from"./shallowequal-1541c82f.js";import{U as de}from"./index-5086b76f.js";import"./index-f9207910.js";import"./index-b0d31435.js";import"./_plugin-vue_export-helper-3f2269c4.js";import"./Col-9a22bf06.js";import"./vnode-aeac980e.js";import"./useState-3936625c.js";import"./useRefs-1a04203f.js";import"./index-cb94b65a.js";import"./isPlainObject-cf478c35.js";import"./usePrice-bc935b83.js";import"./fa_IR-7585613a.js";import"./toArray-4db0bbfe.js";import"./FormItemContext-3ee2389e.js";import"./pickAttrs-fbeac5f6.js";import"./lodash-7eda9a39.js";import"./index-a87160dc.js";import"./index-341f08f3.js";const me=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:s=>s.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"توضیحات",dataIndex:"description",key:"description",slot:"description"},{title:"تصویر",dataIndex:"src_img",key:"src_img",customRender:s=>s.record.src_img||"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:s=>Z(s.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function pe(s){const{data:p,error:c}=await S.from("images_book").insert([s]).select();if(c)throw c;return p}async function _e(s,p){const{data:c,error:d}=await S.from("images_book").update(p).eq("id",s).select();if(d)throw d;return c}async function fe(s){const{error:p}=await S.from("images_book").delete().eq("id",s);if(p)throw p}async function ge(s){const{TableEngineRequest:p}=await ee(()=>import("./buildSupabaseQuery-a116e543.js"),["assets/buildSupabaseQuery-a116e543.js","assets/index-1bce333c.js","assets/index-f59f1398.css","assets/supabaseTableQuery-95762ff3.js"]),c={...s};!c.sort&&!c.order&&(c.order="-id");const d=await p(c,"images_book");try{if(Array.isArray(d==null?void 0:d.rows)){const T=c.page||1,k=c.limit||200,w=(T-1)*k,I=d.rows.map((u,v)=>({id:u.id,title:u.title??null,description:u.description??null,src_img:u.src_img??null,created_at:u.created_at??"",index:w+v,...u}));return{...d,rows:I}}}catch(T){console.log("[getImagesBookTable] normalize error:",T)}return d}const ve={class:"flex justify-between items-center mb-4"},he=o("h2",null,"تصاویر کتاب",-1),xe={class:"gap-2 flex justify-center"},ye=o("span",null,"حذف",-1),be=o("span",null,"ویرایش",-1),ke={class:"space-y-4 relative"},we={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},Ie=o("div",{class:"mb-1 text-sm text-gray-600"},"عنوان",-1),Be=o("div",{class:"mb-1 text-sm text-gray-600"},"توضیحات",-1),Te=o("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر",-1),Ce={key:0},Me=o("div",null,"آپلود تصویر",-1),Ue={key:0,class:"mt-1"},De={class:"h-2 rounded bg-gray-200 overflow-hidden"},$e={class:"text-xs text-gray-700 font-semibold text-center mt-1"},ut=te({__name:"index",setup(s){const{TextArea:p}=ue,[c,d]=Q(),T=b({columns:me,api:ge,defaultPageLimit:20}),k=b(!1),w=b(!1),I=b(null),u=b([]),v=b(0),h=b(0),_=b({title:null,description:null,src_img:null});function N(){u.value=[],w.value=!1,I.value=null,_.value={title:null,description:null,src_img:null},k.value=!0}function z(){k.value=!1}function O(a){return a.type.startsWith("image/")?a.size/1024/1024<5?!0:(g.error("حجم تصویر باید کمتر از 5MB باشد!"),!1):(g.error("فقط فایلهای تصویری مجاز است"),!1)}async function V(a){const{file:e,onSuccess:m,onError:i,onProgress:x}=a,M=new FormData;M.append("file",e);const L=`${le}/upload/machartaa-img`;h.value=0,v.value++,await new Promise((l,C)=>{const n=new XMLHttpRequest;n.open("POST",L),n.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("token")||""}`),n.upload.onprogress=t=>{if(t.lengthComputable){const y=Math.round(t.loaded/t.total*100);h.value=y,x==null||x({percent:y})}},n.onload=()=>{if(h.value=100,n.status>=200&&n.status<300)try{const t=JSON.parse(n.responseText||"{}"),y=t.full_src||t.url||t.src||t.path||t.data&&(t.data.full_src||t.data.url||t.data.src||t.data.path)||"";let U=y;y!=null&&y.startsWith("http")&&(U=y.replace(/^https?:\/\/[^\/]+/,""));const q=A(U);_.value.src_img=U,u.value=q?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:q,response:{path:U}}]:[],m==null||m(t,n),g.success("تصویر با موفقیت آپلود شد!"),l()}catch(t){i==null||i(t,n),C(t)}else{const t=new Error("خطا در آپلود تصویر");i==null||i(t,n),C(t)}},n.onerror=()=>{const t=new Error("خطا در آپلود تصویر");i==null||i(t,n),C(t)},n.onloadend=()=>{v.value=Math.max(0,v.value-1),h.value=0},n.send(M)})}function j(a){return{width:`${Math.max(0,Math.min(100,a))}%`}}async function H(){var e,m,i;if(v.value>0){g.warning("لطفاً تا پایان آپلود صبر کنید");return}const a={title:((e=_.value.title)==null?void 0:e.trim())||null,description:((m=_.value.description)==null?void 0:m.trim())||null,src_img:((i=_.value.src_img)==null?void 0:i.trim())||null};try{w.value&&I.value?(await _e(I.value,a),g.success("تصویر با موفقیت ویرایش شد")):(await pe(a),g.success("تصویر با موفقیت افزوده شد")),z(),await d()}catch(x){console.error("Error saving image:",x),g.error("خطا در ذخیره تصویر: "+(x.message||"خطای ناشناخته"))}}function W(a){w.value=!0,I.value=a.id;let e=a.src_img||null;e&&e.startsWith("http")&&(e=e.replace(/^https?:\/\/[^\/]+/,"")),_.value={title:a.title||null,description:a.description||null,src_img:e};const m=e?A(e):null;u.value=m?[{uid:"-1",name:"image.jpg",status:"done",url:m,response:{path:e}}]:[],k.value=!0}function F(a){re.confirm({title:"حذف تصویر",content:"آیا مطمئن هستید که میخواهید این تصویر را حذف کنید؟",okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await fe(a.id),g.success("تصویر با موفقیت حذف شد"),await d()}catch(e){console.error("Error deleting image:",e),g.error("خطا در حذف تصویر: "+(e.message||"خطای ناشناخته"))}}})}return(a,e)=>{const m=Y,i=K,x=X,M=G,L=J;return D(),$("div",null,[r(L,null,{default:f(()=>[o("div",ve,[he,r(m,{type:"primary",onClick:N},{default:f(()=>[ae("افزودن تصویر")]),_:1})]),r(i,oe(T.value,{ref:"table",onRegister:B(c)}),{description:f(({record:l})=>[r(ne,{text:l.description},null,8,["text"])]),action:f(({record:l})=>[o("div",xe,[r(B(E),{class:"cursor-pointer"},{title:f(()=>[ye]),default:f(()=>[r(P,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:C=>F(l)},null,8,["onClick"])]),_:2},1024),r(B(E),{class:"cursor-pointer"},{title:f(()=>[be]),default:f(()=>[r(P,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:C=>W(l)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),r(M,{visible:k.value,"onUpdate:visible":e[3]||(e[3]=l=>k.value=l),title:w.value?"ویرایش تصویر":"افزودن تصویر",onOk:H,onCancel:z,width:"80%",confirmLoading:v.value>0},{default:f(()=>[o("div",ke,[v.value>0?(D(),$("div",we,[r(B(ce),{size:"large"})])):R("",!0),o("div",null,[Ie,r(x,{value:_.value.title,"onUpdate:value":e[0]||(e[0]=l=>_.value.title=l),placeholder:"عنوان"},null,8,["value"])]),o("div",null,[Be,r(B(p),{value:_.value.description??void 0,"onUpdate:value":e[1]||(e[1]=l=>_.value.description=l??null),placeholder:"توضیحات",rows:4},null,8,["value"])]),o("div",null,[Te,r(B(de),{"file-list":u.value,"onUpdate:fileList":e[2]||(e[2]=l=>u.value=l),"before-upload":O,"custom-request":V,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:f(()=>[u.value.length<1?(D(),$("div",Ce,[r(P,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),Me])):R("",!0)]),_:1},8,["file-list"]),h.value>0&&h.value<100?(D(),$("div",Ue,[o("div",De,[o("div",{class:"h-2 bg-blue-500 transition-all",style:se(j(h.value))},null,4)]),o("div",$e,ie(h.value)+"%",1)])):R("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{ut as default};
|