1 // 判断手机上
var id=[]
delCookie("message")
if (api.notification){
// 弹出通知栏
api.notification({
notify: {
title: “xx通知”,
content: “你好”
}
},function(ret,err){
// 判断是否有通知
if (getCookie('message')) {
id=JSON.parse(getCookie('message'))
}
if(id.length==0){
id.push({id:ret.id,user_id:data.user_id})
}else{
for (var i in id){
if (data.user_id==id[i].user_id) {
api.cancelNotification({
id: id[i].id
});
// 有的话覆盖
id[i].id=ret.id
break
//判断最后一个元素是否等于当前user_id,没有的话新增
}else if (i==id.length-1&&data.user_id!=id[i].user_id) {
id.push({id:ret.id,user_id:data.user_id})
}
}
addCookie("message",JSON.stringify(id))
// alert(getCookie('message'))
}
});
// 监听通知栏点击
api.addEventListener({
name:'noticeclicked'
},function(ret,err){
router.push({name:"chatxq",query:{user_id:1,to_user_id:2}})
});
}
2.vue删除当前这条数据
shanChu(e,index) {
if ( this.cate[index].id>0) {
this.cate[index].id=-this.cate[index].id
e.target.parentNode.parentNode.style.display="none"
}else if(this.cate[index].id==0){
this.cate.splice(index,1)
}
},
3.新增一条
this.cate.push({
type: this.board1,
club: club1,
certificate_level: this.level1,
coach_id:this.$cookieStore.getCookie("coach_id"),
id:0,
path:this.tu
})
手机监听返回键
var thats=this
if(api.deviceId){
api.addEventListener({
name: 'keyback'
}, function(ret, err) {
thats.$router.go(-1)
})}
双击退出
var first = null;
if(api.deviceId){
api.addEventListener({
name: 'keyback'
}, (res,err)=>{
if (!first) {
first = new Date().getTime();//记录第一次按下回退键的时间
api.toast({
msg : '再点一次退出应用',
duration : 2000,
location : 'bottom'
});
// history.go(-1)//回退到上一页面
setTimeout(function() {//1s中后清除
first = null;
}, 1000);
} else {
if (new Date().getTime() - first < 2000) {//如果两次按下的时间小于1s,
api.closeWidget({
silent : true
});
} }
});
}
4.split
http://192.168.0.14:8981/#/coach_chatxq?user_id=148&to_user_id=162
截取地址栏coach_chatxq
location.href.split("?")[0].split("/")[location.href.split("?")[0].split("/").length-1]
截取user_id里的14
location.href.split("=")[location.href.split("=").length-1]
截取成数字:20181205154936 create_time: "2018-12-05 15:49:36"
this.list[0].create_time.split(" ").join("").split("-").join("").split(":").join("")