|
@@ -8,7 +8,7 @@
|
|
|
|
|
|
var getMsgBuoyActive = {
|
|
|
// 版本号
|
|
|
- version: '0.0.1',
|
|
|
+ version: '0.0.2',
|
|
|
platform: '', // work_bench、wx、app、pc
|
|
|
msgids: '',
|
|
|
floatDOM: '',
|
|
@@ -23,6 +23,7 @@ var getMsgBuoyActive = {
|
|
|
this.getBuoyMsgAjax()
|
|
|
}
|
|
|
} else {
|
|
|
+ this.listenNotification()
|
|
|
this.getBuoyMsgAjax()
|
|
|
}
|
|
|
},
|
|
@@ -384,8 +385,79 @@ var getMsgBuoyActive = {
|
|
|
} else if (isAndroid) {
|
|
|
return 'Android'
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * @date 2023/1/4 消息通知改为 webscoket 获取并调用浏览器消息通知
|
|
|
+ */
|
|
|
+ listenNotification () {
|
|
|
+ /**
|
|
|
+ * 进行浏览器通知,判断上次通知是否与当前一致,一致则不进行重复通知
|
|
|
+ * @param datas - 信息数据
|
|
|
+ */
|
|
|
+ function sendNotification (datas) {
|
|
|
+ var waitShowMessageId = localStorage.getItem('notification-login-clear-info') || -1
|
|
|
+ if (waitShowMessageId === datas.id) {
|
|
|
+ return console.warn('重复消息ID,不进行重复通知')
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Notification.requestPermission(function(status) {
|
|
|
+ if(status === 'granted'){
|
|
|
+ localStorage.setItem('notification-login-clear-info', datas.id)
|
|
|
+ var notify = new Notification(datas.title,{
|
|
|
+ icon: '/images/t3_new.jpg',
|
|
|
+ body: datas.show_content || datas.content || ''
|
|
|
+ })
|
|
|
+ // 点击时桌面消息时触发
|
|
|
+ notify.onclick = function () {
|
|
|
+ try {
|
|
|
+ getMsgBuoyActive.istoReaded(datas.id)
|
|
|
+ notify.close()
|
|
|
+ switch (getMsgBuoyActive.platformOS()) {
|
|
|
+ case 'pc':
|
|
|
+ location.href = '/swordfish/frontPage/messageCenter/sess/index'
|
|
|
+ break;
|
|
|
+ case 'work_bench':
|
|
|
+ window.open('/swordfish/frontPage/messageCenter/sess/index')
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.warn(e)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Notification.requestPermission()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ } catch (e) {
|
|
|
+ console.warn('不支持通知')
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ // 定义 scoket 信息
|
|
|
+ var pushMessageScoket = {
|
|
|
+ url: "ws"+(!isIE9&&"https:"==document.location.protocol?"s":"")+"://"+window.location.host,
|
|
|
+ init: function () {
|
|
|
+ if (typeof CommonWebScoket === 'function') {
|
|
|
+ this._scoket = new CommonWebScoket(this.url + '/webscoket/getBuoyMsg', '', {
|
|
|
+ ajaxReq: function() {},
|
|
|
+ complete: function (data, type) {
|
|
|
+ try {
|
|
|
+ var pushMessage = JSON.parse(data)
|
|
|
+ if (pushMessage.id) {
|
|
|
+ sendNotification(pushMessage)
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ console.warn(e)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }).init()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 初始化
|
|
|
+ pushMessageScoket.init()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 初始化
|