-
Notifications
You must be signed in to change notification settings - Fork 144
/
index.html
226 lines (225 loc) · 7.94 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1"/>
<meta name="renderer" content="webkit"/>
<title>vue-dragging</title>
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"/>
<script src="https://cdn.bootcss.com/vue/2.2.6/vue.js"></script>
<!-- <script src="https://cdn.bootcss.com/vue/1.0.28/vue.js"></script> -->
<script type="text/javascript" src="./vue-dragging.es5.js"></script>
<style>
body{font-family:Helvetica,sans-serif}
h2 {
margin-bottom: 10px;
}
.des {
margin-bottom: 10px;
}
.playground {
display: flex;
margin-top: 4rem;
}
.color-item {
background: #f5f5f5;
padding: .5rem;
color: #5f5f5f;
transition: transform .3s;
}
.color-item.dragging {
background-color: #fff;
}
.color-show {
display: flex;
flex-wrap: wrap;
width: 30rem;
}
.color-box {
width: 33%;
height: 6rem;
background: #efefef;
line-height: 6rem;
text-align: center;
color: #fff;
transition: transform .3s;
}
.color-box.dragging {
transform: scale(1.1);
}
.other-group,
.multi-group {
margin-left: 20px;
}
.multi-group .color-box {
position: relative;
box-sizing: border-box;
}
.multi-group .color-box:hover {
border: 2px solid #fff;
}
.multi-group .color-box .multi-group-btn {
position: absolute;
left: 2px;
top: 2px;
width: 20px;
height: 20px;
line-height: 20px;
border: 1px solid #fff;
}
.in-out-translate-fade-enter-active, .in-out-translate-fade-leave-active {
transition: all .5s;
}
.in-out-translate-fade-enter, .in-out-translate-fade-leave-active {
opacity: 0;
}
.in-out-translate-fade-enter {
transform: translate3d(100%, 0, 0);
}
.in-out-translate-fade-leave-active {
transform: translate3d(-100%, 0, 0);
}
</style>
</head>
<body>
<div id="root">
<div class="playground">
<!-- vue1 test -->
<!-- <div class="color-list">
<div
class="color-item"
v-for="color in colors"
v-dragging="{ item: color, list: colors, group: 'color', key: color.text }">{{color.text}}</div>
</div>
<div class="color-show">
<div
v-for="color in colors"
v-dragging="{ item: color, list: colors, group: 'color', key: color.text }"
class="color-box"
:style="{'background-color': color.text}">
{{color.text}}
</div>
</div> -->
<!-- vue2 test -->
<div>
<h2>基础示例 basic</h2>
<div class="des">用户可以在多个界面中同时操作同一个数据源</div>
<div class="color-show">
<div
v-for="color in colors"
v-dragging="{ list: colors, item: color, group: 'color' }"
class="color-box"
:style="{'background-color': color.text}"
:key="color.text">
{{color.text}}
</div>
</div>
<div class="color-list">
<div
class="color-item"
v-for="color in colors"
v-dragging="{ list: colors, item: color, group: 'color' }"
:key="color.text">
{{color.text}}
</div>
</div>
<button @click="test">change colors</button>
</div>
<div class="other-group">
<h2>页面中另一个组 other group</h2>
<div class="des">页面中可以同时存在多个排序组,用group属性来区分</div>
<div class="color-show">
<div
v-for="color in colors2"
v-dragging="{ list: colors2, item: color, group: 'color2' }"
class="color-box"
:style="{'background-color': color.text}"
:key="color.text">
{{color.text}}
</div>
</div>
</div>
<div class="multi-group">
<h2>多选排序 Multi Select</h2>
<div class="des">可以选中多个元素同时进行拖拽排序</div>
<div class="color-show">
<div
v-for="color in colors3"
v-dragging="{ list: colors3, item: color, group: 'color3', comb: 'isComb' }"
@click="color.isComb=!color.isComb"
class="color-box"
:style="{'background-color': color.text}"
:key="color.text">
<div>{{color.text}}</div>
<div class="multi-group-btn">{{color.isComb?'√':''}}</div>
</div>
</div>
</div>
</div>
</div>
<script>
Vue.use(VueDragging)
new Vue({
el: '#root',
data: {
colors: [
{text: "Aquamarine"},
{text: "Hotpink"},
{text: "Gold"},
{text: "Crimson"},
{text: "Blueviolet"},
{text: "Lightblue"},
{text: "Cornflowerblue"},
{text: "Skyblue"}
],
colors2: [
{text: "Aquamarine"},
{text: "Hotpink"},
{text: "Gold"},
{text: "Crimson"},
{text: "Blueviolet"},
{text: "Lightblue"}
],
colors3: [
{text: "Aquamarine"},
{text: "Hotpink"},
{text: "Gold"},
{text: "Crimson"},
{text: "Blueviolet"},
{text: "Lightblue"},
{text: "Cornflowerblue"},
{text: "Skyblue"}
],
colorShow: true
},
methods: {
test: function () {
this.colors = [
{text: "Aquamarine"},
{text: "Hotpink"},
{text: "Gold"},
{text: "Crimson"},
{text: "Blueviolet"},
{text: "Lightblue"},
{text: "Cornflowerblue"},
{text: "Skyblue"},
{text: "Burlywood"}
]
}
},
mounted: function() {
this.$dragging.$on('dragged', function(data) {
console.log('dragged', data)
})
this.$dragging.$on('dragend', function(data) {
console.log('dragend', data)
})
//多个排序
this.colors3.forEach((item) => {
Vue.set(item, 'isComb', false) // 该元素是否进行多个同时排序 isComb为用户自定义属性 需要在comb字段传入相同名称
})
}
})
</script>
</body>
</html>