From a91300a833d6c7b1d40b429cccbe26a28ff0f669 Mon Sep 17 00:00:00 2001 From: wangbing Date: Thu, 17 Oct 2019 16:51:00 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=97=A5=E6=9C=9F=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/templates/screen/home.ftl | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) 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) {