123
This commit is contained in:
parent
6989b87b8d
commit
e4bdf650bb
|
@ -0,0 +1,10 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
// 查询业务消息
|
||||
export function getNoticeListTop3(query) {
|
||||
return request({
|
||||
url: '/system/notice/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
|
@ -58,7 +58,17 @@ import RuoYiGit from '@/components/RuoYi/Git'
|
|||
import RuoYiDoc from '@/components/RuoYi/Doc'
|
||||
import settings from '@/settings'
|
||||
|
||||
import { getNoticeListTop3 } from "@/api/system/businessNotice";
|
||||
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
url: "ws://localhost:3334/websocket/message",
|
||||
message: "",
|
||||
text_content: "",
|
||||
ws: null,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
Breadcrumb,
|
||||
TopNav,
|
||||
|
@ -92,7 +102,87 @@ export default {
|
|||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
/** 消息推送 */
|
||||
this.notice();
|
||||
const wsuri = this.url;
|
||||
this.ws = new WebSocket(wsuri);
|
||||
const self = this;
|
||||
this.ws.onopen = function (event) {
|
||||
//self.text_content = self.text_content + "已经打开连接!" + "\n";
|
||||
};
|
||||
this.ws.onmessage = function (event) {
|
||||
//self.text_content = event.data + "\n";
|
||||
var messageBody = JSON.parse(event.data);
|
||||
Notification.info({
|
||||
title: "通知",
|
||||
dangerouslyUseHTMLString: true,
|
||||
message: messageBody.noticeContent,
|
||||
duration: 0,
|
||||
offset: 40,
|
||||
onClick: function () {
|
||||
//self.warnDetailByWarnid(messageBody.warnId); //自定义回调,message为传的参数
|
||||
// 点击跳转的页面
|
||||
},
|
||||
});
|
||||
};
|
||||
this.ws.onclose = function (event) {
|
||||
//self.text_content = self.text_content + "已经关闭连接!" + "\n";
|
||||
};
|
||||
/** 消息推送 */
|
||||
},
|
||||
methods: {
|
||||
/** 消息推送 */
|
||||
notice() {
|
||||
getNoticeListTop3().then(response => {
|
||||
for (let i = 0; i < response.length; i++) {
|
||||
let messageBody = response[i];
|
||||
setTimeout(() => {
|
||||
this.notificationInfo(messageBody);
|
||||
}, 100);
|
||||
}
|
||||
})
|
||||
},
|
||||
notificationInfo(messageBody) {
|
||||
Notification.info({
|
||||
title: "通知",
|
||||
dangerouslyUseHTMLString: true,
|
||||
message: messageBody.noticeContent,
|
||||
duration: 0,
|
||||
offset: 40,
|
||||
onClick: function () {
|
||||
//self.warnDetailByWarnid(messageBody.warnId); //自定义回调,message为传的参数
|
||||
// 点击跳转的页面
|
||||
},
|
||||
});
|
||||
},
|
||||
// join() {
|
||||
//
|
||||
// },
|
||||
exit() {
|
||||
if (this.ws) {
|
||||
this.ws.close();
|
||||
this.ws = null;
|
||||
}
|
||||
},
|
||||
send() {
|
||||
if (this.ws) {
|
||||
this.ws.send(this.message);
|
||||
} else {
|
||||
alert("未连接到服务器");
|
||||
}
|
||||
},
|
||||
warnDetailByWarnid(warnid) {
|
||||
// 跳转预警详情页面
|
||||
this.$router.push({
|
||||
path: "/XXX/XXX",
|
||||
query: {
|
||||
warnid: warnid,
|
||||
},
|
||||
});
|
||||
},
|
||||
/** 消息推送 */
|
||||
|
||||
toggleSideBar() {
|
||||
this.$store.dispatch('app/toggleSideBar')
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue