File tree Expand file tree Collapse file tree
components/uni-swipe-action Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
5256 this .startY = 0
5357 this .btnGroupWidth = 0
5458 this .isMoving = false
59+ this .startTime = 0
5560 },
5661 // #ifdef H5
5762 mounted () {
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 },
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 () {
Original file line number Diff line number Diff line change 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" ,
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" ,
670667 ]
671668 },
672669 {
673- "root" : " pages/template/ " ,
670+ "root" : " pages/template" ,
674671 "pages" : [{
675672 "path" : " product-list/product-list" ,
676673 "style" : {
932929 {
933930 "path" : " tabbar-native/tabbar-native" ,
934931 "style" : {
935- "navigationBarTitleText" :" 可拖动顶部选项卡(原生)"
932+ "navigationBarTitleText" : " 可拖动顶部选项卡(原生)"
936933 }
937934 },
938935 // #endif
Original file line number Diff line number Diff line change 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 >
You can’t perform that action at this time.
0 commit comments