通用评论

Upload.js.map 9.7KB

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","loading","handleCancel","bind","handlePreview","handleChange","customRequest","handleCloseClick","onImgLoad","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","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,EAA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;AAME;AAAA;AAAA,cAAM,UAAU,KAAKJ,KAAL,CAAWG,OAA3B;AACE;AACE,mBAAI,QADN;AAEE,qBAAO,EAAEiD,OAAO,MAAT,EAFT;AAGE,mBAAKlD,YAHP;AAIE,sBAAQ,KAAKQ,SAJf;AAKE,uBAAS,KAAKA;AALhB;AADF;AANF;AA1BF,OADF;AA6CD;;;;EAhIe2C,gBAAMC,S;;kBAmIT,uBAAQxD,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 }\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 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 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 <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 showUploadList={{ showPreviewIcon: true, showRemoveIcon: false }}\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 {fileList.map((file, index) => {\n return (\n <div\n className=\"upload-close-icon\"\n onClick={this.handleCloseClick.bind(this, index)}\n key={file.uid}\n style={{\n left: `${(index % 3) * 112 + 98}px`,\n top: `${Math.floor(index / 3) * 112 + 16}px`\n }}\n />\n );\n })}\n <Modal\n className=\"upload-img-preview\"\n visible={previewVisible}\n footer={null}\n onCancel={this.handleCancel}\n >\n <Spin spinning={this.state.loading}>\n <img\n alt=\"upload\"\n style={{ width: \"100%\" }}\n src={previewImage}\n onLoad={this.onImgLoad}\n onError={this.onImgLoad}\n />\n </Spin>\n </Modal>\n </div>\n );\n }\n}\n\nexport default Comment(App);\n"]}