最近我发现SortableJS / Vue.Draggable库(https://github.com/SortableJS/Vue.Draggable)有一个新选项,可以启用多重拖动以从数组中选择多个元素并将它们一起移动(https://github.com/SortableJS/Vue.Draggable/pull/744)。
我已经看到了可以完美运行的示例,例如:
- https://jsfiddle.net/zr042g3j/3/
- https://codepen.io/Flip535/pen/jOOKBZj
- https://github.com/SortableJS/Vue.Draggable/pull/744
但是当我尝试在我的项目中使用它时,我只能找到让它工作的方法。
以下是我的项目的详细信息:
- Vue:2.6.10
- 可拖动:2.23.2
在我的 vue 组件中,我以这种方式导入了 vuedraggable:
import draggable from 'vuedraggable'
我已经应用了这种方式(为此帖子的目的已减少代码):
<template>
<v-flex class="pa-3">
<div class="instructions-wrapper py-4">
<v-avatar size="40" color="#4C2159" class="white--text"><b>4</b></v-avatar>
<div class="px-2">
<h2>Revisa y asigna</h2>
<p>Revisa la optimización del sistema y asigna o personaliza una ruta</p>
</div>
</div>
<template v-for="(vehicle, key) in sortedRoutes.routes">
<v-card class="my-4" :key="vehicle.stops.location_id">
<v-toolbar color="primary" dark>
<v-toolbar-title>{{ Object.keys(sortedRoutes.routes).find(key => sortedRoutes.routes[key] === vehicle) }}</v-toolbar-title>
</v-toolbar>
<draggable
:key="vehicle.stops.location_id"
:list="vehicle.stops"
:id="key"
group="vehicle"
animation="150"
:multi-drag="true"
selected-class="multi-drag"
ghost-class="ghost"
:move="moveChecker"
@start="dragStart"
@end="dragEnd"
>
<div v-for="(delivery, index) in vehicle.stops" :key="delivery.id" class="draggable-element">
<v-list v-if="delivery.location_name !== 'CEDIS'" :key="delivery.title">
<v-list-tile>
<v-icon>drag_indicator</v-icon>
<v-list-tile-avatar>
<img :src="`https://ui-avatars.com/api/?color=fff&background=4C2159&size=128&name=${index}`">
</v-list-tile-avatar>
<v-list-tile-content>
<div>{{delivery.location_name}} {{deliveries.find(key => key.location.company_name === delivery.location_name).start_time_window ? `(${deliveries.find(key => key.location.company_name === delivery.location_name).start_time_window} - ${deliveries.find(key => key.location.company_name === delivery.location_name).end_time_window})` : ''}}
</div>
</v-list-tile-content>
</v-list-tile>
</v-list>
</div>
</draggable>
</v-card>
</template>
</v-flex>
</template>
我已经注意添加了select-class
SortableJS / Vue.Draggable 文档中使用多拖动选项所需的属性。
打印为可拖动列表的对象位于此 JSON 结构下:
{
"routes": {
"vehicle_1": {
"stops": [
{
"stop_id": 0,
"order_id": 1,
"location_id": "DEPOT",
"location_name": "Centro de distribución",
"lat": -100,
"lng": 100,
"arrival_time": "08:00",
"departure_time": "16:00"
},
{
"stop_id": 1,
"order_id": 2,
"location_id": "order_2",
"location_name": "Foo Zaas",
"lat": -100,
"lng": 100,
"arrival_time": "10:00",
"departure_time": "10:15"
}
],
"cost_matrix": [
[
{
"distance_in_meters": 10,
"travel_time_in_minutes": 10
},
{
"distance_in_meters": 100,
"travel_time_in_minutes": 100
}
],
[
{
"distance_in_meters": 10,
"travel_time_in_minutes": 10
},
{
"distance_in_meters": 100,
"travel_time_in_minutes": 100
}
]
],
"summary": {
"depot_name": "DEPOT",
"demand_assigned": 234,
"distance_in_meters": 3004,
"travel_time_in_minutes": 157,
"waiting_time_in_minutes": 70.1
}
}
}
}
尽管做了所有这些努力,我还是无法让它发挥作用。我什至必须根据我之前找到的一个 codepen 复制一个更精简的代码版本,并且它可以工作(https://codepen.io/Juan-Sin-Miedos/pen/jOWOyWW)
为什么它不适用于我的项目?
任何帮助将不胜感激,非常感谢!