From 3153a1b10bc32e1650c644d829f284d37ee044c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8A=B1=E8=A3=A4=E8=A1=A9?= Date: Fri, 25 Jan 2019 12:50:21 +0800 Subject: [PATCH] perf[UploadExcel]: optimized code (#1552) --- src/components/UploadExcel/index.vue | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/components/UploadExcel/index.vue b/src/components/UploadExcel/index.vue index 20e16398..a6b8dbce 100644 --- a/src/components/UploadExcel/index.vue +++ b/src/components/UploadExcel/index.vue @@ -82,8 +82,7 @@ export default { const reader = new FileReader() reader.onload = e => { const data = e.target.result - const fixedData = this.fixData(data) - const workbook = XLSX.read(btoa(fixedData), { type: 'base64' }) + const workbook = XLSX.read(data, { type: 'array' }) const firstSheetName = workbook.SheetNames[0] const worksheet = workbook.Sheets[firstSheetName] const header = this.getHeaderRow(worksheet) @@ -95,14 +94,6 @@ export default { reader.readAsArrayBuffer(rawFile) }) }, - fixData(data) { - let o = '' - let l = 0 - const w = 10240 - for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w))) - o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w))) - return o - }, getHeaderRow(sheet) { const headers = [] const range = XLSX.utils.decode_range(sheet['!ref'])