Skip to content

Commit a8b7798

Browse files
committed
swipe-action添加跟手配置;蓝牙示例修改标题不对的问题
1 parent 005962c commit a8b7798

3 files changed

Lines changed: 57 additions & 18 deletions

File tree

‎components/uni-swipe-action/uni-swipe-action.vue‎

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
export default {
1919
name: 'uni-swipe-action',
2020
props: {
21+
isDrag: {
22+
type: Boolean,
23+
default: false
24+
},
2125
isOpened: {
2226
type: Boolean,
2327
default: false
@@ -52,6 +56,7 @@
5256
this.startY = 0
5357
this.btnGroupWidth = 0
5458
this.isMoving = false
59+
this.startTime = 0
5560
},
5661
// #ifdef H5
5762
mounted() {
@@ -87,6 +92,7 @@
8792
}
8893
},
8994
touchStart(event) {
95+
this.startTime = event.timeStamp;
9096
this.startX = event.touches[0].pageX;
9197
this.startY = event.touches[0].pageY;
9298
},
@@ -102,18 +108,50 @@
102108
}
103109
this.direction = moveX > 0 ? 'right' : 'left';
104110
this.isMoving = true;
111+
if (this.isDrag) {
112+
let movedLength = this.isShowBtn ? -this.btnGroupWidth : 0;
113+
if (movedLength + moveX >= 0) {
114+
this.transformX = `translateX(0px)`;
115+
return;
116+
}
117+
if (-movedLength - moveX >= this.btnGroupWidth) {
118+
this.transformX = `translateX(${-this.btnGroupWidth}px)`;
119+
return;
120+
}
121+
if (movedLength - moveX > 0) {
122+
this.transformX = `translateX(${moveX}px)`;
123+
} else {
124+
if (moveX >= -this.btnGroupWidth) {
125+
this.transformX = `translateX(${moveX - this.btnGroupWidth}px)`;
126+
}
127+
}
128+
}
105129
},
106130
touchEnd(event) {
107131
this.isMoving = false;
108132
if (this.direction !== 'right' && this.direction !== 'left') {
109133
this.direction = '';
110134
return;
111135
}
112-
if (this.direction == 'right') {
113-
this.isShowBtn = false
136+
if (this.isDrag) {
137+
let movedLength = Math.abs(Number(this.transformX.slice(11, -3)));
138+
let movedTime = event.timeStamp - this.startTime;
139+
this.isShowBtn = movedLength >= this.btnGroupWidth / 2 ? true : false;
140+
if (50 < movedTime && movedTime < 300 && movedLength > 20) { //在这个时间里面,且滑动了一定的距离
141+
if (this.direction == 'right') {
142+
this.isShowBtn = false
143+
} else {
144+
this.isShowBtn = true
145+
}
146+
}
114147
} else {
115-
this.isShowBtn = true
148+
if (this.direction == 'right') {
149+
this.isShowBtn = false
150+
} else {
151+
this.isShowBtn = true
152+
}
116153
}
154+
117155
this.endMove()
118156
},
119157
endMove() {

‎pages.json‎

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -535,18 +535,15 @@
535535
}
536536
},
537537
// #ifdef APP-PLUS || MP-WEIXIN
538-
{
539-
"path" : "pages/API/bluetooth/bluetooth",
540-
"style" : {
541-
"style": {
542-
"navigationBarTitleText": "蓝牙"
543-
}
544-
}
545-
}
546-
// #endif
547-
],
538+
{
539+
"path": "pages/API/bluetooth/bluetooth",
540+
"style": {
541+
"navigationBarTitleText": "蓝牙"
542+
}
543+
}
544+
// #endif
545+
],
548546
"subPackages": [{
549-
550547
"root": "pages/extUI",
551548
"pages": [{
552549
"path": "badge/badge",
@@ -656,10 +653,10 @@
656653
"path": "swipe-action/swipe-action",
657654
"style": {
658655
"navigationBarTitleText": "SwipeAction 滑动操作",
656+
"disableScroll": true,
659657
"app-plus": {
660658
"bounce": "none"
661-
},
662-
"disableScroll": true
659+
}
663660
}
664661
}, {
665662
"path": "calendar/calendar",
@@ -670,7 +667,7 @@
670667
]
671668
},
672669
{
673-
"root": "pages/template/",
670+
"root": "pages/template",
674671
"pages": [{
675672
"path": "product-list/product-list",
676673
"style": {
@@ -932,7 +929,7 @@
932929
{
933930
"path": "tabbar-native/tabbar-native",
934931
"style": {
935-
"navigationBarTitleText":"可拖动顶部选项卡(原生)"
932+
"navigationBarTitleText": "可拖动顶部选项卡(原生)"
936933
}
937934
},
938935
// #endif

‎pages/extUI/swipe-action/swipe-action.vue‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
<uni-swipe-action :disabled="true">
99
<view class='cont'>SwipeAction 禁止滑动展示</view>
1010
</uni-swipe-action>
11+
<view class="example-title">跟手滑动</view>
12+
<uni-swipe-action :is-drag="true" :options="options2" @click="bindClick">
13+
<view class='cont'>SwipeAction 跟手滑动</view>
14+
</uni-swipe-action>
1115
<view class="example-title">使用变量控制开关</view>
1216
<view class="button-view">
1317
<view class="button" @click="setOpened">当前状态:{{isOpened ? '开' : '关'}}</view>

0 commit comments

Comments
 (0)