1
1
<template >
2
2
<div >
3
- <input id =" excel-upload-input" ref =" excel-upload-input" type =" file" accept =" .xlsx, .xls" class = " c-hide " @change =" handkeFileChange " >
3
+ <input id =" excel-upload-input" ref =" excel-upload-input" type =" file" accept =" .xlsx, .xls" @change =" handleClick " >
4
4
<div id =" drop" @drop =" handleDrop" @dragover =" handleDragover" @dragenter =" handleDragover" >
5
5
Drop excel file here or
6
- <el-button :loading =" loading" 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 >
@@ -25,11 +25,12 @@ export default {
25
25
generateDate ({ header, results }) {
26
26
this .excelData .header = header
27
27
this .excelData .results = results
28
- this .$emit (' on-selected-file ' , this .excelData )
28
+ this .$emit (' success ' , this .excelData )
29
29
},
30
30
handleDrop (e ) {
31
31
e .stopPropagation ()
32
32
e .preventDefault ()
33
+ if (this .loading ) return
33
34
const files = e .dataTransfer .files
34
35
if (files .length !== 1 ) {
35
36
this .$message .error (' Only support uploading one file!' )
@@ -48,17 +49,16 @@ export default {
48
49
handleUpload () {
49
50
document .getElementById (' excel-upload-input' ).click ()
50
51
},
51
- handkeFileChange (e ) {
52
+ handleClick (e ) {
52
53
const files = e .target .files
53
54
const itemFile = files[0 ] // only use files[0]
54
55
if (! itemFile) return
55
- this .loading = true
56
56
this .readerData (itemFile).then (() => {
57
57
this .$refs [' excel-upload-input' ].value = null // fix can't select the same excel
58
- this .loading = false
59
58
})
60
59
},
61
60
readerData (itemFile ) {
61
+ this .loading = true
62
62
return new Promise ((resolve , reject ) => {
63
63
const reader = new FileReader ()
64
64
reader .onload = e => {
@@ -70,6 +70,7 @@ export default {
70
70
const header = this .get_header_row (worksheet)
71
71
const results = XLSX .utils .sheet_to_json (worksheet)
72
72
this .generateDate ({ header, results })
73
+ this .loading = false
73
74
resolve ()
74
75
}
75
76
reader .readAsArrayBuffer (itemFile)
0 commit comments