2 lines
8.8 KiB
JavaScript
2 lines
8.8 KiB
JavaScript
import{_ as J}from"./BasicMainCard-9c458ce7.js";import{_ as G}from"./BasicModal.vue_vue_type_style_index_0_lang-5bce5515.js";import{_ as X}from"./BasicInput.vue_vue_type_style_index_0_lang-cee0843c.js";import{_ as K,u as Q}from"./useBaseTable-3b2d0853.js";import{_ as Y}from"./button.vue_vue_type_style_index_0_lang-95946c23.js";import{I as P}from"./Icon-06d3f751.js";import{t as Z}from"./useDataTime-c147e135.js";import{_ as ee,G as S,d as te,g as b,o as D,c as $,b as n,w as f,a as o,e as ae,H as oe,j as B,k as R,y as se,t as ie,D as g,I as le}from"./index-20d5dab1.js";import{g as A}from"./convert-2ad76038.js";import{_ as re}from"./TextPreview.vue_vue_type_script_setup_true_lang-bacd5482.js";import{M as ne}from"./index-4f6342fa.js";import{S as ce}from"./index-38a2f111.js";import{I as ue}from"./index-f6eb678e.js";import{T as E}from"./isSymbol-f04930e1.js";import{U as de}from"./index-44ec8c49.js";import"./index-857151a7.js";import"./index-4284a867.js";import"./_plugin-vue_export-helper-26f60d29.js";import"./useState-3cc4a0be.js";import"./vnode-18b1f518.js";import"./useRefs-03151dab.js";import"./_flatRest-12208321.js";import"./index-0d016563.js";import"./Col-6ec89065.js";import"./styleChecker-6ae1ce26.js";import"./isPlainObject-769b8c03.js";import"./usePrice-bc935b83.js";import"./updateLocale-6ea9ed84.js";import"./toArray-fb96c8b9.js";import"./FormItemContext-28b30746.js";import"./pickAttrs-93039156.js";import"./lodash-28ee46da.js";import"./css-0bca533a.js";import"./DialogWrap-a4cda90f.js";import"./index-f75dc027.js";import"./textUtils-c37780ad.js";import"./index-84af5005.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-4c9afa46.js"),["assets/buildSupabaseQuery-4c9afa46.js","assets/index-20d5dab1.js","assets/index-2b0c085a.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"},ft=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 r=new XMLHttpRequest;r.open("POST",L),r.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("token")||""}`),r.upload.onprogress=t=>{if(t.lengthComputable){const y=Math.round(t.loaded/t.total*100);h.value=y,x==null||x({percent:y})}},r.onload=()=>{if(h.value=100,r.status>=200&&r.status<300)try{const t=JSON.parse(r.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,r),g.success("تصویر با موفقیت آپلود شد!"),l()}catch(t){i==null||i(t,r),C(t)}else{const t=new Error("خطا در آپلود تصویر");i==null||i(t,r),C(t)}},r.onerror=()=>{const t=new Error("خطا در آپلود تصویر");i==null||i(t,r),C(t)},r.onloadend=()=>{v.value=Math.max(0,v.value-1),h.value=0},r.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){ne.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,[n(L,null,{default:f(()=>[o("div",ve,[he,n(m,{type:"primary",onClick:N},{default:f(()=>[ae("افزودن تصویر")]),_:1})]),n(i,oe(T.value,{ref:"table",onRegister:B(c)}),{description:f(({record:l})=>[n(re,{text:l.description},null,8,["text"])]),action:f(({record:l})=>[o("div",xe,[n(B(E),{class:"cursor-pointer"},{title:f(()=>[ye]),default:f(()=>[n(P,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:C=>F(l)},null,8,["onClick"])]),_:2},1024),n(B(E),{class:"cursor-pointer"},{title:f(()=>[be]),default:f(()=>[n(P,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:C=>W(l)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),n(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,[n(B(ce),{size:"large"})])):R("",!0),o("div",null,[Ie,n(x,{value:_.value.title,"onUpdate:value":e[0]||(e[0]=l=>_.value.title=l),placeholder:"عنوان"},null,8,["value"])]),o("div",null,[Be,n(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,n(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,[n(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{ft as default};
|