Files
appco_dist/.output/public/_nuxt/BCp6lGS1.js
T

2 lines
2.4 KiB
JavaScript

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