59 lines
2.1 KiB
JavaScript
59 lines
2.1 KiB
JavaScript
export const notifyNotice = () => {
|
|
var notifyInterval;
|
|
console.log(window.Notification.permission);
|
|
if (window.Notification) {
|
|
$.ajax({
|
|
url: "/admin/dynamic/verify/notifySwitch",
|
|
success: function (json) {
|
|
if (json == 'true') {
|
|
notifyInterval = setInterval(notify, 50000);
|
|
console.log('notifyInterval : ' + notifyInterval);
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
alert('浏览器不支持Notification');
|
|
}
|
|
|
|
function notify() {
|
|
$.ajax({
|
|
url: "/admin/dynamic/verify/notify",
|
|
success: function (json) {
|
|
if (json != null && json != "" && json != undefined && json != 'undefined') {
|
|
var dynamicCount = json.dynamic;
|
|
var voiceCount = json.voice;
|
|
if ((dynamicCount != null && dynamicCount > 0) || (voiceCount != null && voiceCount > 0)) {
|
|
if (Notification.permission == "granted") {
|
|
popNotice(dynamicCount, voiceCount);
|
|
} else if (Notification.permission != "denied") {
|
|
Notification.requestPermission(function (permission) {
|
|
console.log(permission);
|
|
popNotice(dynamicCount, voiceCount);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
function popNotice(dynamic, voice) {
|
|
if (Notification.permission == "granted") {
|
|
var bodyStr = '您有';
|
|
if (dynamic) {
|
|
bodyStr += '【' + dynamic + '】条待审核动态';
|
|
}
|
|
if (voice) {
|
|
bodyStr += '【' + voice + '】条待审核声音瓶子';
|
|
}
|
|
var notification = new Notification("【66后台】系统推送", {
|
|
body: bodyStr,
|
|
type: 'info',
|
|
offset: 100,
|
|
});
|
|
notification.onclick = function () {
|
|
notification.close();
|
|
};
|
|
}
|
|
}
|
|
} |