From 6ecf8b820a1dffb7880c8aa4035768f6f7d64c74 Mon Sep 17 00:00:00 2001 From: Shaw Date: Tue, 4 Sep 2018 18:09:01 +0800 Subject: [PATCH] fix poor naming formats and typo in UploadExcel component (#1047) --- src/components/UploadExcel/index.vue | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/components/UploadExcel/index.vue b/src/components/UploadExcel/index.vue index 909c3b4a..261bea38 100644 --- a/src/components/UploadExcel/index.vue +++ b/src/components/UploadExcel/index.vue @@ -26,7 +26,7 @@ export default { } }, methods: { - generateDate({ header, results }) { + generateData({ header, results }) { this.excelData.header = header this.excelData.results = results this.onSuccess && this.onSuccess(this.excelData) @@ -82,20 +82,20 @@ export default { const reader = new FileReader() reader.onload = e => { const data = e.target.result - const fixedData = this.fixdata(data) + const fixedData = this.fixData(data) const workbook = XLSX.read(btoa(fixedData), { type: 'base64' }) const firstSheetName = workbook.SheetNames[0] const worksheet = workbook.Sheets[firstSheetName] - const header = this.get_header_row(worksheet) + const header = this.getHeaderRow(worksheet) const results = XLSX.utils.sheet_to_json(worksheet) - this.generateDate({ header, results }) + this.generateData({ header, results }) this.loading = false resolve() } reader.readAsArrayBuffer(rawFile) }) }, - fixdata(data) { + fixData(data) { let o = '' let l = 0 const w = 10240 @@ -103,14 +103,16 @@ export default { o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w))) return o }, - get_header_row(sheet) { + getHeaderRow(sheet) { const headers = [] const range = XLSX.utils.decode_range(sheet['!ref']) let C - const R = range.s.r /* start in the first row */ + const R = range.s.r + /* start in the first row */ for (C = range.s.c; C <= range.e.c; ++C) { /* walk every column in the range */ - var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */ - var hdr = 'UNKNOWN ' + C // <-- replace with your desired default + const cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] + /* find the cell in the first row */ + let hdr = 'UNKNOWN ' + C // <-- replace with your desired default if (cell && cell.t) hdr = XLSX.utils.format_cell(cell) headers.push(hdr) }