We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<BatchImportForNew columns={mapKeyValueCol( keyMapForWin(defaultValue.pricingMannerCode) ).map((item) => ({ ...item, align: "center" }))} keyMap={keyMapForWin(defaultValue.pricingMannerCode)} tableKey="" beforeimport={this.beforeimport} downParams={{ }} fileName={imfileName} downLoadUrl={ } downMethod="post" callback={this.importCallBackForNew} defaultValue={defaultValue} />
<Upload showUploadList={false} style={{ width: "100%" }} fileList={this.state.fileList} beforeUpload={this.beforeUpload} onChange={this.getUploadFile} > <Button style={{ marginLeft: 5 }} key="chooseFile" loading={loading} type="primary" > <Icon type="upload" />选择文件 </Button> </Upload>
// 前端解析 getUploadFile = (e) => { const { keyMap, tableKey } = this.props; const fileName = e.file.name; // 导入文件类型 if(!fileName.includes('xls')) { return; } //拿到所导入文件的名字 let fileList = [...e.fileList]; fileList = fileList.slice(-1); this.setState({ fileList, loading: true }); //定义reader,存放文件读取方法 const reader = new FileReader() const _that = this; if (e.file.status !== 'uploading') { reader.onload = (function (theFile) { return function (e) { let binary = ''; var wb; var outData; const bytes = new Uint8Array(e.target.result); const length = bytes.byteLength; for (let i = 0; i < length; i++) { binary += String.fromCharCode(bytes[i]); } wb = XLSX.read(binary, { type: 'binary' }); outData = XLSX.utils.sheet_to_json(wb.Sheets[wb.SheetNames[0]]); // 处理outData if (!isEmptyArray(outData)) { const newImportList = outData.map((item) => { return dealimportObj(item, keyMap); }); newImportList.forEach((item, index) => { // 前端自定义行号 item[tableKey] = (Array(4).join(0) + (index+1)).slice(-4) + '0'; item.whetherNew = true; }) _that.setState({ data: newImportList, loading: false }); } }; })(fileList[0].originFileObj); } //启动函数 reader.readAsArrayBuffer(fileList[0].originFileObj); //onload在文件被读取时自动触发 }
export const dealimportObj =(obj, keyMap)=>{ if(!obj) return; const a = Object.keys(obj).reduce((newData, key) => { let newKey = keyMap[key] || key newData[newKey] = obj[key] return newData }, {}); return a; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
复用组件
上传组件
前端解析
处理解析数据函数
The text was updated successfully, but these errors were encountered: