Files
appco_dist/.output/public/_nuxt/CiPTnasW.js
T
2025-07-27 10:51:22 +03:30

2 lines
2.3 KiB
JavaScript

import{d as z,r,k as O,y as b,z as n,a4 as j,H as x,A as p,C as h,D as k,S as q,F as y,av as D,da as E,Q as m,N as w}from"./vNwORUzZ.js";import{B as F}from"./DSh6TMV1.js";import{u as M}from"./BqtpcZoZ.js";import{_ as S}from"./DBOJSw9z.js";const $={class:"flex items-center justify-center overflow-hidden border border-solid border-blue-600 bg-gray-50 rounded-md p-2"},H={key:0},Q=["src"],K=z({__name:"IndexImageUploader",props:{fileList:{},bucket:{default:"productimg"}},emits:["update:fileList","ok","delete"],setup(C,{emit:U}){const{prefixCls:L}=M("index-image-uploader"),i=r(!1),v=r(""),u=r(""),l=r(!1),c=C,d=U,o=O({get(){return c.fileList||[]},set(e){d("update:fileList",e)}}),B=async e=>{v.value=e.src,i.value=!0,u.value=e.name||e.url.substring(e.url.lastIndexOf("/")+1)},I=()=>{i.value=!1,u.value=""},N=e=>{const t=e.size/1024/1024<.2;return t||m.error("حداکثر حجم بارگذاری 200 کیلو بایت میباشد"),t};function P(e){if(e.file.status==="uploading"){l.value=!0;return}e.file.status==="error"&&(l.value=!1,o.value=[],m.error("خطا در بارگذاری")),e.file.status==="done"&&(l.value=!1,m.success("تصویر شاخص با موفقیت بارگذاری شد"),d("ok",e.file.response.id)),e.file.status==="removed"&&d("delete",e.file.uid)}async function A(e){const{onSuccess:t,onError:f,file:a}=e;try{const s=`${Date.now()}-${a.name}`,{data:g,error:_}=await w.storage.from(c.bucket).upload(s,a);if(_)throw _;t(g,a);const V=w.storage.from(c.bucket).getPublicUrl(s);o.value=[{uid:s,name:a.name,status:"done",url:V.data.publicUrl,subUrl:g.fullPath}]}catch(s){console.error("Upload error:",s),f(s)}}return(e,t)=>{const f=S,a=E;return n(),b("div",{class:j([x(L)])},[p("div",$,[h(f,{"file-list":o.value,"onUpdate:fileList":t[0]||(t[0]=s=>o.value=s),name:"file","list-type":"picture-card",showUploadList:!0,multiple:!1,customRequest:A,"before-upload":N,onChange:P,onPreview:B},{default:k(()=>[o.value.length===0?(n(),b("div",H,[l.value?(n(),y(x(D),{key:0})):(n(),y(F,{key:1,icon:"vuesax-linear:add",color:"#6B7280",class:"justify-center"})),t[1]||(t[1]=p("div",{class:"text-gray-500 text-center text-xs font-normal"},"Add Image",-1))])):q("",!0)]),_:1},8,["file-list"]),h(a,{open:i.value,title:u.value,footer:null,onCancel:I},{default:k(()=>[p("img",{alt:"example",style:{width:"100%"},src:v.value},null,8,Q)]),_:1},8,["open","title"])])],2)}}});export{K as _};