|
3 | 3 | <input id="excel-upload-input" ref="excel-upload-input" type="file" accept=".xlsx, .xls" class="c-hide" @change="handkeFileChange">
|
4 | 4 | <div id="drop" @drop="handleDrop" @dragover="handleDragover" @dragenter="handleDragover">
|
5 | 5 | Drop excel file here or
|
6 |
| - <el-button style="margin-left:16px;" size="mini" type="primary" @click="handleUpload">browse</el-button> |
| 6 | + <el-button :loading="loading" style="margin-left:16px;" size="mini" type="primary" @click="handleUpload">browse</el-button> |
7 | 7 | </div>
|
8 | 8 | </div>
|
9 | 9 | </template>
|
@@ -52,22 +52,28 @@ export default {
|
52 | 52 | const files = e.target.files
|
53 | 53 | const itemFile = files[0] // only use files[0]
|
54 | 54 | if (!itemFile) return
|
55 |
| - this.readerData(itemFile) |
56 |
| - this.$refs['excel-upload-input'].value = null // fix can't select the same excel |
| 55 | + this.loading = true |
| 56 | + this.readerData(itemFile).then(() => { |
| 57 | + this.$refs['excel-upload-input'].value = null // fix can't select the same excel |
| 58 | + this.loading = false |
| 59 | + }) |
57 | 60 | },
|
58 | 61 | readerData(itemFile) {
|
59 |
| - const reader = new FileReader() |
60 |
| - reader.onload = e => { |
61 |
| - const data = e.target.result |
62 |
| - const fixedData = this.fixdata(data) |
63 |
| - const workbook = XLSX.read(btoa(fixedData), { type: 'base64' }) |
64 |
| - const firstSheetName = workbook.SheetNames[0] |
65 |
| - const worksheet = workbook.Sheets[firstSheetName] |
66 |
| - const header = this.get_header_row(worksheet) |
67 |
| - const results = XLSX.utils.sheet_to_json(worksheet) |
68 |
| - this.generateDate({ header, results }) |
69 |
| - } |
70 |
| - reader.readAsArrayBuffer(itemFile) |
| 62 | + return new Promise((resolve, reject) => { |
| 63 | + const reader = new FileReader() |
| 64 | + reader.onload = e => { |
| 65 | + const data = e.target.result |
| 66 | + const fixedData = this.fixdata(data) |
| 67 | + const workbook = XLSX.read(btoa(fixedData), { type: 'base64' }) |
| 68 | + const firstSheetName = workbook.SheetNames[0] |
| 69 | + const worksheet = workbook.Sheets[firstSheetName] |
| 70 | + const header = this.get_header_row(worksheet) |
| 71 | + const results = XLSX.utils.sheet_to_json(worksheet) |
| 72 | + this.generateDate({ header, results }) |
| 73 | + resolve() |
| 74 | + } |
| 75 | + reader.readAsArrayBuffer(itemFile) |
| 76 | + }) |
71 | 77 | },
|
72 | 78 | fixdata(data) {
|
73 | 79 | let o = ''
|
|
0 commit comments