2018-10-24 08:06:24 +00:00
|
|
|
<template>
|
2018-11-08 09:30:17 +00:00
|
|
|
<el-select ref="dragSelect" v-model="selectVal" v-bind="$attrs" class="drag-select" multiple v-on="$listeners">
|
2019-03-17 09:40:51 +00:00
|
|
|
<slot />
|
2018-10-24 08:06:24 +00:00
|
|
|
</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() {
|
2018-11-08 09:19:12 +00:00
|
|
|
const el = this.$refs.dragSelect.$el.querySelectorAll('.el-select__tags > span')[0]
|
2018-10-24 08:06:24 +00:00
|
|
|
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>
|
2019-04-11 02:41:36 +00:00
|
|
|
.drag-select >>> .sortable-ghost {
|
2018-10-24 08:06:24 +00:00
|
|
|
opacity: .8;
|
|
|
|
color: #fff!important;
|
|
|
|
background: #42b983!important;
|
|
|
|
}
|
|
|
|
|
2019-04-11 02:41:36 +00:00
|
|
|
.drag-select >>> .el-tag {
|
2018-10-24 08:06:24 +00:00
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
</style>
|