From 279c1b7dd3273df5b8e60eca6a8866390f6eb4b3 Mon Sep 17 00:00:00 2001 From: srcrs Date: Wed, 2 Aug 2023 00:38:56 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=87=AA=E5=8A=A8=E5=8E=BB?= =?UTF-8?q?=E9=87=8D=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=9C=80=E5=90=8E=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E6=97=B6=E9=97=B4=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 462d506..ce9df4b 100644 --- a/index.html +++ b/index.html @@ -87,6 +87,12 @@ + + lastUpdate: {{ lastUpdateTime }}
+ rss-reader + | + By srcrs +
@@ -100,6 +106,7 @@ data() { return { feeds: [], + lastUpdateTime: '-', }; }, async mounted() { @@ -107,9 +114,34 @@ const socket = new WebSocket(protocol + window.location.host + "/ws"); socket.onmessage = event => { const feed = JSON.parse(event.data); - this.feeds.push(feed); + const existingFeed = this.feeds.find(f => f.link === feed.link); + if (existingFeed) { + Object.assign(existingFeed, feed); + } else { + this.feeds.push(feed); + } + this.getCurrentTime() }; }, + beforeDestroy() { + // 在组件销毁前手动关闭 WebSocket 连接 + this.socket.close(); + }, + methods: { + getCurrentTime() { + const date = new Date() + const year = date.getFullYear() + const month = this.formatTime(date.getMonth() + 1) + const day = this.formatTime(date.getDate()) + const hours = this.formatTime(date.getHours()) + const minutes = this.formatTime(date.getMinutes()) + const seconds = this.formatTime(date.getSeconds()) + this.lastUpdateTime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds}` + }, + formatTime(time) { + return time < 10 ? `0${time}` : time + } + } }); app.use(ElementPlus);