diff --git a/src/main/resources/modules/SpringBoot/resources/templates/layout/index.ftl b/src/main/resources/modules/SpringBoot/resources/templates/layout/index.ftl index 8368675f..041da5e4 100644 --- a/src/main/resources/modules/SpringBoot/resources/templates/layout/index.ftl +++ b/src/main/resources/modules/SpringBoot/resources/templates/layout/index.ftl @@ -1,7 +1,8 @@ - + 首页 + 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 85fcc1a4..60dd3df8 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) {