index-legacy.bd6987bf.js 6.1 KB

1
  1. System.register(["./index-legacy.eb062188.js","./index-legacy.b7c35e0c.js","./index-legacy.fecc738b.js","./function-call-legacy.0bd16987.js"],(function(e){"use strict";var l,a,t,i,o,n,r,s,c,u,d,p,m,v,f,g,b,w,y,x,h,z,R,U,j,k,S,V,F,L;return{setters:[function(e){l=e.t,a=e.a2,t=e.M,i=e.d,o=e.z,n=e.aB,r=e.c,s=e.a5,c=e.L,u=e.bF,d=e.a1,p=e.aR,m=e.N,v=e.w,f=e.u,g=e.v,b=e.av,w=e.R,y=e.ab,x=e.W,h=e.b8,z=e.ac,R=e.ay,U=e.K,j=e.am,k=e.E,S=e.r,V=e.D},function(){},function(e){F=e.I},function(e){L=e.s}],execute:function(){const[A,C,B]=l("uploader");function O(e,l){return new Promise((a=>{if("file"===l)return void a();const t=new FileReader;t.onload=e=>{a(e.target.result)},"dataUrl"===l?t.readAsDataURL(e):"text"===l&&t.readAsText(e)}))}function P(e,l){return a(e).some((e=>!!e.file&&(t(l)?l(e.file):e.file.size>+l)))}const I=/\.(jpeg|jpg|gif|png|svg|webp|jfif|bmp|dpg|avif)/i;function D(e){return!!e.isImage||(e.file&&e.file.type?0===e.file.type.indexOf("image"):e.url?(l=e.url,I.test(l)):"string"==typeof e.content&&0===e.content.indexOf("data:image"));var l}var T=i({props:{name:o,item:n(Object),index:Number,imageFit:String,lazyLoad:Boolean,deletable:Boolean,reupload:Boolean,previewSize:[Number,String,Array],beforeDelete:Function},emits:["delete","preview","reupload"],setup(e,{emit:l,slots:a}){const t=()=>{const{status:l,message:a}=e.item;if("uploading"===l||"failed"===l){const e="failed"===l?r(s,{name:"close",class:C("mask-icon")},null):r(c,{class:C("loading")},null),t=d(a)&&""!==a;return r("div",{class:C("mask")},[e,t&&r("div",{class:C("mask-message")},[a])])}},i=a=>{const{name:t,item:i,index:o,beforeDelete:n}=e;a.stopPropagation(),p(n,{args:[i,{name:t,index:o}],done:()=>l("delete")})},o=()=>l("preview"),n=()=>l("reupload"),v=()=>{if(e.deletable&&"uploading"!==e.item.status){const e=a["preview-delete"];return r("div",{role:"button",class:C("preview-delete",{shadow:!e}),tabindex:0,"aria-label":B("delete"),onClick:i},[e?e():r(s,{name:"cross",class:C("preview-delete-icon")},null)])}},f=()=>{if(a["preview-cover"]){const{index:l,item:t}=e;return r("div",{class:C("preview-cover")},[a["preview-cover"](m({index:l},t))])}},g=()=>{const{item:l,lazyLoad:a,imageFit:t,previewSize:i,reupload:c}=e;return D(l)?r(F,{fit:t,src:l.objectUrl||l.content||l.url,class:C("preview-image"),width:Array.isArray(i)?i[0]:i,height:Array.isArray(i)?i[1]:i,lazyLoad:a,onClick:c?n:o},{default:f}):r("div",{class:C("file"),style:u(e.previewSize)},[r(s,{class:C("file-icon"),name:"description"},null),r("div",{class:[C("file-name"),"van-ellipsis"]},[l.file?l.file.name:l.url]),f()])};return()=>r("div",{class:C("preview")},[g(),t(),v()])}});const N={name:v(""),accept:f("image/*"),capture:String,multiple:Boolean,disabled:Boolean,readonly:Boolean,lazyLoad:Boolean,maxCount:v(1/0),imageFit:f("cover"),resultType:f("dataUrl"),uploadIcon:f("photograph"),uploadText:String,deletable:g,reupload:Boolean,afterRead:Function,showUpload:g,modelValue:b(),beforeRead:Function,beforeDelete:Function,previewSize:[Number,String,Array],previewImage:g,previewOptions:Object,previewFullImage:g,maxSize:{type:[Number,String,Function],default:1/0}};var E=i({name:A,props:N,emits:["delete","oversize","clickUpload","closePreview","clickPreview","clickReupload","update:modelValue"],setup(e,{emit:l,slots:t}){const i=w(),o=[],n=w(-1),c=(l=e.modelValue.length)=>({name:e.name,index:l}),d=()=>{i.value&&(i.value.value="")},p=t=>{if(d(),P(t,e.maxSize)){if(!Array.isArray(t))return void l("oversize",t,c());{const a=function(e,l){const a=[],t=[];return e.forEach((e=>{P(e,l)?t.push(e):a.push(e)})),{valid:a,invalid:t}}(t,e.maxSize);if(t=a.valid,l("oversize",a.invalid,c()),!t.length)return}}if(t=S(t),n.value>-1){const a=[...e.modelValue];a.splice(n.value,1,t),l("update:modelValue",a),n.value=-1}else l("update:modelValue",[...e.modelValue,...a(t)]);e.afterRead&&e.afterRead(t,c())},v=l=>{const{maxCount:a,modelValue:t,resultType:i}=e;if(Array.isArray(l)){const e=+a-t.length;l.length>e&&(l=l.slice(0,e)),Promise.all(l.map((e=>O(e,i)))).then((e=>{const a=l.map(((l,a)=>{const t={file:l,status:"",message:"",objectUrl:URL.createObjectURL(l)};return e[a]&&(t.content=e[a]),t}));p(a)}))}else O(l,i).then((e=>{const a={file:l,status:"",message:"",objectUrl:URL.createObjectURL(l)};e&&(a.content=e),p(a)}))},f=l=>{const{files:a}=l.target;if(e.disabled||!a||!a.length)return;const t=1===a.length?a[0]:[].slice.call(a);if(e.beforeRead){const l=e.beforeRead(t,c());if(!l)return void d();if(U(l))return void l.then((e=>{v(e||t)})).catch(d)}v(t)};let g;const b=()=>l("closePreview"),V=(a,i)=>{const s=["imageFit","deletable","reupload","previewSize","beforeDelete"],u=m(j(e,s),j(a,s,!0));return r(T,k({item:a,index:i,onClick:()=>l(e.reupload?"clickReupload":"clickPreview",a,c(i)),onDelete:()=>((a,t)=>{const i=e.modelValue.slice(0);i.splice(t,1),l("update:modelValue",i),l("delete",a,c(t))})(a,i),onPreview:()=>(l=>{if(e.previewFullImage){const a=e.modelValue.filter(D),t=a.map((e=>(e.objectUrl&&!e.url&&"failed"!==e.status&&(e.url=e.objectUrl,o.push(e.url)),e.url))).filter(Boolean);g=L(m({images:t,startPosition:a.indexOf(l),onClose:b},e.previewOptions))}})(a),onReupload:()=>(e=>{I(),n.value=e})(i)},j(e,["name","lazyLoad"]),u),j(t,["preview-cover","preview-delete"]))},F=()=>{if(e.previewImage)return e.modelValue.map(V)},A=e=>l("clickUpload",e),B=()=>{if(e.modelValue.length>=+e.maxCount&&!e.reupload)return;const l=e.modelValue.length>=+e.maxCount&&e.reupload,a=e.readonly?null:r("input",{ref:i,type:"file",class:C("input"),accept:e.accept,capture:e.capture,multiple:e.multiple&&-1===n.value,disabled:e.disabled,onChange:f},null);return t.default?z(r("div",{class:C("input-wrapper"),onClick:A},[t.default(),a]),[[R,!l]]):z(r("div",{class:C("upload",{readonly:e.readonly}),style:u(e.previewSize),onClick:A},[r(s,{name:e.uploadIcon,class:C("upload-icon")},null),e.uploadText&&r("span",{class:C("upload-text")},[e.uploadText]),a]),[[R,e.showUpload&&!l]])},I=()=>{i.value&&!e.disabled&&i.value.click()};return y((()=>{o.forEach((e=>URL.revokeObjectURL(e)))})),x({chooseFile:I,closeImagePreview:()=>{g&&g.close()}}),h((()=>e.modelValue)),()=>r("div",{class:C()},[r("div",{class:C("wrapper",{disabled:e.disabled})},[F(),B()])])}});e("U",V(E))}}}));