|
@@ -24,12 +24,13 @@
|
|
|
return
|
|
|
}
|
|
|
const h = this.$createElement
|
|
|
- let json = JSON.parse(data)
|
|
|
- console.log('json = ' + JSON.stringify(json))
|
|
|
- if (json) {
|
|
|
- this.$emit('noticeAdded', json.length)
|
|
|
- if (json.length <= 5) {
|
|
|
- json.forEach((item) => {
|
|
|
+ let newMsgCollections = JSON.parse(data)
|
|
|
+ console.log('newMsgCollections = ' + JSON.stringify(newMsgCollections))
|
|
|
+ if (newMsgCollections) {
|
|
|
+ this.updateMsgCollections(newMsgCollections)
|
|
|
+ this.$emit('noticeAdded', this.$store.state.common.msgCollection.length)
|
|
|
+ if (newMsgCollections.length <= 5) {
|
|
|
+ newMsgCollections.forEach((item) => {
|
|
|
this.$notify({
|
|
|
title: item.title,
|
|
|
message: h('div', {}, [
|
|
@@ -41,30 +42,32 @@
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- // const newmsg = JSON.parse(newstr)
|
|
|
- // if (newstr && newstr.indexOf('[') === -1) {
|
|
|
- // // 收到信消息
|
|
|
- // this.$notification.open({
|
|
|
- // message: newmsg.objName,
|
|
|
- // description: newmsg.title
|
|
|
- // })
|
|
|
- // // 刷新消息
|
|
|
- // this.$store.dispatch('websocket/WEBSOCKET_SEND', 'refreshMessage')
|
|
|
- // } else {
|
|
|
- // this.noticeData = []
|
|
|
- // this.messageData = []
|
|
|
- // this.msgCount = newmsg.length
|
|
|
- // for (var i = 0; i < newmsg.length; i++) {
|
|
|
- // var m = newmsg[i]
|
|
|
- // m.createDate = m.objName + ' · ' + this.nowTimeAgo(m.createDate)
|
|
|
- // if (m.messageType.indexOf('Notice') !== -1) {
|
|
|
- // this.noticeData.push(m)
|
|
|
- // }
|
|
|
- // if (m.messageType.indexOf('Message') !== -1) {
|
|
|
- // this.messageData.push(m)
|
|
|
- // }
|
|
|
- // }
|
|
|
+ // 刷新消息
|
|
|
+ this.$store.dispatch('websocket/WEBSOCKET_SEND', 'refreshMessage')
|
|
|
+ // const newmsg = JSON.parse(newstr)
|
|
|
+ // if (newstr && newstr.indexOf('[') === -1) {
|
|
|
+ // // 收到信消息
|
|
|
+ // this.$notification.open({
|
|
|
+ // message: newmsg.objName,
|
|
|
+ // description: newmsg.title
|
|
|
+ // })
|
|
|
+ // // 刷新消息
|
|
|
+ // this.$store.dispatch('websocket/WEBSOCKET_SEND', 'refreshMessage')
|
|
|
+ // } else {
|
|
|
+ // this.noticeData = []
|
|
|
+ // this.messageData = []
|
|
|
+ // this.msgCount = newmsg.length
|
|
|
+ // for (var i = 0; i < newmsg.length; i++) {
|
|
|
+ // var m = newmsg[i]
|
|
|
+ // m.createDate = m.objName + ' · ' + this.nowTimeAgo(m.createDate)
|
|
|
+ // if (m.messageType.indexOf('Notice') !== -1) {
|
|
|
+ // this.noticeData.push(m)
|
|
|
+ // }
|
|
|
+ // if (m.messageType.indexOf('Message') !== -1) {
|
|
|
+ // this.messageData.push(m)
|
|
|
+ // }
|
|
|
// }
|
|
|
+ // }
|
|
|
}
|
|
|
},
|
|
|
// mounted () {
|
|
@@ -105,6 +108,16 @@
|
|
|
} else {
|
|
|
return '未知消息类型'
|
|
|
}
|
|
|
+ },
|
|
|
+ // 更新通知列表
|
|
|
+ updateMsgCollections (newCollections) {
|
|
|
+ if (!newCollections || newCollections.length === 0) return
|
|
|
+ newCollections.forEach((item) => {
|
|
|
+ // 判断是否包含当前通知
|
|
|
+ if (this.$store.state.common.msgCollection.findIndex(item1 => item1.noticeId === item.noticeId) === -1) {
|
|
|
+ this.$store.state.common.msgCollection.push(item)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
}
|