通用评论

1
  1. {"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","handleCancel","bind","handlePreview","handleChange","customRequest","app","sOssSts","setState","thumbUrl","fileList","onChangeFileList","info","onProgress","percent","reader","FileReader","readAsDataURL","onloadend","DRIVER_LICENSE_PATH","onSuccess","onUpload","name","uid","msg","e","message","ERROR_DEFAULT","showError","onError","response","maxUpload","multiple","uploadButton","intl","get","length","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,MAAMT,WAAWC,IAAX,EAAiBC,IAAjB,CAAZ;AACA,SAAO,IAAIQ,OAAJ,CAAY,U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AUtB,QAJZ;AAKE,2BAAe,KAAKL,aALtB;AAME,uBAAW,KAAKF,aANlB;AAOE,sBAAU,KAAKC;AAPjB;AASGM,mBAAS0B,MAAT,IAAmBL,SAAnB,GAA+B,IAA/B,GAAsCE;AATzC,SADF;AAYE;AAAA;AAAA;AACE,qBAASlC,cADX;AAEE,oBAAQ,IAFV;AAGE,sBAAU,KAAKE;AAHjB;AAKE,iDAAK,KAAI,QAAT,EAAkB,OAAO,EAAEoC,OAAO,MAAT,EAAzB,EAA4C,KAAKrC,YAAjD;AALF;AAZF,OADF;AAsBD;;;;EA1FesC,gBAAMC,S;;kBA6FT,uBAAQ3C,GAAR,C","file":"Upload.js","sourcesContent":["import React from \"react\";\nimport { Upload, Icon, Modal, message } 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 };\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 }\n\n componentDidMount() {\n this.props.app.sOssSts();\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 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();\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 render() {\n const { previewVisible, previewImage } = this.state;\n const { fileList, maxUpload, multiple } = this.props;\n const uploadButton = (\n <div>\n <Icon type=\"plus\" />\n <div className=\"ant-upload-text\">{intl.get(\"editor.uploadBtn\")}</div>\n </div>\n );\n return (\n <div>\n <Upload\n accept=\"image/jpg,image/jpeg,image/png,image/bmp\"\n multiple={multiple}\n listType=\"picture-card\"\n fileList={fileList}\n customRequest={this.customRequest}\n onPreview={this.handlePreview}\n onChange={this.handleChange}\n >\n {fileList.length >= maxUpload ? null : uploadButton}\n </Upload>\n <Modal\n visible={previewVisible}\n footer={null}\n onCancel={this.handleCancel}\n >\n <img alt=\"upload\" style={{ width: \"100%\" }} src={previewImage} />\n </Modal>\n </div>\n );\n }\n}\n\nexport default Comment(App);\n"]}