|
@@ -13,25 +13,27 @@
|
|
|
dataForm: {}
|
|
|
}
|
|
|
},
|
|
|
- mounted () {
|
|
|
- const that = this
|
|
|
- const h = this.$createElement
|
|
|
- this.$nextTick(() => {
|
|
|
- this.$store.state.websocket.webSocket.onmessage = async function (event) {
|
|
|
- if (!event || !event.data) {
|
|
|
- return
|
|
|
- }
|
|
|
- let json = JSON.parse(event.data)
|
|
|
- console.log('json = ' + JSON.stringify(json))
|
|
|
- if (json) {
|
|
|
- that.$emit('noticeAdded', json.length)
|
|
|
+ computed: {
|
|
|
+ listenWebsocket () {
|
|
|
+ return this.$store.state.websocket.message
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ listenWebsocket: function (data) {
|
|
|
+ if (!data || data.indexOf('[') !== 0) {
|
|
|
+ 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) => {
|
|
|
- that.$notify({
|
|
|
+ this.$notify({
|
|
|
title: item.title,
|
|
|
- // dangerouslyUseHTMLString: true,
|
|
|
- // message: h('i', {style: 'color: teal'}, item.content),
|
|
|
message: h('div', {}, [
|
|
|
- h('p', {}, '消息类别:' + that.getMsgType(item.type)),
|
|
|
+ h('p', {}, '消息类别:' + this.getMsgType(item.type)),
|
|
|
h('p', {}, '消息内容:' + item.content)
|
|
|
]),
|
|
|
duration: 0
|
|
@@ -39,8 +41,60 @@
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
+ // 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 () {
|
|
|
+ // const that = this
|
|
|
+ // const h = this.$createElement
|
|
|
+ // this.$nextTick(() => {
|
|
|
+ // this.$store.state.websocket.webSocket.onmessage = async function (event) {
|
|
|
+ // if (!event || !event.data) {
|
|
|
+ // return
|
|
|
+ // }
|
|
|
+ // let json = JSON.parse(event.data)
|
|
|
+ // console.log('json = ' + JSON.stringify(json))
|
|
|
+ // if (json) {
|
|
|
+ // that.$emit('noticeAdded', json.length)
|
|
|
+ // json.forEach((item) => {
|
|
|
+ // that.$notify({
|
|
|
+ // title: item.title,
|
|
|
+ // // dangerouslyUseHTMLString: true,
|
|
|
+ // // message: h('i', {style: 'color: teal'}, item.content),
|
|
|
+ // message: h('div', {}, [
|
|
|
+ // h('p', {}, '消息类别:' + that.getMsgType(item.type)),
|
|
|
+ // h('p', {}, '消息内容:' + item.content)
|
|
|
+ // ]),
|
|
|
+ // duration: 0
|
|
|
+ // })
|
|
|
+ // })
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // })
|
|
|
+ // },
|
|
|
methods: {
|
|
|
getMsgType (type) {
|
|
|
if (!type) return '未知消息类型'
|