no message

Former-commit-id: 8f2e5ff5153fc8f3880d0e09f2676a9cd0933b47
Former-commit-id: 3f833a015053f2735833ee6e36d90197a861e127
Former-commit-id: 666087a518ffe7186b5dffc74abe9fddea50b6ab
This commit is contained in:
李杨
2018-02-15 15:13:25 +08:00
parent ae7a6bcacb
commit 41b0c014e0

View File

@@ -57,37 +57,20 @@ export default {
this.table.data = results this.table.data = results
}, },
handleUpload(file) { handleUpload(file) {
// document.getElementById('excel-upload-input').click() this.readerData(file)
this.handkeFileChange(file)
return false return false
}, },
handkeFileChange(file) { readerData(file) {
const itemFile = file
this.readerData(itemFile)
},
readerData(itemFile) {
const reader = new FileReader() const reader = new FileReader()
reader.onload = e => { const fixdata = data => {
const data = e.target.result
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 results = XLSX.utils.sheet_to_json(worksheet)
this.generateDate({ header, results })
}
reader.readAsArrayBuffer(itemFile)
},
fixdata(data) {
let o = '' let o = ''
let l = 0 let l = 0
const w = 10240 const w = 10240
for (; l < data.byteLength / w; ++l) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w, l * w + w))) 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))) o += String.fromCharCode.apply(null, new Uint8Array(data.slice(l * w)))
return o return o
}, }
get_header_row(sheet) { const get_header_row = sheet => {
const headers = [] const headers = []
const range = XLSX.utils.decode_range(sheet['!ref']) const range = XLSX.utils.decode_range(sheet['!ref'])
let C let C
@@ -100,6 +83,18 @@ export default {
} }
return headers return headers
} }
reader.onload = e => {
const data = e.target.result
const fixedData = fixdata(data)
const workbook = XLSX.read(btoa(fixedData), { type: 'base64' })
const firstSheetName = workbook.SheetNames[0]
const worksheet = workbook.Sheets[firstSheetName]
const header = get_header_row(worksheet)
const results = XLSX.utils.sheet_to_json(worksheet)
this.generateDate({ header, results })
}
reader.readAsArrayBuffer(file)
}
} }
} }
</script> </script>