UNPKG

yk-element-components

Version:

2 lines (1 loc) 3.52 kB
(function(t,r){typeof exports=="object"&&typeof module<"u"?module.exports=r(require("vue")):typeof define=="function"&&define.amd?define(["vue"],r):(t=typeof globalThis<"u"?globalThis:t||self,t.index=r(t.Vue))})(this,function(t){"use strict";const r={__name:"index",props:{showFileList:{type:Boolean,default:!0},cropperWidth:{type:Number,default:150},cropperHeight:{type:Number,default:150},cropBoxResizable:{type:Boolean,default(){return!0}},guides:{type:Boolean,default(){return!0}},action:{type:String,required:!1,default:"#"},aspectRatio:{type:Number,default:1},headers:{type:Object,default(){return{}}},data:Object,multiple:Boolean,name:{type:String,default:"file"},drag:Boolean,accept:String,beforeUpload:Function,beforeRemove:Function,onRemove:{type:Function,default:()=>{}},onChange:{type:Function,default:()=>{}},onPreview:{type:Function},onSuccess:{type:Function,default:()=>{}},onProgress:{type:Function,default:()=>{}},onError:{type:Function,default:()=>{}},fileList:{type:Array,default(){return[]}},autoUpload:{type:Boolean,default:!0},listType:{type:String,default:"text"},httpRequest:Function,disabled:Boolean,limit:Number,onExceed:{type:Function,default:()=>{}},orCropper:{type:Boolean,default:!1},type:{type:String,default:"select"}},setup(e){const a=e;let i=t.reactive({show:!1,file:null,loading:!1,submitted:!1,uploadFiles:[]});const c=(o,n)=>{let l=new FileReader;l.onload=d=>{typeof n=="function"&&n(d.target.result)},l.readAsDataURL(o)},s=t.ref(),p=(o,n)=>{o.status==="ready"&&(a.orCropper?m({...o,file:o.raw,fileList:n}):a.autoUpload&&(s.value.submit(),u())),a.onChange(o,n)},m=o=>{if(o.file instanceof File){if(i.show)return;i.file=o.file,i.show=!0}},u=()=>{const o=a.fileList;o.splice(o.indexOf(i.file),1),i.show=!1},y=o=>{if(o){let n=new File([o],i.file.name,{type:o.type}),l=a.fileList[a.fileList.length-1];n.uid=l.raw.uid,l.raw=n,c(l.raw,d=>{l.url=d,a.autoUpload&&s.value.submit(),u()})}else a.autoUpload&&s.value.submit(),u()},h=()=>{},g=()=>{},R=()=>{};return(o,n)=>{const l=t.resolveComponent("el-upload"),d=t.resolveComponent("yk-imgCropper");return t.openBlock(),t.createElementBlock(t.Fragment,null,[t.createVNode(l,{ref_key:"yUpload",ref:s,"auto-upload":!1,action:e.action,headers:e.headers,data:e.data,multiple:e.multiple,name:e.name,drag:e.drag,accept:e.accept,type:e.type,beforeUpload:e.beforeUpload,beforeRemove:e.beforeRemove,onRemove:e.onRemove,onChange:p,onPreview:e.onPreview,onSuccess:e.onSuccess,onProgress:e.onProgress,onError:e.onError,"file-list":e.fileList,"onUpdate:file-list":n[0]||(n[0]=f=>t.isRef(fileList)?fileList.value=f:null),listType:e.listType,httpRequest:e.httpRequest,disabled:e.disabled,limit:e.limit,onExceed:e.onExceed,"show-file-list":e.showFileList},{default:t.withCtx(()=>[t.renderSlot(o.$slots,"default")]),_:3},8,["action","headers","data","multiple","name","drag","accept","type","beforeUpload","beforeRemove","onRemove","onPreview","onSuccess","onProgress","onError","file-list","listType","httpRequest","disabled","limit","onExceed","show-file-list"]),t.createVNode(d,{show:t.unref(i).show,"onUpdate:show":n[1]||(n[1]=f=>t.unref(i).show=f),file:t.unref(i).file,aspectRatio:e.aspectRatio,aspectRatioDeviation:.1,cropBoxResizable:e.cropBoxResizable,guides:e.guides,onConfirm:y,onCancel:u,onClose:h,onOpen:R,onClosed:g,cropperWidth:e.cropperWidth,cropperHeight:e.cropperHeight},null,8,["show","file","aspectRatio","aspectRatioDeviation","cropBoxResizable","guides","cropperWidth","cropperHeight"])],64)}}};return{install(e){e.component("yk-upload",r)}}});