{"version":3,"sources":["../../../src/components/Editor/Upload.js"],"names":["client","window","OSS","Wrapper","accessKeyId","oss","access_key_id","accessKeySecret","access_key_secret","stsToken","security_token","endpoint","OSS_ENDPOINT","bucket","OSS_BUCKET","uploadPath","path","file","format","shortid","generate","type","split","UploadToOss","url","Promise","resolve","reject","multipartUpload","then","data","catch","error","App","props","state","previewVisible","previewImage","loading","handleCancel","bind","handlePreview","handleChange","customRequest","handleCloseClick","onImgLoad","app","sOssSts","onRef","setState","thumbUrl","fileList","onChangeFileList","info","console","log","onProgress","percent","reader","FileReader","readAsDataURL","onloadend","DRIVER_LICENSE_PATH","onSuccess","onUpload","name","uid","msg","e","message","ERROR_DEFAULT","showError","onError","response","index","newFileList","splice","maxUpload","multiple","uploadButton","intl","get","showPreviewIcon","showRemoveIcon","length","map","left","top","Math","floor","width","React","Component"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;AAEA;;;;AACA;;;;AACA;;;;AACA;;AAMA;;;;AACA;;;;;;;;;;AAEA,IAAMA,SAAS,SAATA,MAAS,MAAO;AACpB,SAAO,IAAIC,OAAOC,GAAP,CAAWC,OAAf,CAAuB;AAC5BC,iBAAaC,IAAIC,aADW;AAE5BC,qBAAiBF,IAAIG,iBAFO;AAG5BC,cAAUJ,IAAIK,cAHc;AAI5BC,cAAUC,sBAJkB,EAIJ;AACxBC,YAAQC;AALoB,GAAvB,CAAP;AAOD,CARD;;AAUA,IAAMC,aAAa,SAAbA,UAAa,CAACC,IAAD,EAAOC,IAAP,EAAgB;AACjC,SAAUD,IAAV,SAAkB,uBAAQE,MAAR,CAAe,UAAf,CAAlB,SAAgDC,kBAAQC,QAAR,EAAhD,SACEH,KAAKI,IAAL,CAAUC,KAAV,CAAgB,GAAhB,EAAqB,CAArB,CADF;AAGD,CAJD;;AAMA,IAAMC,cAAc,SAAdA,WAAc,CAAClB,GAAD,EAAMW,IAAN,EAAYC,IAAZ,EAAqB;AACvC,MAAMO,MA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AWD,SAZA,CAbH;AA0BE;AAAA;AAAA;AACE,2BAAc,oBADhB;AAEE,qBAAStC,cAFX;AAGE,oBAAQ,IAHV;AAIE,sBAAU,KAAKG;AAJjB;AAME;AAAA;AAAA,cAAM,UAAU,KAAKJ,KAAL,CAAWG,OAA3B;AACE;AACE,mBAAI,QADN;AAEE,qBAAO,EAAEoD,OAAO,MAAT,EAFT;AAGE,mBAAKrD,YAHP;AAIE,sBAAQ,KAAKQ,SAJf;AAKE,uBAAS,KAAKA;AALhB;AADF;AANF;AA1BF,OADF;AA6CD;;;;EApIe8C,gBAAMC,S;;kBAuIT,uBAAQ3D,GAAR,C","file":"Upload.js","sourcesContent":["import React from \"react\";\nimport { Upload, Icon, Modal, message, Spin } from \"antd\";\nimport dayjs from \"dayjs\";\nimport shortid from \"shortid\";\nimport intl from \"react-intl-universal\";\nimport {\n OSS_ENDPOINT,\n OSS_BUCKET,\n DRIVER_LICENSE_PATH,\n ERROR_DEFAULT\n} from \"../../constant\";\nimport Comment from \"../../Comment\";\nimport \"./Upload.css\";\n\nconst client = oss => {\n return new window.OSS.Wrapper({\n accessKeyId: oss.access_key_id,\n accessKeySecret: oss.access_key_secret,\n stsToken: oss.security_token,\n endpoint: OSS_ENDPOINT, //常量,你可以自己定义\n bucket: OSS_BUCKET\n });\n};\n\nconst uploadPath = (path, file) => {\n return `${path}/${dayjs().format(\"YYYYMMDD\")}/${shortid.generate()}.${\n file.type.split(\"/\")[1]\n }`;\n};\n\nconst UploadToOss = (oss, path, file) => {\n const url = uploadPath(path, file);\n return new Promise((resolve, reject) => {\n client(oss)\n .multipartUpload(url, file)\n .then(data => {\n resolve(data);\n })\n .catch(error => {\n reject(error);\n });\n });\n};\n\nclass App extends React.Component {\n constructor(props) {\n super(props);\n this.state = {\n previewVisible: false,\n previewImage: \"\",\n loading: false\n };\n this.handleCancel = this.handleCancel.bind(this);\n this.handlePreview = this.handlePreview.bind(this);\n this.handleChange = this.handleChange.bind(this);\n this.customRequest = this.customRequest.bind(this);\n this.handleCloseClick = this.handleCloseClick.bind(this);\n this.onImgLoad = this.onImgLoad.bind(this);\n }\n\n componentDidMount() {\n this.props.app.sOssSts();\n if (this.props.onRef) {\n this.props.onRef(this);\n }\n }\n\n onImgLoad() {\n this.setState({\n loading: false\n });\n }\n\n handleCancel() {\n this.setState({ previewVisible: false });\n }\n\n handlePreview(file) {\n this.setState({\n previewImage: file.url || file.thumbUrl,\n previewVisible: true\n });\n }\n\n handleChange({ fileList }) {\n this.props.onChangeFileList(fileList);\n }\n\n customRequest(info) {\n const { file } = info;\n console.log(file);\n info.onProgress({ percent: 10 });\n let reader = new FileReader();\n reader.readAsDataURL(info.file);\n reader.onloadend = () => {\n info.onProgress({ percent: 20 });\n // DRIVER_LICENSE_PATH oss 的存储路径位置\n UploadToOss(this.props.app.oss, DRIVER_LICENSE_PATH, file)\n .then(data => {\n info.onProgress({ percent: 100 });\n info.onSuccess(data);\n this.props.onUpload({ path: data.name, uid: file.uid });\n })\n .catch(e => {\n const msg = e.message || ERROR_DEFAULT;\n if (this.props.showError) {\n message.error(msg);\n }\n if (this.props.onError) {\n this.props.onError(msg, { response: e.response });\n }\n info.onError(e);\n });\n };\n }\n\n handleCloseClick(index) {\n let newFileList = this.props.fileList;\n newFileList.splice(index, 1);\n this.props.onChangeFileList(newFileList);\n }\n\n render() {\n const { previewVisible, previewImage } = this.state;\n const { fileList, maxUpload, multiple } = this.props;\n const uploadButton = (\n
\n \n
{intl.get(\"editor.uploadBtn\")}
\n
\n );\n return (\n
\n \n {fileList.length >= maxUpload ? null : uploadButton}\n \n {fileList.map((file, index) => {\n return (\n \n );\n })}\n \n \n \n \n \n
\n );\n }\n}\n\nexport default Comment(App);\n"]}