Files
machartaa_admin_dist/dist/assets/index-2d23e660.js
T

2 lines
7.4 KiB
JavaScript

import{_ as F}from"./BasicMainCard-ddae39ab.js";import{M as H,_ as J}from"./BasicModal.vue_vue_type_style_index_0_lang-5afc1014.js";import{_ as X}from"./BasicInput.vue_vue_type_style_index_0_lang-86bcfe9c.js";import{_ as G}from"./index-9454089e.js";import{_ as K}from"./button.vue_vue_type_style_index_0_lang-241a9705.js";import{I as U}from"./Icon-967ca316.js";import{u as Q}from"./useBaseTable-3aeb2499.js";import{t as Y}from"./useDataTime-56db82be.js";import{getBooksTable as Z,updateBook as ee,addBook as te,deleteBook as ae}from"./books-68b5883a.js";import{d as le,r as f,o as $,c as I,b as r,w as m,a as l,e as oe,a2 as se,L as k,N as T,X as re,O as ne,a0 as c,a4 as L}from"./index-a9671513.js";import{T as N}from"./styleChecker-8312d0ee.js";import{S as ie}from"./index-d4552ccf.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"./index-837b6155.js";import"./usePrice-7afab779.js";import"./index-b5eb525c.js";const ce=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:v=>v.record.index+1},{title:"عنوان",dataIndex:"title",key:"title"},{title:"زیرعنوان",dataIndex:"sub_title",key:"sub_title"},{title:"تعداد قصه ها",dataIndex:"total_storys",key:"total_storys",align:"center",width:120,customRender:v=>v.record.total_storys??0},{title:"تصویر کاور",dataIndex:"cover",key:"cover",customRender:v=>v.record.cover||"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:v=>Y(v.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],de={class:"flex justify-between items-center mb-4"},me=l("h2",null,"کتاب ها",-1),ve={class:"gap-2 flex justify-center"},pe=l("span",null,"حذف",-1),_e=l("span",null,"ویرایش",-1),fe={class:"space-y-4 relative"},he={key:0,class:"absolute inset-0 bg-white/60 z-10 flex items-center justify-center"},ge=l("div",{class:"mb-1 text-sm text-gray-600"},"عنوان *",-1),be=l("div",{class:"mb-1 text-sm text-gray-600"},"زیرعنوان",-1),xe=l("div",{class:"mb-1 text-sm text-gray-600"},"آپلود تصویر کاور",-1),ye={key:0},ke=l("div",null,"آپلود کاور",-1),we={key:0,class:"mt-1"},Be={class:"h-2 rounded bg-gray-200 overflow-hidden"},Ce={class:"text-xs text-gray-700 font-semibold text-center mt-1"},Je=le({__name:"index",setup(v){const[R,D]=Q(),z=f({columns:ce,api:Z,defaultPageLimit:20}),x=f(!1),w=f(!1),B=f(null),h=f([]),g=f(0),p=f(0),u=f({title:"",sub_title:null,cover:null});function O(){h.value=[],w.value=!1,B.value=null,u.value={title:"",sub_title:null,cover:null},x.value=!0}function P(){x.value=!1}function W(a){return a.type.startsWith("image/")?a.size/1024/1024<5?!0:(c.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(c.error("فقط فایل‌های تصویری مجاز است"),!1)}async function V(a){const{file:e,onSuccess:n,onError:o,onProgress:d}=a,C=new FormData;C.append("file",e);const M=`${L}/upload/machartaa-img`;p.value=0,g.value++,await new Promise((i,y)=>{const s=new XMLHttpRequest;s.open("POST",M),s.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("token")||""}`),s.upload.onprogress=t=>{if(t.lengthComputable){const _=Math.round(t.loaded/t.total*100);p.value=_,d==null||d({percent:_})}},s.onload=()=>{if(p.value=100,s.status>=200&&s.status<300)try{const t=JSON.parse(s.responseText||"{}"),_=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=_;_!=null&&_.startsWith("http")&&(b=_.replace(/^https?:\/\/[^\/]+/,""));const S=b.startsWith("http")?b:`${L}${b}`;u.value.cover=b,h.value=S?[{uid:`${Date.now()}`,name:"cover.jpg",status:"done",url:S,response:{path:b}}]:[],n==null||n(t,s),c.success("کاور با موفقیت آپلود شد!"),i()}catch(t){o==null||o(t,s),y(t)}else{const t=new Error("خطا در آپلود تصویر");o==null||o(t,s),y(t)}},s.onerror=()=>{const t=new Error("خطا در آپلود کاور");o==null||o(t,s),y(t)},s.onloadend=()=>{g.value=Math.max(0,g.value-1),p.value=0},s.send(C)})}function j(a){return{width:`${Math.max(0,Math.min(100,a))}%`}}async function q(){var e,n,o;if(!((e=u.value.title)!=null&&e.trim())){c.error("لطفاً عنوان کتاب را وارد کنید");return}if(g.value>0){c.warning("لطفاً تا پایان آپلود صبر کنید");return}const a={title:u.value.title.trim(),sub_title:((n=u.value.sub_title)==null?void 0:n.trim())||null,cover:((o=u.value.cover)==null?void 0:o.trim())||null};try{w.value&&B.value?(await ee(B.value,a),c.success("کتاب با موفقیت ویرایش شد")):(await te(a),c.success("کتاب با موفقیت افزوده شد")),P(),await D()}catch(d){console.error("Error saving book:",d),c.error("خطا در ذخیره کتاب: "+(d.message||"خطای ناشناخته"))}}function E(a){w.value=!0,B.value=a.id;let e=a.cover||null;e&&e.startsWith("http")&&(e=e.replace(/^https?:\/\/[^\/]+/,"")),u.value={title:a.title||"",sub_title:a.sub_title||null,cover:e};const n=e?e.startsWith("http")?e:`${L}${e}`:null;h.value=n?[{uid:"-1",name:"cover.jpg",status:"done",url:n,response:{path:e}}]:[],x.value=!0}function A(a){H.confirm({title:"حذف کتاب",content:`آیا مطمئن هستید که می‌خواهید کتاب "${a.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await ae(a.id),c.success("کتاب با موفقیت حذف شد"),await D()}catch(e){console.error("Error deleting book:",e),c.error("خطا در حذف کتاب: "+(e.message||"خطای ناشناخته"))}}})}return(a,e)=>{const n=K,o=G,d=X,C=J,M=F;return $(),I("div",null,[r(M,null,{default:m(()=>[l("div",de,[me,r(n,{type:"primary",onClick:O},{default:m(()=>[oe("افزودن کتاب")]),_:1})]),r(o,se(z.value,{ref:"table",onRegister:k(R)}),{action:m(({record:i})=>[l("div",ve,[r(k(N),{class:"cursor-pointer"},{title:m(()=>[pe]),default:m(()=>[r(U,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:y=>A(i)},null,8,["onClick"])]),_:2},1024),r(k(N),{class:"cursor-pointer"},{title:m(()=>[_e]),default:m(()=>[r(U,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:y=>E(i)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),r(C,{visible:x.value,"onUpdate:visible":e[3]||(e[3]=i=>x.value=i),title:w.value?"ویرایش کتاب":"افزودن کتاب",onOk:q,onCancel:P,width:"80%",confirmLoading:g.value>0},{default:m(()=>[l("div",fe,[g.value>0?($(),I("div",he,[r(k(ie),{size:"large"})])):T("",!0),l("div",null,[ge,r(d,{value:u.value.title,"onUpdate:value":e[0]||(e[0]=i=>u.value.title=i),placeholder:"عنوان کتاب"},null,8,["value"])]),l("div",null,[be,r(d,{value:u.value.sub_title,"onUpdate:value":e[1]||(e[1]=i=>u.value.sub_title=i),placeholder:"زیرعنوان کتاب"},null,8,["value"])]),l("div",null,[xe,r(k(ue),{"file-list":h.value,"onUpdate:fileList":e[2]||(e[2]=i=>h.value=i),"before-upload":W,"custom-request":V,accept:"image/*","max-count":1,"list-type":"picture-card"},{default:m(()=>[h.value.length<1?($(),I("div",ye,[r(U,{icon:"vuesax-linear:image",class:"text-2xl mb-2"}),ke])):T("",!0)]),_:1},8,["file-list"]),p.value>0&&p.value<100?($(),I("div",we,[l("div",Be,[l("div",{class:"h-2 bg-blue-500 transition-all",style:re(j(p.value))},null,4)]),l("div",Ce,ne(p.value)+"%",1)])):T("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{Je as default};