优化页面加载与数据展示
This commit is contained in:
parent
8af861f1eb
commit
356a66df5e
83
index.html
83
index.html
@ -1,4 +1,3 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
@ -33,22 +32,15 @@
|
||||
}
|
||||
|
||||
.list-item-title {
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
display: flex;
|
||||
/* white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-overflow: ellipsis; */
|
||||
flex-grow: 1;
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.title-link {
|
||||
display: block;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
a {
|
||||
color: black;
|
||||
@ -61,6 +53,11 @@
|
||||
.feed-col {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.time {
|
||||
font-size: 12px;
|
||||
color: #999;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@ -69,7 +66,10 @@
|
||||
<el-header>
|
||||
<h1>RSS Reader</h1>
|
||||
</el-header>
|
||||
<el-main>
|
||||
<el-main
|
||||
v-loading.fullscreen.lock="fullscreenLoading"
|
||||
element-loading-text="拼命加载中"
|
||||
>
|
||||
<el-row :gutter="20">
|
||||
<el-col :xs="24" :sm="12" :md="8" :lg="6" v-for="(feed, index) in feeds" :key="index" class="feed-col">
|
||||
<el-card class="box-card">
|
||||
@ -79,17 +79,22 @@
|
||||
<el-scrollbar style="height: 300px;">
|
||||
<el-list v-for="(item, i) in feed.items" :key="i">
|
||||
<el-list-item>
|
||||
<el-link class="list-item-title" :href="item.link" target="_blank" :title="item.title">{{ item.title }}</el-link>
|
||||
<div class="list-item-title">
|
||||
<span>{{ i+1 }}. </span>
|
||||
<el-link :href="item.link" target="_blank" :title="item.title">{{ item.title }}</el-link>
|
||||
</div>
|
||||
</el-list-item>
|
||||
</el-list>
|
||||
</el-scrollbar>
|
||||
<div slot="footer" class="card-footer" style="height: 10px;">
|
||||
<time class="time">{{ feed.custom.lastupdate }}</time>
|
||||
</div>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</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>
|
||||
<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>
|
||||
@ -106,45 +111,33 @@
|
||||
data() {
|
||||
return {
|
||||
feeds: [],
|
||||
lastUpdateTime: '-',
|
||||
fullscreenLoading: true,
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
|
||||
const socket = new WebSocket(protocol + window.location.host + "/ws");
|
||||
socket.onmessage = event => {
|
||||
if (event.data === 'heartbeat') {
|
||||
// 心跳消息,忽略处理
|
||||
return;
|
||||
}
|
||||
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.getCurrentTime()
|
||||
const connect = () => {
|
||||
const socket = new WebSocket(protocol + window.location.host + "/ws");
|
||||
socket.onmessage = event => {
|
||||
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.fullscreenLoading = false;
|
||||
};
|
||||
socket.onclose = event => {
|
||||
console.log("WebSocket closed. Reconnecting...");
|
||||
setTimeout(connect, 60000);
|
||||
};
|
||||
};
|
||||
connect();
|
||||
},
|
||||
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
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user