优化页面加载与数据展示

This commit is contained in:
srcrs 2023-08-09 02:08:01 +08:00
parent 8af861f1eb
commit 356a66df5e

View File

@ -1,4 +1,3 @@
<!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
@ -33,22 +32,15 @@
} }
.list-item-title { .list-item-title {
display: block; display: flex;
white-space: nowrap; /* white-space: nowrap;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis; */
flex-grow: 1; flex-grow: 1;
text-align: left; text-align: left;
width: 100%; width: 100%;
margin-bottom: 10px; margin-bottom: 10px;
} }
.title-link {
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: left;
}
a { a {
color: black; color: black;
@ -61,6 +53,11 @@
.feed-col { .feed-col {
margin-bottom: 20px; margin-bottom: 20px;
} }
.time {
font-size: 12px;
color: #999;
}
</style> </style>
</head> </head>
<body> <body>
@ -69,7 +66,10 @@
<el-header> <el-header>
<h1>RSS Reader</h1> <h1>RSS Reader</h1>
</el-header> </el-header>
<el-main> <el-main
v-loading.fullscreen.lock="fullscreenLoading"
element-loading-text="拼命加载中"
>
<el-row :gutter="20"> <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-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"> <el-card class="box-card">
@ -79,17 +79,22 @@
<el-scrollbar style="height: 300px;"> <el-scrollbar style="height: 300px;">
<el-list v-for="(item, i) in feed.items" :key="i"> <el-list v-for="(item, i) in feed.items" :key="i">
<el-list-item> <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-item>
</el-list> </el-list>
</el-scrollbar> </el-scrollbar>
<div slot="footer" class="card-footer" style="height: 10px;">
<time class="time">{{ feed.custom.lastupdate }}</time>
</div>
</el-card> </el-card>
</el-col> </el-col>
</el-row> </el-row>
</el-main> </el-main>
<el-footer> <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> <span> | </span>
<el-link href="https://github.com/srcrs" target="_blank">By srcrs</el-link> <el-link href="https://github.com/srcrs" target="_blank">By srcrs</el-link>
</el-footer> </el-footer>
@ -106,45 +111,33 @@
data() { data() {
return { return {
feeds: [], feeds: [],
lastUpdateTime: '-', fullscreenLoading: true,
}; };
}, },
async mounted() { async mounted() {
const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; const protocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://';
const socket = new WebSocket(protocol + window.location.host + "/ws"); const connect = () => {
socket.onmessage = event => { const socket = new WebSocket(protocol + window.location.host + "/ws");
if (event.data === 'heartbeat') { socket.onmessage = event => {
// 心跳消息,忽略处理 const feed = JSON.parse(event.data);
return; const existingFeed = this.feeds.find(f => f.link === feed.link);
} if (existingFeed) {
const feed = JSON.parse(event.data); Object.assign(existingFeed, feed);
const existingFeed = this.feeds.find(f => f.link === feed.link); } else {
if (existingFeed) { this.feeds.push(feed);
Object.assign(existingFeed, feed); }
} else { this.fullscreenLoading = false;
this.feeds.push(feed); };
} socket.onclose = event => {
this.getCurrentTime() console.log("WebSocket closed. Reconnecting...");
setTimeout(connect, 60000);
};
}; };
connect();
}, },
beforeDestroy() { beforeDestroy() {
// 在组件销毁前手动关闭 WebSocket 连接 // 在组件销毁前手动关闭 WebSocket 连接
this.socket.close(); 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
}
} }
}); });