2 lines
8.8 KiB
JavaScript
2 lines
8.8 KiB
JavaScript
import{_ as G}from"./BasicModal.vue_vue_type_style_index_0_lang-a23efd75.js";import{_ as K,u as Q}from"./useBaseTable-eabb6e73.js";import{_ as Y}from"./button.vue_vue_type_style_index_0_lang-58c562e7.js";import{I as $}from"./Icon-2ca0951c.js";import{t as Z}from"./useDataTime-a9a38277.js";import{g as M}from"./convert-2ad76038.js";import{_ as q}from"./TextPreview.vue_vue_type_script_setup_true_lang-c7e75dc6.js";import{_ as D}from"./CustomTag.vue_vue_type_script_setup_true_lang-d1eb92b3.js";import{b as a,d as ee,g as d,r as te,v as ae,l as oe,o as F,c as j,a as _,w as r,e as ie,j as c,H as le,k as se,D as m,I as ne}from"./index-02897754.js";import{g as O}from"./index-2537f09f.js";import{l as re}from"./lodash-f280de5a.js";import{a as ue,u as ce,c as pe,d as me}from"./category-38da4822.js";import{M as de,_ as fe}from"./index-4652c849.js";import{I as _e,a as ge}from"./index-b0c72faa.js";import{_ as ve,F as he}from"./index-a571a3ce.js";import{U as be}from"./index-fd46be7d.js";import{T as N}from"./isSymbol-792a2a97.js";import"./index-644e91ea.js";import"./vnode-65917850.js";import"./_plugin-vue_export-helper-2dea18d7.js";import"./updateLocale-ed1a4c67.js";import"./useState-4419625c.js";import"./index-1d9cca6c.js";import"./toArray-b84867a5.js";import"./FormItemContext-0ec501fb.js";import"./pickAttrs-66d27c5c.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-2e8a6602.js";import"./index-9a9a9cd2.js";import"./isNumeric-3f69e2aa.js";import"./index-f459a9b9.js";import"./index-4cf251d4.js";import"./styleChecker-ce90d19e.js";import"./index-834ba08a.js";import"./LeftOutlined-0f3263d7.js";import"./css-aae66f86.js";import"./DialogWrap-b41f46aa.js";import"./index-066e71ee.js";import"./textUtils-c37780ad.js";import"./isPlainObject-6a522913.js";import"./_flatRest-bac800e2.js";import"./Col-880c700f.js";import"./useRefs-44db43e1.js";const xe=[{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:"public",key:"public",filterField:"public",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"}],ye={class:"flex justify-between items-center mb-4"},ke=_("h2",null,"دسته بندی ها",-1),we={class:"gap-2 flex justify-center"},Ie=_("span",null,"حذف",-1),Ce=_("span",null,"ویرایش",-1),Ue={class:"grid grid-cols-3 gap-4"},Be={key:0},Te=_("div",{style:{"margin-top":"8px"}},"آپلود",-1),vt=ee({__name:"index",setup(e){`${O()||localStorage.getItem("tamin_token")||""}`;const[k,R]=Q(),E=d({columns:xe,api:ue,defaultPageLimit:20}),h=d(!1),w=d(!1),I=d(null),V=d([]),b=d(0),C=d(0),s=te({title:"",active:!0,image:void 0,owner_id:void 0,id:void 0,description:void 0,public:void 0});let z=re.cloneDeep(s);d();const g=d([]);function H(){V.value=[],w.value=!1,I.value=null,h.value=!0}function L(){Object.assign(s,z),g.value=[],h.value=!1}function S(l){return l.type.startsWith("image/")?l.size/1024/1024<5?!0:(m.error("حجم تصویر باید کمتر از 5MB باشد"),!1):(m.error("فقط فایلهای تصویری مجاز است"),!1)}async function W(l){const{file:t,onSuccess:p,onError:u,onProgress:x}=l,f=new FormData;f.append("file",t);const U=`${ne}/upload/machartaa-img`;C.value=0,b.value++,await new Promise((B,y)=>{const n=new XMLHttpRequest;n.open("POST",U);const T=O()||localStorage.getItem("tamin_token")||"";n.setRequestHeader("Authorization",`Bearer ${T}`),n.upload.onprogress=o=>{if(o.lengthComputable){const i=Math.round(o.loaded/o.total*100);C.value=i,x==null||x({percent:i})}},n.onload=()=>{if(C.value=100,n.status>=200&&n.status<300)try{const o=JSON.parse(n.responseText||"{}"),i=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=i;i!=null&&i.startsWith("http")&&(v=i.replace(/^https?:\/\/[^\/]+/,""));const P=M(v);s.image=v,g.value=P?[{uid:`${Date.now()}`,name:"image.jpg",status:"done",url:P,response:{path:v}}]:[],p==null||p(o,n),m.success("کاور با موفقیت آپلود شد!"),B()}catch(o){u==null||u(o,n),y(o)}else{const o=new Error("خطا در آپلود تصویر");u==null||u(o,n),y(o)}},n.onerror=()=>{const o=new Error("خطا در آپلود کاور");u==null||u(o,n),y(o)},n.onloadend=()=>{b.value=Math.max(0,b.value-1),C.value=0},n.send(f)})}async function A(){var l;if(!((l=s.title)!=null&&l.trim())){m.error("لطفاً عنوان دسته بندی را وارد کنید");return}if(b.value>0){m.warning("لطفاً تا پایان آپلود صبر کنید");return}try{w.value&&I.value?(await ce(I.value,s),m.success("دسته بندی با موفقیت ویرایش شد")):(await pe(s),m.success("دسته بندی با موفقیت افزوده شد")),L(),await R()}catch(t){console.error("Error saving Product:",t),m.error("خطا در ذخیره دسته بندی: "+(t.message||"خطای ناشناخته"))}}function J(l){w.value=!0,I.value=l.id,console.log(l);let t=l.image||null;t&&t.startsWith("http")&&(t=t.replace(/^https?:\/\/[^\/]+/,""));for(const p in s)l.hasOwnProperty(p)&&(s[p]=l[p]);g.value=t?[{uid:"-1",name:"image.jpg",status:"done",url:M(t),response:{path:t}}]:[],h.value=!0}function X(l){de.confirm({title:"حذف دسته بندی",content:`آیا مطمئن هستید که میخواهید دسته بندی "${l.title}" را حذف کنید؟`,okText:"بله، حذف کن",cancelText:"انصراف",okType:"danger",centered:!0,onOk:async()=>{try{await me(l.id),m.success("دسته بندی با موفقیت حذف شد"),await R()}catch(t){console.error("Error deleting Product:",t),m.error("خطا در حذف دسته بندی: "+(t.message||"خطای ناشناخته"))}}})}return ae(async()=>{}),(l,t)=>{const p=Y,u=K,x=_e,f=ve,U=fe,B=ge,y=oe("plus-outlined"),n=be,T=he,o=G;return F(),j("div",null,[_("div",ye,[ke,a(p,{type:"primary",onClick:H},{default:r(()=>[ie("افزودن دسته بندی")]),_:1})]),a(u,le(E.value,{ref:"table",onRegister:c(k)}),{text:r(({record:i})=>[a(q,{text:i.description},null,8,["text"])]),action:r(({record:i})=>[_("div",we,[a(c(N),{class:"cursor-pointer"},{title:r(()=>[Ie]),default:r(()=>[a($,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:v=>X(i)},null,8,["onClick"])]),_:2},1024),a(c(N),{class:"cursor-pointer"},{title:r(()=>[Ce]),default:r(()=>[a($,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:v=>J(i)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),a(o,{visible:h.value,"onUpdate:visible":t[5]||(t[5]=i=>h.value=i),title:w.value?"ویرایش دسته بندی":"افزودن دسته بندی",onOk:A,onClose:L,width:"80%",confirmLoading:b.value>0},{default:r(()=>[a(T,{layout:"vertical",class:"grid grid-cols-2 gap-2"},{default:r(()=>[a(f,{label:"عنوان دسته بندی",required:""},{default:r(()=>[a(x,{value:c(s).title,"onUpdate:value":t[0]||(t[0]=i=>c(s).title=i),placeholder:"عنوان فارسی محصول"},null,8,["value"])]),_:1}),_("div",Ue,[a(f,{label:"فعال"},{default:r(()=>[a(U,{checked:c(s).active,"onUpdate:checked":t[1]||(t[1]=i=>c(s).active=i)},null,8,["checked"])]),_:1}),a(f,{label:"دسترسی عمومی"},{default:r(()=>[a(U,{checked:c(s).public,"onUpdate:checked":t[2]||(t[2]=i=>c(s).public=i)},null,8,["checked"])]),_:1})]),a(f,{label:"توضیحات دسته بندی"},{default:r(()=>[a(B,{value:c(s).description,"onUpdate:value":t[3]||(t[3]=i=>c(s).description=i),rows:"4",placeholder:"توضیحات محصول"},null,8,["value"])]),_:1}),a(f,{label:"تصویر اصلی"},{default:r(()=>[a(n,{"file-list":g.value,"onUpdate:fileList":t[4]||(t[4]=i=>g.value=i),"before-upload":S,"custom-request":W,accept:"image/*","list-type":"picture-card","max-count":1},{default:r(()=>[g.value.length<1?(F(),j("div",Be,[a(y),Te])):se("",!0)]),_:1},8,["file-list"])]),_:1})]),_:1})]),_:1},8,["visible","title","confirmLoading"])])}}});export{vt as default};
|