Files
ClassContent/项目合集/菜谱App/fontend/js/page/likeinfo.js
2024-09-27 02:06:13 +08:00

83 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

class LikeInfo {
constructor() {
this.ListData = JSON.parse(localStorage.getItem("like"))
this.actionsheet = new auiActionsheet();
this.renderList()
this.deleat()
// this.deleatli()
}
renderList() {
this.ListData.forEach((v, ix) => {
$(".content ul").append(`
<li>
<a href="./info.html?url=${v.url}">
<img src="${v.img}" alt="">
</a>
<p>${v.title}</p>
</li>
`)
});
}
// deleatli(){
// var sss = this;
// $(".content ul li").each(function(i,v){
// console.log(sss.ListData.splice($(this).i, 1));
// })
// // localStorage.setItem("like", JSON.stringify(sss.ListData))
// // $.remove()
// }
deleat() {
var self = this;
var longClick = 0,
timeOutEvent;
$(".content ul li").on({
touchstart: function (e) {
longClick = 0;//设置初始为0
timeOutEvent = setTimeout(function () {
//此处为长按事件-----在此显示遮罩层及删除按钮
// longClick = 1;//假如长按则设置为1
// $(".shadow").css("display", "block")
self.openActionsheet()
e.preventDefault();
}, 300);
},
touchmove: function () {
clearTimeout(timeOutEvent);
timeOutEvent = 0;
e.preventDefault();
},
});
$(".cancel").on("click", function () {
$(".shadow").css("display", "none")
})
}
openActionsheet(){
var ss =this
this.actionsheet.init({
frameBounces:true,//当前页面是否弹动,(主要针对安卓端)
destructiveTitle:'删除',
buttons:['取消']
},function(ret){
if(ret){
if (ret.buttonIndex == 2) {
// ss.deleatli()
ss.ListData.splice($(this).attr("data-index"), 1)
localStorage.setItem("like", JSON.stringify(ss.ListData))
$(this).attr("data-index").remove()
}
}
})
}
}
new LikeInfo()