diff --git a/src/main/resources/modules/SpringBoot/resources/templates/screen/home.ftl b/src/main/resources/modules/SpringBoot/resources/templates/screen/home.ftl index 29c3c09d..05edbf45 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/screen/home.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/screen/home.ftl @@ -194,6 +194,27 @@ + + + + + 开始推送 + + 停止推送 + + + + var evtSource = new EventSource('http://localhost:8080/sse/1'); + + evtSource.addEventListener('message', function (e) { + + console.log(e.data); + + }); + + + + 普通消息 @@ -1003,6 +1024,23 @@ } }) }, + doPush: function () { + if (window.EventSource) { + window.evtSource = new EventSource('http://localhost:8080/sse/1'); + window.evtSource.addEventListener('message', function (e) { + console.log(e.data); + this.$notify.info({ + title: '消息', + message: "收到一条新的消息:" + e.data + }); + }.bind(this)); + } + }, + doUnPush: function () { + if (typeof window.evtSource !== "undefined") { + window.evtSource.close(); + } + }, handleUpload: function (req) { ajax.fileUpload(req.file).then(function (response) { if (response.errors.length > 0) {
var evtSource = new EventSource('http://localhost:8080/sse/1');
evtSource.addEventListener('message', function (e) {
console.log(e.data);
});