Files
machartaa_admin_dist/dist/assets/index-c3053de7.js
T

2 lines
8.3 KiB
JavaScript

import{_ as J}from"./BasicMainCard-ddae39ab.js";import{M as X,_ as G}from"./BasicModal.vue_vue_type_style_index_0_lang-5afc1014.js";import{_ as K}from"./BasicInput.vue_vue_type_style_index_0_lang-86bcfe9c.js";import{_ as Q}from"./index-9454089e.js";import{_ as Y}from"./button.vue_vue_type_style_index_0_lang-241a9705.js";import{I as P}from"./Icon-967ca316.js";import{u as Z}from"./useBaseTable-3aeb2499.js";import{t as ee}from"./useDataTime-56db82be.js";import{a3 as te,a5 as z,d as ae,r as b,o as U,c as L,b as r,w as f,a as s,e as se,a2 as oe,L as T,N as R,X as ie,O as le,a0 as g,a4 as S}from"./index-a9671513.js";import{_ as ne}from"./TextPreview.vue_vue_type_script_setup_true_lang-21db7f3a.js";import{S as re}from"./index-d4552ccf.js";import{I as ce}from"./index-837b6155.js";import{T as E}from"./styleChecker-8312d0ee.js";import{U as ue}from"./index-0d82943c.js";import"./_plugin-vue_export-helper-d21b9c52.js";import"./index-470b960b.js";import"./useState-4aa9b7fe.js";import"./vnode-e4b7f976.js";import"./Col-ca1a058e.js";import"./usePrice-7afab779.js";import"./index-b5eb525c.js";const de=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:o=>o.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"توضیحات",dataIndex:"description",key:"description",slot:"description"},{title:"تصویر",dataIndex:"src_img",key:"src_img",customRender:o=>o.record.src_img||"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:o=>ee(o.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function me(o){const{data:p,error:c}=await z.from("images_book").insert([o]).select();if(c)throw c;return p}async function pe(o,p){const{data:c,error:d}=await z.from("images_book").update(p).eq("id",o).select();if(d)throw d;return c}async function _e(o){const{error:p}=await z.from("images_book").delete().eq("id",o);if(p)throw p}async function fe(o){const{TableEngineRequest:p}=await te(()=>import("./buildSupabaseQuery-895aec07.js"),["assets/buildSupabaseQuery-895aec07.js","assets/index-a9671513.js","assets/index-6c22dd25.css"]),c={...o};!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 $=c.page||1,k=c.limit||200,w=($-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($){console.log("[getImagesBookTable] normalize error:",$)}return d}const ge={class:"flex justify-between items-center mb-4"},ve=s("h2",null,"تصاویر کتاب",-1),he={class:"gap-2 flex justify-center"},xe=s("span",null,"حذف",-1),ye=s("span",null,"ویرایش",-1),be={class:"space-y-4 relative"},ke={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},we=s("div",{class:"mb-1 text-sm text-gray-600"},"عنوان",-1),Ie=s("div",{class:"mb-1 text-sm text-gray-600"},"توضیحات",-1),Be=s("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر",-1),Te={key:0},$e=s("div",null,"آپلود تصویر",-1),Ce={key:0,class:"mt-1"},Me={class:"h-2 rounded bg-gray-200 overflow-hidden"},Ue={class:"text-xs text-gray-700 font-semibold text-center mt-1"},Ye=ae({__name:"index",setup(o){const{TextArea:p}=ce,[c,d]=Z(),$=b({columns:de,api:fe,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 q(){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 D=`${S}/upload/machartaa-img`;h.value=0,v.value++,await new Promise((l,C)=>{const n=new XMLHttpRequest;n.open("POST",D),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 B=y;y!=null&&y.startsWith("http")&&(B=y.replace(/^https?:\/\/[^\/]+/,""));const A=B.startsWith("http")?B:`${S}${B}`;_.value.src_img=B,u.value=A?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:A,response:{path:B}}]:[],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 W(a){return{width:`${Math.max(0,Math.min(100,a))}%`}}async function j(){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 pe(I.value,a),g.success("تصویر با موفقیت ویرایش شد")):(await me(a),g.success("تصویر با موفقیت افزوده شد")),q(),await d()}catch(x){console.error("Error saving image:",x),g.error("خطا در ذخیره تصویر: "+(x.message||"خطای ناشناخته"))}}function F(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?e.startsWith("http")?e:`${S}${e}`:null;u.value=m?[{uid:"-1",name:"image.jpg",status:"done",url:m,response:{path:e}}]:[],k.value=!0}function H(a){X.confirm({title:"حذف تصویر",content:"آیا مطمئن هستید که می‌خواهید این تصویر را حذف کنید؟",okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await _e(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=Q,x=K,M=G,D=J;return U(),L("div",null,[r(D,null,{default:f(()=>[s("div",ge,[ve,r(m,{type:"primary",onClick:N},{default:f(()=>[se("افزودن تصویر")]),_:1})]),r(i,oe($.value,{ref:"table",onRegister:T(c)}),{description:f(({record:l})=>[r(ne,{text:l.description},null,8,["text"])]),action:f(({record:l})=>[s("div",he,[r(T(E),{class:"cursor-pointer"},{title:f(()=>[xe]),default:f(()=>[r(P,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:C=>H(l)},null,8,["onClick"])]),_:2},1024),r(T(E),{class:"cursor-pointer"},{title:f(()=>[ye]),default:f(()=>[r(P,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:C=>F(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:j,onCancel:q,width:"80%",confirmLoading:v.value>0},{default:f(()=>[s("div",be,[v.value>0?(U(),L("div",ke,[r(T(re),{size:"large"})])):R("",!0),s("div",null,[we,r(x,{value:_.value.title,"onUpdate:value":e[0]||(e[0]=l=>_.value.title=l),placeholder:"عنوان"},null,8,["value"])]),s("div",null,[Ie,r(T(p),{value:_.value.description??void 0,"onUpdate:value":e[1]||(e[1]=l=>_.value.description=l??null),placeholder:"توضیحات",rows:4},null,8,["value"])]),s("div",null,[Be,r(T(ue),{"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?(U(),L("div",Te,[r(P,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),$e])):R("",!0)]),_:1},8,["file-list"]),h.value>0&&h.value<100?(U(),L("div",Ce,[s("div",Me,[s("div",{class:"h-2 bg-blue-500 transition-all",style:ie(W(h.value))},null,4)]),s("div",Ue,le(h.value)+"%",1)])):R("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{Ye as default};