11<template >
22 <div >
3- <el-button :loading =" loading" type =" primary" @click =" handleUpload" >select excel file</el-button >
43 <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 >
58 </div >
69</template >
710
@@ -22,16 +25,35 @@ export default {
2225 generateDate ({ header, results }) {
2326 this .excelData .header = header
2427 this .excelData .results = results
25- this .loading = false
2628 this .$emit (' on-selected-file' , this .excelData )
2729 },
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+ },
2848 handleUpload () {
2949 document .getElementById (' excel-upload-input' ).click ()
3050 },
3151 handkeFileChange (e ) {
32- this .loading = true
3352 const files = e .target .files
3453 const itemFile = files[0 ] // only use files[0]
54+ this .readerData (itemFile)
55+ },
56+ readerData (itemFile ) {
3557 const reader = new FileReader ()
3658 reader .onload = e => {
3759 const data = e .target .result
@@ -75,4 +97,16 @@ export default {
7597 display : none ;
7698 z-index : -9999 ;
7799}
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+ }
78112 </style >
0 commit comments