1
1
<template >
2
2
<div class =" app-container calendar-list-container" >
3
-
4
- <el-table :data =" list" v-loading.body =" listLoading" border fit highlight-current-row style =" width : 100% " >
3
+ <!-- Note that row-key is necessary to get a correct row order. -->
4
+ <el-table :data =" list" row-key = " id " v-loading.body =" listLoading" border fit highlight-current-row style =" width : 100% " >
5
5
6
6
<el-table-column align =" center" label =" 序号" width =" 65" >
7
7
<template slot-scope="scope">
27
27
</template >
28
28
</el-table-column >
29
29
30
- <el-table-column width =" 80px " label =" 重要性" >
30
+ <el-table-column width =" 100px " label =" 重要性" >
31
31
<template slot-scope="scope">
32
- <svg-icon v-for =" n in +scope.row.importance" icon-class =" star" class =" meta-item__icon " :key =" n" ></svg-icon >
32
+ <svg-icon v-for =" n in +scope.row.importance" icon-class =" star" class =" icon-star " :key =" n" ></svg-icon >
33
33
</template >
34
34
</el-table-column >
35
35
45
45
</template >
46
46
</el-table-column >
47
47
48
- <el-table-column align =" center" label =" 拖拽" width =" 95 " >
48
+ <el-table-column align =" center" label =" 拖拽" width =" 80 " >
49
49
<template slot-scope="scope">
50
50
<svg-icon class =' drag-handler' icon-class =" drag" ></svg-icon >
51
51
</template >
52
52
</el-table-column >
53
53
54
54
</el-table >
55
55
56
- <div class =' show-d' >默认顺序   ; {{ olderList }}</div >
56
+ <div class =' show-d' >默认顺序   ; {{ oldList }}</div >
57
57
<div class =' show-d' >拖拽后顺序{{newList}}</div >
58
58
59
59
</div >
@@ -75,7 +75,7 @@ export default {
75
75
limit: 10
76
76
},
77
77
sortable: null ,
78
- olderList : [],
78
+ oldList : [],
79
79
newList: []
80
80
}
81
81
},
@@ -99,8 +99,8 @@ export default {
99
99
this .list = response .data .items
100
100
this .total = response .data .total
101
101
this .listLoading = false
102
- this .olderList = this .list .map (v => v .id )
103
- this .newList = this .olderList .slice ()
102
+ this .oldList = this .list .map (v => v .id )
103
+ this .newList = this .oldList .slice ()
104
104
this .$nextTick (() => {
105
105
this .setSort ()
106
106
})
@@ -109,7 +109,12 @@ export default {
109
109
setSort () {
110
110
const el = document .querySelectorAll (' .el-table__body-wrapper > table > tbody' )[0 ]
111
111
this .sortable = Sortable .create (el, {
112
+ ghostClass: ' sortable-ghost' , // Class name for the drop placeholder,
112
113
onEnd : evt => {
114
+ const targetRow = this .list .splice (evt .oldIndex , 1 )[0 ]
115
+ this .list .splice (evt .newIndex , 0 , targetRow)
116
+
117
+ // for show the changes, you can delete in you code
113
118
const tempIndex = this .newList .splice (evt .oldIndex , 1 )[0 ]
114
119
this .newList .splice (evt .newIndex , 0 , tempIndex)
115
120
}
@@ -119,10 +124,21 @@ export default {
119
124
}
120
125
</script >
121
126
127
+ <style >
128
+ .sortable-ghost {
129
+ opacity : .8 ;
130
+ color : #fff !important ;
131
+ background : #42b983 !important ;
132
+ }
133
+ </style >
134
+
122
135
<style scoped>
136
+ .icon-star {
137
+ margin-right :2px ;
138
+ }
123
139
.drag-handler {
124
- width : 30 px ;
125
- height : 30 px ;
140
+ width : 20 px ;
141
+ height : 20 px ;
126
142
cursor : pointer ;
127
143
}
128
144
.show-d {
0 commit comments