perf[UploadExcel-component]: set readerData to promise
This commit is contained in:
parent
8c685cc4c6
commit
9f8ac37497
|
@ -3,7 +3,7 @@
|
||||||
<input id="excel-upload-input" ref="excel-upload-input" type="file" accept=".xlsx, .xls" class="c-hide" @change="handkeFileChange">
|
<input id="excel-upload-input" ref="excel-upload-input" type="file" accept=".xlsx, .xls" class="c-hide" @change="handkeFileChange">
|
||||||
<div id="drop" @drop="handleDrop" @dragover="handleDragover" @dragenter="handleDragover">
|
<div id="drop" @drop="handleDrop" @dragover="handleDragover" @dragenter="handleDragover">
|
||||||
Drop excel file here or
|
Drop excel file here or
|
||||||
<el-button style="margin-left:16px;" size="mini" type="primary" @click="handleUpload">browse</el-button>
|
<el-button :loading="loading" style="margin-left:16px;" size="mini" type="primary" @click="handleUpload">browse</el-button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -52,10 +52,14 @@ export default {
|
||||||
const files = e.target.files
|
const files = e.target.files
|
||||||
const itemFile = files[0] // only use files[0]
|
const itemFile = files[0] // only use files[0]
|
||||||
if (!itemFile) return
|
if (!itemFile) return
|
||||||
this.readerData(itemFile)
|
this.loading = true
|
||||||
|
this.readerData(itemFile).then(() => {
|
||||||
this.$refs['excel-upload-input'].value = null // fix can't select the same excel
|
this.$refs['excel-upload-input'].value = null // fix can't select the same excel
|
||||||
|
this.loading = false
|
||||||
|
})
|
||||||
},
|
},
|
||||||
readerData(itemFile) {
|
readerData(itemFile) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
const reader = new FileReader()
|
const reader = new FileReader()
|
||||||
reader.onload = e => {
|
reader.onload = e => {
|
||||||
const data = e.target.result
|
const data = e.target.result
|
||||||
|
@ -66,8 +70,10 @@ export default {
|
||||||
const header = this.get_header_row(worksheet)
|
const header = this.get_header_row(worksheet)
|
||||||
const results = XLSX.utils.sheet_to_json(worksheet)
|
const results = XLSX.utils.sheet_to_json(worksheet)
|
||||||
this.generateDate({ header, results })
|
this.generateDate({ header, results })
|
||||||
|
resolve()
|
||||||
}
|
}
|
||||||
reader.readAsArrayBuffer(itemFile)
|
reader.readAsArrayBuffer(itemFile)
|
||||||
|
})
|
||||||
},
|
},
|
||||||
fixdata(data) {
|
fixdata(data) {
|
||||||
let o = ''
|
let o = ''
|
||||||
|
|
Loading…
Reference in New Issue