pwa notification

孤街浪徒 提交于 2019-12-02 08:05:05

randomNotification(res) {
let that = this;
let games = {
name:res.companyName,
author:res.status.log,
time:res.receiveTime,
slug:’/assets/images/logo.png’
};
let notifTitle = games.name + ’ ’ + games.time;
let notifBody = games.author+’.’;
let notifImg = games.slug;
let options = {
body: notifBody,
icon: notifImg
}
let notif = new Notification(notifTitle, options);
notif.onclick = function(e){
e.preventDefault();
that.showCompanyDetail(res.companyCode)
}
},

toRandomNotification(){
let rtnData = []//根据上一个方法的games需求的字段随便设置点
let storageErrorData = [];
for(let i in rtnData){
if(rtnData[i].status.value*1 >= 8){
if(util.getStorage(‘storageErrorData’)){
console.log(‘有storage’)
let getedData = util.getStorage(‘storageErrorData’)
if(!getedData.find(item => {return item.companyCode == rtnData[i].companyCode})){
storageErrorData.push(rtnData[i])
if (window.Notification) {
Notification.requestPermission(function (status) {
if(status === “granted”) {
that.randomNotification(rtnData[i]);
}
});
} else {
console.log(‘浏览器不支持notification’)
}
}
}else{
console.log(‘无storage’)
storageErrorData.push(rtnData[i])
if (window.Notification) {
Notification.requestPermission(function (status) {
if(status === “granted”) {
that.randomNotification(rtnData[i]);
}
});
} else {
console.log(‘浏览器不支持notification’)
}
}
}
}
util.setStorage(‘storageErrorData’,storageErrorData)
}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!