2 lines
9.1 KiB
JavaScript
2 lines
9.1 KiB
JavaScript
import{_ as J}from"./BasicMainCard-4b9ba85b.js";import{_ as G}from"./BasicModal.vue_vue_type_style_index_0_lang-661b0a06.js";import{_ as X}from"./BasicInput.vue_vue_type_style_index_0_lang-17ae6919.js";import{_ as K,u as Q}from"./useBaseTable-3c30fe12.js";import{_ as Y}from"./button.vue_vue_type_style_index_0_lang-f6f5b6a0.js";import{I as P}from"./Icon-889d6eab.js";import{t as Z}from"./useDataTime-5a269444.js";import{_ as tt,G as S,d as et,g as b,o as D,c as $,b as n,w as f,a as o,e as at,H as ot,j as B,k as R,y as it,t as st,D as g,I as rt}from"./index-f8ee37b9.js";import{g as A}from"./convert-2ad76038.js";import{_ as lt}from"./TextPreview.vue_vue_type_script_setup_true_lang-53f928ef.js";import{M as nt}from"./index-ef1f8a61.js";import{S as ct}from"./index-0e72b27c.js";import{I as ut}from"./index-1ab617ae.js";import{T as E}from"./isSymbol-cdcd460d.js";import{U as mt}from"./index-c0e94d73.js";import"./Grid-30a17a21.js";import"./index-6e8a4b4f.js";import"./_plugin-vue_export-helper-775bc553.js";import"./index-b8cc71e2.js";import"./vnode-b0e810ae.js";import"./omit-bdd3cea5.js";import"./useState-f5985d90.js";import"./useRefs-bff35432.js";import"./_flatRest-6305d35d.js";import"./index-ee1b3469.js";import"./Col-97627e24.js";import"./styleChecker-c1fc9f39.js";import"./isPlainObject-6382de01.js";import"./usePrice-bc935b83.js";import"./updateLocale-d5a764a4.js";import"./index-bc659f42.js";import"./index-f923b666.js";import"./toArray-53a55fc4.js";import"./FormItemContext-5821e8c8.js";import"./pickAttrs-69f29e9c.js";import"./lodash-7c51d08d.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-2e892f80.js";import"./index-78e4e5e0.js";import"./Badge-47d7b0bb.js";import"./isNumeric-3f69e2aa.js";import"./index-89210322.js";import"./index-8bcedf66.js";import"./index-0441c4fc.js";import"./DialogWrap-192ddaf7.js";import"./css-aae66f86.js";import"./index-bf59f845.js";import"./textUtils-c37780ad.js";import"./index-9594c53b.js";const dt=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:i=>i.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"توضیحات",dataIndex:"description",key:"description",slot:"description"},{title:"تصویر",dataIndex:"src_img",key:"src_img",customRender:i=>i.record.src_img||"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:i=>Z(i.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function pt(i){const{data:p,error:c}=await S.from("images_book").insert([i]).select();if(c)throw c;return p}async function _t(i,p){const{data:c,error:m}=await S.from("images_book").update(p).eq("id",i).select();if(m)throw m;return c}async function ft(i){const{error:p}=await S.from("images_book").delete().eq("id",i);if(p)throw p}async function gt(i){const{TableEngineRequest:p}=await tt(()=>import("./buildSupabaseQuery-6dd7a8c2.js"),["assets/buildSupabaseQuery-6dd7a8c2.js","assets/index-f8ee37b9.js","assets/index-8e1e8848.css","assets/supabaseTableQuery-95762ff3.js"]),c={...i};!c.sort&&!c.order&&(c.order="-id");const m=await p(c,"images_book");try{if(Array.isArray(m==null?void 0:m.rows)){const T=c.page||1,k=c.limit||200,w=(T-1)*k,I=m.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{...m,rows:I}}}catch(T){console.log("[getImagesBookTable] normalize error:",T)}return m}const vt={class:"flex justify-between items-center mb-4"},ht=o("h2",null,"تصاویر کتاب",-1),xt={class:"gap-2 flex justify-center"},yt=o("span",null,"حذف",-1),bt=o("span",null,"ویرایش",-1),kt={class:"space-y-4 relative"},wt={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},It=o("div",{class:"mb-1 text-sm text-gray-600"},"عنوان",-1),Bt=o("div",{class:"mb-1 text-sm text-gray-600"},"توضیحات",-1),Tt=o("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر",-1),Ct={key:0},Mt=o("div",null,"آپلود تصویر",-1),Ut={key:0,class:"mt-1"},Dt={class:"h-2 rounded bg-gray-200 overflow-hidden"},$t={class:"text-xs text-gray-700 font-semibold text-center mt-1"},Te=et({__name:"index",setup(i){const{TextArea:p}=ut,[c,m]=Q(),T=b({columns:dt,api:gt,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:t,onSuccess:d,onError:s,onProgress:x}=a,M=new FormData;M.append("file",t);const L=`${rt}/upload/machartaa-img`;h.value=0,v.value++,await new Promise((r,C)=>{const l=new XMLHttpRequest;l.open("POST",L),l.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("token")||""}`),l.upload.onprogress=e=>{if(e.lengthComputable){const y=Math.round(e.loaded/e.total*100);h.value=y,x==null||x({percent:y})}},l.onload=()=>{if(h.value=100,l.status>=200&&l.status<300)try{const e=JSON.parse(l.responseText||"{}"),y=e.full_src||e.url||e.src||e.path||e.data&&(e.data.full_src||e.data.url||e.data.src||e.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}}]:[],d==null||d(e,l),g.success("تصویر با موفقیت آپلود شد!"),r()}catch(e){s==null||s(e,l),C(e)}else{const e=new Error("خطا در آپلود تصویر");s==null||s(e,l),C(e)}},l.onerror=()=>{const e=new Error("خطا در آپلود تصویر");s==null||s(e,l),C(e)},l.onloadend=()=>{v.value=Math.max(0,v.value-1),h.value=0},l.send(M)})}function j(a){return{width:`${Math.max(0,Math.min(100,a))}%`}}async function H(){var t,d,s;if(v.value>0){g.warning("لطفاً تا پایان آپلود صبر کنید");return}const a={title:((t=_.value.title)==null?void 0:t.trim())||null,description:((d=_.value.description)==null?void 0:d.trim())||null,src_img:((s=_.value.src_img)==null?void 0:s.trim())||null};try{w.value&&I.value?(await _t(I.value,a),g.success("تصویر با موفقیت ویرایش شد")):(await pt(a),g.success("تصویر با موفقیت افزوده شد")),z(),await m()}catch(x){console.error("Error saving image:",x),g.error("خطا در ذخیره تصویر: "+(x.message||"خطای ناشناخته"))}}function W(a){w.value=!0,I.value=a.id;let t=a.src_img||null;t&&t.startsWith("http")&&(t=t.replace(/^https?:\/\/[^\/]+/,"")),_.value={title:a.title||null,description:a.description||null,src_img:t};const d=t?A(t):null;u.value=d?[{uid:"-1",name:"image.jpg",status:"done",url:d,response:{path:t}}]:[],k.value=!0}function F(a){nt.confirm({title:"حذف تصویر",content:"آیا مطمئن هستید که میخواهید این تصویر را حذف کنید؟",okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await ft(a.id),g.success("تصویر با موفقیت حذف شد"),await m()}catch(t){console.error("Error deleting image:",t),g.error("خطا در حذف تصویر: "+(t.message||"خطای ناشناخته"))}}})}return(a,t)=>{const d=Y,s=K,x=X,M=G,L=J;return D(),$("div",null,[n(L,null,{default:f(()=>[o("div",vt,[ht,n(d,{type:"primary",onClick:N},{default:f(()=>[at("افزودن تصویر")]),_:1})]),n(s,ot(T.value,{ref:"table",onRegister:B(c)}),{description:f(({record:r})=>[n(lt,{text:r.description},null,8,["text"])]),action:f(({record:r})=>[o("div",xt,[n(B(E),{class:"cursor-pointer"},{title:f(()=>[yt]),default:f(()=>[n(P,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:C=>F(r)},null,8,["onClick"])]),_:2},1024),n(B(E),{class:"cursor-pointer"},{title:f(()=>[bt]),default:f(()=>[n(P,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:C=>W(r)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),n(M,{visible:k.value,"onUpdate:visible":t[3]||(t[3]=r=>k.value=r),title:w.value?"ویرایش تصویر":"افزودن تصویر",onOk:H,onCancel:z,width:"80%",confirmLoading:v.value>0},{default:f(()=>[o("div",kt,[v.value>0?(D(),$("div",wt,[n(B(ct),{size:"large"})])):R("",!0),o("div",null,[It,n(x,{value:_.value.title,"onUpdate:value":t[0]||(t[0]=r=>_.value.title=r),placeholder:"عنوان"},null,8,["value"])]),o("div",null,[Bt,n(B(p),{value:_.value.description??void 0,"onUpdate:value":t[1]||(t[1]=r=>_.value.description=r??null),placeholder:"توضیحات",rows:4},null,8,["value"])]),o("div",null,[Tt,n(B(mt),{"file-list":u.value,"onUpdate:fileList":t[2]||(t[2]=r=>u.value=r),"before-upload":O,"custom-request":V,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:f(()=>[u.value.length<1?(D(),$("div",Ct,[n(P,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),Mt])):R("",!0)]),_:1},8,["file-list"]),h.value>0&&h.value<100?(D(),$("div",Ut,[o("div",Dt,[o("div",{class:"h-2 bg-blue-500 transition-all",style:it(j(h.value))},null,4)]),o("div",$t,st(h.value)+"%",1)])):R("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{Te as default};
|