更新自动去重,增加最后更新时间展示

This commit is contained in:
srcrs 2023-08-02 00:38:56 +08:00
parent dc9c95942e
commit 279c1b7dd3

View File

@ -87,6 +87,12 @@
</el-col> </el-col>
</el-row> </el-row>
</el-main> </el-main>
<el-footer>
<el-link href="" target="_blank">lastUpdate: {{ lastUpdateTime }}</el-link></br>
<el-link href="https://github.com/srcrs/rss-reader" target="_blank">rss-reader</el-link>
<span> | </span>
<el-link href="https://github.com/srcrs" target="_blank">By srcrs</el-link>
</el-footer>
</el-container> </el-container>
</div> </div>
@ -100,6 +106,7 @@
data() { data() {
return { return {
feeds: [], feeds: [],
lastUpdateTime: '-',
}; };
}, },
async mounted() { async mounted() {
@ -107,9 +114,34 @@
const socket = new WebSocket(protocol + window.location.host + "/ws"); const socket = new WebSocket(protocol + window.location.host + "/ws");
socket.onmessage = event => { socket.onmessage = event => {
const feed = JSON.parse(event.data); const feed = JSON.parse(event.data);
const existingFeed = this.feeds.find(f => f.link === feed.link);
if (existingFeed) {
Object.assign(existingFeed, feed);
} else {
this.feeds.push(feed); 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); app.use(ElementPlus);