feat: 一个妥协的拖动方案,暂时用用得了
This commit is contained in:
1 parent
5a843bf24a
commit
d89978a44f
3 files changed
+24
-5
No files matched your search
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div ref="divRef" @dragstart="onDs" :draggable="true">
|
<div ref="divRef" @dragstart="onDs" :draggable="isDraggable">
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -7,6 +7,9 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
// import Sortable from 'sortablejs'
|
// import Sortable from 'sortablejs'
|
||||||
|
const props = defineProps<{
|
||||||
|
isDraggable: boolean
|
||||||
|
}>()
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
onDragStart: [e: DragEvent]
|
onDragStart: [e: DragEvent]
|
||||||
@@ -19,6 +22,11 @@ const onDs = (e: DragEvent) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
divRef?.value?.addEventListener('dragstart', function (ev) {
|
||||||
|
var img = new Image();
|
||||||
|
img.src = "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' %3E%3Cpath /%3E%3C/svg%3E";
|
||||||
|
ev?.dataTransfer?.setDragImage(img, 0, 0);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
// import 'drag-drop-touch'
|
import 'drag-drop-touch'
|
||||||
|
|
||||||
createApp(App).mount('#app')
|
createApp(App).mount('#app')
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<miao-draggable-div class="miao-item" :isDraggable="draggable" ref="itemRef" @on-drag-start="handleDragStart">
|
<miao-draggable-div class="miao-item" :isDraggable="!draggable" ref="itemRef" @on-drag-start="handleDragStart">
|
||||||
<miaoContextMenu :options="dropDownOptions ?? []" :touch-time-out="500" @select="handleDropdownSelect">
|
<miaoContextMenu :options="dropDownOptions ?? []" :touch-time-out="500" @select="handleDropdownSelect">
|
||||||
<div class="item-main" :class="selected ? 'item-main-selected' : ''" ref="mainRef">
|
<div class="item-main" :class="selected ? 'item-main-selected' : ''" ref="mainRef">
|
||||||
<div class="item-main-front" :style="{ backgroundColor: props.color }"></div>
|
<div class="item-main-front" :style="{ backgroundColor: props.color }"></div>
|
||||||
@@ -13,6 +13,9 @@
|
|||||||
{{ time }}
|
{{ time }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<miao-draggable-div class="item-main-dragBtn" :isDraggable="draggable">
|
||||||
|
<ReorderFourOutline></ReorderFourOutline>
|
||||||
|
</miao-draggable-div>
|
||||||
</div>
|
</div>
|
||||||
</miaoContextMenu>
|
</miaoContextMenu>
|
||||||
</miao-draggable-div>
|
</miao-draggable-div>
|
||||||
@@ -30,7 +33,8 @@ import {
|
|||||||
LogoJavascript,
|
LogoJavascript,
|
||||||
LogoVue,
|
LogoVue,
|
||||||
PlayCircle,
|
PlayCircle,
|
||||||
Disc
|
Disc,
|
||||||
|
ReorderFourOutline,
|
||||||
} from '@vicons/ionicons5'
|
} from '@vicons/ionicons5'
|
||||||
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
||||||
import dateFormatter from '@/hooks/dateFormatter'
|
import dateFormatter from '@/hooks/dateFormatter'
|
||||||
@@ -86,7 +90,6 @@ const time = computed(() => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
// 是不是可以直接在这里面实现?
|
|
||||||
// 应该将所有事件emit出去才对
|
// 应该将所有事件emit出去才对
|
||||||
const handleDropdownSelect = (key: string) => {
|
const handleDropdownSelect = (key: string) => {
|
||||||
if (key === 'rename') {
|
if (key === 'rename') {
|
||||||
@@ -242,6 +245,7 @@ onBeforeUnmount(() => {
|
|||||||
&-date {
|
&-date {
|
||||||
user-select: none;
|
user-select: none;
|
||||||
font-size: small;
|
font-size: small;
|
||||||
|
text-wrap: nowrap;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,4 +293,11 @@ onBeforeUnmount(() => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.item-main-dragBtn {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
position: absolute;
|
||||||
|
right: 5px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in new issue
Block a user