Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
admin-fe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Pleroma
admin-fe
Commits
cb3578e5
Commit
cb3578e5
authored
7 years ago
by
Pan
Browse files
Options
Downloads
Patches
Plain Diff
perf[drag-table]:refine the effect && fixed row-key bug
parent
fe25c4d9
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/views/example/table/dragTable.vue
+27
-11
27 additions, 11 deletions
src/views/example/table/dragTable.vue
with
27 additions
and
11 deletions
src/views/example/table/dragTable.vue
+
27
−
11
View file @
cb3578e5
<
template
>
<
template
>
<div
class=
"app-container calendar-list-container"
>
<div
class=
"app-container calendar-list-container"
>
<!-- Note that row-key is necessary to get a correct row order. -->
<el-table
:data=
"list"
v-loading.body=
"listLoading"
border
fit
highlight-current-row
style=
"width: 100%"
>
<el-table
:data=
"list"
row-key=
"id"
v-loading.body=
"listLoading"
border
fit
highlight-current-row
style=
"width: 100%"
>
<el-table-column
align=
"center"
label=
"序号"
width=
"65"
>
<el-table-column
align=
"center"
label=
"序号"
width=
"65"
>
<template
slot-scope=
"scope"
>
<template
slot-scope=
"scope"
>
...
@@ -27,9 +27,9 @@
...
@@ -27,9 +27,9 @@
<
/template
>
<
/template
>
<
/el-table-column
>
<
/el-table-column
>
<
el
-
table
-
column
width
=
"
8
0px
"
label
=
"
重要性
"
>
<
el
-
table
-
column
width
=
"
10
0px
"
label
=
"
重要性
"
>
<
template
slot
-
scope
=
"
scope
"
>
<
template
slot
-
scope
=
"
scope
"
>
<
svg
-
icon
v
-
for
=
"
n in +scope.row.importance
"
icon
-
class
=
"
star
"
class
=
"
meta-item__icon
"
:
key
=
"
n
"
><
/svg-icon
>
<
svg
-
icon
v
-
for
=
"
n in +scope.row.importance
"
icon
-
class
=
"
star
"
class
=
"
icon-star
"
:
key
=
"
n
"
><
/svg-icon
>
<
/template
>
<
/template
>
<
/el-table-column
>
<
/el-table-column
>
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
<
/template
>
<
/template
>
<
/el-table-column
>
<
/el-table-column
>
<
el
-
table
-
column
align
=
"
center
"
label
=
"
拖拽
"
width
=
"
95
"
>
<
el
-
table
-
column
align
=
"
center
"
label
=
"
拖拽
"
width
=
"
80
"
>
<
template
slot
-
scope
=
"
scope
"
>
<
template
slot
-
scope
=
"
scope
"
>
<
svg
-
icon
class
=
'
drag-handler
'
icon
-
class
=
"
drag
"
><
/svg-icon
>
<
svg
-
icon
class
=
'
drag-handler
'
icon
-
class
=
"
drag
"
><
/svg-icon
>
<
/template
>
<
/template
>
...
@@ -53,7 +53,7 @@
...
@@ -53,7 +53,7 @@
<
/el-table
>
<
/el-table
>
<
div
class
=
'
show-d
'
>
默认顺序
&
nbsp
;
{{
old
er
List
}}
<
/div
>
<
div
class
=
'
show-d
'
>
默认顺序
&
nbsp
;
{{
oldList
}}
<
/div
>
<
div
class
=
'
show-d
'
>
拖拽后顺序
{{
newList
}}
<
/div
>
<
div
class
=
'
show-d
'
>
拖拽后顺序
{{
newList
}}
<
/div
>
<
/div
>
<
/div
>
...
@@ -75,7 +75,7 @@ export default {
...
@@ -75,7 +75,7 @@ export default {
limit
:
10
limit
:
10
}
,
}
,
sortable
:
null
,
sortable
:
null
,
old
er
List
:
[],
oldList
:
[],
newList
:
[]
newList
:
[]
}
}
}
,
}
,
...
@@ -99,8 +99,8 @@ export default {
...
@@ -99,8 +99,8 @@ export default {
this
.
list
=
response
.
data
.
items
this
.
list
=
response
.
data
.
items
this
.
total
=
response
.
data
.
total
this
.
total
=
response
.
data
.
total
this
.
listLoading
=
false
this
.
listLoading
=
false
this
.
old
er
List
=
this
.
list
.
map
(
v
=>
v
.
id
)
this
.
oldList
=
this
.
list
.
map
(
v
=>
v
.
id
)
this
.
newList
=
this
.
old
er
List
.
slice
()
this
.
newList
=
this
.
oldList
.
slice
()
this
.
$nextTick
(()
=>
{
this
.
$nextTick
(()
=>
{
this
.
setSort
()
this
.
setSort
()
}
)
}
)
...
@@ -109,7 +109,12 @@ export default {
...
@@ -109,7 +109,12 @@ export default {
setSort
()
{
setSort
()
{
const
el
=
document
.
querySelectorAll
(
'
.el-table__body-wrapper > table > tbody
'
)[
0
]
const
el
=
document
.
querySelectorAll
(
'
.el-table__body-wrapper > table > tbody
'
)[
0
]
this
.
sortable
=
Sortable
.
create
(
el
,
{
this
.
sortable
=
Sortable
.
create
(
el
,
{
ghostClass
:
'
sortable-ghost
'
,
// Class name for the drop placeholder,
onEnd
:
evt
=>
{
onEnd
:
evt
=>
{
const
targetRow
=
this
.
list
.
splice
(
evt
.
oldIndex
,
1
)[
0
]
this
.
list
.
splice
(
evt
.
newIndex
,
0
,
targetRow
)
// for show the changes, you can delete in you code
const
tempIndex
=
this
.
newList
.
splice
(
evt
.
oldIndex
,
1
)[
0
]
const
tempIndex
=
this
.
newList
.
splice
(
evt
.
oldIndex
,
1
)[
0
]
this
.
newList
.
splice
(
evt
.
newIndex
,
0
,
tempIndex
)
this
.
newList
.
splice
(
evt
.
newIndex
,
0
,
tempIndex
)
}
}
...
@@ -119,10 +124,21 @@ export default {
...
@@ -119,10 +124,21 @@ export default {
}
}
<
/script
>
<
/script
>
<
style
>
.
sortable
-
ghost
{
opacity
:
.
8
;
color
:
#fff
!
important
;
background
:
#
42
b983
!
important
;
}
<
/style
>
<
style
scoped
>
<
style
scoped
>
.
icon
-
star
{
margin
-
right
:
2
px
;
}
.
drag
-
handler
{
.
drag
-
handler
{
width
:
3
0
px
;
width
:
2
0
px
;
height
:
3
0
px
;
height
:
2
0
px
;
cursor
:
pointer
;
cursor
:
pointer
;
}
}
.
show
-
d
{
.
show
-
d
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment