2 lines
8.4 KiB
JavaScript
2 lines
8.4 KiB
JavaScript
import{_ as K}from"./BasicModal.vue_vue_type_style_index_0_lang-a547157a.js";import{_ as Q,u as Y}from"./useBaseTable-13b436e1.js";import{_ as Z}from"./button.vue_vue_type_style_index_0_lang-851afdd8.js";import{I as T}from"./Icon-04c02c0b.js";import{t as ee}from"./useDataTime-10f46d84.js";import{g as M}from"./convert-c2e7255b.js";import{_ as E}from"./TextPreview.vue_vue_type_script_setup_true_lang-38b465eb.js";import{_ as D}from"./CustomTag.vue_vue_type_script_setup_true_lang-6745f6a1.js";import{b as a,d as te,g as m,r as ae,l as oe,x as se,n as ne,o as j,c as F,a as g,w as r,e as ie,j as c,G as le,k as re,D as p,H as O}from"./index-82b07f49.js";import{g as N}from"./index-e3788657.js";import{a as ue,u as ce,c as de,d as pe}from"./category-3a849218.js";import{M as me,_ as fe}from"./index-5dc3a2fa.js";import{I as _e,_ as ge}from"./index-c6d6dccd.js";import{_ as ve,F as he}from"./index-2a5d6560.js";import{U as xe}from"./index-0f0f5d8d.js";import{T as q}from"./shallowequal-17b27246.js";import"./index-1f61ecf5.js";import"./vnode-007df887.js";import"./Col-5d52aed9.js";import"./_plugin-vue_export-helper-f81f33f1.js";import"./index-7e5faec0.js";import"./toArray-e3bbd719.js";import"./FormItemContext-f4f190fd.js";import"./pickAttrs-b9acd388.js";import"./useState-e0a5bff5.js";import"./index-d634ff29.js";import"./isPlainObject-f3a46277.js";import"./useRefs-e9385981.js";const ye=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:e=>e.index+1},{title:"تصویر ",dataIndex:"image",key:"image",width:80,customRender:e=>{const k=M(e.record.image);return k?a("img",{src:k,width:60},null):a(T,{icon:"vuesax-linear:category"},null)}},{title:"عنوان",dataIndex:"title",key:"title"},{title:"توضیحات",dataIndex:"description",key:"description",width:500,customRender:e=>a(E,{text:e.record.description},null)},{title:"وضعیت ",dataIndex:"active",key:"active",type:"Boolean",width:150,customRender:e=>a("div",{class:"flex justify-center"},[a(D,{class:"px-3 font-bold py-1",textColor:e!=null&&e.record.active?"#65a30d":"#dc2626",bgColor:e!=null&&e.record.active?"#ecfccb":"#fee2e2"},{default:()=>[e!=null&&e.record.active?"فعال":"غیر فعال"]})])},{title:"وضعیت دسترسی ",dataIndex:"active",key:"active",type:"Boolean",width:150,customRender:e=>a("div",{class:"flex justify-center"},[a(D,{class:"px-3 font-bold py-1",textColor:e!=null&&e.record.public?"#0d6fa3":"#333333",bgColor:e!=null&&e.record.public?"#cbe9fc":"#eaeaea"},{default:()=>[e!=null&&e.record.public?"عمومی":"خصوصی"]})])},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",width:80,customRender:e=>e.record.created_at?ee(e.record.created_at):"-"},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],be={class:"flex justify-between items-center mb-4"},ke=g("h2",null,"دسته بندی ها",-1),we={class:"gap-2 flex justify-center"},Ce=g("span",null,"حذف",-1),Ie=g("span",null,"ویرایش",-1),Ue={class:"grid grid-cols-3 gap-4"},$e={key:0},Be=g("div",{style:{"margin-top":"8px"}},"آپلود",-1),ot=te({__name:"index",setup(e){`${N()||localStorage.getItem("tamin_token")||""}`;const[k,R]=Y(),V=m({columns:ye,api:ue,defaultPageLimit:20}),h=m(!1),w=m(!1),C=m(null),W=m([]),x=m(0),I=m(0),i=ae({title:"",active:!0,image:void 0,owner_id:void 0,id:void 0,description:void 0,public:void 0});let z=oe.cloneDeep(i);m();const v=m([]);function H(){W.value=[],w.value=!1,C.value=null,h.value=!0}function L(){Object.assign(i,z),v.value=[],h.value=!1}function S(n){return n.type.startsWith("image/")?n.size/1024/1024<5?!0:(p.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(p.error("فقط فایلهای تصویری مجاز است"),!1)}async function A(n){const{file:t,onSuccess:d,onError:u,onProgress:y}=n,f=new FormData;f.append("file",t);const U=`${O}/upload/machartaa-img`;I.value=0,x.value++,await new Promise(($,b)=>{const l=new XMLHttpRequest;l.open("POST",U);const B=N()||localStorage.getItem("tamin_token")||"";l.setRequestHeader("Authorization",`Bearer ${B}`),l.upload.onprogress=o=>{if(o.lengthComputable){const s=Math.round(o.loaded/o.total*100);I.value=s,y==null||y({percent:s})}},l.onload=()=>{if(I.value=100,l.status>=200&&l.status<300)try{const o=JSON.parse(l.responseText||"{}"),s=o.full_src||o.url||o.src||o.path||o.data&&(o.data.full_src||o.data.url||o.data.src||o.data.path)||"";let _=s;s!=null&&s.startsWith("http")&&(_=s.replace(/^https?:\/\/[^\/]+/,""));const P=_.startsWith("http")?_:`${O}${_}`;i.image=_,v.value=P?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:P,response:{path:_}}]:[],d==null||d(o,l),p.success("کاور با موفقیت آپلود شد!"),$()}catch(o){u==null||u(o,l),b(o)}else{const o=new Error("خطا در آپلود تصویر");u==null||u(o,l),b(o)}},l.onerror=()=>{const o=new Error("خطا در آپلود کاور");u==null||u(o,l),b(o)},l.onloadend=()=>{x.value=Math.max(0,x.value-1),I.value=0},l.send(f)})}async function J(){var n;if(!((n=i.title)!=null&&n.trim())){p.error("لطفاً عنوان دسته بندی را وارد کنید");return}if(x.value>0){p.warning("لطفاً تا پایان آپلود صبر کنید");return}try{w.value&&C.value?(await ce(C.value,i),p.success("دسته بندی با موفقیت ویرایش شد")):(await de(i),p.success("دسته بندی با موفقیت افزوده شد")),L(),await R()}catch(t){console.error("Error saving Product:",t),p.error("خطا در ذخیره دسته بندی: "+(t.message||"خطای ناشناخته"))}}function G(n){w.value=!0,C.value=n.id,console.log(n);let t=n.image||null;t&&t.startsWith("http")&&(t=t.replace(/^https?:\/\/[^\/]+/,""));for(const d in i)n.hasOwnProperty(d)&&(i[d]=n[d]);v.value=t?[{uid:"-1",name:"image.jpg",status:"done",url:M(t),response:{path:M(t)}}]:[],h.value=!0}function X(n){me.confirm({title:"حذف دسته بندی",content:`آیا مطمئن هستید که میخواهید دسته بندی "${n.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await pe(n.id),p.success("دسته بندی با موفقیت حذف شد"),await R()}catch(t){console.error("Error deleting Product:",t),p.error("خطا در حذف دسته بندی: "+(t.message||"خطای ناشناخته"))}}})}return se(async()=>{}),(n,t)=>{const d=Z,u=Q,y=_e,f=ve,U=fe,$=ge,b=ne("plus-outlined"),l=xe,B=he,o=K;return j(),F("div",null,[g("div",be,[ke,a(d,{type:"primary",onClick:H},{default:r(()=>[ie("افزودن دسته بندی")]),_:1})]),a(u,le(V.value,{ref:"table",onRegister:c(k)}),{text:r(({record:s})=>[a(E,{text:s.description},null,8,["text"])]),action:r(({record:s})=>[g("div",we,[a(c(q),{class:"cursor-pointer"},{title:r(()=>[Ce]),default:r(()=>[a(T,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:_=>X(s)},null,8,["onClick"])]),_:2},1024),a(c(q),{class:"cursor-pointer"},{title:r(()=>[Ie]),default:r(()=>[a(T,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:_=>G(s)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),a(o,{visible:h.value,"onUpdate:visible":t[5]||(t[5]=s=>h.value=s),title:w.value?"ویرایش دسته بندی":"افزودن دسته بندی",onOk:J,onClose:L,width:"80%",confirmLoading:x.value>0},{default:r(()=>[a(B,{layout:"vertical",class:"grid grid-cols-2 gap-2"},{default:r(()=>[a(f,{label:"عنوان دسته بندی",required:""},{default:r(()=>[a(y,{value:c(i).title,"onUpdate:value":t[0]||(t[0]=s=>c(i).title=s),placeholder:"عنوان فارسی محصول"},null,8,["value"])]),_:1}),g("div",Ue,[a(f,{label:"فعال"},{default:r(()=>[a(U,{checked:c(i).active,"onUpdate:checked":t[1]||(t[1]=s=>c(i).active=s)},null,8,["checked"])]),_:1}),a(f,{label:"دسترسی عمومی"},{default:r(()=>[a(U,{checked:c(i).public,"onUpdate:checked":t[2]||(t[2]=s=>c(i).public=s)},null,8,["checked"])]),_:1})]),a(f,{label:"توضیحات دسته بندی"},{default:r(()=>[a($,{value:c(i).description,"onUpdate:value":t[3]||(t[3]=s=>c(i).description=s),rows:"4",placeholder:"توضیحات محصول"},null,8,["value"])]),_:1}),a(f,{label:"تصویر اصلی"},{default:r(()=>[a(l,{"file-list":v.value,"onUpdate:fileList":t[4]||(t[4]=s=>v.value=s),"before-upload":S,"custom-request":A,accept:"image/*","list-type":"picture-card","max-count":1},{default:r(()=>[v.value.length<1?(j(),F("div",$e,[a(b),Be])):re("",!0)]),_:1},8,["file-list"])]),_:1})]),_:1})]),_:1},8,["visible","title","confirmLoading"])])}}});export{ot as default};
|