微信小程序实现长按触发某一事件
约 249 字
预计阅读 1 分钟
次阅读
1 实现代码
1.1 message/message.js
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
|
/**
* 消息长按部分代码
*/
//touch start
handleTouchStart: function (e) {
this.startTime = e.timeStamp;
},
//touch end
handleTouchEnd: function (e) {
this.endTime = e.timeStamp;
},
handleLongPress: function (e) {
var that = this;
var id = e.currentTarget.dataset.id;
wx.showModal({
title: '提示',
content: '是否删除这条消息?',
success: function (res) {
if (res.confirm) {
wx.request({
url: app.buildUrl("/message/delMess"),
header: app.getRequestHeader(),
data: {
id: id,
},
success: function (res) {
if (res.data.code == 200) {
that.onLoad();
app.showSuccess("消息删除成功!");
}else{
app.showFail("消息删除失败!");
}
}
})
}
}
})
},
|
1.2 message/message.wxml
1
2
3
|
<view class="message-right-text-box" bindtouchstart="handleTouchStart" bindtouchend="handleTouchEnd" bindlongpress="handleLongPress" data-id="{{item.id}}">
<text class="message-right-text">{{item.message}}</text>
</view>
|
2 效果展示