市北人才赋能平台 --小程序端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

85 lines
2.2 KiB

// pages/topics/common/interactive/common/imageCell/index.js
Component({
/**
* 组件的属性列表
*/
properties: {
topicId: String,
title: String,
topicImg: String,
userIcon: String,
userName: String,
time: String,
commentNum: Number,
type:String,
dataIndex: Number,
isTouchMove: Boolean,
},
/**
* 组件的初始数据
*/
data: {
startX: 0, //开始坐标
startY: 0
},
/**
* 组件的方法列表
*/
methods: {
onTap() {
let item = {
topicId: this.properties.topicId,
title: this.properties.title,
topicImg: this.properties.topicImg,
userIcon: this.properties.userIcon,
userName: this.properties.userName,
time: this.properties.time,
commentNum: this.properties.commentNum,
type: this.properties.type
}
this.triggerEvent('clickListItem', { item: item })
},
touchstart: function (e) {
//开始触摸时 重置所有删除
if (this.properties.isTouchMove) {
this.setData({
isTouchMove: false
})
}
this.setData({
startX: e.changedTouches[0].clientX,
startY: e.changedTouches[0].clientY,
})
},
touchmove: function (e) {
var that = this
// index = e.currentTarget.dataset.index,//当前索引
const startX = that.data.startX//开始X坐标
const startY = that.data.startY//开始Y坐标
const touchMoveX = e.changedTouches[0].clientX//滑动变化坐标
const touchMoveY = e.changedTouches[0].clientY//滑动变化坐标
//获取滑动角度
const angle = that.angle({ X: startX, Y: startY }, { X: touchMoveX, Y: touchMoveY })
if (Math.abs(angle) > 30) return;
if (touchMoveX > startX) //右滑
that.setData({
isTouchMove: false
})
else //左滑
that.setData({
isTouchMove: true
})
},
angle: function (start, end) {
var _X = end.X - start.X,
_Y = end.Y - start.Y
//返回角度 /Math.atan()返回数字的反正切值
return 360 * Math.atan(_Y / _X) / (2 * Math.PI);
},
del: function (e) {
this.triggerEvent('deleteListItem', { id: e.currentTarget.dataset.id })
}
}
})