1
1
<template >
2
2
<div >
3
- <el-button :loading =" loading" type =" primary" @click =" handleUpload" >select excel file</el-button >
4
3
<input id =" excel-upload-input" type =" file" accept =" .xlsx, .xls" class =" c-hide" @change =" handkeFileChange" >
4
+ <div id =" drop" @drop =" handleDrop" @dragover =" handleDragover" @dragenter =" handleDragover" >
5
+ Drop excel file here or
6
+ <el-button style =" margin-left :16px ;" size =" mini" type =" primary" @click =" handleUpload" >browse</el-button >
7
+ </div >
5
8
</div >
6
9
</template >
7
10
@@ -22,16 +25,35 @@ export default {
22
25
generateDate ({ header, results }) {
23
26
this .excelData .header = header
24
27
this .excelData .results = results
25
- this .loading = false
26
28
this .$emit (' on-selected-file' , this .excelData )
27
29
},
30
+ handleDrop (e ) {
31
+ e .stopPropagation ()
32
+ e .preventDefault ()
33
+ const files = e .dataTransfer .files
34
+ if (files .length !== 1 ) {
35
+ this .$message .error (' Only support uploading one file!' )
36
+ return
37
+ }
38
+ const itemFile = files[0 ] // only use files[0]
39
+ this .readerData (itemFile)
40
+ e .stopPropagation ()
41
+ e .preventDefault ()
42
+ },
43
+ handleDragover (e ) {
44
+ e .stopPropagation ()
45
+ e .preventDefault ()
46
+ e .dataTransfer .dropEffect = ' copy'
47
+ },
28
48
handleUpload () {
29
49
document .getElementById (' excel-upload-input' ).click ()
30
50
},
31
51
handkeFileChange (e ) {
32
- this .loading = true
33
52
const files = e .target .files
34
53
const itemFile = files[0 ] // only use files[0]
54
+ this .readerData (itemFile)
55
+ },
56
+ readerData (itemFile ) {
35
57
const reader = new FileReader ()
36
58
reader .onload = e => {
37
59
const data = e .target .result
@@ -75,4 +97,16 @@ export default {
75
97
display : none ;
76
98
z-index : -9999 ;
77
99
}
100
+ #drop {
101
+ border : 2px dashed #bbb ;
102
+ width : 600px ;
103
+ height : 160px ;
104
+ line-height : 160px ;
105
+ margin : 0 auto ;
106
+ font-size : 24px ;
107
+ border-radius : 5px ;
108
+ text-align : center ;
109
+ color : #bbb ;
110
+ position : relative ;
111
+ }
78
112
</style >
0 commit comments