/*! * Name: vue-upload-component * Version: 2.8.9 * Author: LianYue */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.VueUploadComponent=t()}(this,function(){"use strict";var r=function(t){var i=new XMLHttpRequest;return i.open(t.method||"GET",t.url),i.responseType="json",t.headers&&Object.keys(t.headers).forEach(function(e){i.setRequestHeader(e,t.headers[e])}),i};function e(e){var n,t,i=r(e);return n=i,t=e.body,new Promise(function(e,i){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 i(n.response)},n.onerror=function(){return i(n.response)},n.send(JSON.stringify(t))})}var t=function(){function n(e,t){for(var i=0;i=this.maximum)break;if(r.push(s),1===this.maximum)break}}if(!r.length)return!1;1===this.maximum&&this.clear();var u=void 0;!0===t||0===t?u=r.concat(this.files):t?(u=r.concat([])).splice(t,0,r):u=this.files.concat(r),this.files=u;for(var c=0;c=r.maximum)return n(r.add(o));r.getEntry(e).then(function(e){o.push.apply(o,h(e)),t(i+1)})}(0)})}if(e.files.length){for(var n=0;n=this.maximum));n++);return Promise.resolve(this.add(o))}return Promise.resolve([])},getEntry:function(s){var a=this,u=1=a.maximum?r(o):e[i]?void a.getEntry(e[i],u+s.name+"/").then(function(e){o.push.apply(o,h(e)),t(i+1)}):n()}(0)})}()}else r([])})},replace:function(e,t){var i=this.get(e),n=this.get(t);if(!i||!n||i===n)return!1;var r=this.files.concat([]),o=r.indexOf(i),s=r.indexOf(n);return-1!==o&&-1!==s&&(r[o]=n,r[s]=i,this.files=r,this.emitInput(),!0)},remove:function(e){var t=this.get(e);if(t){if(this.emitFilter(void 0,t))return!1;var i=this.files.concat([]),n=i.indexOf(t);if(-1===n)return console.error("remove",t),!1;i.splice(n,1),this.files=i,delete this.maps[t.id],this.emitInput(),this.emitFile(void 0,t)}return t},update:function(e,t){var i=this.get(e);if(i){var n=f({},i,t);if(!i.fileObject||!i.active||n.active||n.error||n.success||(n.error="abort"),this.emitFilter(n,i))return!1;var r=this.files.concat([]),o=r.indexOf(i);return-1===o?(console.error("update",i),!1):(r.splice(o,1,n),this.files=r,delete this.maps[i.id],this.maps[n.id]=n,this.emitInput(),this.emitFile(n,i),n)}return!1},emitFilter:function(e,t){var i=!1;return this.$emit("input-filter",e,t,function(){return i=!0}),i},emitFile:function(i,e){this.$emit("input-file",i,e),!(i&&i.fileObject&&i.active)||e&&e.active?i&&i.fileObject&&i.active||!e||!e.fileObject||!e.active||this.uploading--:(this.uploading++,this.$nextTick(function(){var t=this;setTimeout(function(){t.upload(i).then(function(){(i=t.get(i))&&i.fileObject&&t.update(i,{active:!1,success:!i.error})}).catch(function(e){t.update(i,{active:!1,success:!1,error:e.code||e.error||e.message||e})})},parseInt(50*Math.random()+50,10))})),!this.active||Boolean(i)===Boolean(e)&&i.active===e.active||this.watchActive(!0)},emitInput:function(){this.$emit("input",this.files)},upload:function(e){var t=this.get(e);if(!t)return Promise.reject("not_exists");if(!t.fileObject)return Promise.reject("file_object");if(t.error)return Promise.reject(t.error);if(t.success)return Promise.resolve(t);var i=this.extensions;if(i&&(i.length||void 0===i.length)&&("object"===(void 0===i?"undefined":l(i))&&i instanceof RegExp||("string"==typeof i&&(i=i.split(",").map(function(e){return e.trim()}).filter(function(e){return e})),i=new RegExp("\\.("+i.join("|").replace(/\./g,"\\.")+")$","i")),-1===t.name.search(i)))return Promise.reject("extension");if(0this.size)return Promise.reject("size");if(this.customAction)return this.customAction(t,this);if(this.features.html5){if(this.shouldUseChunkUpload(t))return this.uploadChunk(t);if(t.putAction)return this.uploadPut(t);if(t.postAction)return this.uploadHtml5(t)}return t.postAction?this.uploadHtml4(t):Promise.reject("No action configured")},shouldUseChunkUpload:function(e){return this.chunkEnabled&&!!this.chunkOptions.handler&&e.size>this.chunkOptions.minSize},uploadChunk:function(e){var t=this.chunkOptions.handler;return e.chunk=new t(e,this.chunkOptions),e.chunk.upload()},uploadPut:function(e){var t=[],i=void 0;for(var n in e.data)null!=(i=e.data[n])&&t.push(encodeURIComponent(n)+"="+encodeURIComponent(i));var r=t.length?(-1===e.putAction.indexOf("?")?"?":"&")+t.join("&"):"",o=new XMLHttpRequest;return o.open("PUT",e.putAction+r),this.uploadXhr(o,e,e.file)},uploadHtml5:function(e){var t=new window.FormData,i=void 0;for(var n in e.data)(i=e.data[n])&&"object"===(void 0===i?"undefined":l(i))&&"function"!=typeof i.toString?i instanceof File?t.append(n,i,i.name):t.append(n,JSON.stringify(i)):null!=i&&t.append(n,i);t.append(this.name,e.file,e.file.filename||e.name);var r=new XMLHttpRequest;return r.open("POST",e.postAction),this.uploadXhr(r,e,t)},uploadXhr:function(s,e,i){var a=this,u=e,n=0,r=0;s.upload.onprogress=function(e){if(u=a.get(u),e.lengthComputable&&u&&u.fileObject&&u.active){var t=Math.round(Date.now()/1e3);t!==n&&(n=t,u=a.update(u,{progress:(e.loaded/e.total*100).toFixed(2),speed:e.loaded-r}),r=e.loaded)}};var c=setInterval(function(){if(!(u=a.get(u))||!u.fileObject||u.success||u.error||!u.active){c&&(clearInterval(c),c=!1);try{s.abort(),s.timeout=1}catch(e){}}},100);return new Promise(function(n,r){var o=void 0,e=function(e){if(!o){if(o=!0,c&&(clearInterval(c),c=!1),!(u=a.get(u)))return r("not_exists");if(!u.fileObject)return r("file_object");if(u.error)return r(u.error);if(!u.active)return r("abort");if(u.success)return n(u);var t={};switch(e.type){case"timeout":case"abort":t.error=e.type;break;case"error":s.status?500<=s.status?t.error="server":400<=s.status&&(t.error="denied"):t.error="network";break;default:500<=s.status?t.error="server":400<=s.status?t.error="denied":t.progress="100.00"}if(s.responseText){var i=s.getResponseHeader("Content-Type");i&&-1!==i.indexOf("/json")?t.response=JSON.parse(s.responseText):t.response=s.responseText}return(u=a.update(u,t)).error?r(u.error):n(u)}};for(var t in s.onload=e,s.onerror=e,s.onabort=e,s.ontimeout=e,u.timeout&&(s.timeout=u.timeout),u.headers)s.setRequestHeader(t,u.headers[t]);u=a.update(u,{xhr:s}),s.send(i)})},uploadHtml4:function(e){var a=this,u=e,c=function(e){27===e.keyCode&&e.preventDefault()},d=document.createElement("iframe");d.id="upload-iframe-"+u.id,d.name="upload-iframe-"+u.id,d.src="about:blank",d.setAttribute("style","width:1px;height:1px;top:-999em;position:absolute; margin-top:-999em;");var t=document.createElement("form");t.action=u.postAction,t.name="upload-form-"+u.id,t.setAttribute("method","POST"),t.setAttribute("target","upload-iframe-"+u.id),t.setAttribute("enctype","multipart/form-data");var i=void 0,n=void 0;for(var r in u.data)(i=u.data[r])&&"object"===(void 0===i?"undefined":l(i))&&"function"!=typeof i.toString&&(i=JSON.stringify(i)),null!=i&&((n=document.createElement("input")).type="hidden",n.name=r,n.value=i,t.appendChild(n));t.appendChild(u.el),document.body.appendChild(d).appendChild(t);return new Promise(function(o,s){setTimeout(function(){if(!(u=a.update(u,{iframe:d})))return s("not_exists");var n=setInterval(function(){(u=a.get(u))&&u.fileObject&&!u.success&&!u.error&&u.active||(n&&(clearInterval(n),n=!1),d.onabort({type:u?"abort":"not_exists"}))},100),r=void 0,e=function(e){if(!r){if(r=!0,n&&(clearInterval(n),n=!1),document.body.removeEventListener("keydown",c),!(u=a.get(u)))return s("not_exists");if(!u.fileObject)return s("file_object");if(u.error)return s(u.error);if(!u.active)return s("abort");if(u.success)return o(u);var t=function(){var t=void 0;try{d.contentWindow&&(t=d.contentWindow.document)}catch(e){}if(!t)try{t=d.contentDocument?d.contentDocument:d.document}catch(e){t=d.document}return t&&t.body?t.body.innerHTML:null}(),i={};switch(e.type){case"abort":i.error="abort";break;case"error":u.error?i.error=u.error:i.error=null===t?"network":"denied";break;default:u.error?i.error=u.error:null===i?i.error="network":i.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){}i.response=t}return(u=a.update(u,i)).error?s(u.error):o(u)}};d.onload=e,d.onerror=e,d.onabort=e,document.body.addEventListener("keydown",c),t.submit()},50)}).then(function(e){return d.parentNode&&d.parentNode.removeChild(d),e}).catch(function(e){return d.parentNode&&d.parentNode.removeChild(d),e})},watchActive:function(e){for(var t=void 0,i=0;t=this.files[i];)if(i++,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=e;if(this.features.drop){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?"string"==typeof t?t=document.querySelector(t)||this.$root.$el.querySelector(t):!0===t&&(t=this.$parent.$el):t=!1,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){e.preventDefault(),this.dropActive||(this.dropActive=!0)},onDragleave:function(e){e.preventDefault(),("HTML"===e.target.nodeName||e.target===e.explicitOriginalTarget||0===e.screenX&&0===e.screenY&&!e.fromElement&&e.offsetX<=0)&&(this.dropActive=!1)},onDragover:function(e){e.preventDefault()},onDocumentDrop:function(){this.dropActive=!1},onDrop:function(e){e.preventDefault(),this.addDataTransfer(e.dataTransfer)}}},v=function(){var e=this,t=e.$createElement,i=e._self._c||t;return i("label",{class:e.className},[e._t("default"),e._ssrNode(" "),i("input-file")],2)};function y(o){if(o||"undefined"==typeof __VUE_SSR_CONTEXT__||(o=__VUE_SSR_CONTEXT__),!o)return function(){};return o.hasOwnProperty("styles")||(Object.defineProperty(o,"styles",{enumerable:!0,get:function(){return o._styles}}),o._renderStyles=function(e){var t="",i=!0,n=!1,r=void 0;try{for(var o,s=e[Symbol.iterator]();!(i=(o=s.next()).done);i=!0){var a=o.value,u=a.ids,c=a.media,d=a.parts;t+='"}}catch(e){n=!0,r=e}finally{try{!i&&s.return&&s.return()}finally{if(n)throw r}}return t}),function(e,t){var i=t.media||"default",n=o._styles[i]||(o._styles[i]={ids:[],parts:[]});if(!n.ids.includes(e)){n.media=t.media,n.ids.push(e);var r=t.source;n.parts.push(r)}}}var g=function(e,t,i,n,r,o,s,a){var u,c=i||{};if(c.render||(c.render=e.render,c.staticRenderFns=e.staticRenderFns,c._compiled=!0,r&&(c.functional=!0)),c._scopeId=n,u=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),t&&t.call(this,a(e)),e&&e._registeredComponents&&e._registeredComponents.add(o)},void 0!==(c._ssrRegister=u))if(c.functional){var d=c.render;c.render=function(e,t){return u.call(t),d(e,t)}}else{var l=c.beforeCreate;c.beforeCreate=l?[].concat(l,u):[u]}return c}(void 0!==v?{render:v,staticRenderFns:[]}:{},function(e){e&&e("data-v-00c97c04_0",{source:"\n.file-uploads{overflow:hidden;position:relative;text-align:center;display:inline-block\n}\n.file-uploads.file-uploads-html4 input[type=file]{opacity:0;font-size:20em;z-index:1;top:0;left:0;right:0;bottom:0;position:absolute;width:100%;height:100%\n}\n.file-uploads.file-uploads-html5 input[type=file]{overflow:hidden;position:fixed;width:1px;height:1px;z-index:-1;opacity:0\n}",map:void 0,media:void 0})},void 0===m?{}:m,void 0,!1,"data-v-00c97c04","undefined"!=typeof __vue_create_injector__&&__vue_create_injector__,void 0!==y?y:function(){}),b=Object.freeze({default:g});return b&&g||b});