upload-oss-cloud
Version:
A package for uploading file to ali oss with vue component and iview library
1 lines • 17 kB
JavaScript
(function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports["UploadOssCloud"]=t():e["UploadOssCloud"]=t()})("undefined"!==typeof self?self:this,(function(){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};return e[n].call(i.exports,i,i.exports,r),i.l=!0,i.exports}return r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)r.d(n,i,function(t){return e[t]}.bind(null,i));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e["default"]}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s="fb15")}({"1e97":function(e,t,r){"use strict";var n=r("4769"),i=r.n(n);i.a},"24fb":function(e,t,r){"use strict";function n(e,t){var r=e[1]||"",n=e[3];if(!n)return r;if(t&&"function"===typeof btoa){var o=i(n),a=n.sources.map((function(e){return"/*# sourceURL=".concat(n.sourceRoot||"").concat(e," */")}));return[r].concat(a).concat([o]).join("\n")}return[r].join("\n")}function i(e){var t=btoa(unescape(encodeURIComponent(JSON.stringify(e)))),r="sourceMappingURL=data:application/json;charset=utf-8;base64,".concat(t);return"/*# ".concat(r," */")}e.exports=function(e){var t=[];return t.toString=function(){return this.map((function(t){var r=n(t,e);return t[2]?"@media ".concat(t[2]," {").concat(r,"}"):r})).join("")},t.i=function(e,r,n){"string"===typeof e&&(e=[[null,e,""]]);var i={};if(n)for(var o=0;o<this.length;o++){var a=this[o][0];null!=a&&(i[a]=!0)}for(var s=0;s<e.length;s++){var c=[].concat(e[s]);n&&i[c[0]]||(r&&(c[2]?c[2]="".concat(r," and ").concat(c[2]):c[2]=r),t.push(c))}},t}},4769:function(e,t,r){var n=r("e0cd");"string"===typeof n&&(n=[[e.i,n,""]]),n.locals&&(e.exports=n.locals);var i=r("499e").default;i("28f29d51",n,!0,{sourceMap:!1,shadowMode:!1})},"499e":function(e,t,r){"use strict";function n(e,t){for(var r=[],n={},i=0;i<t.length;i++){var o=t[i],a=o[0],s=o[1],c=o[2],u=o[3],d={id:e+":"+i,css:s,media:c,sourceMap:u};n[a]?n[a].parts.push(d):r.push(n[a]={id:a,parts:[d]})}return r}r.r(t),r.d(t,"default",(function(){return h}));var i="undefined"!==typeof document;if("undefined"!==typeof DEBUG&&DEBUG&&!i)throw new Error("vue-style-loader cannot be used in a non-browser environment. Use { target: 'node' } in your Webpack config to indicate a server-rendering environment.");var o={},a=i&&(document.head||document.getElementsByTagName("head")[0]),s=null,c=0,u=!1,d=function(){},l=null,f="data-vue-ssr-id",p="undefined"!==typeof navigator&&/msie [6-9]\b/.test(navigator.userAgent.toLowerCase());function h(e,t,r,i){u=r,l=i||{};var a=n(e,t);return g(a),function(t){for(var r=[],i=0;i<a.length;i++){var s=a[i],c=o[s.id];c.refs--,r.push(c)}t?(a=n(e,t),g(a)):a=[];for(i=0;i<r.length;i++){c=r[i];if(0===c.refs){for(var u=0;u<c.parts.length;u++)c.parts[u]();delete o[c.id]}}}}function g(e){for(var t=0;t<e.length;t++){var r=e[t],n=o[r.id];if(n){n.refs++;for(var i=0;i<n.parts.length;i++)n.parts[i](r.parts[i]);for(;i<r.parts.length;i++)n.parts.push(y(r.parts[i]));n.parts.length>r.parts.length&&(n.parts.length=r.parts.length)}else{var a=[];for(i=0;i<r.parts.length;i++)a.push(y(r.parts[i]));o[r.id]={id:r.id,refs:1,parts:a}}}}function m(){var e=document.createElement("style");return e.type="text/css",a.appendChild(e),e}function y(e){var t,r,n=document.querySelector("style["+f+'~="'+e.id+'"]');if(n){if(u)return d;n.parentNode.removeChild(n)}if(p){var i=c++;n=s||(s=m()),t=b.bind(null,n,i,!1),r=b.bind(null,n,i,!0)}else n=m(),t=x.bind(null,n),r=function(){n.parentNode.removeChild(n)};return t(e),function(n){if(n){if(n.css===e.css&&n.media===e.media&&n.sourceMap===e.sourceMap)return;t(e=n)}else r()}}var v=function(){var e=[];return function(t,r){return e[t]=r,e.filter(Boolean).join("\n")}}();function b(e,t,r,n){var i=r?"":n.css;if(e.styleSheet)e.styleSheet.cssText=v(t,i);else{var o=document.createTextNode(i),a=e.childNodes;a[t]&&e.removeChild(a[t]),a.length?e.insertBefore(o,a[t]):e.appendChild(o)}}function x(e,t){var r=t.css,n=t.media,i=t.sourceMap;if(n&&e.setAttribute("media",n),l.ssrId&&e.setAttribute(f,t.id),i&&(r+="\n/*# sourceURL="+i.sources[0]+" */",r+="\n/*# sourceMappingURL=data:application/json;base64,"+btoa(unescape(encodeURIComponent(JSON.stringify(i))))+" */"),e.styleSheet)e.styleSheet.cssText=r;else{while(e.firstChild)e.removeChild(e.firstChild);e.appendChild(document.createTextNode(r))}}},8875:function(e,t,r){var n,i,o;(function(r,a){i=[],n=a,o="function"===typeof n?n.apply(t,i):n,void 0===o||(e.exports=o)})("undefined"!==typeof self&&self,(function(){function e(){if(document.currentScript)return document.currentScript;try{throw new Error}catch(l){var e,t,r,n=/.*at [^(]*\((.*):(.+):(.+)\)$/gi,i=/@([^@]*):(\d+):(\d+)\s*$/gi,o=n.exec(l.stack)||i.exec(l.stack),a=o&&o[1]||!1,s=o&&o[2]||!1,c=document.location.href.replace(document.location.hash,""),u=document.getElementsByTagName("script");a===c&&(e=document.documentElement.outerHTML,t=new RegExp("(?:[^\\n]+?\\n){0,"+(s-2)+"}[^<]*<script>([\\d\\D]*?)<\\/script>[\\d\\D]*","i"),r=e.replace(t,"$1").trim());for(var d=0;d<u.length;d++){if("interactive"===u[d].readyState)return u[d];if(u[d].src===a)return u[d];if(a===c&&u[d].innerHTML&&u[d].innerHTML.trim()===r)return u[d]}return null}}return e}))},e0cd:function(e,t,r){var n=r("24fb");t=n(!1),t.push([e.i,".upload-disabled .drag-zone[data-v-18dd5272]{opacity:.5;cursor:not-allowed}.drag-zone[data-v-18dd5272]{width:58px;height:58px;line-height:58px;background:#fff;border:1px dashed #dcdee2;border-radius:4px;text-align:center;cursor:pointer;position:relative;overflow:hidden;-webkit-transition:border-color .2s ease;-o-transition:border-color .2s ease;-moz-transition:border-color .2s ease;transition:border-color .2s ease}.drag-zone[data-v-18dd5272]:hover{border-color:#4098ff}",""]),e.exports=t},fb15:function(e,t,r){"use strict";if(r.r(t),"undefined"!==typeof window){var n=window.document.currentScript,i=r("8875");n=i(),"currentScript"in document||Object.defineProperty(document,"currentScript",{get:i});var o=n&&n.src.match(/(.+\/)[^/]+\.js(\?.*)?$/);o&&(r.p=o[1])}var a=function(){var e=this,t=e.$createElement,r=e._self._c||t;return r("Upload",{ref:"upload",class:e.innerDisabled?"upload-disabled":"",attrs:{action:e.innerAction,headers:e.headers,multiple:e.multiple,paste:e.paste,disabled:e.innerDisabled,data:e.params,name:e.name,"with-credentials":e.withCredentials,"show-upload-list":e.showUploadList,type:e.type,accept:e.innerAccept,format:e.innerFormat,"max-size":e.innerMaxSize,"default-file-list":e.defaultFileList,"on-format-error":e.formatError,"on-exceeded-size":e.exceed,"before-upload":e.before,"on-progress":e.progress,"on-success":e.done,"on-error":e.fail,"on-preview":e.preview,"on-remove":e.remove}},[e.$slots.default?e._t("default",null,{slot:"default"}):r("div",{staticClass:"drag-zone"},[r("Icon",{attrs:{type:"md-add",size:"20"}})],1),e._t("tip",null,{slot:"tip"})],2)},s=[],c={encode:d,decode:l};const u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";function d(e){var t,r,n,i,o,a,s,c="",d=0;e=f(e);while(d<e.length)t=e.charCodeAt(d++),r=e.charCodeAt(d++),n=e.charCodeAt(d++),i=t>>2,o=(3&t)<<4|r>>4,a=(15&r)<<2|n>>6,s=63&n,isNaN(r)?a=s=64:isNaN(n)&&(s=64),c=c+u.charAt(i)+u.charAt(o)+u.charAt(a)+u.charAt(s);return c}function l(e){var t,r,n,i,o,a,s,c="",d=0;e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");while(d<e.length)i=u.indexOf(e.charAt(d++)),o=u.indexOf(e.charAt(d++)),a=u.indexOf(e.charAt(d++)),s=u.indexOf(e.charAt(d++)),t=i<<2|o>>4,r=(15&o)<<4|a>>2,n=(3&a)<<6|s,c+=String.fromCharCode(t),64!=a&&(c+=String.fromCharCode(r)),64!=s&&(c+=String.fromCharCode(n));return c=p(c),c}function f(e){e=e.replace(/\r\n/g,"\n");for(var t="",r=0;r<e.length;r++){var n=e.charCodeAt(r);n<128?t+=String.fromCharCode(n):n>127&&n<2048?(t+=String.fromCharCode(n>>6|192),t+=String.fromCharCode(63&n|128)):(t+=String.fromCharCode(n>>12|224),t+=String.fromCharCode(n>>6&63|128),t+=String.fromCharCode(63&n|128))}return t}function p(e){var t="",r=0,n=c1=c2=0;while(r<e.length)n=e.charCodeAt(r),n<128?(t+=String.fromCharCode(n),r++):n>191&&n<224?(c2=e.charCodeAt(r+1),t+=String.fromCharCode((31&n)<<6|63&c2),r+=2):(c2=e.charCodeAt(r+1),c3=e.charCodeAt(r+2),t+=String.fromCharCode((15&n)<<12|(63&c2)<<6|63&c3),r+=3);return t}const h={mode:{}},g="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",m={rotl:function(e,t){return e<<t|e>>>32-t},rotr:function(e,t){return e<<32-t|e>>>t},endian:function(e){if(e.constructor==Number)return 16711935&m.rotl(e,8)|4278255360&m.rotl(e,24);for(var t=0;t<e.length;t++)e[t]=m.endian(e[t]);return e},randomBytes:function(e){for(var t=[];e>0;e--)t.push(Math.floor(256*Math.random()));return t},stringToBytes:function(e){for(var t=[],r=0;r<e.length;r++)t.push(e.charCodeAt(r));return t},bytesToString:function(e){for(var t=[],r=0;r<e.length;r++)t.push(String.fromCharCode(e[r]));return t.join("")},stringToWords:function(e){for(var t=[],r=0,n=0;r<e.length;r++,n+=8)t[n>>>5]|=e.charCodeAt(r)<<24-n%32;return t},bytesToWords:function(e){for(var t=[],r=0,n=0;r<e.length;r++,n+=8)t[n>>>5]|=e[r]<<24-n%32;return t},wordsToBytes:function(e){for(var t=[],r=0;r<32*e.length;r+=8)t.push(e[r>>>5]>>>24-r%32&255);return t},bytesToHex:function(e){for(var t=[],r=0;r<e.length;r++)t.push((e[r]>>>4).toString(16)),t.push((15&e[r]).toString(16));return t.join("")},hexToBytes:function(e){for(var t=[],r=0;r<e.length;r+=2)t.push(parseInt(e.substr(r,2),16));return t},bytesToBase64:function(e){if("function"==typeof btoa)return btoa(m.bytesToString(e));for(var t,r=[],n=0;n<e.length;n++)switch(n%3){case 0:r.push(g.charAt(e[n]>>>2)),t=(3&e[n])<<4;break;case 1:r.push(g.charAt(t|e[n]>>>4)),t=(15&e[n])<<2;break;case 2:r.push(g.charAt(t|e[n]>>>6)),r.push(g.charAt(63&e[n])),t=-1}void 0!=t&&-1!=t&&r.push(g.charAt(t));while(r.length%4!=0)r.push("=");return r.join("")},base64ToBytes:function(e){if("function"==typeof atob)return m.stringToBytes(atob(e));e=e.replace(/[^A-Z0-9+\/]/gi,"");for(var t=[],r=0;r<e.length;r++)switch(r%4){case 1:t.push(g.indexOf(e.charAt(r-1))<<2|g.indexOf(e.charAt(r))>>>4);break;case 2:t.push((15&g.indexOf(e.charAt(r-1)))<<4|g.indexOf(e.charAt(r))>>>2);break;case 3:t.push((3&g.indexOf(e.charAt(r-1)))<<6|g.indexOf(e.charAt(r)));break}return t}};Object.assign(h,{mode:{},util:m,hmac:y,sha1:v});function y(e,t,r,n){r=r.length>4*e._blocksize?e(r,{asBytes:!0}):m.stringToBytes(r);for(var i=r,o=r.slice(0),a=0;a<4*e._blocksize;a++)i[a]^=92,o[a]^=54;var s=e(m.bytesToString(i)+e(m.bytesToString(o)+t,{asString:!0}),{asBytes:!0});return n&&n.asBytes?s:n&&n.asString?m.bytesToString(s):m.bytesToHex(s)}function v(e,t){var r=m.wordsToBytes(v.core(e));return t&&t.asBytes?r:t&&t.asString?m.bytesToString(r):m.bytesToHex(r)}function b(){var e=(new Date).getTime();return"xxxxxxxxxxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){var r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?r:3&r|8).toString(16)}))}function x(e,t){t=parseFloat(t),t=1024*(isNaN(t)?100:t)*1024;var r={expiration:new Date(Date.now()+864e5).toISOString(),conditions:[["content-length-range",0,t]]},n=c.encode(JSON.stringify(r)),i=y(v,n,e,{asBytes:!0}),o=m.bytesToBase64(i);return{policy:n,signature:o}}Object.assign(v,{core:function(e){var t=m.stringToWords(e),r=8*e.length,n=[],i=1732584193,o=-271733879,a=-1732584194,s=271733878,c=-1009589776;t[r>>5]|=128<<24-r%32,t[15+(r+64>>>9<<4)]=r;for(var u=0;u<t.length;u+=16){for(var d=i,l=o,f=a,p=s,h=c,g=0;g<80;g++){if(g<16)n[g]=t[u+g];else{var y=n[g-3]^n[g-8]^n[g-14]^n[g-16];n[g]=y<<1|y>>>31}var v=(i<<5|i>>>27)+c+(n[g]>>>0)+(g<20?1518500249+(o&a|~o&s):g<40?1859775393+(o^a^s):g<60?(o&a|o&s|a&s)-1894007588:(o^a^s)-899497514);c=s,s=a,a=o<<30|o>>>2,o=i,i=v}i+=d,o+=l,a+=f,s+=p,c+=h}return[i,o,a,s,c]},_blocksize:16});var S={name:"upload-oss-cloud",props:{action:{type:String,default:()=>""},headers:{type:Object,default:()=>({})},multiple:{type:Boolean,default:()=>!1},paste:{type:Boolean,default:()=>!1},disabled:{type:Boolean,default:()=>!1},data:{type:Object,default:()=>({})},name:{type:String,default:()=>"file"},withCredentials:{type:Boolean,default:()=>!1},showUploadList:{type:Boolean,default:()=>!0},type:{type:String,default:()=>"select"},accept:{type:String},format:{type:Array},maxSize:{type:[Number,String],default:()=>100},defaultFileList:{type:Array,default:()=>[]},stop:{type:Function,default:()=>!0},toast:{type:Boolean,default:()=>!0},image:{type:Boolean,default:()=>!1},video:{type:Boolean,default:()=>!1},accessKeyId:{type:String},accessKeySecret:{type:String},directory:{type:String,default:()=>""},policy:{type:String},signature:{type:String},securityToken:{type:String}},model:{prop:"defaultFileList"},data(){return{innerAction:this.action,wait:!0,params:Object.assign({OSSAccessKeyId:"",policy:"",signature:"",name:"file",success_action_status:200,key:""},this.data)}},computed:{innerAccept(){return this.accept?this.accept:this.image?"image/png, image/jpeg, image/jpg":this.video?"video/MP4, video/MOV, video/AVI, video/MPEG, video/FLV, video/RMVB":"image/png, image/jpeg, image/jpg, video/MP4, video/MOV, video/AVI, video/MPEG, video/FLV, video/RMVB"},innerFormat(){return this.format?this.format:this.image?["jpg","jpeg","png"]:this.video?["MP4","MOV","AVI","MPEG","FLV","RMVB"]:["jpg","jpeg","png","MP4","MOV","AVI","MPEG","FLV","RMVB"]},innerDisabled(){return this.disabled||this.wait},innerMaxSize(){let e=parseFloat(this.maxSize,10);return isNaN(e)?102400:1024*this.maxSize}},watch:{action(e){this.innerAction=e},accessKeyId(){this.init()},accessKeySecret(){this.init()},policy(){this.init()},signature(){this.init()},securityToken(){this.init()},data(){}},created(){this.uuid=b,this.genPolicySignature=x,this.init()},beforeDestroy(){this.beforeUploadFiles=null},methods:{async init(){this.securityToken?this.params["x-oss-security-token"]=this.securityToken:this.accessKeyId&&this.accessKeySecret?this.setParams(this.accessKeyId,this.accessKeySecret):this.accessKeyId&&this.policy&&this.signature&&this.setParams(this.accessKeyId,null,this.policy,this.signature)},setParams(e,t,r,n){if(this.wait=!1,t){let e=x(t,this.maxSize);r=e.policy,n=e.signature}this.params.OSSAccessKeyId=e,this.params.policy=r,this.params.signature=n},before(e){return this.cacheFile(e),this.$emit("upload",{status:0,file:e}),this.stop()},cacheFile(e){let t=this.directory||"",r=t+b()+e.name.slice(e.name.lastIndexOf("."));e.key=r,this.params.key=r,this.beforeUploadFiles=this.beforeUploadFiles||[],this.beforeUploadFiles.push(e)},progress(e,t){let r=t&&t.percentage;this.$emit("upload",{status:1,percentage:r,file:t})},done(e,t,r){r=this.getList(r),t=this.getFile(t),this.$emit("input",r),this.$nextTick(()=>this.$emit("upload",{status:2,file:t}))},exceed(e){let t=new Error("文件过大");t.code=1,this.fail(t,e)},formatError(e){let t=new Error("文件格式不对");t.code=2,this.fail(t,e)},fail(e,t){console.log(e),void 0===e.code&&(e.code=-1),void 0===e.message&&(e.message="上传失败"),"boolean"===typeof this.toast&&this.toast&&this.$Message.error(e.message),t=this.getFile(t),this.$emit("upload",{status:-1,error:e,file:t})},preview(e){e=this.getFile(e),this.$emit("preview",e)},remove(e,t){t=this.getList(t),e=this.getFile(e),this.$emit("input",t),this.$nextTick(()=>this.$emit("remove",e))},clear(){this.$refs.upload.clearFiles()},getList(e){return e.map(e=>this.getFile(e))},getFile(e){e="object"===typeof e&&e||{};let t=this.beforeUploadFiles&&this.beforeUploadFiles.find(t=>{let r=t&&t.uid,n=e&&e.uid;return r===n}),r=t?this.innerAction+"/"+t.key:e.url||"";var n=t?t.uid:e&&e.uid||"";return Object.assign(e,{url:r,dataUrl:r,name:r.slice(r.lastIndexOf("/")+1),uid:n})}}},C=S;r("1e97");function A(e,t,r,n,i,o,a,s){var c,u="function"===typeof e?e.options:e;if(t&&(u.render=t,u.staticRenderFns=r,u._compiled=!0),n&&(u.functional=!0),o&&(u._scopeId="data-v-"+o),a?(c=function(e){e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext,e||"undefined"===typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),i&&i.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(a)},u._ssrRegister=c):i&&(c=s?function(){i.call(this,(u.functional?this.parent:this).$root.$options.shadowRoot)}:i),c)if(u.functional){u._injectStyles=c;var d=u.render;u.render=function(e,t){return c.call(t),d(e,t)}}else{var l=u.beforeCreate;u.beforeCreate=l?[].concat(l,c):[c]}return{exports:e,options:u}}var w=A(C,a,s,!1,null,"18dd5272",null),T=w.exports;T.install=function(e){e.component(T.name,T)};var O=T;t["default"]=O}})}));