diff --git a/README.md b/README.md index 6a37ec93fedd536123e1492ebeef212eb40831a5..e2d9c034840395cf5509dd688b32cbd8d1efb223 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ Understanding and learning this knowledge in advance will greatly help the use o - Avatar Upload - Back To Top - Drag Dialog + - Drag Select - Drag Kanban - Drag List - SplitPane diff --git a/README.zh-CN.md b/README.zh-CN.md index c7d4efbb84f18a7abb817d9c7dd27ac4ba49c8eb..28fc02403b40b689719ed77690bc6149d91848b1 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -130,6 +130,7 @@ - 头åƒä¸Šä¼ - 返回顶部 - 拖拽Dialog + - 拖拽Select - æ‹–æ‹½çœ‹æ¿ - 列表拖拽 - SplitPane diff --git a/src/components/DragSelect/index.vue b/src/components/DragSelect/index.vue new file mode 100644 index 0000000000000000000000000000000000000000..a08d400a684fb0cdf34c4eee7e86619ff1bdc127 --- /dev/null +++ b/src/components/DragSelect/index.vue @@ -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> diff --git a/src/lang/en.js b/src/lang/en.js index 021bc66ca12f2b17d242102bd12f9e7a01cb73b2..930f0ad1ff287ec671e2772740f152ad4d3e9b2a 100644 --- a/src/lang/en.js +++ b/src/lang/en.js @@ -22,6 +22,7 @@ export default { componentMixin: 'Mixin', backToTop: 'BackToTop', dragDialog: 'Drag Dialog', + dragSelect: 'Drag Select', dragKanban: 'Drag Kanban', charts: 'Charts', keyboardChart: 'Keyboard Chart', diff --git a/src/lang/es.js b/src/lang/es.js index 191719045ea26ee6851ba977726bcbda139de855..f16044c43167a50b06c50f64e9d602a07004a72a 100755 --- a/src/lang/es.js +++ b/src/lang/es.js @@ -22,6 +22,7 @@ export default { componentMixin: 'Mixin', backToTop: 'Ir arriba', dragDialog: 'Drag Dialog', + dragSelect: 'Drag Select', dragKanban: 'Drag Kanban', charts: 'Gráficos', keyboardChart: 'Keyboard Chart', diff --git a/src/lang/zh.js b/src/lang/zh.js index 9da9e9e4bf165b3cacfd8c509bcf91a9bfb86fa7..46e96ccf5c5d1e9f047061c737bd956caa64051d 100644 --- a/src/lang/zh.js +++ b/src/lang/zh.js @@ -22,6 +22,7 @@ export default { componentMixin: 'å°ç»„件', backToTop: '返回顶部', dragDialog: '拖拽 Dialog', + dragSelect: '拖拽 Select', dragKanban: 'å¯æ‹–拽看æ¿', charts: '图表', keyboardChart: '键盘图表', diff --git a/src/router/modules/components.js b/src/router/modules/components.js index 56dad2b124e5175c95e498b4d79d433d309f2f37..5fd9bd2955e692fd9f439cd39d99c152f5b9fb0a 100644 --- a/src/router/modules/components.js +++ b/src/router/modules/components.js @@ -78,6 +78,12 @@ const componentsRouter = { name: 'DragDialogDemo', meta: { title: 'dragDialog' } }, + { + path: 'drag-select', + component: () => import('@/views/components-demo/dragSelect'), + name: 'DragSelectDemo', + meta: { title: 'dragSelect' } + }, { path: 'dnd-list', component: () => import('@/views/components-demo/dndList'), diff --git a/src/views/components-demo/dragSelect.vue b/src/views/components-demo/dragSelect.vue new file mode 100644 index 0000000000000000000000000000000000000000..559e8a578805325be08ea0d336bd148c83561ed6 --- /dev/null +++ b/src/views/components-demo/dragSelect.vue @@ -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>