Files
hedena_gold/apps/admin-panel/dist/assets/AddProduct-BWYbbPfT.js
T

2 lines
22 KiB
JavaScript
Raw Normal View History

import{d as ce,l as we,C as xe,o as i,a as d,p as t,w as s,m as l,t as z,F as E,b as Q,f as V,e as v,k as U,g as re,A as X,U as Ue,r as m,n as Y,x as P,_ as _e,u as $e,v as Ce,i as Ie,y as le,q as F,c as $,B as ze,E as Ve,j as Se}from"./index-BAVzA63z.js";import{I as k}from"./Icon-fSTUMLnE.js";import{_ as ue}from"./ImageUploadInput.vue_vue_type_script_setup_true_lang-BoT7ZqmO.js";const Le={class:"gallery-upload"},Re={class:"gallery-upload__zone"},qe={class:"gallery-upload__title"},Oe={key:0,class:"gallery-upload__grid"},Ee=["src"],je={key:0,class:"tile__progress"},Me={key:1,class:"tile__overlay"},Ne=["onClick"],Pe=["onClick"],Ae={key:1,class:"gallery-upload__meta"},Be={key:0,class:"gallery-upload__pending"},De=["src"],Fe=3,Ge=ce({__name:"GalleryUploadInput",props:{modelValue:{default:()=>[]},purpose:{default:void 0},placeholder:{default:"افزودن تصاویر گالری"}},emits:["update:modelValue"],setup(Z,{emit:ee}){const j=Z,A=ee,f=U([]),S=U(!1),R=U(""),G=()=>f.value.filter(o=>o.status==="done"&&o.url).map(o=>o.url),B=re(()=>f.value.filter(o=>o.status==="done").length),T=re(()=>f.value.filter(o=>o.status==="uploading").length);function J(){A("update:modelValue",G())}we(()=>j.modelValue,o=>{if(JSON.stringify(G())===JSON.stringify(o??[]))return;const p=f.value.filter(r=>r.status==="uploading");f.value=[...(o??[]).map(r=>({uid:r,status:"done",url:r,percent:100})),...p]},{immediate:!0});function H(o){return o.type.startsWith("image/")?!0:(X.error(`«${o.name}» تصویر نیست`),Ue.LIST_IGNORE)}let n=0;const q=[];function D(o){return new Promise((p,r)=>{const g=()=>{n++,o().then(p,r).finally(()=>{var C;n--,(C=q.shift())==null||C()})};n<Fe?g():q.push(g)})}const O=o=>f.value.find(p=>p.uid===o);function W({file:o}){const p=o.uid??`${Date.now()}-${Math.random().toString(36).slice(2,8)}`;f.value.push({uid:p,status:"uploading",preview:URL.createObjectURL(o),percent:0}),D(async()=>{if(!O(p))return null;const r=new FormData;r.append("file",o),j.purpose&&r.append("purpose",j.purpose);const{data:g}=await P.post("file/create",r,{onUploadProgress:C=>{const b=O(p);b&&C.total&&(b.percent=Math.round(C.loaded/C.total*100))}});return g}).then(r=>{const g=O(p);!g||!(r!=null&&r.url)||(g.preview&&URL.revokeObjectURL(g.preview),Object.assign(g,{status:"done",url:r.url,preview:void 0,percent:100}),J())}).catch(r=>{var C,b;const g=((b=(C=r==null?void 0:r.response)==null?void 0:C.data)==null?void 0:b.message)??`بارگذاری «${o.name}» ناموفق بود`;X.error(g),L(p)})}function L(o){const p=f.value.findIndex(g=>g.uid===o);if(p===-1)return;const[r]=f.value.splice(p,1);r.preview&&URL.revokeObjectURL(r.preview)}function M(o){L(o),J()}function N(o){R.value=o.url??o.preview??"",S.value=!0}return xe(()=>{f.value.forEach(o=>o.preview&&URL.revokeObjectURL(o.preview))}),(o,p)=>{const r=m("a-upload-dragger"),g=m("a-progress"),C=m("a-modal");return i(),d("div",Le,[t(r,{accept:"image/*",multiple:"","show-upload-list":!1,"custom-request":W,"before-upload":H},{default:s(()=>[l("div",Re,[t(k,{icon:"vuesax-linear:document-upload",size:"16",class:"gallery-upload__icon"}),l("p",qe,z(Z.placeholder),1),p[1]||(p[1]=l("p",{class:"gallery-upload__hint"}," تصاویر را اینجا بکشید و رها کنید یا کلیک کنید — انتخاب چند تصویر به‌صورت همزمان امکان‌پذیر است ",-1))])]),_:1}),f.value.length?(i(),d("div",Oe,[(i(!0),d(E,null,Q(f.value,b=>(i(),d("div",{key:b.uid,class:Y(["tile",{"is-uploading":b.status==="uploading"}])},[l("img",{src:b.url??b.preview,alt:""},null,8,Ee),b.status==="uploading"?(i(),d("div",je,[t(g,{type:"circle",percent:b.percent,size:40,"stroke-width":8,"stroke-color":"#fff","trail-color":"rgba(255,255,255,.3)","show-info":!1},null,8,["percent"])])):(i(),d("div",Me,[l("button",{type:"button",class:"tile__btn",title:"نمایش",onClick:te=>N(b)},[t(k,{icon:"vuesax-linear:eye",size:"16"})],8,Ne),l("button",{type:"button",class:"tile__btn tile__btn--danger",title:"حذف",onClick:te=>M(b.uid)},[t(k,{icon:"vuesax-linear:trash",size:"16"})],8,Pe)]))],2))),128))])):V("",!