This commit is contained in:
xd 2024-04-23 23:10:20 +08:00
parent 6989b87b8d
commit e4bdf650bb
2 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1,10 @@
import request from '@/utils/request'
// 查询业务消息
export function getNoticeListTop3(query) {
return request({
url: '/system/notice/list',
method: 'get',
params: query
})
}

View File

@ -58,7 +58,17 @@ import RuoYiGit from '@/components/RuoYi/Git'
import RuoYiDoc from '@/components/RuoYi/Doc' import RuoYiDoc from '@/components/RuoYi/Doc'
import settings from '@/settings' import settings from '@/settings'
import { getNoticeListTop3 } from "@/api/system/businessNotice";
export default { export default {
data() {
return {
url: "ws://localhost:3334/websocket/message",
message: "",
text_content: "",
ws: null,
};
},
components: { components: {
Breadcrumb, Breadcrumb,
TopNav, 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: { 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() { toggleSideBar() {
this.$store.dispatch('app/toggleSideBar') this.$store.dispatch('app/toggleSideBar')
}, },