push通知栏

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删除当前这条数据

<div v-for="(c,index) in cate ">

<div>

<i @click="shanChu($event,index)"><img src="../../../../images/icon_shanchu@2x.png" alt=""></i>

</div>

</div>

 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("")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值