/** * 提示启用通知功能 */ function allowNotice() { if (window.webkitNotifications) { window.webkitNotifications.requestPermission(); }else{ alert('放弃'); } } /** * 桌面通知 * @param {Object} imgURL * @param {Object} audioURL * @param {Object} title * @param {Object} body */ function notify(imgURL, audioURL, title, body) { if (window.webkitNotifications) { if (window.webkitNotifications.checkPermission() == 0) { imgURL = imgURL || '/images/logo.jpg'; audioURL = audioURL || '/images/beep.mp3'; var img = new Image(); img.src = imgURL; var msgWindow = window.webkitNotifications.createNotification(img.src, title, body); new Audio(audioURL).play(); setTimeout(function(){ msgWindow.cancel(); //这里也可以使用cancel方法 }, 10000); msgWindow.show(); } else { window.webkitNotifications.requestPermission(); return; } }else{ if(window.Notification) { if (!(!!window.Notification && window.Notification.permission === "denied")) { imgURL = imgURL || '/images/logo.jpg'; audioURL = audioURL || '/images/beep.mp3'; var img = new Image(); img.src = imgURL; var notify = new Notification( title, { icon : imgURL, //tag : title, body : body }); new Audio(audioURL).play(); //for (var i in notify) document.writeln(i + ' : ' + notify[i]); setTimeout(function(){ notify.close(); }, 10000); notify.onclick = function(event){ //location.href = "/wxbackend/Order/orderList"; //window.open('/wxbackend/Order/orderList'); notify.close(); }; }else{ alert("请启用浏览器的订单通知功能"); } }else{ alert("浏览器不支持订单通知"); } } } /*if(img.complete) { alert('该图片已经存在于缓存之中,不会再去重新下载'); }else{ alert('图片不存在缓存之中'); img.onload = function() { alert('图片下载成功!'); } } var msg = new Audio('/images/beep.mp3'); for(var i in msg) document.write(i + ' : ' + msg[i] + '<br>');*/ /** * 订单提醒 * @param {Object} flag */ function orderNotice(flag, imgURL, audioURL){ url = flag == 1 ? '/wxbackend/order/OrderNotice/flag/1' : '/wxbackend/order/OrderNotice'; $.post(url,function(data){ if(data != ''){ var jsonData = JSON.parse(data); var body = '新订单' + jsonData.new_orders + ' 即将发货的订单' + jsonData.new_orders_ship; notify(imgURL, audioURL,'订单通知',body); /*var ship_order = jsonData.ship_order_id; for (var i = 0; i < ship_order.length; i++) document.getElementById('orderID'+ship_order[i]).setAttribute('class','danger');*/ } }, 'text'); }
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-10-12 20:02:26