uview-plus 3.4.62 → 3.4.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/changelog.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="u-count-down">
|
|
3
|
-
<slot
|
|
3
|
+
<slot :days="timeData.days" :hours="timeData.hours"
|
|
4
|
+
:minutes="timeData.minutes" :seconds="timeData.seconds">
|
|
4
5
|
<text class="u-count-down__text">{{ formattedTime }}</text>
|
|
5
6
|
</slot>
|
|
6
7
|
</view>
|
|
@@ -112,6 +113,7 @@
|
|
|
112
113
|
this.remainTime = remain
|
|
113
114
|
// 根据剩余的毫秒时间,得出该有天,小时,分钟等的值,返回一个对象
|
|
114
115
|
const timeData = parseTimeData(remain)
|
|
116
|
+
this.timeData = timeData;
|
|
115
117
|
this.$emit('change', timeData)
|
|
116
118
|
// 得出格式化后的时间
|
|
117
119
|
this.formattedTime = parseFormat(this.format, timeData)
|
|
@@ -1,372 +1,367 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
@touchstart="onTouchStart(index, $event)"
|
|
18
|
-
@touchmove="onTouchMove($event)"
|
|
19
|
-
@touchend="onTouchEnd"
|
|
20
|
-
>
|
|
21
|
-
<!-- 默认插槽,用户可自定义 item 渲染内容 -->
|
|
22
|
-
<slot :item="item" :index="index">
|
|
23
|
-
<!-- 默认内容 -->
|
|
24
|
-
<view class="u-dragsort-item-content">
|
|
25
|
-
{{ item.label }}
|
|
26
|
-
</view>
|
|
27
|
-
</slot>
|
|
2
|
+
<view class="u-dragsort"
|
|
3
|
+
:class="[direction == 'horizontal' ? 'u-dragsort--horizontal' : '', direction == 'all' ? 'u-dragsort--all' : '']">
|
|
4
|
+
<movable-area class="u-dragsort-area" :style="movableAreaStyle">
|
|
5
|
+
<movable-view v-for="(item, index) in list" :key="item.id" :id="`u-dragsort-item-${index}`"
|
|
6
|
+
class="u-dragsort-item" :class="{ 'dragging': dragIndex === index }"
|
|
7
|
+
:direction="direction === 'all' ? 'all' : direction" :x="item.x" :y="item.y" :inertia="false"
|
|
8
|
+
:disabled="!draggable || (item.draggable === false)" @change="onChange(index, $event)"
|
|
9
|
+
@touchstart="onTouchStart(index)" @touchend="onTouchEnd" @touchcancel="onTouchEnd">
|
|
10
|
+
<view class="u-dragsort-item-content">
|
|
11
|
+
<slot :item="item" :index="index">
|
|
12
|
+
{{ item.label }}
|
|
13
|
+
</slot>
|
|
14
|
+
</view>
|
|
15
|
+
</movable-view>
|
|
16
|
+
</movable-area>
|
|
28
17
|
</view>
|
|
29
|
-
</view>
|
|
30
18
|
</template>
|
|
31
19
|
|
|
32
20
|
<script>
|
|
21
|
+
import { mpMixin } from '../../libs/mixin/mpMixin';
|
|
22
|
+
import { mixin } from '../../libs/mixin/mixin';
|
|
23
|
+
import { addStyle, addUnit, sleep } from '../../libs/function/index';
|
|
33
24
|
export default {
|
|
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
|
-
startY: 0,
|
|
62
|
-
itemWidth: 0, // 横向拖动需要宽度
|
|
63
|
-
itemHeight: 80,
|
|
64
|
-
isDragging: false,
|
|
65
|
-
closestIndex: -1, // 用于临时存储最接近的 index
|
|
66
|
-
lastSwapTime: 0, // 新增:记录上次交换时间
|
|
67
|
-
initialTouchY: 0, // 新增:记录初始触摸位置
|
|
68
|
-
minDragDistance: 15, // 新增:最小拖动距离阈值
|
|
69
|
-
dragStartY: 0, // 新增:记录拖动开始位置
|
|
70
|
-
confirmedDirection: null, // 新增:确认的拖动方向
|
|
71
|
-
};
|
|
72
|
-
},
|
|
73
|
-
emits: ['drag-end'],
|
|
74
|
-
async mounted() {
|
|
75
|
-
await this.$nextTick();
|
|
76
|
-
const rect = await this.calculateItemSize(0);
|
|
77
|
-
this.itemWidth = rect.width;
|
|
78
|
-
this.itemHeight = rect.height;
|
|
79
|
-
},
|
|
80
|
-
methods: {
|
|
81
|
-
setItemRef(el, index) {
|
|
82
|
-
this.itemRefs[index] = el;
|
|
25
|
+
name: 'u-dragsort',
|
|
26
|
+
// #ifdef MP
|
|
27
|
+
mixins: [mpMixin, mixin,],
|
|
28
|
+
// #endif
|
|
29
|
+
// #ifndef MP
|
|
30
|
+
mixins: [mixin],
|
|
31
|
+
// #endif
|
|
32
|
+
props: {
|
|
33
|
+
initialList: {
|
|
34
|
+
type: Array,
|
|
35
|
+
required: true,
|
|
36
|
+
default: () => []
|
|
37
|
+
},
|
|
38
|
+
draggable: {
|
|
39
|
+
type: Boolean,
|
|
40
|
+
default: true
|
|
41
|
+
},
|
|
42
|
+
direction: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: 'vertical',
|
|
45
|
+
validator: value => ['vertical', 'horizontal', 'all'].includes(value)
|
|
46
|
+
},
|
|
47
|
+
// 新增列数属性,用于all模式
|
|
48
|
+
columns: {
|
|
49
|
+
type: Number,
|
|
50
|
+
default: 3
|
|
51
|
+
}
|
|
83
52
|
},
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
53
|
+
data() {
|
|
54
|
+
return {
|
|
55
|
+
list: [],
|
|
56
|
+
dragIndex: -1,
|
|
57
|
+
itemHeight: 40,
|
|
58
|
+
itemWidth: 80,
|
|
59
|
+
areaWidth: 0, // 可拖动区域宽度
|
|
60
|
+
areaHeight: 0, // 可拖动区域高度
|
|
61
|
+
originalPositions: [], // 保存原始位置
|
|
62
|
+
currentPosition: {
|
|
63
|
+
x: 0,
|
|
64
|
+
y: 0
|
|
65
|
+
}
|
|
66
|
+
};
|
|
94
67
|
},
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
68
|
+
computed: {
|
|
69
|
+
movableAreaStyle() {
|
|
70
|
+
if (this.direction === 'vertical') {
|
|
71
|
+
return {
|
|
72
|
+
height: `${this.list.length * this.itemHeight}px`,
|
|
73
|
+
width: '100%'
|
|
74
|
+
};
|
|
75
|
+
} else if (this.direction === 'horizontal') {
|
|
76
|
+
return {
|
|
77
|
+
height: '100%',
|
|
78
|
+
width: `${this.list.length * this.itemWidth}px`
|
|
79
|
+
};
|
|
80
|
+
} else {
|
|
81
|
+
// all模式,计算网格布局所需的高度
|
|
82
|
+
const rows = Math.ceil(this.list.length / this.columns);
|
|
83
|
+
return {
|
|
84
|
+
height: `${rows * this.itemHeight}px`,
|
|
85
|
+
width: '100%'
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
98
89
|
},
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
resolve(res || []);
|
|
106
|
-
})
|
|
107
|
-
.exec();
|
|
108
|
-
});
|
|
90
|
+
emits: ['drag-end'],
|
|
91
|
+
async mounted() {
|
|
92
|
+
await this.$nextTick();
|
|
93
|
+
this.initList();
|
|
94
|
+
this.calculateItemSize();
|
|
95
|
+
this.calculateAreaSize();
|
|
109
96
|
},
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
97
|
+
methods: {
|
|
98
|
+
initList() {
|
|
99
|
+
// 初始化列表项的位置
|
|
100
|
+
this.list = this.initialList.map((item, index) => {
|
|
101
|
+
let x = 0, y = 0;
|
|
113
102
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
103
|
+
if (this.direction === 'horizontal') {
|
|
104
|
+
x = index * this.itemWidth;
|
|
105
|
+
y = 0;
|
|
106
|
+
} else if (this.direction === 'vertical') {
|
|
107
|
+
x = 0;
|
|
108
|
+
y = index * this.itemHeight;
|
|
109
|
+
} else {
|
|
110
|
+
// all模式,网格布局
|
|
111
|
+
const col = index % this.columns;
|
|
112
|
+
const row = Math.floor(index / this.columns);
|
|
113
|
+
x = col * this.itemWidth;
|
|
114
|
+
y = row * this.itemHeight;
|
|
115
|
+
}
|
|
123
116
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
117
|
+
return {
|
|
118
|
+
...item,
|
|
119
|
+
x,
|
|
120
|
+
y
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
// 保存初始位置
|
|
124
|
+
this.saveOriginalPositions();
|
|
125
|
+
},
|
|
126
|
+
saveOriginalPositions() {
|
|
127
|
+
// 保存当前位置作为原始位置
|
|
128
|
+
this.originalPositions = this.list.map(item => ({
|
|
129
|
+
x: item.x,
|
|
130
|
+
y: item.y
|
|
131
|
+
}));
|
|
132
|
+
},
|
|
133
|
+
async calculateItemSize() {
|
|
134
|
+
// 计算项目尺寸
|
|
135
|
+
await sleep(30);
|
|
136
|
+
return new Promise((resolve) => {
|
|
137
|
+
uni.createSelectorQuery()
|
|
138
|
+
.in(this)
|
|
139
|
+
.select('.u-dragsort-item-content')
|
|
140
|
+
.boundingClientRect(res => {
|
|
141
|
+
if (res) {
|
|
142
|
+
this.itemHeight = res.height || 40;
|
|
143
|
+
this.itemWidth = res.width || 80;
|
|
127
144
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
145
|
+
// 更新所有项目的位置
|
|
146
|
+
this.updatePositions();
|
|
147
|
+
// 保存原始位置
|
|
148
|
+
this.saveOriginalPositions();
|
|
149
|
+
}
|
|
150
|
+
resolve(res);
|
|
151
|
+
})
|
|
152
|
+
.exec();
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
async calculateAreaSize() {
|
|
156
|
+
// 计算可拖动区域尺寸
|
|
157
|
+
await sleep(30);
|
|
158
|
+
return new Promise((resolve) => {
|
|
159
|
+
uni.createSelectorQuery()
|
|
160
|
+
.in(this)
|
|
161
|
+
.select('.u-dragsort-area')
|
|
162
|
+
.boundingClientRect(res => {
|
|
163
|
+
if (res) {
|
|
164
|
+
this.areaWidth = res.width || 300;
|
|
165
|
+
this.areaHeight = res.height || 300;
|
|
166
|
+
}
|
|
167
|
+
resolve(res);
|
|
168
|
+
})
|
|
169
|
+
.exec();
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
updatePositions() {
|
|
173
|
+
// 更新所有项目的位置
|
|
174
|
+
this.list.forEach((item, index) => {
|
|
175
|
+
if (this.direction === 'vertical') {
|
|
176
|
+
item.y = index * this.itemHeight;
|
|
177
|
+
item.x = 0;
|
|
178
|
+
} else if (this.direction === 'horizontal') {
|
|
179
|
+
item.x = index * this.itemWidth;
|
|
180
|
+
item.y = 0;
|
|
181
|
+
} else {
|
|
182
|
+
// all模式,网格布局
|
|
183
|
+
const col = index % this.columns;
|
|
184
|
+
const row = Math.floor(index / this.columns);
|
|
185
|
+
item.x = col * this.itemWidth;
|
|
186
|
+
item.y = row * this.itemHeight;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
},
|
|
190
|
+
onTouchStart(index) {
|
|
191
|
+
this.dragIndex = index;
|
|
192
|
+
// 保存当前位置作为原始位置
|
|
193
|
+
this.saveOriginalPositions();
|
|
194
|
+
},
|
|
195
|
+
onChange(index, event) {
|
|
196
|
+
if (!event.detail.source || event.detail.source !== 'touch') return;
|
|
142
197
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const currentY = touch.clientY;
|
|
198
|
+
this.currentPosition.x = event.detail.x;
|
|
199
|
+
this.currentPosition.y = event.detail.y;
|
|
146
200
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
// 只更新位置,不检测交换
|
|
155
|
-
this.dragY = currentY - this.initialTouchY;
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// 3. 确认拖动方向(只做一次)
|
|
160
|
-
if (!this.confirmedDirection) {
|
|
161
|
-
this.confirmedDirection = currentY > this.dragStartY ? 'down' : 'up';
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
this.dragY = currentY - this.initialTouchY;
|
|
201
|
+
// all模式下使用更智能的位置计算
|
|
202
|
+
if (this.direction === 'all') {
|
|
203
|
+
this.handleAllModeChange(index);
|
|
204
|
+
} else {
|
|
205
|
+
// 原有的垂直和水平模式逻辑
|
|
206
|
+
let itemSize = 0;
|
|
207
|
+
let targetIndex = -1;
|
|
165
208
|
|
|
166
|
-
|
|
167
|
-
|
|
209
|
+
if (this.direction === 'vertical') {
|
|
210
|
+
itemSize = this.itemHeight;
|
|
211
|
+
targetIndex = Math.max(0, Math.min(
|
|
212
|
+
Math.round(this.currentPosition.y / itemSize),
|
|
213
|
+
this.list.length - 1
|
|
214
|
+
));
|
|
215
|
+
} else if (this.direction === 'horizontal') {
|
|
216
|
+
itemSize = this.itemWidth;
|
|
217
|
+
targetIndex = Math.max(0, Math.min(
|
|
218
|
+
Math.round(this.currentPosition.x / itemSize),
|
|
219
|
+
this.list.length - 1
|
|
220
|
+
));
|
|
221
|
+
}
|
|
168
222
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
223
|
+
// 如果位置发生变化,则重新排序
|
|
224
|
+
if (targetIndex !== index) {
|
|
225
|
+
this.reorderItems(index, targetIndex);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
handleAllModeChange(index) {
|
|
230
|
+
// 在all模式下,根据当前位置计算最近的网格位置
|
|
231
|
+
const col = Math.max(0, Math.min(Math.round(this.currentPosition.x / this.itemWidth), this.columns - 1));
|
|
232
|
+
const row = Math.max(0, Math.round(this.currentPosition.y / this.itemHeight));
|
|
172
233
|
|
|
173
|
-
|
|
174
|
-
|
|
234
|
+
// 计算目标索引
|
|
235
|
+
let targetIndex = row * this.columns + col;
|
|
236
|
+
targetIndex = Math.max(0, Math.min(targetIndex, this.list.length - 1));
|
|
175
237
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
238
|
+
// 如果位置发生变化,则重新排序
|
|
239
|
+
if (targetIndex !== index) {
|
|
240
|
+
this.reorderItems(index, targetIndex);
|
|
241
|
+
}
|
|
242
|
+
},
|
|
243
|
+
reorderItems(fromIndex, toIndex) {
|
|
244
|
+
const movedItem = this.list.splice(fromIndex, 1)[0];
|
|
245
|
+
this.list.splice(toIndex, 0, movedItem);
|
|
179
246
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
247
|
+
// 震动反馈
|
|
248
|
+
if (uni.vibrateShort) {
|
|
249
|
+
uni.vibrateShort();
|
|
183
250
|
}
|
|
184
|
-
});
|
|
185
251
|
|
|
186
|
-
//
|
|
187
|
-
|
|
188
|
-
const temp = this.list[this.dragIndex];
|
|
189
|
-
this.list.splice(this.dragIndex, 1);
|
|
190
|
-
this.list.splice(closestIndex, 0, temp);
|
|
252
|
+
// 更新当前拖拽项目的新索引
|
|
253
|
+
this.dragIndex = toIndex;
|
|
191
254
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
this.
|
|
205
|
-
this.swapItems(targetIndex, event);
|
|
255
|
+
// 更新所有项目的位置
|
|
256
|
+
this.updatePositions();
|
|
257
|
+
|
|
258
|
+
// 保存当前位置作为原始位置
|
|
259
|
+
this.saveOriginalPositions();
|
|
260
|
+
},
|
|
261
|
+
onTouchEnd() {
|
|
262
|
+
// 0.001是为了解决拖动过快等某些极限场景下位置还原不生效问题
|
|
263
|
+
if (this.direction === 'horizontal') {
|
|
264
|
+
this.list[this.dragIndex].x = this.currentPosition.x + 0.001;
|
|
265
|
+
} else if (this.direction === 'vertical' || this.direction === 'all') {
|
|
266
|
+
this.list[this.dragIndex].y = this.currentPosition.y + 0.001;
|
|
267
|
+
this.list[this.dragIndex].x = this.currentPosition.x + 0.001;
|
|
206
268
|
}
|
|
269
|
+
|
|
270
|
+
// 重置到位置,需要延迟触发动,否则无效。
|
|
271
|
+
sleep(50).then(() => {
|
|
272
|
+
this.list.forEach((item, index) => {
|
|
273
|
+
item.x = this.originalPositions[index].x;
|
|
274
|
+
item.y = this.originalPositions[index].y;
|
|
275
|
+
});
|
|
276
|
+
this.dragIndex = -1;
|
|
277
|
+
this.$emit('drag-end', [...this.list]);
|
|
278
|
+
});
|
|
207
279
|
}
|
|
208
280
|
},
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const rectCenterY = rect.top + rect.height / 2;
|
|
226
|
-
const distance = Math.abs(dragCenterY - rectCenterY);
|
|
227
|
-
|
|
228
|
-
// 6. 方向过滤:只考虑当前拖动方向上的元素
|
|
229
|
-
const isDirectionMatch =
|
|
230
|
-
(this.confirmedDirection === 'down' && i > this.dragIndex) ||
|
|
231
|
-
(this.confirmedDirection === 'up' && i < this.dragIndex);
|
|
232
|
-
|
|
233
|
-
if (!isDirectionMatch) continue;
|
|
234
|
-
|
|
235
|
-
// 7. 使用更大的阈值(元素高度的1.2倍)
|
|
236
|
-
const threshold = dragHeight * 1.2;
|
|
237
|
-
|
|
238
|
-
if (distance < minDistance && distance < threshold) {
|
|
239
|
-
minDistance = distance;
|
|
240
|
-
closestIndex = i;
|
|
281
|
+
watch: {
|
|
282
|
+
initialList: {
|
|
283
|
+
handler() {
|
|
284
|
+
this.$nextTick(() => {
|
|
285
|
+
this.initList();
|
|
286
|
+
});
|
|
287
|
+
},
|
|
288
|
+
deep: true
|
|
289
|
+
},
|
|
290
|
+
direction: {
|
|
291
|
+
handler() {
|
|
292
|
+
this.$nextTick(() => {
|
|
293
|
+
this.initList();
|
|
294
|
+
this.calculateItemSize();
|
|
295
|
+
this.calculateAreaSize();
|
|
296
|
+
});
|
|
241
297
|
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
const originalTransform = this.$refs[`u-dragsort-item-${originalIndex}`]?.style.transform;
|
|
253
|
-
|
|
254
|
-
// 执行交换
|
|
255
|
-
const temp = this.list[originalIndex];
|
|
256
|
-
this.list.splice(originalIndex, 1);
|
|
257
|
-
this.list.splice(targetIndex, 0, temp);
|
|
258
|
-
|
|
259
|
-
// 更新索引
|
|
260
|
-
this.dragIndex = targetIndex;
|
|
261
|
-
this.closestIndex = targetIndex;
|
|
262
|
-
|
|
263
|
-
// 7. 使用当前触摸位置更新初始位置
|
|
264
|
-
if (event && event.touches && event.touches[0]) {
|
|
265
|
-
this.initialTouchY = event.touches[0].clientY;
|
|
266
|
-
this.dragY = 0;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// 8. 添加位置平滑过渡
|
|
270
|
-
this.$nextTick(() => {
|
|
271
|
-
const dragItem = this.$refs[`u-dragsort-item-${targetIndex}`];
|
|
272
|
-
if (dragItem) {
|
|
273
|
-
// 保存当前位置
|
|
274
|
-
const currentTransform = dragItem.style.transform;
|
|
275
|
-
|
|
276
|
-
// 临时添加过渡效果
|
|
277
|
-
dragItem.style.transition = 'transform 0.15s ease';
|
|
278
|
-
dragItem.style.transform = currentTransform;
|
|
279
|
-
|
|
280
|
-
// 过渡结束后移除效果
|
|
281
|
-
setTimeout(() => {
|
|
282
|
-
dragItem.style.transition = '';
|
|
283
|
-
}, 150);
|
|
298
|
+
},
|
|
299
|
+
columns: {
|
|
300
|
+
handler() {
|
|
301
|
+
if (this.direction === 'all') {
|
|
302
|
+
this.$nextTick(() => {
|
|
303
|
+
this.initList();
|
|
304
|
+
this.updatePositions();
|
|
305
|
+
this.saveOriginalPositions();
|
|
306
|
+
});
|
|
307
|
+
}
|
|
284
308
|
}
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
// 更新位置缓存
|
|
288
|
-
this.updateItemRects();
|
|
289
|
-
},
|
|
290
|
-
|
|
291
|
-
onTouchMove(event) {
|
|
292
|
-
// 记录当前Y坐标用于方向判断
|
|
293
|
-
if (event.touches && event.touches[0]) {
|
|
294
|
-
this.prevY = event.touches[0].clientY;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
// 使用requestAnimationFrame确保流畅性
|
|
298
|
-
if (!this.rafId) {
|
|
299
|
-
this.rafId = requestAnimationFrame(() => {
|
|
300
|
-
this.handleDragMove(event);
|
|
301
|
-
this.rafId = null;
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
},
|
|
305
|
-
onTouchEnd() {
|
|
306
|
-
// 取消动画帧
|
|
307
|
-
if (this.rafId) {
|
|
308
|
-
cancelAnimationFrame(this.rafId);
|
|
309
|
-
this.rafId = null;
|
|
310
309
|
}
|
|
311
|
-
|
|
312
|
-
// if (this.isDragging && this.closestIndex !== -1 && this.closestIndex !== this.dragIndex) {
|
|
313
|
-
// const temp = this.list[this.dragIndex];
|
|
314
|
-
// this.list.splice(this.dragIndex, 1);
|
|
315
|
-
// this.list.splice(this.closestIndex, 0, temp);
|
|
316
|
-
// this.dragIndex = this.closestIndex;
|
|
317
|
-
// }
|
|
318
|
-
|
|
319
|
-
this.$emit('drag-end', this.list);
|
|
320
|
-
this.dragIndex = -1;
|
|
321
|
-
this.dragX = 0;
|
|
322
|
-
this.dragY = 0;
|
|
323
|
-
this.isDragging = false;
|
|
324
|
-
this.closestIndex = -1;
|
|
325
310
|
}
|
|
326
|
-
}
|
|
327
311
|
};
|
|
328
312
|
</script>
|
|
329
313
|
|
|
330
314
|
<style scoped lang="scss">
|
|
331
315
|
.u-dragsort {
|
|
332
|
-
|
|
316
|
+
width: 100%;
|
|
333
317
|
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
&.dragging {
|
|
338
|
-
// 拖动时禁用过渡
|
|
339
|
-
// transition: none;
|
|
340
|
-
// 确保在最上层
|
|
341
|
-
z-index: 1000;
|
|
342
|
-
// transform: scale(1.05);
|
|
343
|
-
box-shadow: 0 6px 20px rgba(0,0,0,0.15);
|
|
344
|
-
}
|
|
345
|
-
&.nearby {
|
|
346
|
-
opacity: 95;
|
|
347
|
-
transform: scale(1.02);
|
|
318
|
+
.u-dragsort-area {
|
|
319
|
+
width: 100%;
|
|
320
|
+
position: relative;
|
|
348
321
|
}
|
|
349
|
-
.u-dragsort-item-content {
|
|
350
|
-
padding: 10px;
|
|
351
|
-
text-align: center;
|
|
352
|
-
background-color: #f5f5f5;
|
|
353
|
-
border-radius: 8rpx;
|
|
354
|
-
transition: all 0.3s ease;
|
|
355
|
-
}
|
|
356
|
-
}
|
|
357
322
|
|
|
358
|
-
&.u-dragsort--horizontal {
|
|
359
|
-
display: flex;
|
|
360
|
-
flex-direction: row;
|
|
361
|
-
flex-wrap: wrap;
|
|
362
|
-
overflow: visible; // 取消滚动条,允许自然换行
|
|
363
323
|
.u-dragsort-item {
|
|
364
|
-
|
|
365
|
-
|
|
324
|
+
position: absolute;
|
|
325
|
+
width: 100%;
|
|
326
|
+
|
|
327
|
+
&.dragging {
|
|
328
|
+
z-index: 1000;
|
|
329
|
+
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
|
|
330
|
+
}
|
|
331
|
+
|
|
366
332
|
.u-dragsort-item-content {
|
|
367
|
-
|
|
333
|
+
padding: 0px;
|
|
334
|
+
text-align: center;
|
|
335
|
+
box-sizing: border-box;
|
|
336
|
+
padding-bottom: 6px;
|
|
337
|
+
border-radius: 8rpx;
|
|
338
|
+
transition: all 0.3s ease;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
&.u-dragsort--horizontal {
|
|
343
|
+
.u-dragsort-area {
|
|
344
|
+
display: flex;
|
|
345
|
+
white-space: nowrap;
|
|
346
|
+
height: auto;
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
.u-dragsort-item {
|
|
350
|
+
display: flex;
|
|
351
|
+
width: auto;
|
|
352
|
+
height: 100%;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
&.u-dragsort--all {
|
|
357
|
+
.u-dragsort-area {
|
|
358
|
+
height: auto;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.u-dragsort-item {
|
|
362
|
+
width: auto;
|
|
363
|
+
height: auto;
|
|
368
364
|
}
|
|
369
365
|
}
|
|
370
|
-
}
|
|
371
366
|
}
|
|
372
|
-
</style>
|
|
367
|
+
</style>
|
package/package.json
CHANGED