forked from AkkomaGang/admin-fe
perf[UploadExcel-component]: set readerData to promise
This commit is contained in:
parent
8c685cc4c6
commit
9f8ac37497
1 changed files with 21 additions and 15 deletions
|
@ -3,7 +3,7 @@
|
|||
<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">
|
||||
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>
|
||||
</template>
|
||||
|
@ -52,10 +52,14 @@ export default {
|
|||
const files = e.target.files
|
||||
const itemFile = files[0] // only use files[0]
|
||||
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.loading = false
|
||||
})
|
||||
},
|
||||
readerData(itemFile) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
reader.onload = e => {
|
||||
const data = e.target.result
|
||||
|
@ -66,8 +70,10 @@ export default {
|
|||
const header = this.get_header_row(worksheet)
|
||||
const results = XLSX.utils.sheet_to_json(worksheet)
|
||||
this.generateDate({ header, results })
|
||||
resolve()
|
||||
}
|
||||
reader.readAsArrayBuffer(itemFile)
|
||||
})
|
||||
},
|
||||
fixdata(data) {
|
||||
let o = ''
|
||||
|
|
Loading…
Reference in a new issue