Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
VueElementTemplate
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
黄瑜
VueElementTemplate
Commits
1d0b26ce
Commit
1d0b26ce
authored
Jan 02, 2018
by
Pan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf[upload-excel]: support drag upload
parent
ea7e1396
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
3 deletions
+37
-3
index.vue
src/components/UploadExcel/index.vue
+37
-3
No files found.
src/components/UploadExcel/index.vue
View file @
1d0b26ce
<
template
>
<
template
>
<div>
<div>
<el-button
:loading=
"loading"
type=
"primary"
@
click=
"handleUpload"
>
select excel file
</el-button>
<input
id=
"excel-upload-input"
type=
"file"
accept=
".xlsx, .xls"
class=
"c-hide"
@
change=
"handkeFileChange"
>
<input
id=
"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>
</div>
</div>
</div>
</
template
>
</
template
>
...
@@ -22,16 +25,35 @@ export default {
...
@@ -22,16 +25,35 @@ export default {
generateDate
({
header
,
results
})
{
generateDate
({
header
,
results
})
{
this
.
excelData
.
header
=
header
this
.
excelData
.
header
=
header
this
.
excelData
.
results
=
results
this
.
excelData
.
results
=
results
this
.
loading
=
false
this
.
$emit
(
'on-selected-file'
,
this
.
excelData
)
this
.
$emit
(
'on-selected-file'
,
this
.
excelData
)
},
},
handleDrop
(
e
)
{
e
.
stopPropagation
()
e
.
preventDefault
()
const
files
=
e
.
dataTransfer
.
files
if
(
files
.
length
!==
1
)
{
this
.
$message
.
error
(
'Only support uploading one file!'
)
return
}
const
itemFile
=
files
[
0
]
// only use files[0]
this
.
readerData
(
itemFile
)
e
.
stopPropagation
()
e
.
preventDefault
()
},
handleDragover
(
e
)
{
e
.
stopPropagation
()
e
.
preventDefault
()
e
.
dataTransfer
.
dropEffect
=
'copy'
},
handleUpload
()
{
handleUpload
()
{
document
.
getElementById
(
'excel-upload-input'
).
click
()
document
.
getElementById
(
'excel-upload-input'
).
click
()
},
},
handkeFileChange
(
e
)
{
handkeFileChange
(
e
)
{
this
.
loading
=
true
const
files
=
e
.
target
.
files
const
files
=
e
.
target
.
files
const
itemFile
=
files
[
0
]
// only use files[0]
const
itemFile
=
files
[
0
]
// only use files[0]
this
.
readerData
(
itemFile
)
},
readerData
(
itemFile
)
{
const
reader
=
new
FileReader
()
const
reader
=
new
FileReader
()
reader
.
onload
=
e
=>
{
reader
.
onload
=
e
=>
{
const
data
=
e
.
target
.
result
const
data
=
e
.
target
.
result
...
@@ -75,4 +97,16 @@ export default {
...
@@ -75,4 +97,16 @@ export default {
display
:
none
;
display
:
none
;
z-index
:
-9999
;
z-index
:
-9999
;
}
}
#drop
{
border
:
2px
dashed
#bbb
;
width
:
600px
;
height
:
160px
;
line-height
:
160px
;
margin
:
0
auto
;
font-size
:
24px
;
border-radius
:
5px
;
text-align
:
center
;
color
:
#bbb
;
position
:
relative
;
}
</
style
>
</
style
>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment