forked from PanJiaChen/vue-element-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from PanJiaChen/master
feature: add drag select component (PanJiaChen#1249)
- Loading branch information
Showing
8 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,7 @@ | |
- 头像上传 | ||
- 返回顶部 | ||
- 拖拽Dialog | ||
- 拖拽Select | ||
- 拖拽看板 | ||
- 列表拖拽 | ||
- SplitPane | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<template> | ||
<el-select v-model="selectVal" v-bind="$attrs" class="drag-select" multiple> | ||
<slot/> | ||
</el-select> | ||
</template> | ||
|
||
<script> | ||
import Sortable from 'sortablejs' | ||
export default { | ||
name: 'DragSelect', | ||
props: { | ||
value: { | ||
type: Array, | ||
required: true | ||
} | ||
}, | ||
computed: { | ||
selectVal: { | ||
get() { | ||
return [...this.value] | ||
}, | ||
set(val) { | ||
this.$emit('input', [...val]) | ||
} | ||
} | ||
}, | ||
mounted() { | ||
this.setSort() | ||
}, | ||
methods: { | ||
setSort() { | ||
const el = document.querySelectorAll('.el-select__tags > span')[0] | ||
this.sortable = Sortable.create(el, { | ||
ghostClass: 'sortable-ghost', // Class name for the drop placeholder, | ||
setData: function(dataTransfer) { | ||
dataTransfer.setData('Text', '') | ||
// to avoid Firefox bug | ||
// Detail see : https://github.com/RubaXa/Sortable/issues/1012 | ||
}, | ||
onEnd: evt => { | ||
const targetRow = this.value.splice(evt.oldIndex, 1)[0] | ||
this.value.splice(evt.newIndex, 0, targetRow) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style scoped> | ||
.drag-select >>> .sortable-ghost{ | ||
opacity: .8; | ||
color: #fff!important; | ||
background: #42b983!important; | ||
} | ||
.drag-select >>> .el-tag{ | ||
cursor: pointer; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<template> | ||
<div class="components-container"> | ||
|
||
<el-drag-select v-model="value" style="width:500px;" multiple placeholder="请选择"> | ||
<el-option v-for="item in options" :label="item.label" :value="item.value" :key="item.value" /> | ||
</el-drag-select> | ||
|
||
<div style="margin-top:30px;"> | ||
<el-tag v-for="item of value" :key="item" style="margin-right:15px;">{{ item }}</el-tag> | ||
</div> | ||
|
||
</div> | ||
</template> | ||
|
||
<script> | ||
import ElDragSelect from '@/components/DragSelect' // base on element-ui | ||
export default { | ||
name: 'DragSelectDemo', | ||
components: { ElDragSelect }, | ||
data() { | ||
return { | ||
value: ['Apple', 'Banana', 'Orange'], | ||
options: [{ | ||
value: 'Apple', | ||
label: 'Apple' | ||
}, { | ||
value: 'Banana', | ||
label: 'Banana' | ||
}, { | ||
value: 'Orange', | ||
label: 'Orange' | ||
}, { | ||
value: 'Pear', | ||
label: 'Pear' | ||
}, { | ||
value: 'Strawberry', | ||
label: 'Strawberry' | ||
}] | ||
} | ||
} | ||
} | ||
</script> |