From 58ee8c6a7dc1d5d7f60488fc89a68489a910dd83 Mon Sep 17 00:00:00 2001
From: lxf <1371462558@qq.com>
Date: Wed, 16 Jul 2025 18:00:46 +0800
Subject: [PATCH] 添加新闻静默加载
---
src/views/news/index.vue | 63 ++++++++++++++++++++++---------
1 files changed, 45 insertions(+), 18 deletions(-)
diff --git a/src/views/news/index.vue b/src/views/news/index.vue
index db4c777..5f027c6 100644
--- a/src/views/news/index.vue
+++ b/src/views/news/index.vue
@@ -180,10 +180,38 @@
}
const getInformationList = () => {
+ const cachedNews = localStorage.getItem('cachedNews');
+ if (cachedNews) {
+ list.value = JSON.parse(cachedNews);
+ infoLoading.value = false;
+ return;
+ }
_getInformationList().then(data => {
- list.value = data
- infoLoading.value = false
+ updateNewsData(data);
+ infoLoading.value = false;
})
+}
+
+const updateNewsData = (newData) => {
+ const cachedNews = localStorage.getItem('cachedNews');
+ if (cachedNews) {
+ try {
+ const oldData = JSON.parse(cachedNews);
+ // 比较新旧数据是否不同
+ if (JSON.stringify(oldData) !== JSON.stringify(newData)) {
+ list.value = newData;
+ localStorage.setItem('cachedNews', JSON.stringify(newData));
+ }
+ } catch (e) {
+ // 处理JSON解析错误
+ localStorage.removeItem('cachedNews');
+ list.value = newData;
+ localStorage.setItem('cachedNews', JSON.stringify(newData));
+ }
+ } else {
+ list.value = newData;
+ localStorage.setItem('cachedNews', JSON.stringify(newData));
+ }
}
@@ -219,24 +247,23 @@
})
}
+onMounted(() => {
+ // 初始加载新闻数据
+ getInformationList();
-// 添加跳转方法
-const openOriginUrl = (url) => {
- window.open(url, '_blank')
-}
+ // 设置静默更新定时器,每5分钟检查一次
+ const newsUpdateInterval = setInterval(() => {
+ _getInformationList().then(newData => {
+ updateNewsData(newData);
+ }).catch(error => {
+ console.error('Silent update failed:', error);
+ });
+ }, 5 * 60 * 1000); // 5分钟间隔
-const copyInviteLink = () => {
- const inviteLink = 'https://www.thinkmarketga.com/#/pages/register?c=' + usercode.value // 邀请链接
- navigator.clipboard.writeText(inviteLink)
- .then(() => {
- // 可以添加提示,比如使用Toast组件
- showToast({
- message: '邀请链接已复制',
- position: 'bottom',
- })
- })
-}
-
+ onUnmounted(() => {
+ clearInterval(newsUpdateInterval);
+ });
+});
</script>
<style lang="scss" scoped>
@import '@/assets/css/deepseek_css_20250625_30ff932.css';
--
Gitblit v1.9.3