Files
machartaa_admin_dist/dist/assets/index-c6c93b4d.js
T
2026-01-04 20:11:38 +03:30

2 lines
7.4 KiB
JavaScript

import{_ as A}from"./BasicMainCard-e6133669.js";import{M as F,_ as J}from"./BasicModal.vue_vue_type_style_index_0_lang-c4a9b750.js";import{_ as G}from"./BasicInput.vue_vue_type_style_index_0_lang-82327d87.js";import{_ as X}from"./index-f943fa9e.js";import{_ as K}from"./button.vue_vue_type_style_index_0_lang-00692d4d.js";import{I as U}from"./Icon-c7d1ee6c.js";import{u as Q}from"./useBaseTable-3aeb2499.js";import{t as Y}from"./useDataTime-d8f2c6fb.js";import{getBooksTable as Z,updateBook as ee,addBook as te,deleteBook as ae}from"./books-5a8d521f.js";import{d as le,g as f,o as $,c as I,b as r,w as m,a as l,e as oe,G as se,j as k,k as T,z as re,t as ne,D as c,H as D}from"./index-46ad6f18.js";import{T as z}from"./styleChecker-1b8f3fec.js";import{S as ie}from"./index-3e027524.js";import{U as ue}from"./index-c9af1953.js";import"./_plugin-vue_export-helper-296b8bb1.js";import"./index-e9d0cff4.js";import"./index-7154d232.js";import"./useState-ba6a6598.js";import"./vnode-3f18e55e.js";import"./Col-f3e9d12a.js";import"./index-7636dfa0.js";import"./usePrice-7afab779.js";import"./index-10949106.js";const ce=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:p=>p.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:p=>p.record.total_storys??0},{title:"تصویر کاور",dataIndex:"cover",key:"cover",customRender:p=>p.record.cover||"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:p=>Y(p.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),pe={class:"gap-2 flex justify-center"},ve=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"},Ge=le({__name:"index",setup(p){const[L,R]=Q(),N=f({columns:ce,api:Z,defaultPageLimit:20}),x=f(!1),w=f(!1),B=f(null),h=f([]),g=f(0),v=f(0),u=f({title:"",sub_title:null,cover:null});function W(){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 j(a){return a.type.startsWith("image/")?a.size/1024/1024<5?!0:(c.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(c.error("فقط فایل‌های تصویری مجاز است"),!1)}async function O(a){const{file:e,onSuccess:n,onError:o,onProgress:d}=a,C=new FormData;C.append("file",e);const M=`${D}/upload/machartaa-img`;v.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);v.value=_,d==null||d({percent:_})}},s.onload=()=>{if(v.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:`${D}${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),v.value=0},s.send(C)})}function V(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 R()}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:`${D}${e}`:null;h.value=n?[{uid:"-1",name:"cover.jpg",status:"done",url:n,response:{path:e}}]:[],x.value=!0}function H(a){F.confirm({title:"حذف کتاب",content:`آیا مطمئن هستید که می‌خواهید کتاب "${a.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await ae(a.id),c.success("کتاب با موفقیت حذف شد"),await R()}catch(e){console.error("Error deleting book:",e),c.error("خطا در حذف کتاب: "+(e.message||"خطای ناشناخته"))}}})}return(a,e)=>{const n=K,o=X,d=G,C=J,M=A;return $(),I("div",null,[r(M,null,{default:m(()=>[l("div",de,[me,r(n,{type:"primary",onClick:W},{default:m(()=>[oe("افزودن کتاب")]),_:1})]),r(o,se(N.value,{ref:"table",onRegister:k(L)}),{action:m(({record:i})=>[l("div",pe,[r(k(z),{class:"cursor-pointer"},{title:m(()=>[ve]),default:m(()=>[r(U,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:y=>H(i)},null,8,["onClick"])]),_:2},1024),r(k(z),{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":j,"custom-request":O,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"]),v.value>0&&v.value<100?($(),I("div",we,[l("div",Be,[l("div",{class:"h-2 bg-blue-500 transition-all",style:re(V(v.value))},null,4)]),l("div",Ce,ne(v.value)+"%",1)])):T("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{Ge as default};