File tree 8 files changed +115
-0
lines changed
8 files changed +115
-0
lines changed Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ Understanding and learning this knowledge in advance will greatly help the use o
118
118
- Avatar Upload
119
119
- Back To Top
120
120
- Drag Dialog
121
+ - Drag Select
121
122
- Drag Kanban
122
123
- Drag List
123
124
- SplitPane
Original file line number Diff line number Diff line change 130
130
- 头像上传
131
131
- 返回顶部
132
132
- 拖拽Dialog
133
+ - 拖拽Select
133
134
- 拖拽看板
134
135
- 列表拖拽
135
136
- SplitPane
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <el-select v-model =" selectVal" v-bind =" $attrs" class =" drag-select" multiple >
3
+ <slot />
4
+ </el-select >
5
+ </template >
6
+
7
+ <script >
8
+ import Sortable from ' sortablejs'
9
+
10
+ export default {
11
+ name: ' DragSelect' ,
12
+ props: {
13
+ value: {
14
+ type: Array ,
15
+ required: true
16
+ }
17
+ },
18
+ computed: {
19
+ selectVal: {
20
+ get () {
21
+ return [... this .value ]
22
+ },
23
+ set (val ) {
24
+ this .$emit (' input' , [... val])
25
+ }
26
+ }
27
+ },
28
+ mounted () {
29
+ this .setSort ()
30
+ },
31
+ methods: {
32
+ setSort () {
33
+ const el = document .querySelectorAll (' .el-select__tags > span' )[0 ]
34
+ this .sortable = Sortable .create (el, {
35
+ ghostClass: ' sortable-ghost' , // Class name for the drop placeholder,
36
+ setData : function (dataTransfer ) {
37
+ dataTransfer .setData (' Text' , ' ' )
38
+ // to avoid Firefox bug
39
+ // Detail see : https://github.com/RubaXa/Sortable/issues/1012
40
+ },
41
+ onEnd : evt => {
42
+ const targetRow = this .value .splice (evt .oldIndex , 1 )[0 ]
43
+ this .value .splice (evt .newIndex , 0 , targetRow)
44
+ }
45
+ })
46
+ }
47
+ }
48
+ }
49
+ </script >
50
+
51
+ <style scoped>
52
+ .drag-select >>> .sortable-ghost {
53
+ opacity : .8 ;
54
+ color : #fff !important ;
55
+ background : #42b983 !important ;
56
+ }
57
+
58
+ .drag-select >>> .el-tag {
59
+ cursor : pointer ;
60
+ }
61
+ </style >
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export default {
22
22
componentMixin : 'Mixin' ,
23
23
backToTop : 'BackToTop' ,
24
24
dragDialog : 'Drag Dialog' ,
25
+ dragSelect : 'Drag Select' ,
25
26
dragKanban : 'Drag Kanban' ,
26
27
charts : 'Charts' ,
27
28
keyboardChart : 'Keyboard Chart' ,
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export default {
22
22
componentMixin : 'Mixin' ,
23
23
backToTop : 'Ir arriba' ,
24
24
dragDialog : 'Drag Dialog' ,
25
+ dragSelect : 'Drag Select' ,
25
26
dragKanban : 'Drag Kanban' ,
26
27
charts : 'Gráficos' ,
27
28
keyboardChart : 'Keyboard Chart' ,
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ export default {
22
22
componentMixin : '小组件' ,
23
23
backToTop : '返回顶部' ,
24
24
dragDialog : '拖拽 Dialog' ,
25
+ dragSelect : '拖拽 Select' ,
25
26
dragKanban : '可拖拽看板' ,
26
27
charts : '图表' ,
27
28
keyboardChart : '键盘图表' ,
Original file line number Diff line number Diff line change @@ -78,6 +78,12 @@ const componentsRouter = {
78
78
name : 'DragDialogDemo' ,
79
79
meta : { title : 'dragDialog' }
80
80
} ,
81
+ {
82
+ path : 'drag-select' ,
83
+ component : ( ) => import ( '@/views/components-demo/dragSelect' ) ,
84
+ name : 'DragSelectDemo' ,
85
+ meta : { title : 'dragSelect' }
86
+ } ,
81
87
{
82
88
path : 'dnd-list' ,
83
89
component : ( ) => import ( '@/views/components-demo/dndList' ) ,
Original file line number Diff line number Diff line change
1
+ <template >
2
+ <div class =" components-container" >
3
+
4
+ <el-drag-select v-model =" value" style =" width :500px ;" multiple placeholder =" 请选择" >
5
+ <el-option v-for =" item in options" :label =" item.label" :value =" item.value" :key =" item.value" />
6
+ </el-drag-select >
7
+
8
+ <div style =" margin-top :30px ;" >
9
+ <el-tag v-for =" item of value" :key =" item" style =" margin-right :15px ;" >{{ item }}</el-tag >
10
+ </div >
11
+
12
+ </div >
13
+ </template >
14
+
15
+ <script >
16
+ import ElDragSelect from ' @/components/DragSelect' // base on element-ui
17
+
18
+ export default {
19
+ name: ' DragSelectDemo' ,
20
+ components: { ElDragSelect },
21
+ data () {
22
+ return {
23
+ value: [' Apple' , ' Banana' , ' Orange' ],
24
+ options: [{
25
+ value: ' Apple' ,
26
+ label: ' Apple'
27
+ }, {
28
+ value: ' Banana' ,
29
+ label: ' Banana'
30
+ }, {
31
+ value: ' Orange' ,
32
+ label: ' Orange'
33
+ }, {
34
+ value: ' Pear' ,
35
+ label: ' Pear'
36
+ }, {
37
+ value: ' Strawberry' ,
38
+ label: ' Strawberry'
39
+ }]
40
+ }
41
+ }
42
+ }
43
+ </script >
You can’t perform that action at this time.
0 commit comments