|
- (self.webpackChunkant_design_pro=self.webpackChunkant_design_pro||[]).push([[3059],{13059:function(se,j,f){"use strict";f.r(j),f.d(j,{default:function(){return ne}});var D=f(22122),U=f(6610),O=f(5991),$=f(10379),L=f(44144),Z=f(67294),w=f(96156),W=f(81253),T=f(55507),B=f(90484),H=f(92137),A=f(85061),X=f(94184),K=f.n(X),q=f(64217);function x(o,n){var d="cannot ".concat(o.method," ").concat(o.action," ").concat(n.status,"'"),e=new Error(d);return e.status=n.status,e.method=o.method,e.url=o.action,e}function N(o){var n=o.responseText||o.response;if(!n)return n;try{return JSON.parse(n)}catch(d){return n}}function G(o){var n=new XMLHttpRequest;o.onProgress&&n.upload&&(n.upload.onprogress=function(r){r.total>0&&(r.percent=r.loaded/r.total*100),o.onProgress(r)});var d=new FormData;o.data&&Object.keys(o.data).forEach(function(t){var r=o.data[t];if(Array.isArray(r)){r.forEach(function(i){d.append("".concat(t,"[]"),i)});return}d.append(t,r)}),o.file instanceof Blob?d.append(o.filename,o.file,o.file.name):d.append(o.filename,o.file),n.onerror=function(r){o.onError(r)},n.onload=function(){return n.status<200||n.status>=300?o.onError(x(o,n),N(n)):o.onSuccess(N(n),n)},n.open(o.method,o.action,!0),o.withCredentials&&"withCredentials"in n&&(n.withCredentials=!0);var e=o.headers||{};return e["X-Requested-With"]!==null&&n.setRequestHeader("X-Requested-With","XMLHttpRequest"),Object.keys(e).forEach(function(t){e[t]!==null&&n.setRequestHeader(t,e[t])}),n.send(d),{abort:function(){n.abort()}}}var J=+new Date,z=0;function M(){return"rc-upload-".concat(J,"-").concat(++z)}var Q=f(80334),R=function(o,n){if(o&&n){var d=Array.isArray(n)?n:n.split(","),e=o.name||"",t=o.type||"",r=t.replace(/\/.*$/,"");return d.some(function(i){var a=i.trim();if(/^\*(\/\*)?$/.test(i))return!0;if(a.charAt(0)==="."){var l=e.toLowerCase(),s=a.toLowerCase(),c=[s];return(s===".jpg"||s===".jpeg")&&(c=[".jpg",".jpeg"]),c.some(function(v){return l.endsWith(v)})}return/\/\*$/.test(a)?r===a.replace(/\/.*$/,""):t===a?!0:/^\w+$/.test(a)?((0,Q.ZP)(!1,"Upload takes an invalidate 'accept' type '".concat(a,"'.Skip for check.")),!0):!1})}return!0};function V(o,n){var d=o.createReader(),e=[];function t(){d.readEntries(function(r){var i=Array.prototype.slice.apply(r);e=e.concat(i);var a=!i.length;a?n(e):t()})}t()}var Y=function(n,d,e){var t=function r(i,a){i.path=a||"",i.isFile?i.file(function(l){e(l)&&(i.fullPath&&!l.webkitRelativePath&&(Object.defineProperties(l,{webkitRelativePath:{writable:!0}}),l.webkitRelativePath=i.fullPath.replace(/^\//,""),Object.defineProperties(l,{webkitRelativePath:{writable:!1}})),d([l]))}):i.isDirectory&&V(i,function(l){l.forEach(function(s){r(s,"".concat(a).concat(i.name,"/"))})})};n.forEach(function(r){t(r.webkitGetAsEntry())})},_=Y,ee=["component","prefixCls","className","disabled","id","style","multiple","accept","capture","children","directory","openFileDialogOnClick","onMouseEnter","onMouseLeave"],re=function(o){(0,$.Z)(d,o);var n=(0,L.Z)(d);function d(){var e;(0,U.Z)(this,d);for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];return e=n.call.apply(n,[this].concat(r)),e.state={uid:M()},e.reqs={},e.fileInput=void 0,e._isMounted=void 0,e.onChange=function(a){var l=e.props,s=l.accept,c=l.directory,v=a.target.files,p=(0,A.Z)(v).filter(function(h){return!c||R(h,s)});e.uploadFiles(p),e.reset()},e.onClick=function(a){var l=e.fileInput;if(!!l){var s=e.props,c=s.children,v=s.onClick;if(c&&c.type==="button"){var p=l.parentNode;p.focus(),p.querySelector("button").blur()}l.click(),v&&v(a)}},e.onKeyDown=function(a){a.key==="Enter"&&e.onClick(a)},e.onFileDrop=function(a){var l=e.props.multiple;if(a.preventDefault(),a.type!=="dragover")if(e.props.directory)_(Array.prototype.slice.call(a.dataTransfer.items),e.uploadFiles,function(c){return R(c,e.props.accept)});else{var s=(0,A.Z)(a.dataTransfer.files).filter(function(c){return R(c,e.props.accept)});l===!1&&(s=s.slice(0,1)),e.uploadFiles(s)}},e.uploadFiles=function(a){var l=(0,A.Z)(a),s=l.map(function(c){return c.uid=M(),e.processFile(c,l)});Promise.all(s).then(function(c){var v=e.props.onBatchStart;v==null||v(c.map(function(p){var h=p.origin,y=p.parsedFile;return{file:h,parsedFile:y}})),c.filter(function(p){return p.parsedFile!==null}).forEach(function(p){e.post(p)})})},e.processFile=function(){var a=(0,H.Z)((0,T.Z)().mark(function l(s,c){var v,p,h,y,F,C,m,E,k;return(0,T.Z)().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:if(v=e.props.beforeUpload,p=s,!v){u.next=14;break}return u.prev=3,u.next=6,v(s,c);case 6:p=u.sent,u.next=12;break;case 9:u.prev=9,u.t0=u.catch(3),p=!1;case 12:if(p!==!1){u.next=14;break}return u.abrupt("return",{origin:s,parsedFile:null,action:null,data:null});case 14:if(h=e.props.action,typeof h!="function"){u.next=21;break}return u.next=18,h(s);case 18:y=u.sent,u.next=22;break;case 21:y=h;case 22:if(F=e.props.data,typeof F!="function"){u.next=29;break}return u.next=26,F(s);case 26:C=u.sent,u.next=30;break;case 29:C=F;case 30:return m=((0,B.Z)(p)==="object"||typeof p=="string")&&p?p:s,m instanceof File?E=m:E=new File([m],s.name,{type:s.type}),k=E,k.uid=s.uid,u.abrupt("return",{origin:s,data:C,parsedFile:k,action:y});case 35:case"end":return u.stop()}},l,null,[[3,9]])}));return function(l,s){return a.apply(this,arguments)}}(),e.saveFileInput=function(a){e.fileInput=a},e}return(0,O.Z)(d,[{key:"componentDidMount",value:function(){this._isMounted=!0}},{key:"componentWillUnmount",value:function(){this._isMounted=!1,this.abort()}},{key:"post",value:function(t){var r=this,i=t.data,a=t.origin,l=t.action,s=t.parsedFile;if(!!this._isMounted){var c=this.props,v=c.onStart,p=c.customRequest,h=c.name,y=c.headers,F=c.withCredentials,C=c.method,m=a.uid,E=p||G,k={action:l,filename:h,data:i,file:s,headers:y,withCredentials:F,method:C||"post",onProgress:function(u){var g=r.props.onProgress;g==null||g(u,s)},onSuccess:function(u,g){var b=r.props.onSuccess;b==null||b(u,s,g),delete r.reqs[m]},onError:function(u,g){var b=r.props.onError;b==null||b(u,g,s),delete r.reqs[m]}};v(a),this.reqs[m]=E(k)}}},{key:"reset",value:function(){this.setState({uid:M()})}},{key:"abort",value:function(t){var r=this.reqs;if(t){var i=t.uid?t.uid:t;r[i]&&r[i].abort&&r[i].abort(),delete r[i]}else Object.keys(r).forEach(function(a){r[a]&&r[a].abort&&r[a].abort(),delete r[a]})}},{key:"render",value:function(){var t,r=this.props,i=r.component,a=r.prefixCls,l=r.className,s=r.disabled,c=r.id,v=r.style,p=r.multiple,h=r.accept,y=r.capture,F=r.children,C=r.directory,m=r.openFileDialogOnClick,E=r.onMouseEnter,k=r.onMouseLeave,P=(0,W.Z)(r,ee),u=K()((t={},(0,w.Z)(t,a,!0),(0,w.Z)(t,"".concat(a,"-disabled"),s),(0,w.Z)(t,l,l),t)),g=C?{directory:"directory",webkitdirectory:"webkitdirectory"}:{},b=s?{}:{onClick:m?this.onClick:function(){},onKeyDown:m?this.onKeyDown:function(){},onMouseEnter:E,onMouseLeave:k,onDrop:this.onFileDrop,onDragOver:this.onFileDrop,tabIndex:"0"};return Z.createElement(i,(0,D.Z)({},b,{className:u,role:"button",style:v}),Z.createElement("input",(0,D.Z)({},(0,q.Z)(P,{aria:!0,data:!0}),{id:c,type:"file",ref:this.saveFileInput,onClick:function(oe){return oe.stopPropagation()},key:this.state.uid,style:{display:"none"},accept:h},g,{multiple:p,onChange:this.onChange},y!=null?{capture:y}:{})),F)}}]),d}(Z.Component),te=re;function S(){}var I=function(o){(0,$.Z)(d,o);var n=(0,L.Z)(d);function d(){var e;(0,U.Z)(this,d);for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];return e=n.call.apply(n,[this].concat(r)),e.uploader=void 0,e.saveUploader=function(a){e.uploader=a},e}return(0,O.Z)(d,[{key:"abort",value:function(t){this.uploader.abort(t)}},{key:"render",value:function(){return Z.createElement(te,(0,D.Z)({},this.props,{ref:this.saveUploader}))}}]),d}(Z.Component);I.defaultProps={component:"span",prefixCls:"rc-upload",data:{},headers:{},name:"file",multipart:!1,onStart:S,onError:S,onSuccess:S,multiple:!1,beforeUpload:null,customRequest:null,withCredentials:!1,openFileDialogOnClick:!0};var ae=I,ne=ae}}]);
|