Files
machartaa_admin_dist/dist/assets/index-793ffa81.js
T
2026-06-06 12:08:21 +03:30

2 lines
8.3 KiB
JavaScript

import{_ as X}from"./BasicModal.vue_vue_type_style_index_0_lang-fe75b677.js";import{_ as K,u as Q}from"./useBaseTable-ce8a2e7a.js";import{_ as Y}from"./button.vue_vue_type_style_index_0_lang-cc92a672.js";import{I as $}from"./Icon-f953806c.js";import{t as Z}from"./useDataTime-a21b0163.js";import{g as M}from"./convert-67c23be8.js";import{_ as q}from"./TextPreview.vue_vue_type_script_setup_true_lang-72c34227.js";import{_ as D}from"./CustomTag.vue_vue_type_script_setup_true_lang-d61f572d.js";import{b as a,d as ee,g as m,r as te,l as ae,x as oe,n as ne,o as j,c as F,a as _,w as r,e as se,j as c,G as le,k as ie,D as p,H as re}from"./index-d35b2fe0.js";import{g as O}from"./index-40da6560.js";import{a as ue,u as ce,c as de,d as pe}from"./category-45652f4f.js";import{M as me,_ as fe}from"./index-2f27e483.js";import{I as _e,_ as ge}from"./index-dad1078f.js";import{_ as ve,F as he}from"./index-f397d805.js";import{U as xe}from"./index-b1ee5e27.js";import{T as N}from"./shallowequal-ea4257d9.js";import"./index-b9c4c4f8.js";import"./vnode-aa932a38.js";import"./Col-933c6a21.js";import"./_plugin-vue_export-helper-43ffde73.js";import"./index-46a03291.js";import"./toArray-2d2bb2c2.js";import"./FormItemContext-02f2f90e.js";import"./pickAttrs-389dae7d.js";import"./useState-5645ad4c.js";import"./index-63acc1cf.js";import"./isPlainObject-31d795a5.js";import"./useRefs-07fc8b5a.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($,{icon:"vuesax-linear:category"},null)}},{title:"عنوان",dataIndex:"title",key:"title"},{title:"توضیحات",dataIndex:"description",key:"description",width:500,customRender:e=>a(q,{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?Z(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=_("h2",null,"دسته بندی ها",-1),we={class:"gap-2 flex justify-center"},Ce=_("span",null,"حذف",-1),Ie=_("span",null,"ویرایش",-1),Ue={class:"grid grid-cols-3 gap-4"},Be={key:0},Te=_("div",{style:{"margin-top":"8px"}},"آپلود",-1),ot=ee({__name:"index",setup(e){`${O()||localStorage.getItem("tamin_token")||""}`;const[k,R]=Q(),E=m({columns:ye,api:ue,defaultPageLimit:20}),h=m(!1),w=m(!1),C=m(null),V=m([]),x=m(0),I=m(0),l=te({title:"",active:!0,image:void 0,owner_id:void 0,id:void 0,description:void 0,public:void 0});let z=ae.cloneDeep(l);m();const g=m([]);function H(){V.value=[],w.value=!1,C.value=null,h.value=!0}function L(){Object.assign(l,z),g.value=[],h.value=!1}function S(s){return s.type.startsWith("image/")?s.size/1024/1024<5?!0:(p.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(p.error("فقط فایل‌های تصویری مجاز است"),!1)}async function W(s){const{file:t,onSuccess:d,onError:u,onProgress:y}=s,f=new FormData;f.append("file",t);const U=`${re}/upload/machartaa-img`;I.value=0,x.value++,await new Promise((B,b)=>{const i=new XMLHttpRequest;i.open("POST",U);const T=O()||localStorage.getItem("tamin_token")||"";i.setRequestHeader("Authorization",`Bearer ${T}`),i.upload.onprogress=o=>{if(o.lengthComputable){const n=Math.round(o.loaded/o.total*100);I.value=n,y==null||y({percent:n})}},i.onload=()=>{if(I.value=100,i.status>=200&&i.status<300)try{const o=JSON.parse(i.responseText||"{}"),n=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 v=n;n!=null&&n.startsWith("http")&&(v=n.replace(/^https?:\/\/[^\/]+/,""));const P=M(v);l.image=v,g.value=P?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:P,response:{path:v}}]:[],d==null||d(o,i),p.success("کاور با موفقیت آپلود شد!"),B()}catch(o){u==null||u(o,i),b(o)}else{const o=new Error("خطا در آپلود تصویر");u==null||u(o,i),b(o)}},i.onerror=()=>{const o=new Error("خطا در آپلود کاور");u==null||u(o,i),b(o)},i.onloadend=()=>{x.value=Math.max(0,x.value-1),I.value=0},i.send(f)})}async function A(){var s;if(!((s=l.title)!=null&&s.trim())){p.error("لطفاً عنوان دسته بندی را وارد کنید");return}if(x.value>0){p.warning("لطفاً تا پایان آپلود صبر کنید");return}try{w.value&&C.value?(await ce(C.value,l),p.success("دسته بندی با موفقیت ویرایش شد")):(await de(l),p.success("دسته بندی با موفقیت افزوده شد")),L(),await R()}catch(t){console.error("Error saving Product:",t),p.error("خطا در ذخیره دسته بندی: "+(t.message||"خطای ناشناخته"))}}function J(s){w.value=!0,C.value=s.id,console.log(s);let t=s.image||null;t&&t.startsWith("http")&&(t=t.replace(/^https?:\/\/[^\/]+/,""));for(const d in l)s.hasOwnProperty(d)&&(l[d]=s[d]);g.value=t?[{uid:"-1",name:"image.jpg",status:"done",url:M(t),response:{path:t}}]:[],h.value=!0}function G(s){me.confirm({title:"حذف دسته بندی",content:`آیا مطمئن هستید که می‌خواهید دسته بندی "${s.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await pe(s.id),p.success("دسته بندی با موفقیت حذف شد"),await R()}catch(t){console.error("Error deleting Product:",t),p.error("خطا در حذف دسته بندی: "+(t.message||"خطای ناشناخته"))}}})}return oe(async()=>{}),(s,t)=>{const d=Y,u=K,y=_e,f=ve,U=fe,B=ge,b=ne("plus-outlined"),i=xe,T=he,o=X;return j(),F("div",null,[_("div",be,[ke,a(d,{type:"primary",onClick:H},{default:r(()=>[se("افزودن دسته بندی")]),_:1})]),a(u,le(E.value,{ref:"table",onRegister:c(k)}),{text:r(({record:n})=>[a(q,{text:n.description},null,8,["text"])]),action:r(({record:n})=>[_("div",we,[a(c(N),{class:"cursor-pointer"},{title:r(()=>[Ce]),default:r(()=>[a($,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:v=>G(n)},null,8,["onClick"])]),_:2},1024),a(c(N),{class:"cursor-pointer"},{title:r(()=>[Ie]),default:r(()=>[a($,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:v=>J(n)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),a(o,{visible:h.value,"onUpdate:visible":t[5]||(t[5]=n=>h.value=n),title:w.value?"ویرایش دسته بندی":"افزودن دسته بندی",onOk:A,onClose:L,width:"80%",confirmLoading:x.value>0},{default:r(()=>[a(T,{layout:"vertical",class:"grid grid-cols-2 gap-2"},{default:r(()=>[a(f,{label:"عنوان دسته بندی",required:""},{default:r(()=>[a(y,{value:c(l).title,"onUpdate:value":t[0]||(t[0]=n=>c(l).title=n),placeholder:"عنوان فارسی محصول"},null,8,["value"])]),_:1}),_("div",Ue,[a(f,{label:"فعال"},{default:r(()=>[a(U,{checked:c(l).active,"onUpdate:checked":t[1]||(t[1]=n=>c(l).active=n)},null,8,["checked"])]),_:1}),a(f,{label:"دسترسی عمومی"},{default:r(()=>[a(U,{checked:c(l).public,"onUpdate:checked":t[2]||(t[2]=n=>c(l).public=n)},null,8,["checked"])]),_:1})]),a(f,{label:"توضیحات دسته بندی"},{default:r(()=>[a(B,{value:c(l).description,"onUpdate:value":t[3]||(t[3]=n=>c(l).description=n),rows:"4",placeholder:"توضیحات محصول"},null,8,["value"])]),_:1}),a(f,{label:"تصویر اصلی"},{default:r(()=>[a(i,{"file-list":g.value,"onUpdate:fileList":t[4]||(t[4]=n=>g.value=n),"before-upload":S,"custom-request":W,accept:"image/*","list-type":"picture-card","max-count":1},{default:r(()=>[g.value.length<1?(j(),F("div",Be,[a(b),Te])):ie("",!0)]),_:1},8,["file-list"])]),_:1})]),_:1})]),_:1},8,["visible","title","confirmLoading"])])}}});export{ot as default};