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);