vue-upload-component
Advanced tools
Comparing version 3.0.48 to 3.0.50
/*! | ||
Name: vue-upload-component | ||
Component URI: https://github.com/lian-yue/vue-upload-component#readme | ||
Version: 3.0.47 | ||
Version: 3.0.49 | ||
Author: LianYue | ||
@@ -867,3 +867,5 @@ License: Apache-2.0 | ||
this.watchDrop(false); | ||
this.watchDrop(false); // 销毁不激活 | ||
this.watchActive(false); | ||
}, | ||
@@ -870,0 +872,0 @@ computed: { |
/*! | ||
Name: vue-upload-component | ||
Component URI: https://github.com/lian-yue/vue-upload-component#readme | ||
Version: 3.0.47 | ||
Version: 3.0.49 | ||
Author: LianYue | ||
@@ -9,3 +9,3 @@ License: Apache-2.0 | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueUploadComponent=t(e.Vue)}(this,function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r,h=t(e);return function(e){function c(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function d(n){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?t(Object(i),!0).forEach(function(e){var t,r;t=n,e=i[r=e],r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})}return n}function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function s(n){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?r(Object(i),!0).forEach(function(e){var t,r;t=n,e=i[r=e],r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})}return n}function a(e){var n,t,r=l(e);return n=r,t=e.body,new Promise(function(e,r){n.onload=function(){if(200<=n.status&&n.status<300){var t;try{t=JSON.parse(n.response)}catch(e){t=n.response}e(t)}else r(n.response)},n.onerror=function(){return r(n.response)},n.send(JSON.stringify(t))})}var u,l,f;e.exports=(u=h.default,l=function(t){var r=new XMLHttpRequest;return r.open(t.method||"GET",t.url),r.responseType="json",t.headers&&Object.keys(t.headers).forEach(function(e){r.setRequestHeader(e,t.headers[e])}),r},f={headers:{},action:"",minSize:1048576,maxActive:3,maxRetries:5,handler:function(){function r(e,t){!function(e){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this),this.file=e,this.options=t,this.chunks=[],this.sessionId=null,this.chunkSize=null,this.speedInterval=null}var e,t,n;return e=r,(t=[{key:"createChunks",value:function(){this.chunks=[];for(var e=0,t=this.chunkSize;e<this.fileSize;)this.chunks.push({blob:this.file.file.slice(e,t),startOffset:e,active:!1,retries:this.maxRetries}),t=(e=t)+this.chunkSize}},{key:"updateFileProgress",value:function(){this.file.progress=this.progress}},{key:"pause",value:function(){this.file.active=!1,this.stopChunks()}},{key:"stopChunks",value:function(){this.chunksUploading.forEach(function(e){e.xhr.abort(),e.active=!1}),this.stopSpeedCalc()}},{key:"resume",value:function(){this.file.active=!0,this.startChunking()}},{key:"upload",value:function(){var r=this;return this.promise=new Promise(function(e,t){r.resolve=e,r.reject=t}),this.start(),this.promise}},{key:"start",value:function(){var t=this;a({method:"POST",headers:s(s({},this.headers),{},{"Content-Type":"application/json"}),url:this.action,body:Object.assign(this.startBody,{phase:"start",mime_type:this.fileType,size:this.fileSize,name:this.fileName})}).then(function(e){return"success"!==e.status?(t.file.response=e,t.reject("server")):(t.sessionId=e.data.session_id,t.chunkSize=e.data.end_offset,t.createChunks(),void t.startChunking())}).catch(function(e){t.file.response=e,t.reject("server")})}},{key:"startChunking",value:function(){for(var e=0;e<this.maxActiveChunks;e++)this.uploadNextChunk();this.startSpeedCalc()}},{key:"uploadNextChunk",value:function(){if(this.file.active)return this.hasChunksToUpload?this.uploadChunk(this.chunksToUpload[0]):0===this.chunksUploading.length?this.finish():void 0}},{key:"uploadChunk",value:function(t){var r=this;t.progress=0,t.active=!0,this.updateFileProgress(),t.xhr=l({method:"POST",headers:this.headers,url:this.action}),t.xhr.upload.addEventListener("progress",function(e){e.lengthComputable&&(t.progress=Math.round(e.loaded/e.total*100))},!1),function(n,e){var t,i=new FormData;for(t in e)i.append(t,e[t]);return new Promise(function(e,r){n.onload=function(){if(200<=n.status&&n.status<300){var t;try{t=JSON.parse(n.response)}catch(e){t=n.response}e(t)}else r(n.response)},n.onerror=function(){return r(n.response)},n.send(i)})}(t.xhr,Object.assign(this.uploadBody,{phase:"upload",session_id:this.sessionId,start_offset:t.startOffset,chunk:t.blob})).then(function(e){if(t.active=!1,"success"===e.status)t.uploaded=!0;else if(t.retries--<=0)return r.stopChunks(),r.reject("upload");r.uploadNextChunk()}).catch(function(){return t.active=!1,t.retries--<=0?(r.stopChunks(),r.reject("upload")):void r.uploadNextChunk()})}},{key:"finish",value:function(){var t=this;this.updateFileProgress(),this.stopSpeedCalc(),a({method:"POST",headers:s(s({},this.headers),{},{"Content-Type":"application/json"}),url:this.action,body:Object.assign(this.finishBody,{phase:"finish",session_id:this.sessionId})}).then(function(e){return"success"!==(t.file.response=e).status?t.reject("server"):void t.resolve(e)}).catch(function(e){t.file.response=e,t.reject("server")})}},{key:"startSpeedCalc",value:function(){var t=this,r=this.file.speed=0;this.speedInterval||(this.speedInterval=window.setInterval(function(){var e=t.progress/100*t.fileSize;t.file.speed=e-r,r=e},1e3))}},{key:"stopSpeedCalc",value:function(){this.speedInterval&&window.clearInterval(this.speedInterval),this.speedInterval=null,this.file.speed=0}},{key:"maxRetries",get:function(){return parseInt(this.options.maxRetries,10)}},{key:"maxActiveChunks",get:function(){return parseInt(this.options.maxActive,10)}},{key:"fileType",get:function(){return this.file.type}},{key:"fileSize",get:function(){return this.file.size}},{key:"fileName",get:function(){return this.file.name}},{key:"action",get:function(){return this.options.action||null}},{key:"startBody",get:function(){return this.options.startBody||{}}},{key:"uploadBody",get:function(){return this.options.uploadBody||{}}},{key:"finishBody",get:function(){return this.options.finishBody||{}}},{key:"headers",get:function(){return this.options.headers||{}}},{key:"readyToUpload",get:function(){return!!this.chunks}},{key:"progress",get:function(){var r=this,e=this.chunksUploaded.length/this.chunks.length*100,t=this.chunksUploading.reduce(function(e,t){return e+(0|t.progress)/r.chunks.length},0);return Math.min(e+t,100)}},{key:"chunksToUpload",get:function(){return this.chunks.filter(function(e){return!e.active&&!e.uploaded})}},{key:"hasChunksToUpload",get:function(){return 0<this.chunksToUpload.length}},{key:"chunksUploading",get:function(){return this.chunks.filter(function(e){return!!e.xhr&&!!e.active})}},{key:"chunksUploaded",get:function(){return this.chunks.filter(function(e){return!!e.uploaded})}}])&&i(e.prototype,t),n&&i(e,n),r}()},e=u.defineComponent({props:{inputId:{type:String},name:{type:String,default:"file"},accept:{type:String},capture:{},disabled:{default:!1},multiple:{type:Boolean,default:!1},maximum:{type:Number},addIndex:{type:[Boolean,Number]},directory:{type:Boolean},createDirectory:{type:Boolean,default:!1},postAction:{type:String},putAction:{type:String},customAction:{type:Function},headers:{type:Object,default:function(){return{}}},data:{type:Object,default:function(){return{}}},timeout:{type:Number,default:0},drop:{default:!1},dropDirectory:{type:Boolean,default:!0},size:{type:Number,default:0},extensions:{type:[RegExp,String,Array],default:function(){return[]}},modelValue:{type:Array,default:function(){return[]}},thread:{type:Number,default:1},chunkEnabled:{type:Boolean,default:!1},chunk:{type:Object,default:function(){return f}}},emits:["update:modelValue","input-filter","input-file"],data:function(){return{files:this.modelValue,features:{html5:!0,directory:!1,drop:!1},active:!1,dropActive:!1,uploading:0,destroy:!1,maps:{},dropElement:null,reload:!1}},mounted:function(){var e=this,t=document.createElement("input");if(t.type="file",t.multiple=!0,window.FormData&&t.files?("boolean"!=typeof t.webkitdirectory&&"boolean"!=typeof t.directory||(this.features.directory=!0),this.features.html5&&void 0!==t.ondrop&&(this.features.drop=!0)):this.features.html5=!1,this.maps={},this.files)for(var r=0;r<this.files.length;r++){var n=this.files[r];this.maps[n.id]=n}this.$nextTick(function(){e.$parent?(e.$parent.$forceUpdate(),e.$parent.$nextTick(function(){e.watchDrop(e.drop)})):e.watchDrop(e.drop)})},beforeUnmount:function(){this.destroy=!0,this.active=!1,this.watchDrop(!1)},computed:{uploaded:function(){for(var e,t=0;t<this.files.length;t++)if((e=this.files[t]).fileObject&&!e.error&&!e.success)return!1;return!0},chunkOptions:function(){return Object.assign(f,this.chunk)},className:function(){return["file-uploads",this.features.html5?"file-uploads-html5":"file-uploads-html4",this.features.directory&&this.directory?"file-uploads-directory":void 0,this.features.drop&&this.drop?"file-uploads-drop":void 0,this.disabled?"file-uploads-disabled":void 0]},forId:function(){return this.inputId||this.name},iMaximum:function(){return void 0===this.maximum?this.multiple?0:1:this.maximum},iExtensions:function(){if(this.extensions){if(this.extensions instanceof RegExp)return this.extensions;if(this.extensions.length){var e=[];return e=(e="string"==typeof this.extensions?this.extensions.split(","):this.extensions).map(function(e){return e.trim()}).filter(function(e){return e}),new RegExp("\\.("+e.join("|").replace(/\./g,"\\.")+")$","i")}}}},watch:{active:function(e){this.watchActive(e)},dropActive:function(){this.$parent&&this.$parent.$forceUpdate()},drop:function(e){this.watchDrop(e)},modelValue:function(e){if(this.files!==e){this.files=e;var t=this.maps;this.maps={};for(var r,n,i=0;i<this.files.length;i++){var o=this.files[i];this.maps[o.id]=o}for(r in this.maps){var s=this.maps[r],a=t[r];s!==a&&this.emitFile(s,a)}for(n in t)this.maps[n]||this.emitFile(void 0,t[n])}}},methods:{newId:function(){return Math.random().toString(36).substr(2)},clear:function(){if(this.files.length){var e=this.files;this.files=[],this.maps={},this.emitInput();for(var t=0;t<e.length;t++)this.emitFile(void 0,e[t])}return!0},get:function(e){return!!e&&("object"===o(e)?this.maps[e.id||""]||!1:this.maps[e]||!1)},add:function(e,t){var r=e instanceof Array?e:[e];void 0===t&&(t=this.addIndex);for(var n,i=[],o=0;o<r.length;o++){var s=r[o];this.features.html5&&s instanceof Blob&&(s={id:"",file:s,size:s.size,name:s.webkitRelativePath||s.relativePath||s.name||"unknown",type:s.type});var a=!1;if(!1===s.fileObject||(s.fileObject||"undefined"!=typeof Element&&s.el instanceof HTMLInputElement||"undefined"!=typeof Blob&&s.file instanceof Blob)&&(a=!0),a&&((s=d(d({fileObject:!0,size:-1,name:"Filename",type:"",active:!1,error:"",success:!1,putAction:this.putAction,postAction:this.postAction,timeout:this.timeout},s),{},{response:{},progress:"0.00",speed:0})).data=d(d({},this.data),s.data||{}),s.headers=d(d({},this.headers),s.headers||{})),s.id||(s.id=this.newId()),!this.emitFilter(s,void 0)){if(1<this.iMaximum&&i.length+this.files.length>=this.iMaximum)break;if(i.push(s),1===this.iMaximum)break}}if(i.length){1===this.iMaximum&&this.clear(),!0===t||0===t?n=i.concat(this.files):t?(n=this.files.concat([])).splice.apply(n,[t,0].concat(i)):n=this.files.concat(i),this.files=n;for(var u=0;u<i.length;u++){var l=i[u];this.maps[l.id]=l}this.emitInput();for(var c=0;c<i.length;c++)this.emitFile(i[c],void 0);return e instanceof Array?i:i[0]}},addInputFile:function(e){var t=this,r=[],n=(this.iMaximum,e.webkitEntries||e.entries||void 0);if(null!=n&&n.length)return this.getFileSystemEntry(n).then(function(e){return t.add(e)});if(e.files)for(var i=0;i<e.files.length;i++){var o=e.files[i];r.push({id:"",size:o.size,name:o.webkitRelativePath||o.relativePath||o.name,type:o.type,file:o})}else{n=e.value.replace(/\\/g,"/").split("/");n&&n.length||(n=[e.value]),delete e.__vuex__,r.push({id:"",name:n[n.length-1],el:e})}return Promise.resolve(this.add(r))},addDataTransfer:function(e){var t,r=this;if(null!=e&&null!==(t=e.items)&&void 0!==t&&t.length){for(var n=[],i=0;i<e.items.length;i++){var o=e.items[i],s=void 0;(s=o.getAsEntry?o.getAsEntry()||o.getAsFile():o.webkitGetAsEntry&&o.webkitGetAsEntry()||o.getAsFile())&&n.push(s)}return this.getFileSystemEntry(n).then(function(e){return r.add(e)})}var a=this.iMaximum,u=[];if(e.files.length){for(var l=0;l<e.files.length&&(u.push(e.files[l]),!(0<a&&u.length>=a));l++);return Promise.resolve(this.add(u))}return Promise.resolve([])},getFileSystemEntry:function(a){var u=this,l=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return new Promise(function(i){var n,o,e,s=u.iMaximum;a?a instanceof Array?(n=[],function t(r){var e=a[r];if(!e||0<s&&n.length>=s)return i(n);u.getFileSystemEntry(e,l).then(function(e){n.push.apply(n,c(e)),t(r+1)})}(0)):a instanceof Blob?i([{id:"",size:a.size,name:l+a.name,type:a.type,file:a}]):a.isFile?a.file(function(e){i([{id:"",size:e.size,name:l+e.name,type:e.type,file:e}])}):a.isDirectory&&u.dropDirectory?(o=[],u.createDirectory&&o.push({id:"",name:l+a.name,size:0,type:"text/directory",file:new File([],l+a.name,{type:"text/directory"})}),e=a.createReader(),function n(){e.readEntries(function(e){(function t(r){return!e[r]&&0===r||0<s&&o.length>=s?i(o):e[r]?void u.getFileSystemEntry(e[r],l+a.name+"/").then(function(e){o.push.apply(o,c(e)),t(r+1)}):n()})(0)})}()):i([]):i([])})},replace:function(e,t){var r=this.get(e),n=this.get(t);if(!r||!n||r===n)return!1;var i=this.files.concat([]),e=i.indexOf(r),t=i.indexOf(n);return-1!==e&&-1!==t&&(i[e]=n,i[t]=r,this.files=i,this.emitInput(),!0)},remove:function(e){var t=this.get(e);if(t){if(this.emitFilter(void 0,t))return!1;var r=this.files.concat([]),e=r.indexOf(t);if(-1===e)return console.error("remove",t),!1;r.splice(e,1),this.files=r,delete this.maps[t.id],this.emitInput(),this.emitFile(void 0,t)}return t},update:function(e,t){var r=this.get(e);if(r){var n=d(d({},r),t);if(!r.fileObject||!r.active||n.active||n.error||n.success||(n.error="abort"),this.emitFilter(n,r))return!1;e=this.files.concat([]),t=e.indexOf(r);return-1===t?(console.error("update",r),!1):(e.splice(t,1,n),this.files=e,delete this.maps[r.id],this.maps[n.id]=n,this.emitInput(),this.emitFile(n,r),n)}return!1},emitFilter:function(e,t){var r=!1;return this.$emit("input-filter",e,t,function(){return r=!(0<arguments.length&&void 0!==arguments[0])||arguments[0]}),r},emitFile:function(t,e){var r=this;this.$emit("input-file",t,e),null==t||!t.fileObject||!t.active||e&&e.active?t&&t.fileObject&&t.active||!e||!e.fileObject||!e.active||this.uploading--:(this.uploading++,this.$nextTick(function(){setTimeout(function(){t&&r.upload(t).then(function(){null!==(t=t&&(r.get(t)||void 0))&&void 0!==t&&t.fileObject&&r.update(t,{active:!1,success:!t.error})}).catch(function(e){t&&r.update(t,{active:!1,success:!1,error:e.code||e.error||e.message||e})})},Math.ceil(50*Math.random()+50))})),!this.active||Boolean(t)===Boolean(e)&&t.active===e.active||this.watchActive(!0)},emitInput:function(){this.$emit("update:modelValue",this.files)},upload:function(e){e=this.get(e);if(!e)return Promise.reject(new Error("not_exists"));if(!e.fileObject)return Promise.reject(new Error("file_object"));if(e.error)return e.error instanceof Error?Promise.reject(e.error):Promise.reject(new Error(e.error));if(e.success)return Promise.resolve(e);if(e.name&&this.iExtensions&&-1===e.name.search(this.iExtensions))return Promise.reject(new Error("extension"));if(0<this.size&&void 0!==e.size&&0<=e.size&&e.size>this.size)return Promise.reject(new Error("size"));if(this.customAction)return this.customAction(e,this);if(this.features.html5){if(this.shouldUseChunkUpload(e))return this.uploadChunk(e);if(e.putAction)return this.uploadPut(e);if(e.postAction)return this.uploadHtml5(e)}return e.postAction?this.uploadHtml4(e):Promise.reject(new Error("No action configured"))},shouldUseChunkUpload:function(e){return this.chunkEnabled&&!!this.chunkOptions.handler&&e.size&&e.size>this.chunkOptions.minSize},uploadChunk:function(t){var e=this.chunkOptions.handler;return t.chunk=new e(t,this.chunkOptions),t.chunk.upload().then(function(e){return t})},uploadPut:function(e){var t,r,n=[];for(r in e.data)null!=(t=e.data[r])&&n.push(encodeURIComponent(r)+"="+encodeURIComponent(t));var i=e.putAction||"",o=n.length?(-1===i.indexOf("?")?"?":"&")+n.join("&"):"",s=new XMLHttpRequest;return s.open("PUT",i+o),this.uploadXhr(s,e,e.file)},uploadHtml5:function(e){var t,r,n=new window.FormData;for(r in e.data)(t=e.data[r])&&"object"===o(t)&&"function"!=typeof t.toString?t instanceof File?n.append(r,t,t.name):n.append(r,JSON.stringify(t)):null!=t&&n.append(r,t);n.append(this.name,e.file,e.file.name||e.file.filename||e.name);var i=new XMLHttpRequest;return i.open("POST",e.postAction||""),this.uploadXhr(i,e,n)},uploadXhr:function(s,e,r){var a=this,u=e,n=0,i=0;s.upload.onprogress=function(e){var t;u&&(u=a.get(u),e.lengthComputable&&u&&u.fileObject&&u.active&&((t=Math.round(Date.now()/1e3))!==n&&(n=t,u=a.update(u,{progress:(e.loaded/e.total*100).toFixed(2),speed:e.loaded-i}),i=e.loaded)))};var l=window.setInterval(function(){if(u&&((u=a.get(u))&&null!==u&&void 0!==u&&u.fileObject&&!u.success&&!u.error&&u.active))return;l&&(clearInterval(l),l=void 0);try{s.abort(),s.timeout=1}catch(e){}},100);return new Promise(function(n,i){if(u){var o,e,t=function(e){if(!o){if(o=!0,l&&(clearInterval(l),l=void 0),!u)return i(new Error("not_exists"));if(!(u=a.get(u)))return i(new Error("not_exists"));if(!u.fileObject)return i(new Error("file_object"));if(u.error)return u.error instanceof Error?i(u.error):i(new Error(u.error));if(!u.active)return i(new Error("abort"));if(u.success)return n(u);var t,r={};switch(e.type){case"timeout":case"abort":r.error=e.type;break;case"error":s.status?500<=s.status?r.error="server":400<=s.status&&(r.error="denied"):r.error="network";break;default:500<=s.status?r.error="server":400<=s.status?r.error="denied":r.progress="100.00"}return s.responseText&&((t=s.getResponseHeader("Content-Type"))&&-1!==t.indexOf("/json")?r.response=JSON.parse(s.responseText):r.response=s.responseText),(u=a.update(u,r))?u.error?u.error instanceof Error?i(u.error):i(new Error(u.error)):n(u):i(new Error("abort"))}};for(e in s.onload=t,s.onerror=t,s.onabort=t,s.ontimeout=t,u.timeout&&(s.timeout=u.timeout),u.headers)s.setRequestHeader(e,u.headers[e]);(u=a.update(u,{xhr:s}))&&s.send(r)}else i(new Error("not_exists"))})},uploadHtml4:function(e){var a=this,u=e;if(!u)return Promise.reject(new Error("not_exists"));function l(e){27===e.keyCode&&e.preventDefault()}var c=document.createElement("iframe");c.id="upload-iframe-"+u.id,c.name="upload-iframe-"+u.id,c.src="about:blank",c.setAttribute("style","width:1px;height:1px;top:-999em;position:absolute; margin-top:-999em;");var t,r=document.createElement("form");for(t in r.setAttribute("action",u.postAction||""),r.name="upload-form-"+u.id,r.setAttribute("method","POST"),r.setAttribute("target","upload-iframe-"+u.id),r.setAttribute("enctype","multipart/form-data"),u.data){var n,i=u.data[t];i&&"object"===o(i)&&"function"!=typeof i.toString&&(i=JSON.stringify(i)),null!=i&&((n=document.createElement("input")).type="hidden",n.name=t,n.value=i,r.appendChild(n))}r.appendChild(u.el),document.body.appendChild(c).appendChild(r);return new Promise(function(o,s){setTimeout(function(){if(u){if(!(u=a.update(u,{iframe:c})))return s(new Error("not_exists"));var n,i=window.setInterval(function(){(u=u&&a.get(u))&&u.fileObject&&!u.success&&!u.error&&u.active||(i&&(clearInterval(i),i=void 0),c.onabort({type:u?"abort":"not_exists"}))},100),e=function(e){if(!n){if(n=!0,i&&(clearInterval(i),i=void 0),document.body.removeEventListener("keydown",l),!u)return s(new Error("not_exists"));if(!(u=a.get(u)))return s(new Error("not_exists"));if(!u.fileObject)return s(new Error("file_object"));if(u.error)return u.error instanceof Error?s(u.error):s(new Error(u.error));if(!u.active)return s(new Error("abort"));if(u.success)return o(u);var t=function(){var t;try{c.contentWindow&&(t=c.contentWindow.document)}catch(e){}if(!t)try{t=c.contentDocument||c.document}catch(e){t=c.document}return null!==t&&void 0!==t&&t.body?t.body.innerHTML:null}(),r={};if("string"==typeof e)return s(new Error(e));switch(e.type){case"abort":r.error="abort";break;case"error":u.error?r.error=u.error:r.error=null===t?"network":"denied";break;default:u.error?r.error=u.error:null===t?r.error="network":r.progress="100.00"}if(null!==t){if(t&&"{"===t.substr(0,1)&&"}"===t.substr(t.length-1,1))try{t=JSON.parse(t)}catch(e){}r.response=t}return(u=a.update(u,r))?null!==u&&void 0!==u&&u.error?u.error instanceof Error?s(u.error):s(new Error(u.error)):o(u):s(new Error("not_exists"))}};c.onload=e,c.onerror=e,c.onabort=e,document.body.addEventListener("keydown",l),r.submit()}else s(new Error("not_exists"))},50)}).then(function(e){var t;return null==c||null!==(t=c.parentNode)&&void 0!==t&&t.removeChild(c),e}).catch(function(e){var t;return null==c||null!==(t=c.parentNode)&&void 0!==t&&t.removeChild(c),e})},watchActive:function(e){for(var t,r=0;t=this.files[r];)if(r++,t.fileObject)if(e&&!this.destroy){if(this.uploading>=this.thread||this.uploading&&!this.features.html5)break;t.active||t.error||t.success||this.update(t,{active:!0})}else t.active&&this.update(t,{active:!1});else;0===this.uploading&&(this.active=!1)},watchDrop:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:void 0;if(this.features.drop&&e!==t){if(this.dropElement)try{document.removeEventListener("dragenter",this.onDragenter,!1),document.removeEventListener("dragleave",this.onDragleave,!1),document.removeEventListener("drop",this.onDocumentDrop,!1),this.dropElement.removeEventListener("dragover",this.onDragover,!1),this.dropElement.removeEventListener("drop",this.onDrop,!1)}catch(e){}t=null;e&&(t="string"==typeof e?document.querySelector(e)||this.$root.$el.querySelector(e):!0===e?this.$parent.$el:e),this.dropElement=t,this.dropElement&&(document.addEventListener("dragenter",this.onDragenter,!1),document.addEventListener("dragleave",this.onDragleave,!1),document.addEventListener("drop",this.onDocumentDrop,!1),this.dropElement.addEventListener("dragover",this.onDragover,!1),this.dropElement.addEventListener("drop",this.onDrop,!1))}},onDragenter:function(e){var t;e.preventDefault(),this.dropActive||!e.dataTransfer||(null!=(e=e.dataTransfer)&&null!==(t=e.files)&&void 0!==t&&t.length||!e.types||e.types.indexOf&&-1!==e.types.indexOf("Files")||null!==(t=e.types)&&void 0!==t&&t.contains&&e.types.contains("Files"))&&(this.dropActive=!0)},onDragleave:function(e){e.preventDefault(),this.dropActive&&("HTML"===e.target.nodeName||e.target===e.explicitOriginalTarget||!e.fromElement&&(e.clientX<=0||e.clientY<=0||e.clientX>=window.innerWidth||e.clientY>=window.innerHeight))&&(this.dropActive=!1)},onDragover:function(e){e.preventDefault()},onDocumentDrop:function(){this.dropActive=!1},onDrop:function(e){e.preventDefault(),e.dataTransfer&&this.addDataTransfer(e.dataTransfer)},inputOnChange:async function(e){var t=this;if(!(e.target instanceof HTMLInputElement))return Promise.reject(new Error("not HTMLInputElement"));function r(e){return t.reload=!0,t.$nextTick(function(){t.reload=!1}),e}e.target;return this.addInputFile(e.target).then(r).catch(r)}}}),function(e,t){void 0===t&&(t={});var r,n=t.insertAt;e&&"undefined"!=typeof document&&(r=document.head||document.getElementsByTagName("head")[0],(t=document.createElement("style")).type="text/css","top"===n&&r.firstChild?r.insertBefore(t,r.firstChild):r.appendChild(t),t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e)))}("\n.file-uploads {\n overflow: hidden;\n position: relative;\n text-align: center;\n display: inline-block;\n}\n.file-uploads.file-uploads-html4 input, .file-uploads.file-uploads-html5 label {\n /* background fix ie click */\n background: #fff;\n opacity: 0;\n font-size: 20em;\n z-index: 1;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n}\n.file-uploads.file-uploads-html5 input, .file-uploads.file-uploads-html4 label {\n /* background fix ie click */\n background: rgba(255, 255, 255, 0);\n overflow: hidden;\n position: fixed;\n width: 1px;\n height: 1px;\n z-index: -1;\n opacity: 0;\n}\n"),e.render=function(e,t,r,n,i,o){return u.openBlock(),u.createBlock("span",{class:e.className},[u.renderSlot(e.$slots,"default"),u.createVNode("label",{for:e.forId},null,8,["for"]),e.reload?u.createCommentVNode("",!0):(u.openBlock(),u.createBlock("input",{key:0,ref:"input",type:"file",name:e.name,id:e.forId,accept:e.accept,capture:e.capture,disabled:e.disabled,webkitdirectory:e.directory&&e.features.directory,allowdirs:e.directory&&e.features.directory,directory:e.directory&&e.features.directory,multiple:e.multiple&&e.features.html5,onChange:t[1]||(t[1]=function(){return e.inputOnChange&&e.inputOnChange.apply(e,arguments)})},null,40,["name","id","accept","capture","disabled","webkitdirectory","allowdirs","directory","multiple"]))],2)},e)}(r={exports:{}}),r.exports}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("vue")):"function"==typeof define&&define.amd?define(["vue"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).VueUploadComponent=t(e.Vue)}(this,function(e){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r,h=t(e);return function(e){function c(e){return function(e){if(Array.isArray(e))return n(e)}(e)||function(e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(e))return Array.from(e)}(e)||function(e,t){if(!e)return;if("string"==typeof e)return n(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(e,t)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function n(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function t(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function d(n){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?t(Object(i),!0).forEach(function(e){var t,r;t=n,e=i[r=e],r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):t(Object(i)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})}return n}function o(e){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function i(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function r(t,e){var r,n=Object.keys(t);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(t),e&&(r=r.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),n.push.apply(n,r)),n}function s(n){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?r(Object(i),!0).forEach(function(e){var t,r;t=n,e=i[r=e],r in t?Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}):t[r]=e}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))})}return n}function a(e){var n,t,r=l(e);return n=r,t=e.body,new Promise(function(e,r){n.onload=function(){if(200<=n.status&&n.status<300){var t;try{t=JSON.parse(n.response)}catch(e){t=n.response}e(t)}else r(n.response)},n.onerror=function(){return r(n.response)},n.send(JSON.stringify(t))})}var u,l,f;e.exports=(u=h.default,l=function(t){var r=new XMLHttpRequest;return r.open(t.method||"GET",t.url),r.responseType="json",t.headers&&Object.keys(t.headers).forEach(function(e){r.setRequestHeader(e,t.headers[e])}),r},f={headers:{},action:"",minSize:1048576,maxActive:3,maxRetries:5,handler:function(){function r(e,t){!function(e){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}(this),this.file=e,this.options=t,this.chunks=[],this.sessionId=null,this.chunkSize=null,this.speedInterval=null}var e,t,n;return e=r,(t=[{key:"createChunks",value:function(){this.chunks=[];for(var e=0,t=this.chunkSize;e<this.fileSize;)this.chunks.push({blob:this.file.file.slice(e,t),startOffset:e,active:!1,retries:this.maxRetries}),t=(e=t)+this.chunkSize}},{key:"updateFileProgress",value:function(){this.file.progress=this.progress}},{key:"pause",value:function(){this.file.active=!1,this.stopChunks()}},{key:"stopChunks",value:function(){this.chunksUploading.forEach(function(e){e.xhr.abort(),e.active=!1}),this.stopSpeedCalc()}},{key:"resume",value:function(){this.file.active=!0,this.startChunking()}},{key:"upload",value:function(){var r=this;return this.promise=new Promise(function(e,t){r.resolve=e,r.reject=t}),this.start(),this.promise}},{key:"start",value:function(){var t=this;a({method:"POST",headers:s(s({},this.headers),{},{"Content-Type":"application/json"}),url:this.action,body:Object.assign(this.startBody,{phase:"start",mime_type:this.fileType,size:this.fileSize,name:this.fileName})}).then(function(e){return"success"!==e.status?(t.file.response=e,t.reject("server")):(t.sessionId=e.data.session_id,t.chunkSize=e.data.end_offset,t.createChunks(),void t.startChunking())}).catch(function(e){t.file.response=e,t.reject("server")})}},{key:"startChunking",value:function(){for(var e=0;e<this.maxActiveChunks;e++)this.uploadNextChunk();this.startSpeedCalc()}},{key:"uploadNextChunk",value:function(){if(this.file.active)return this.hasChunksToUpload?this.uploadChunk(this.chunksToUpload[0]):0===this.chunksUploading.length?this.finish():void 0}},{key:"uploadChunk",value:function(t){var r=this;t.progress=0,t.active=!0,this.updateFileProgress(),t.xhr=l({method:"POST",headers:this.headers,url:this.action}),t.xhr.upload.addEventListener("progress",function(e){e.lengthComputable&&(t.progress=Math.round(e.loaded/e.total*100))},!1),function(n,e){var t,i=new FormData;for(t in e)i.append(t,e[t]);return new Promise(function(e,r){n.onload=function(){if(200<=n.status&&n.status<300){var t;try{t=JSON.parse(n.response)}catch(e){t=n.response}e(t)}else r(n.response)},n.onerror=function(){return r(n.response)},n.send(i)})}(t.xhr,Object.assign(this.uploadBody,{phase:"upload",session_id:this.sessionId,start_offset:t.startOffset,chunk:t.blob})).then(function(e){if(t.active=!1,"success"===e.status)t.uploaded=!0;else if(t.retries--<=0)return r.stopChunks(),r.reject("upload");r.uploadNextChunk()}).catch(function(){return t.active=!1,t.retries--<=0?(r.stopChunks(),r.reject("upload")):void r.uploadNextChunk()})}},{key:"finish",value:function(){var t=this;this.updateFileProgress(),this.stopSpeedCalc(),a({method:"POST",headers:s(s({},this.headers),{},{"Content-Type":"application/json"}),url:this.action,body:Object.assign(this.finishBody,{phase:"finish",session_id:this.sessionId})}).then(function(e){return"success"!==(t.file.response=e).status?t.reject("server"):void t.resolve(e)}).catch(function(e){t.file.response=e,t.reject("server")})}},{key:"startSpeedCalc",value:function(){var t=this,r=this.file.speed=0;this.speedInterval||(this.speedInterval=window.setInterval(function(){var e=t.progress/100*t.fileSize;t.file.speed=e-r,r=e},1e3))}},{key:"stopSpeedCalc",value:function(){this.speedInterval&&window.clearInterval(this.speedInterval),this.speedInterval=null,this.file.speed=0}},{key:"maxRetries",get:function(){return parseInt(this.options.maxRetries,10)}},{key:"maxActiveChunks",get:function(){return parseInt(this.options.maxActive,10)}},{key:"fileType",get:function(){return this.file.type}},{key:"fileSize",get:function(){return this.file.size}},{key:"fileName",get:function(){return this.file.name}},{key:"action",get:function(){return this.options.action||null}},{key:"startBody",get:function(){return this.options.startBody||{}}},{key:"uploadBody",get:function(){return this.options.uploadBody||{}}},{key:"finishBody",get:function(){return this.options.finishBody||{}}},{key:"headers",get:function(){return this.options.headers||{}}},{key:"readyToUpload",get:function(){return!!this.chunks}},{key:"progress",get:function(){var r=this,e=this.chunksUploaded.length/this.chunks.length*100,t=this.chunksUploading.reduce(function(e,t){return e+(0|t.progress)/r.chunks.length},0);return Math.min(e+t,100)}},{key:"chunksToUpload",get:function(){return this.chunks.filter(function(e){return!e.active&&!e.uploaded})}},{key:"hasChunksToUpload",get:function(){return 0<this.chunksToUpload.length}},{key:"chunksUploading",get:function(){return this.chunks.filter(function(e){return!!e.xhr&&!!e.active})}},{key:"chunksUploaded",get:function(){return this.chunks.filter(function(e){return!!e.uploaded})}}])&&i(e.prototype,t),n&&i(e,n),r}()},e=u.defineComponent({props:{inputId:{type:String},name:{type:String,default:"file"},accept:{type:String},capture:{},disabled:{default:!1},multiple:{type:Boolean,default:!1},maximum:{type:Number},addIndex:{type:[Boolean,Number]},directory:{type:Boolean},createDirectory:{type:Boolean,default:!1},postAction:{type:String},putAction:{type:String},customAction:{type:Function},headers:{type:Object,default:function(){return{}}},data:{type:Object,default:function(){return{}}},timeout:{type:Number,default:0},drop:{default:!1},dropDirectory:{type:Boolean,default:!0},size:{type:Number,default:0},extensions:{type:[RegExp,String,Array],default:function(){return[]}},modelValue:{type:Array,default:function(){return[]}},thread:{type:Number,default:1},chunkEnabled:{type:Boolean,default:!1},chunk:{type:Object,default:function(){return f}}},emits:["update:modelValue","input-filter","input-file"],data:function(){return{files:this.modelValue,features:{html5:!0,directory:!1,drop:!1},active:!1,dropActive:!1,uploading:0,destroy:!1,maps:{},dropElement:null,reload:!1}},mounted:function(){var e=this,t=document.createElement("input");if(t.type="file",t.multiple=!0,window.FormData&&t.files?("boolean"!=typeof t.webkitdirectory&&"boolean"!=typeof t.directory||(this.features.directory=!0),this.features.html5&&void 0!==t.ondrop&&(this.features.drop=!0)):this.features.html5=!1,this.maps={},this.files)for(var r=0;r<this.files.length;r++){var n=this.files[r];this.maps[n.id]=n}this.$nextTick(function(){e.$parent?(e.$parent.$forceUpdate(),e.$parent.$nextTick(function(){e.watchDrop(e.drop)})):e.watchDrop(e.drop)})},beforeUnmount:function(){this.destroy=!0,this.active=!1,this.watchDrop(!1),this.watchActive(!1)},computed:{uploaded:function(){for(var e,t=0;t<this.files.length;t++)if((e=this.files[t]).fileObject&&!e.error&&!e.success)return!1;return!0},chunkOptions:function(){return Object.assign(f,this.chunk)},className:function(){return["file-uploads",this.features.html5?"file-uploads-html5":"file-uploads-html4",this.features.directory&&this.directory?"file-uploads-directory":void 0,this.features.drop&&this.drop?"file-uploads-drop":void 0,this.disabled?"file-uploads-disabled":void 0]},forId:function(){return this.inputId||this.name},iMaximum:function(){return void 0===this.maximum?this.multiple?0:1:this.maximum},iExtensions:function(){if(this.extensions){if(this.extensions instanceof RegExp)return this.extensions;if(this.extensions.length){var e=[];return e=(e="string"==typeof this.extensions?this.extensions.split(","):this.extensions).map(function(e){return e.trim()}).filter(function(e){return e}),new RegExp("\\.("+e.join("|").replace(/\./g,"\\.")+")$","i")}}}},watch:{active:function(e){this.watchActive(e)},dropActive:function(){this.$parent&&this.$parent.$forceUpdate()},drop:function(e){this.watchDrop(e)},modelValue:function(e){if(this.files!==e){this.files=e;var t=this.maps;this.maps={};for(var r,n,i=0;i<this.files.length;i++){var o=this.files[i];this.maps[o.id]=o}for(r in this.maps){var s=this.maps[r],a=t[r];s!==a&&this.emitFile(s,a)}for(n in t)this.maps[n]||this.emitFile(void 0,t[n])}}},methods:{newId:function(){return Math.random().toString(36).substr(2)},clear:function(){if(this.files.length){var e=this.files;this.files=[],this.maps={},this.emitInput();for(var t=0;t<e.length;t++)this.emitFile(void 0,e[t])}return!0},get:function(e){return!!e&&("object"===o(e)?this.maps[e.id||""]||!1:this.maps[e]||!1)},add:function(e,t){var r=e instanceof Array?e:[e];void 0===t&&(t=this.addIndex);for(var n,i=[],o=0;o<r.length;o++){var s=r[o];this.features.html5&&s instanceof Blob&&(s={id:"",file:s,size:s.size,name:s.webkitRelativePath||s.relativePath||s.name||"unknown",type:s.type});var a=!1;if(!1===s.fileObject||(s.fileObject||"undefined"!=typeof Element&&s.el instanceof HTMLInputElement||"undefined"!=typeof Blob&&s.file instanceof Blob)&&(a=!0),a&&((s=d(d({fileObject:!0,size:-1,name:"Filename",type:"",active:!1,error:"",success:!1,putAction:this.putAction,postAction:this.postAction,timeout:this.timeout},s),{},{response:{},progress:"0.00",speed:0})).data=d(d({},this.data),s.data||{}),s.headers=d(d({},this.headers),s.headers||{})),s.id||(s.id=this.newId()),!this.emitFilter(s,void 0)){if(1<this.iMaximum&&i.length+this.files.length>=this.iMaximum)break;if(i.push(s),1===this.iMaximum)break}}if(i.length){1===this.iMaximum&&this.clear(),!0===t||0===t?n=i.concat(this.files):t?(n=this.files.concat([])).splice.apply(n,[t,0].concat(i)):n=this.files.concat(i),this.files=n;for(var u=0;u<i.length;u++){var l=i[u];this.maps[l.id]=l}this.emitInput();for(var c=0;c<i.length;c++)this.emitFile(i[c],void 0);return e instanceof Array?i:i[0]}},addInputFile:function(e){var t=this,r=[],n=(this.iMaximum,e.webkitEntries||e.entries||void 0);if(null!=n&&n.length)return this.getFileSystemEntry(n).then(function(e){return t.add(e)});if(e.files)for(var i=0;i<e.files.length;i++){var o=e.files[i];r.push({id:"",size:o.size,name:o.webkitRelativePath||o.relativePath||o.name,type:o.type,file:o})}else{n=e.value.replace(/\\/g,"/").split("/");n&&n.length||(n=[e.value]),delete e.__vuex__,r.push({id:"",name:n[n.length-1],el:e})}return Promise.resolve(this.add(r))},addDataTransfer:function(e){var t,r=this;if(null!=e&&null!==(t=e.items)&&void 0!==t&&t.length){for(var n=[],i=0;i<e.items.length;i++){var o=e.items[i],s=void 0;(s=o.getAsEntry?o.getAsEntry()||o.getAsFile():o.webkitGetAsEntry&&o.webkitGetAsEntry()||o.getAsFile())&&n.push(s)}return this.getFileSystemEntry(n).then(function(e){return r.add(e)})}var a=this.iMaximum,u=[];if(e.files.length){for(var l=0;l<e.files.length&&(u.push(e.files[l]),!(0<a&&u.length>=a));l++);return Promise.resolve(this.add(u))}return Promise.resolve([])},getFileSystemEntry:function(a){var u=this,l=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"";return new Promise(function(i){var n,o,e,s=u.iMaximum;a?a instanceof Array?(n=[],function t(r){var e=a[r];if(!e||0<s&&n.length>=s)return i(n);u.getFileSystemEntry(e,l).then(function(e){n.push.apply(n,c(e)),t(r+1)})}(0)):a instanceof Blob?i([{id:"",size:a.size,name:l+a.name,type:a.type,file:a}]):a.isFile?a.file(function(e){i([{id:"",size:e.size,name:l+e.name,type:e.type,file:e}])}):a.isDirectory&&u.dropDirectory?(o=[],u.createDirectory&&o.push({id:"",name:l+a.name,size:0,type:"text/directory",file:new File([],l+a.name,{type:"text/directory"})}),e=a.createReader(),function n(){e.readEntries(function(e){(function t(r){return!e[r]&&0===r||0<s&&o.length>=s?i(o):e[r]?void u.getFileSystemEntry(e[r],l+a.name+"/").then(function(e){o.push.apply(o,c(e)),t(r+1)}):n()})(0)})}()):i([]):i([])})},replace:function(e,t){var r=this.get(e),n=this.get(t);if(!r||!n||r===n)return!1;var i=this.files.concat([]),e=i.indexOf(r),t=i.indexOf(n);return-1!==e&&-1!==t&&(i[e]=n,i[t]=r,this.files=i,this.emitInput(),!0)},remove:function(e){var t=this.get(e);if(t){if(this.emitFilter(void 0,t))return!1;var r=this.files.concat([]),e=r.indexOf(t);if(-1===e)return console.error("remove",t),!1;r.splice(e,1),this.files=r,delete this.maps[t.id],this.emitInput(),this.emitFile(void 0,t)}return t},update:function(e,t){var r=this.get(e);if(r){var n=d(d({},r),t);if(!r.fileObject||!r.active||n.active||n.error||n.success||(n.error="abort"),this.emitFilter(n,r))return!1;e=this.files.concat([]),t=e.indexOf(r);return-1===t?(console.error("update",r),!1):(e.splice(t,1,n),this.files=e,delete this.maps[r.id],this.maps[n.id]=n,this.emitInput(),this.emitFile(n,r),n)}return!1},emitFilter:function(e,t){var r=!1;return this.$emit("input-filter",e,t,function(){return r=!(0<arguments.length&&void 0!==arguments[0])||arguments[0]}),r},emitFile:function(t,e){var r=this;this.$emit("input-file",t,e),null==t||!t.fileObject||!t.active||e&&e.active?t&&t.fileObject&&t.active||!e||!e.fileObject||!e.active||this.uploading--:(this.uploading++,this.$nextTick(function(){setTimeout(function(){t&&r.upload(t).then(function(){null!==(t=t&&(r.get(t)||void 0))&&void 0!==t&&t.fileObject&&r.update(t,{active:!1,success:!t.error})}).catch(function(e){t&&r.update(t,{active:!1,success:!1,error:e.code||e.error||e.message||e})})},Math.ceil(50*Math.random()+50))})),!this.active||Boolean(t)===Boolean(e)&&t.active===e.active||this.watchActive(!0)},emitInput:function(){this.$emit("update:modelValue",this.files)},upload:function(e){e=this.get(e);if(!e)return Promise.reject(new Error("not_exists"));if(!e.fileObject)return Promise.reject(new Error("file_object"));if(e.error)return e.error instanceof Error?Promise.reject(e.error):Promise.reject(new Error(e.error));if(e.success)return Promise.resolve(e);if(e.name&&this.iExtensions&&-1===e.name.search(this.iExtensions))return Promise.reject(new Error("extension"));if(0<this.size&&void 0!==e.size&&0<=e.size&&e.size>this.size)return Promise.reject(new Error("size"));if(this.customAction)return this.customAction(e,this);if(this.features.html5){if(this.shouldUseChunkUpload(e))return this.uploadChunk(e);if(e.putAction)return this.uploadPut(e);if(e.postAction)return this.uploadHtml5(e)}return e.postAction?this.uploadHtml4(e):Promise.reject(new Error("No action configured"))},shouldUseChunkUpload:function(e){return this.chunkEnabled&&!!this.chunkOptions.handler&&e.size&&e.size>this.chunkOptions.minSize},uploadChunk:function(t){var e=this.chunkOptions.handler;return t.chunk=new e(t,this.chunkOptions),t.chunk.upload().then(function(e){return t})},uploadPut:function(e){var t,r,n=[];for(r in e.data)null!=(t=e.data[r])&&n.push(encodeURIComponent(r)+"="+encodeURIComponent(t));var i=e.putAction||"",o=n.length?(-1===i.indexOf("?")?"?":"&")+n.join("&"):"",s=new XMLHttpRequest;return s.open("PUT",i+o),this.uploadXhr(s,e,e.file)},uploadHtml5:function(e){var t,r,n=new window.FormData;for(r in e.data)(t=e.data[r])&&"object"===o(t)&&"function"!=typeof t.toString?t instanceof File?n.append(r,t,t.name):n.append(r,JSON.stringify(t)):null!=t&&n.append(r,t);n.append(this.name,e.file,e.file.name||e.file.filename||e.name);var i=new XMLHttpRequest;return i.open("POST",e.postAction||""),this.uploadXhr(i,e,n)},uploadXhr:function(s,e,r){var a=this,u=e,n=0,i=0;s.upload.onprogress=function(e){var t;u&&(u=a.get(u),e.lengthComputable&&u&&u.fileObject&&u.active&&((t=Math.round(Date.now()/1e3))!==n&&(n=t,u=a.update(u,{progress:(e.loaded/e.total*100).toFixed(2),speed:e.loaded-i}),i=e.loaded)))};var l=window.setInterval(function(){if(u&&((u=a.get(u))&&null!==u&&void 0!==u&&u.fileObject&&!u.success&&!u.error&&u.active))return;l&&(clearInterval(l),l=void 0);try{s.abort(),s.timeout=1}catch(e){}},100);return new Promise(function(n,i){if(u){var o,e,t=function(e){if(!o){if(o=!0,l&&(clearInterval(l),l=void 0),!u)return i(new Error("not_exists"));if(!(u=a.get(u)))return i(new Error("not_exists"));if(!u.fileObject)return i(new Error("file_object"));if(u.error)return u.error instanceof Error?i(u.error):i(new Error(u.error));if(!u.active)return i(new Error("abort"));if(u.success)return n(u);var t,r={};switch(e.type){case"timeout":case"abort":r.error=e.type;break;case"error":s.status?500<=s.status?r.error="server":400<=s.status&&(r.error="denied"):r.error="network";break;default:500<=s.status?r.error="server":400<=s.status?r.error="denied":r.progress="100.00"}return s.responseText&&((t=s.getResponseHeader("Content-Type"))&&-1!==t.indexOf("/json")?r.response=JSON.parse(s.responseText):r.response=s.responseText),(u=a.update(u,r))?u.error?u.error instanceof Error?i(u.error):i(new Error(u.error)):n(u):i(new Error("abort"))}};for(e in s.onload=t,s.onerror=t,s.onabort=t,s.ontimeout=t,u.timeout&&(s.timeout=u.timeout),u.headers)s.setRequestHeader(e,u.headers[e]);(u=a.update(u,{xhr:s}))&&s.send(r)}else i(new Error("not_exists"))})},uploadHtml4:function(e){var a=this,u=e;if(!u)return Promise.reject(new Error("not_exists"));function l(e){27===e.keyCode&&e.preventDefault()}var c=document.createElement("iframe");c.id="upload-iframe-"+u.id,c.name="upload-iframe-"+u.id,c.src="about:blank",c.setAttribute("style","width:1px;height:1px;top:-999em;position:absolute; margin-top:-999em;");var t,r=document.createElement("form");for(t in r.setAttribute("action",u.postAction||""),r.name="upload-form-"+u.id,r.setAttribute("method","POST"),r.setAttribute("target","upload-iframe-"+u.id),r.setAttribute("enctype","multipart/form-data"),u.data){var n,i=u.data[t];i&&"object"===o(i)&&"function"!=typeof i.toString&&(i=JSON.stringify(i)),null!=i&&((n=document.createElement("input")).type="hidden",n.name=t,n.value=i,r.appendChild(n))}r.appendChild(u.el),document.body.appendChild(c).appendChild(r);return new Promise(function(o,s){setTimeout(function(){if(u){if(!(u=a.update(u,{iframe:c})))return s(new Error("not_exists"));var n,i=window.setInterval(function(){(u=u&&a.get(u))&&u.fileObject&&!u.success&&!u.error&&u.active||(i&&(clearInterval(i),i=void 0),c.onabort({type:u?"abort":"not_exists"}))},100),e=function(e){if(!n){if(n=!0,i&&(clearInterval(i),i=void 0),document.body.removeEventListener("keydown",l),!u)return s(new Error("not_exists"));if(!(u=a.get(u)))return s(new Error("not_exists"));if(!u.fileObject)return s(new Error("file_object"));if(u.error)return u.error instanceof Error?s(u.error):s(new Error(u.error));if(!u.active)return s(new Error("abort"));if(u.success)return o(u);var t=function(){var t;try{c.contentWindow&&(t=c.contentWindow.document)}catch(e){}if(!t)try{t=c.contentDocument||c.document}catch(e){t=c.document}return null!==t&&void 0!==t&&t.body?t.body.innerHTML:null}(),r={};if("string"==typeof e)return s(new Error(e));switch(e.type){case"abort":r.error="abort";break;case"error":u.error?r.error=u.error:r.error=null===t?"network":"denied";break;default:u.error?r.error=u.error:null===t?r.error="network":r.progress="100.00"}if(null!==t){if(t&&"{"===t.substr(0,1)&&"}"===t.substr(t.length-1,1))try{t=JSON.parse(t)}catch(e){}r.response=t}return(u=a.update(u,r))?null!==u&&void 0!==u&&u.error?u.error instanceof Error?s(u.error):s(new Error(u.error)):o(u):s(new Error("not_exists"))}};c.onload=e,c.onerror=e,c.onabort=e,document.body.addEventListener("keydown",l),r.submit()}else s(new Error("not_exists"))},50)}).then(function(e){var t;return null==c||null!==(t=c.parentNode)&&void 0!==t&&t.removeChild(c),e}).catch(function(e){var t;return null==c||null!==(t=c.parentNode)&&void 0!==t&&t.removeChild(c),e})},watchActive:function(e){for(var t,r=0;t=this.files[r];)if(r++,t.fileObject)if(e&&!this.destroy){if(this.uploading>=this.thread||this.uploading&&!this.features.html5)break;t.active||t.error||t.success||this.update(t,{active:!0})}else t.active&&this.update(t,{active:!1});else;0===this.uploading&&(this.active=!1)},watchDrop:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:void 0;if(this.features.drop&&e!==t){if(this.dropElement)try{document.removeEventListener("dragenter",this.onDragenter,!1),document.removeEventListener("dragleave",this.onDragleave,!1),document.removeEventListener("drop",this.onDocumentDrop,!1),this.dropElement.removeEventListener("dragover",this.onDragover,!1),this.dropElement.removeEventListener("drop",this.onDrop,!1)}catch(e){}t=null;e&&(t="string"==typeof e?document.querySelector(e)||this.$root.$el.querySelector(e):!0===e?this.$parent.$el:e),this.dropElement=t,this.dropElement&&(document.addEventListener("dragenter",this.onDragenter,!1),document.addEventListener("dragleave",this.onDragleave,!1),document.addEventListener("drop",this.onDocumentDrop,!1),this.dropElement.addEventListener("dragover",this.onDragover,!1),this.dropElement.addEventListener("drop",this.onDrop,!1))}},onDragenter:function(e){var t;e.preventDefault(),this.dropActive||!e.dataTransfer||(null!=(e=e.dataTransfer)&&null!==(t=e.files)&&void 0!==t&&t.length||!e.types||e.types.indexOf&&-1!==e.types.indexOf("Files")||null!==(t=e.types)&&void 0!==t&&t.contains&&e.types.contains("Files"))&&(this.dropActive=!0)},onDragleave:function(e){e.preventDefault(),this.dropActive&&("HTML"===e.target.nodeName||e.target===e.explicitOriginalTarget||!e.fromElement&&(e.clientX<=0||e.clientY<=0||e.clientX>=window.innerWidth||e.clientY>=window.innerHeight))&&(this.dropActive=!1)},onDragover:function(e){e.preventDefault()},onDocumentDrop:function(){this.dropActive=!1},onDrop:function(e){e.preventDefault(),e.dataTransfer&&this.addDataTransfer(e.dataTransfer)},inputOnChange:async function(e){var t=this;if(!(e.target instanceof HTMLInputElement))return Promise.reject(new Error("not HTMLInputElement"));function r(e){return t.reload=!0,t.$nextTick(function(){t.reload=!1}),e}e.target;return this.addInputFile(e.target).then(r).catch(r)}}}),function(e,t){void 0===t&&(t={});var r,n=t.insertAt;e&&"undefined"!=typeof document&&(r=document.head||document.getElementsByTagName("head")[0],(t=document.createElement("style")).type="text/css","top"===n&&r.firstChild?r.insertBefore(t,r.firstChild):r.appendChild(t),t.styleSheet?t.styleSheet.cssText=e:t.appendChild(document.createTextNode(e)))}("\n.file-uploads {\n overflow: hidden;\n position: relative;\n text-align: center;\n display: inline-block;\n}\n.file-uploads.file-uploads-html4 input, .file-uploads.file-uploads-html5 label {\n /* background fix ie click */\n background: #fff;\n opacity: 0;\n font-size: 20em;\n z-index: 1;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n position: absolute;\n width: 100%;\n height: 100%;\n}\n.file-uploads.file-uploads-html5 input, .file-uploads.file-uploads-html4 label {\n /* background fix ie click */\n background: rgba(255, 255, 255, 0);\n overflow: hidden;\n position: fixed;\n width: 1px;\n height: 1px;\n z-index: -1;\n opacity: 0;\n}\n"),e.render=function(e,t,r,n,i,o){return u.openBlock(),u.createBlock("span",{class:e.className},[u.renderSlot(e.$slots,"default"),u.createVNode("label",{for:e.forId},null,8,["for"]),e.reload?u.createCommentVNode("",!0):(u.openBlock(),u.createBlock("input",{key:0,ref:"input",type:"file",name:e.name,id:e.forId,accept:e.accept,capture:e.capture,disabled:e.disabled,webkitdirectory:e.directory&&e.features.directory,allowdirs:e.directory&&e.features.directory,directory:e.directory&&e.features.directory,multiple:e.multiple&&e.features.html5,onChange:t[1]||(t[1]=function(){return e.inputOnChange&&e.inputOnChange.apply(e,arguments)})},null,40,["name","id","accept","capture","disabled","webkitdirectory","allowdirs","directory","multiple"]))],2)},e)}(r={exports:{}}),r.exports}); | ||
//# sourceMappingURL=vue-upload-component.min.js.map |
/*! | ||
Name: vue-upload-component | ||
Component URI: https://github.com/lian-yue/vue-upload-component#readme | ||
Version: 3.0.47 | ||
Version: 3.0.49 | ||
Author: LianYue | ||
@@ -867,3 +867,5 @@ License: Apache-2.0 | ||
this.watchDrop(false); | ||
this.watchDrop(false); // 销毁不激活 | ||
this.watchActive(false); | ||
}, | ||
@@ -870,0 +872,0 @@ computed: { |
@@ -14,3 +14,3 @@ /*! | ||
* Component URI: https://github.com/lian-yue/vue-upload-component#readme | ||
* Version: 3.0.48 | ||
* Version: 3.0.50 | ||
* Author: LianYue | ||
@@ -30,3 +30,3 @@ * License: Apache-2.0 | ||
Component URI: https://github.com/lian-yue/vue-upload-component#readme | ||
Version: 3.0.47 | ||
Version: 3.0.49 | ||
Author: LianYue | ||
@@ -33,0 +33,0 @@ License: Apache-2.0 |
{ | ||
"name": "vue-upload-component", | ||
"description": "Vue.js file upload component, Multi-file upload, Upload directory, Drag upload, Drag the directory, Upload multiple files at the same time, html4 (IE 9), `PUT` method, Customize the filter", | ||
"version": "3.0.48", | ||
"version": "3.0.50", | ||
"author": "LianYue", | ||
@@ -6,0 +6,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3041472
9728